def get_geogrid(nlat, nlon, geodata=None):
    """
    Get the geogrid data.
    If geodata is None, a regular grid is returned. In this case, it is assumed that
    the origin of the 2D input data is the upper left corner ("upper").

    Parameters
    ----------
    nlat: int
        Number of grid points along the latitude axis
    nlon: int
        Number of grid points along the longitude axis
    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     |
        +----------------+----------------------------------------------------+

    Returns
    -------
    x_grid: 2D array
        X grid with dimensions of (nlat, nlon) with the same `y-origin` as the one
        specified in the geodata (or "upper" if geodata is None).
    y_grid: 2D array
        Y grid with dimensions of (nlat, nlon) with the same `y-origin` as the one
        specified in the geodata (or "upper" if geodata is None).
    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).
    regular_grid: bool
        True if the grid is regular. False otherwise.
    origin: str
        Place the [0, 0] index of the array to plot in the upper left or lower left
        corner of the axes.
    """

    if geodata is not None:
        regular_grid = geodata.get("regular_grid", True)

        x_lims = sorted((geodata["x1"], geodata["x2"]))
        x, xpixelsize = np.linspace(
            x_lims[0], x_lims[1], nlon, endpoint=False, retstep=True
        )
        x += xpixelsize / 2.0

        y_lims = sorted((geodata["y1"], geodata["y2"]))
        y, ypixelsize = np.linspace(
            y_lims[0], y_lims[1], nlat, endpoint=False, retstep=True
        )
        y += ypixelsize / 2.0

        extent = (geodata["x1"], geodata["x2"], geodata["y1"], geodata["y2"])

        x_grid, y_grid = np.meshgrid(x, y)

        if geodata["yorigin"] == "upper":
            y_grid = np.flipud(y_grid)

        return x_grid, y_grid, extent, regular_grid, geodata["yorigin"]

    # Default behavior: return a simple regular grid
    # Assume yorigin = upper
    x_grid, y_grid = np.meshgrid(np.arange(nlon), np.arange(nlat))
    y_grid = np.flipud(y_grid)
    extent = (0, nlon - 1, 0, nlat - 1)
    regular_grid = True
    return x_grid, y_grid, extent, regular_grid, "upper"
Get the geogrid data.
If geodata is None, a regular grid is returned. In this case, it is assumed that
the origin of the 2D input data is the upper left corner ("upper").

Parameters
----------
nlat: int
Number of grid points along the latitude axis
nlon: int
Number of grid points along the longitude axis
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     |
+----------------+----------------------------------------------------+

Returns
-------
x_grid: 2D array
X grid with dimensions of (nlat, nlon) with the same `y-origin` as the one
specified in the geodata (or "upper" if geodata is None).
y_grid: 2D array
Y grid with dimensions of (nlat, nlon) with the same `y-origin` as the one
specified in the geodata (or "upper" if geodata is None).
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).
regular_grid: bool
True if the grid is regular. False otherwise.
origin: str
Place the [0, 0] index of the array to plot in the upper left or lower left
corner of the axes.
pysteps/visualization/utils.py