Regridding an ancillary field to a target grid#
Producing an ancillary usually means taking source data on one grid and
regridding it onto a target model grid. ANTS provides regridding capability
that goes beyond what Iris offers directly, in particular schemes that are
useful when moving between very different grid types (for example a
lat-lon source and a rotated pole or cubesphere target). See
ants.regrid for the full picture; Iris itself is the right place to
look for capability that ANTS does not add to
(see iris.analysis).
Horizontal and vertical regridding#
ANTS provides three groups of regridding scheme:
ants.regrid.rectilinear- horizontal regridding/interpolation schemes for rectilinear grids, for exampleLinear,AreaWeightedand aTwoStagescheme that performs an intermediate linear regrid before an area weighted regrid, which is useful when the source and target coordinate reference systems differ substantially.
ants.regrid.interpolation- vertical, points-based interpolation schemes.
ants.regrid.esmf- regridding schemes that use the ESMF framework, useful for more complex source/target grid combinations (for example unstructured or cubesphere grids).
Rather than choosing a horizontal or vertical scheme directly in your
application code, use ants.regrid.GeneralRegridScheme. This lets the
regridding method be swapped later via configuration, without changing your
application:
import ants
scheme = ants.regrid.GeneralRegridScheme(horizontal_scheme="TwoStage")
Worked example#
The following mirrors the approach taken by the ancil_general_regrid
application (see Worked examples: the ANTS command line tools). We build a small source
cube and a target grid, both using ants.tests.stock, and regrid the
source onto the target:
import numpy as np
import ants
import ants.tests.stock as stock
# source data on a coarse grid; data must already be shaped to match
# the cube's shape, so reshape the flat array of values first
source = stock.geodetic((4, 4), data=np.arange(16).reshape(4, 4))
# target grid to regrid onto
target = stock.geodetic((8, 8))
scheme = ants.regrid.GeneralRegridScheme(horizontal_scheme="TwoStage")
regridding_result = source.regrid(target, scheme)
regridding_result is a cube on the target grid. In an application dealing with
larger, real datasets you would typically pass the regridding operation through
ants.decomposition.decompose() rather than calling regrid directly,
so that the regrid can be split into pieces that fit into memory - see
ANTS Decomposition Framework for details.
Note
For the example above using the TwoStage scheme is redundant as the source
and target are on the same grid - it achieves the same result as directly
calling the AreaWeighted scheme.
Regridding onto a land sea mask#
Where the target has a land sea mask, you will usually want the regridded
result to be consistent with it, so that land points do not end up with sea
sourced values and vice versa. Use
ants.analysis.make_consistent_with_lsm() after regridding to fill any
points that need correcting:
target_lsm = ants.io.load.load_landsea_mask("/path/to/target_lsm.nc")
ants.analysis.make_consistent_with_lsm(
result, target_lsm, invert_mask=True, method="kdtree"
)
See Merging datasets and filling missing data for more on the fill algorithms
make_consistent_with_lsm uses under the hood, including which one is
recommended.
Zonal mean behaviour#
If the source and target both have global extent in the x axis, or the
source has only a single column in x, the target is treated specially so
that the result is a proper zonal mean, regardless of how many longitude
points the target actually has.
Key Points#
Use
ants.regrid.GeneralRegridSchemerather than a specific rectilinear/esmf/interpolation scheme directly, so the regrid method remains configurable.
TwoStageis useful when source and target use substantially different coordinate reference systems; a plainAreaWeightedorLinearregrid may be sufficient (and cheaper) otherwise.After regridding onto a masked target, use
ants.analysis.make_consistent_with_lsm()to resolve any land/sea inconsistencies.For large datasets, combine regridding with
ants.decomposition.decompose()(see ANTS Decomposition Framework).If you only need to regrid vertically (source and target already share the same horizontal grid), the dedicated
ancil_vertical_regridcommand line tool may be simpler thanancil_general_regrid- see Worked examples: the ANTS command line tools.
See Also#
Loading and saving data with ANTS for loading the source data and target grid.
Merging datasets and filling missing data for filling any remaining missing data after a regrid.
ancil_general_regrid.py for the command line tool that wraps this workflow.