i7aof.vert¶
Vertical interpolation helpers. See i7aof.vert for developer details.
- class i7aof.vert.interp.VerticalInterpolator(src_valid, src_coord, dst_coord, config)¶
Bases:
object
A class to perform vertical interpolation to the ISMIP reference grid.
Notes
The ISMIP grid path is obtained from
i7aof.grid.ismip.get_ismip_grid_filename()
. If this path is relative and not found from the current working directory, we will attempt to resolve it against[workdir] base_dir
fromconfig
. If still not found, a FileNotFoundError is raised with the attempted paths. Ensure the ISMIP grid exists (seei7aof.grid.ismip.write_ismip_grid()
) and use a consistent working directory or provide[workdir] base_dir
in the config.- src_valid¶
A boolean array indicating valid source data points, same size as input data except for
time
dimension (if any)- Type:
xarray.DataArray
- src_coord¶
The source coordinate variable name in the dataset.
- Type:
str
- dst_coord¶
The destination coordinate variable from the ISMIP reference grid.
- Type:
{‘z’, ‘z_extrap’}
- config¶
Configuration options, including threshold for normalization.
- Type:
mpas_tools.config.MpasConfigParser
- threshold¶
The threshold value for normalization after interpolation.
- Type:
float
- src_frac_interp¶
The fraction of valid source data after interpolation.
- Type:
xarray.DataArray
- z_src¶
The source vertical coordinate from the dataset, corrected to be positive up if needed
- Type:
xarray.DataArray
- interp(da_masked)¶
Interpolate a data array to the ISMIP vertical coordinate.
- Parameters:
da_masked (xarray.DataArray) – The masked data array to be interpolated.
- Returns:
da_interp – The data array after interpolation to the ISMIP vertical coordinate.
- Return type:
xarray.DataArray
- mask_and_sort(da)¶
Mask the data array based on the source valid mask and sort so the source coordinate is in ascending order.
- Parameters:
da (xarray.DataArray) – The data array to be masked.
- Returns:
da_masked – The masked data array.
- Return type:
xarray.DataArray
- normalize(da_interp)¶
Normalize the data array following interpolation. We remap a mask of where the data is valid, which becomes a fraction of how much of a destination cell overlapped with valid data. For many “state” fields like temperature and salinity, we want to renormalize them by the valid fraction. Otherwise, the values would be lower than expected by a factor of the valid fraction. Locations that have less than a threshold fraction of overlap (1e-3 by default) will be set to invalid values.
- Parameters:
da_interp (xarray.DataArray) – The data array after interpolation to the ISMIP vertical coordinate.
- Returns:
da_normalized – The data array normalized by the valid source fraction
- Return type:
xarray.DataArray
- i7aof.vert.interp.fix_src_z_coord(ds, z_coord, z_bnds)¶
Invert the coordinate and convert to meters if necessary.
- Parameters:
ds (xarray.Dataset) – The dataset containing the vertical coordinates.
z_coord (str) – The name of the vertical coordinate variable.
z_bnds (str) – The name of the vertical coordinate bounds variable.
- Returns:
z_src (xarray.DataArray) – The source vertical coordinate from the dataset, corrected to be positive up if needed.
z_bnds_src (xarray.DataArray) – The source vertical coordinate bounds from the dataset, corrected to be positive up if needed.
- class i7aof.vert.resamp.VerticalResampler(src_valid, src_coord, dst_coord, config)¶
Bases:
object
Conservative vertical resampling from a source Z coordinate to a destination Z coordinate using layer-overlap weights.
This is designed to resample from
z_extrap
toz
but works for any pair of coordinates present in the ISMIP grid file.Notes
The ISMIP grid path is obtained from
i7aof.grid.ismip.get_ismip_grid_filename()
. If this path is relative and not found from the current working directory, we will attempt to resolve it against[workdir] base_dir
fromconfig
. If still not found, a FileNotFoundError is raised with the attempted paths. Ensure the ISMIP grid exists (seei7aof.grid.ismip.write_ismip_grid()
) and use a consistent working directory or provide[workdir] base_dir
in the config.- resample(da: DataArray) DataArray ¶
Resample an intensive field conservatively from src_coord to dst_coord.
- Parameters:
da (xarray.DataArray) – Data with a vertical dimension
src_coord
. Other dims such as time/y/x are preserved.- Returns:
Resampled data with vertical dimension
dst_coord
.- Return type:
xr.DataArray