def get_basemap_axis(extent, geodata=None, ax=None, map_kwargs=None):
    """
    Safely get a basemap axis. If ax is None, the current axis is returned.

    If geodata is not None and ax is not a cartopy axis already, it creates a basemap
    axis and return it.

    Parameters
    ----------
    extent: tuple
        Four-element tuple specifying the extent of the domain according to
        (lower left x, upper right x, lower left y, upper right y).
    geodata:
        geodata: dictionary or None
        Optional dictionary containing geographical information about
        the field.

        If geodata is not None, it must contain the following key-value pairs:

        .. tabularcolumns:: |p{1.5cm}|L|

        +----------------+----------------------------------------------------+
        |        Key     |                  Value                             |
        +================+====================================================+
        |   projection   | PROJ.4-compatible projection definition            |
        +----------------+----------------------------------------------------+
        |    x1          | x-coordinate of the lower-left corner of the data  |
        |                | raster                                             |
        +----------------+----------------------------------------------------+
        |    y1          | y-coordinate of the lower-left corner of the data  |
        |                | raster                                             |
        +----------------+----------------------------------------------------+
        |    x2          | x-coordinate of the upper-right corner of the data |
        |                | raster                                             |
        +----------------+----------------------------------------------------+
        |    y2          | y-coordinate of the upper-right corner of the data |
        |                | raster                                             |
        +----------------+----------------------------------------------------+
        |    yorigin     | a string specifying the location of the first      |
        |                | element in the data raster w.r.t. y-axis:          |
        |                | 'upper' = upper border, 'lower' = lower border     |
        +----------------+----------------------------------------------------+

    ax: axis object
        Optional axis object to use for plotting.
    map_kwargs: dict
        Optional parameters that need to be passed to
        :py:func:`pysteps.visualization.basemaps.plot_geography`.

    Returns
    -------
    ax: axis object
    """
    if map_kwargs is None:
        map_kwargs = dict()

    if ax is None:
        # If no axes is passed, use the current axis.
        ax = plt.gca()

    # Create the cartopy axis if the axis is not a cartopy axis.
    if geodata is not None:
        if not CARTOPY_IMPORTED:
            warnings.warn(
                "cartopy package is required for the get_geogrid function "
                "but it is not installed. Ignoring geographical information."
            )
            return ax

        if not PYPROJ_IMPORTED:
            warnings.warn(
                "pyproj package is required for the get_geogrid function "
                "but it is not installed. Ignoring geographical information."
            )
            return ax

        if not isinstance(ax, GeoAxesSubplot):
            # Check `ax` is not a GeoAxesSubplot axis to avoid overwriting the map.
            ax = basemaps.plot_geography(geodata["projection"], extent, **map_kwargs)

    return ax
Safely get a basemap axis. If ax is None, the current axis is returned.

If geodata is not None and ax is not a cartopy axis already, it creates a basemap
axis and return it.

Parameters
----------
extent: tuple
Four-element tuple specifying the extent of the domain according to
(lower left x, upper right x, lower left y, upper right y).
geodata:
geodata: dictionary or None
Optional dictionary containing geographical information about
the field.

If geodata is not None, it must contain the following key-value pairs:

.. tabularcolumns:: |p{1.5cm}|L|

+----------------+----------------------------------------------------+
|        Key     |                  Value                             |
+================+====================================================+
|   projection   | PROJ.4-compatible projection definition            |
+----------------+----------------------------------------------------+
|    x1          | x-coordinate of the lower-left corner of the data  |
|                | raster                                             |
+----------------+----------------------------------------------------+
|    y1          | y-coordinate of the lower-left corner of the data  |
|                | raster                                             |
+----------------+----------------------------------------------------+
|    x2          | x-coordinate of the upper-right corner of the data |
|                | raster                                             |
+----------------+----------------------------------------------------+
|    y2          | y-coordinate of the upper-right corner of the data |
|                | raster                                             |
+----------------+----------------------------------------------------+
|    yorigin     | a string specifying the location of the first      |
|                | element in the data raster w.r.t. y-axis:          |
|                | 'upper' = upper border, 'lower' = lower border     |
+----------------+----------------------------------------------------+

ax: axis object
Optional axis object to use for plotting.
map_kwargs: dict
Optional parameters that need to be passed to
:py:func:`pysteps.visualization.basemaps.plot_geography`.

Returns
-------
ax: axis object
pysteps/visualization/utils.py