Geotools¶
GeographicField
¶
Bases: Field
geo_metadata = GeographicMetadata(cast('Metadata', field.metadata()), geography)
instance-attribute
¶
clone(*, values=None, metadata=None, **kwargs)
¶
message()
¶
Delegate message generation to the underlying field.
to_latlon(flatten=True, dtype=None, index=None)
¶
Return the latitudes and longitudes for the field.
We take these from the geography as GeographicField might be a wrapper around a differently-sized field. This is done, for example, in ReprojectFilter.
to_numpy(flatten=False, dtype=None, index=None)
¶
Delegate creation of numpy array to the underlying field.
It is important to do this rather than relying on the base class implementation
since self._field might override the base class method.
GeographicGrid
¶
Bases: Geography
resolution_ = resolution
instance-attribute
¶
native_crs = native_crs
instance-attribute
¶
latitudes_ = None
instance-attribute
¶
longitudes_ = None
instance-attribute
¶
latitudes(dtype=None)
¶
longitudes(dtype=None)
¶
x(dtype=None)
¶
y(dtype=None)
¶
bounding_box()
¶
mars_area()
¶
mars_grid()
¶
resolution()
¶
shape()
¶
gridspec()
¶
grid_spec()
¶
projection()
¶
regrid_forecast_run(predictions, target_latitudes, target_longitudes, first_valid_day, *, variable='ice_conc', output_variable='siconc', source_crs=None)
¶
Regrid a single forecast run onto a regular lat/lon grid.
Selects the forecast run whose first lead time is valid on first_valid_day and
bilinearly interpolates it from its native grid onto the target lat/lon grid,
cropping to the target extent. The interpolation is done in the CRS in which the
native grid is regular, which is EASE-Grid 2.0 unless source_crs is given. The
output follows the CMEMS layout, with dimensions (time, latitude, longitude) and
a daily (00:00) time axis.
If the predictions have a land mask, land cells are left out of the interpolation, so that they do not pull coastal values towards zero. Target points that are mostly land are set to NaN, and the land mask is regridded into the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
Dataset
|
Predictions with dimensions (forecast_reference_time, lead_time,
y, x), 2-D latitude/longitude coordinates and a valid_time coordinate, as
written by the prediction writer. Unless |
required |
target_latitudes
|
DataArray
|
1-D latitudes of the target grid. |
required |
target_longitudes
|
DataArray
|
1-D longitudes of the target grid. |
required |
first_valid_day
|
str | datetime64
|
Day on which the first lead time of the selected run is valid, e.g. "2024-01-14". |
required |
variable
|
str
|
Name of the variable to regrid in |
'ice_conc'
|
output_variable
|
str
|
Name of the regridded variable in the output. |
'siconc'
|
source_crs
|
str | None
|
CRS in which the prediction grid is regular, e.g. "EPSG:3413". Defaults to the EASE-Grid 2.0 CRS for the predictions' hemisphere. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset containing |
Dataset
|
longitude), where time holds the valid day of each lead time. The latitude |
Dataset
|
and longitude coordinates have CF attributes, overridden by any attributes |
Dataset
|
of |
Dataset
|
keeps the attributes of |
Dataset
|
in |
Dataset
|
range where one is defined. If the predictions have a land mask, the |
Dataset
|
output also contains a (latitude, longitude) "land_mask" (1 for ocean, 0 |
Dataset
|
for land, missing outside the prediction grid), linked from |
Dataset
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target latitudes or longitudes are not 1-D, if no run has
its first lead time valid on |
nearest_neighbour_indices(input_latlons, output_latlons)
¶
Calculate the nearest neighbour input cell for each cell in the output grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_latlons
|
ArrayHWV
|
Array of shape [input_h, input_w, 2] containing the latitudes and longitudes of each cell in the input grid. |
required |
output_latlons
|
ArrayHWV
|
Array of shape [output_h, output_w, 2] containing the latitudes and longitudes of each cell in the output grid. |
required |
Returns:
| Type | Description |
|---|---|
ArrayIndices2D
|
Tuple of (nn_indices_h, nn_indices_w) where each is a numpy array of shape |
ArrayIndices2D
|
[output_height, output_width] containing, for each output cell, the index in |
tuple[ArrayIndices2D, ArrayIndices2D]
|
the H and W dimensions of the nearest neighbour input cell that should be |
tuple[ArrayIndices2D, ArrayIndices2D]
|
used as the source. |