The datain module.¶
This module implements functions to various input tasks for subfilter
.
New at 0.5
Relocated to
subfilter.io
.
Detailed Module Contents¶
The entire module is documented below.
Created on Mon Aug 2 11:01:11 2021
@author: paclk
- subfilter.io.datain.correct_grid_and_units(var_name: str, vard: xarray.core.dataarray.DataArray, source_dataset: xarray.core.dataset.Dataset, options: dict)¶
Correct input grid specification.
- Parameters
var_name (str) – Name of variable to retrieve.
vard (xarray.core.dataarray.DataArray) – Input (at least 2D) data.
source_dataset (xarray.core.dataset.Dataset) – Source dataset for vard
options (dict) – Options possibly used are ‘dx’ and ‘dy’.
- Returns
vard – DESCRIPTION.
- Return type
TYPE
- subfilter.io.datain.get_derived_vars(source_dataset, ref_dataset, options, var_name: str, derived_vars: dict)¶
Get data from source_dataset and compute required variable.
- Parameters
source_dataset (xarray Dataset) – Input (at least 2D) data.
ref_dataset (xarray Dataset) – Contains reference profiles. Can be None.
options (dict) – Options. Options possibly used are ‘dx’ and ‘dy’.
var_name (str) – Name of variable to retrieve.
derived_vars (dict) – Maps var_name to function name and argument list.
- Returns
vard – DESCRIPTION.
- Return type
TYPE
- subfilter.io.datain.get_data(source_dataset, ref_dataset, var_name: str, options: dict, allow_none: bool = False)¶
Extract data or derived data field from source NetCDF dataset.
If var_name is in source_dataset it is retrieved; if one of the primary variables with a key in var_properties the grid is corrected. Otherwise, it is assumed to be on a ‘p’ point.
Currently written for MONC data, enforcing C-grid. Returned coords are ‘x_p’, ‘x_u’, ‘y_p’, ‘y_v’, ‘z’, ‘zn’. Coordinate x- and -y values are retrieved from the MONC options_database in source_dataset or from ‘dx’ and ‘dy’ in options otherwise.
Alternative names of variables can be supplied in options[‘aliases’] as a list of strings. If var_name is not found in source_dataset the first alias present in source_dataset is retrieved and renamed to var_name.
Currently supported derived data are specified if the thermodynamics module.
The special var_name ‘thref’ retrieves the reference theta profile.
- Parameters
source_dataset (xarray Dataset) – Input (at least 2D) data.
ref_dataset (xarray Dataset) – Contains reference profiles. Can be None.
var_name (str) – Name of variable to retrieve.
options (dict) – Options possibly used are ‘dx’ and ‘dy’.
allow_none (bool (optional - default=False)) – If True, return None if not found.
- Returns
vard – Output data field.
- Return type
xarray
@author: Peter Clark
- subfilter.io.datain.get_and_transform(source_dataset, ref_dataset, var_name, options, grid='p')¶
Extract data from dataset and transform to alternative grid.
See get_data for derived variables.
- Parameters
source_dataset (xarray Dataset) – Input (at least 2D) data.
ref_dataset (xarray Dataset) – Contains reference profiles. Can be None.
var_name (str) – Name of variable to retrieve.
options (dict) – Options. Options possibly used are ‘dx’ and ‘dy’.
grid (str, optional) – Destination grid ‘u’, ‘v’, ‘w’ or ‘p’. Default is ‘p’.
- Returns
var – Output data field.
- Return type
xarray
@author: Peter Clark
- subfilter.io.datain.get_data_on_grid(source_dataset, ref_dataset, derived_dataset, var_name, options, grid='p')¶
Find data from source_dataset remapped to destination grid.
Uses data from derived_dataset if present, otherwise uses get_and_transform to input from source_dataset and remap grid. In this case, if options[‘save_all’]==’yes’, save the remapped data to derived_dataset.
See get_data for derived variables.
- Parameters
source_dataset (xarray Dataset) – Input (at least 2D) data.
ref_dataset (xarray Dataset) – Contains reference profiles. Can be None.
derived_dataset (dict) – ‘ds’ points to xarray Dataset, ‘file’ to output file path.
var_name (str) – Name of variable to retrieve.
options (dict) – Options. Options possibly used are ‘dx’ and ‘dy’.
grid (str, optional) – Destination grid ‘u’, ‘v’, ‘w’ or ‘p’. Default is ‘p’.
- Returns
var – Output data field.
- Return type
xarray
@author: Peter Clark
- subfilter.io.datain.get_pref(source_dataset, ref_dataset, options)¶
Get reference pressure profile for source_dataset.
Calculate from ref_dataset or from surface_press in source_dataset options_database and options[‘th_ref’].
- Parameters
source_dataset (netCDF4 file) – MONC output file.
ref_dataset (netCDF4 file or None) – MONC output file containing 1D variable prefn.
options (dict) – Options. Options possibly used are th_ref.
- Returns
- Return type
(pref, piref)
- subfilter.io.datain.get_thref(ref_dataset, options)¶
Get thref profile from ref_dataset.
- Parameters
ref_dataset (netCDF4 file or None) – MONC output file containing pref
options (dict) – Options. Options possibly used are th_ref.
- Returns
thref – Reference theta constant or profile
- Return type
float or float array.
- subfilter.io.datain.configure_model_resolution(dataset, options)¶
Find model resolution from available sources.
This routine applies an order of precedence between potential pre-existing records of MONC horizontal resolutions and ensures that the options dictionary contains these values.
Files written via io/dataout.py’s setup_child_file will have the correct value listed in the file’s global attributes, as this routine is called within that space.
Repeated calls to this routine (for instance, to simply obtain dx and dy) will not modify the options contents.
- Precedence:
options_database
dataset attributes
subfilter options
parse file path containing resolution encoding
- Parameters
dataset (xarray dataset) – any subfilter-compatible dataset
options (dict) – dataset-associated options dictionary
- Returns
dx (float (expected)) – x-direction MONC resolution [m]
dy (float (expected)) – y-direction MONC resolution [m]
options (dict) – input options dictionary, possibly updated with dx and dy keys
- subfilter.io.datain.path_to_resolution(inpath)¶
Pull resolution value from an encoded path as a float.
e.g., ‘BOMEX_m0020_g0800’ i.e., it should have ‘_m[0-9][0-9][0-9]’ (at least 3 integers)
- Parameters
inpath (str) – file path
- Returns
dx – MONC horizontal resolution [m]
- Return type
float
Created on Mon Aug 2 11:21:15 2021
@author: paclk