The datain module.¶
This module implements functions to various input tasks for monc_utils.
Detailed Module Contents¶
The entire module is documented below.
Created on Mon Aug 2 11:01:11 2021.
@author: Peter Clark
- monc_utils.io.datain.correct_grid_and_units(var_name: str, vard: DataArray, source_dataset: Dataset, options: Optional[dict] = None)¶
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(optional - default=None)) – Options possibly used are ‘dx’ and ‘dy’.
- Returns:
vard – Required data with corrected grid.
- Return type:
xarray
- monc_utils.io.datain.get_derived_vars(source_dataset, ref_dataset, var_name: str, derived_vars: dict, options: Optional[dict] = None)¶
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.
var_name (str) – Name of variable to retrieve.
derived_vars (dict) – Maps var_name to function name and argument list.
options (dict (optional - default=None)) – Options. Options possibly used are ‘dx’ and ‘dy’.
- Returns:
vard – DESCRIPTION.
- Return type:
TYPE
- monc_utils.io.datain.get_data(source_dataset, ref_dataset, var_name: str, options: Optional[dict] = None, 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_w’, ‘z_p’. 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 (optional - default=None)) – 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
- monc_utils.io.datain.get_and_transform(source_dataset, ref_dataset, var_name, options=None, 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 (optional - default=None)) – 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
- monc_utils.io.datain.get_data_on_grid(source_dataset, ref_dataset, var_name, derived_dataset=None, options=None, 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.
var_name (str) – Name of variable to retrieve.
derived_dataset (dict, optional) – ‘ds’ points to xarray Dataset, ‘file’ to output file path.
options (dict, (optional - default=None)) – 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
- monc_utils.io.datain.get_pref(source_dataset, ref_dataset, options=None)¶
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 (optional - default=None)) – Options. Options possibly used are th_ref.
- Return type:
pref
- monc_utils.io.datain.get_thref(ref_dataset, options=None)¶
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.
Created on Mon Aug 2 11:21:15 2021
@author: Peter Clark