unifhy.LatLonGrid.from_extent_and_resolution

classmethod LatLonGrid.from_extent_and_resolution(latitude_extent, longitude_extent, latitude_resolution, longitude_resolution, latitude_longitude_location='centre')

Instantiate a LatLonGrid from the extent and the resolution of latitude, longitude (and optionally altitude) coordinates.

Parameters
latitude_extent: pair of float or int

The extent of latitude coordinates in degrees North for the desired grid. The first element of the pair is the location of the start of the extent along the latitude coordinate, the second element of the pair is the location of the end of the extent along the latitude coordinate. Extent must be from South to North. May be any type that can be unpacked (e.g. tuple, list, numpy.ndarray).

Parameter example:

latitude_extent=(30, 70)
longitude_extent: pair of float or int

The extent of longitude coordinates in degrees East for the desired grid. The first element of the pair is the location of the start of the extent along the longitude coordinate, the second element of the pair is the location of the end of the extent along the longitude coordinate. Extent must be from West to East. May be any type that can be unpacked (e.g. tuple, list, numpy.ndarray).

Parameter example:

longitude_extent=(0, 90)
latitude_resolution: float or int

The spacing between two consecutive latitude coordinates in degrees North for the desired grid. Must be positive.

Parameter example:

latitude_resolution=10
longitude_resolution: float or int

The spacing between two consecutive longitude coordinates in degrees East for the desired grid. Must be positive.

Parameter example:

longitude_resolution=10
latitude_longitude_location: str or int, optional

The location of the latitude and longitude coordinates in relation to their grid cells (i.e. their bounds). This information is required to generate the latitude and longitude bounds for each grid coordinate. If not provided, set to default ‘centre’.

The locations left and right are related to the longitude coordinates (X-axis), while the locations lower and upper are related to the latitude coordinates (Y-axis). The orientation of the coordinate system considered is detailed below (i.e. positive directions are northwards and eastwards).

Y, latitude (degrees North)
↑
·
* · → X, longitude (degrees East)

This parameter can be set using the labels (as a str) or the indices (as an int) detailed in the table below.

label

idx

description

'centre'

0

The latitude and longitude bounds extend equally on both sides of the coordinate along the two axes of a length equal to half the resolution along the given coordinate axis.

'lower left'

1

The latitude bounds extend northwards of a length equal to the latitude resolution. The longitude bounds extend eastwards of a length equal to the longitude resolution.

'upper left'

2

The latitude bounds extend southwards of a length equal to the latitude resolution. The longitude bounds extend eastwards of a length equal to the longitude resolution.

'lower right'

3

The latitude bounds extend northwards of a length equal to the latitude resolution. The longitude bounds extend westwards of a length equal to the longitude resolution.

'upper right'

4

The latitude bounds extend southwards of a length equal to the latitude resolution. The longitude bounds extend westwards of a length equal to the longitude resolution.

The indices defining the location of the coordinate in relation to its grid cell are made explicit below, where the ‘+’ characters depict the coordinates, and the ‘·’ characters delineate the relative location of the grid cell whose height and width are determined using the latitude and longitude resolutions, respectively.

2             4               northwards
 +  ·  ·  ·  +                    ↑
 ·           ·                    ·
 ·   0 +     ·      westwards ← · * · → eastwards
 ·           ·                    ·
 +  ·  ·  ·  +                    ↓
1             3               southwards

Parameter example:

latitude_longitude_location='centre'

Parameter example:

latitude_longitude_location=0
Returns

LatLonGrid

Examples

Instantiating grid using non-standard coordinates location in their cells:

>>> sd = LatLonGrid.from_extent_and_resolution(
...     latitude_extent=(30, 70),
...     longitude_extent=(0, 90),
...     latitude_resolution=5,
...     longitude_resolution=10,
...     latitude_longitude_location='upper right'
... )
>>> print(sd)
LatLonGrid(
    shape {Y, X}: (8, 9)
    Y, latitude (8,): [35.0, ..., 70.0] degrees_north
    X, longitude (9,): [10.0, ..., 90.0] degrees_east
    Y_bounds (8, 2): [[30.0, ..., 70.0]] degrees_north
    X_bounds (9, 2): [[0.0, ..., 90.0]] degrees_east
)