cordex.cmor.cmorize_variable#
- cmorize_variable(ds, out_name, cmor_table, dataset_table, mapping_table=None, grids_table=None, inpath=None, replace_coords=False, allow_units_convert=False, allow_resample=False, input_freq=None, domain_id=None, crop=None, time_units=None, rewrite_time_axis=False, outpath=None, **kwargs)[source]#
Cmorizes a variable.
This functions call the python cmor API and creates a cmorized NetCDF file from the input dataset. Coordinates of the input dataset should be understandable by
cf_xarrayif they follow basic CF conventions. If a vertical coordinate is available, it should have anaxis="Z"attribute so it can be understood bycf_xarrayand it should be named after the unique key of the coordinate in the cmor grids table (not the out_name), e.g., name itsdepthif you need a soil layer coordinate instead ofdepth. Variables may have one of the following attributes that are used as keyword arguments in the call to cmor_variable, e.g.,positive,missing_value,original_name,historyorcomment.- Parameters:
ds (xr.Dataset) – Dataset containing at least the variable that should be cmorized.
out_name (str) – CF out_name of the variable that should be cmorized. The corresponding variable name in the dataset is looked up from the mapping_table if provided.
cmor_table (str or dict) – Cmor table dict of filepath to cmor table (json).
dataset_table (str or dict) – Dataset table dict of filepath to dataset cmor table (json).
mapping_table (dict) – Mapping of input variable names and meta data to CF out_name. Required if the variable name in the input dataset is not equal to out_name.
grids_table (str) – Filepath to cmor grids table.
inpath (str) – Path to cmor tables, if
inpath == None, inpath is the path tocmor_table. This is required to find additional cmor tables, likeCMIP6_coordinates,CMIP6_gridsetc.replace_coords (bool) – Replace coordinates from input file and create them from archive specifications. Only possible, if a domain identifier is given in the global attributes or as a keyword argument, e.g., see the
domain_idkeyword.allow_units_convert (bool) – Allow units to be converted if they do not agree with the units in the cmor table. Defaults to
Falseto make the user aware of having correctunitsattributes set.allow_resample (bool) – Allow to resample temporal data to the frequency required from the cmor table. Handles both downsampling and upsampling. Defaults to
Falseto make users aware of the correct frequency input.input_freq (str) – The frequency of the input dataset in pandas notation. It
Noneand the dataset contains a time axis, the frequency will be determined automatically usingpandas.infer_freqif possible.domain_id (str) – Cordex domain identifier. If
None, the domain will be determined by thedomain_idglobal attribute if available. Ifdomain_idis given as a keyword, it will override a possibledomain_idglobal attribute.crop (bool) – Crop dataset to official Cordex domain if it contains, e.g., a nudging zone. If set to
None, cropping will be done if a domain identifier is given or the domain can be identified automatically. Set tocrop=False, if you have an ‘unofficial’ domain_id.time_units (str) – Time units of the cmorized dataset (
ISO 8601). IfNone, time units will be set to default ("days since 1950-01-01T00:00:00"). Iftime_units='input', the original time units of the input dataset are used.rewrite_time_axis (bool) – Rewrite the time axis to CF compliant timestamps.
outpath (str) – Root directory for output (can be either a relative or full path). This will override the outpath defined in the dataset cmor input table (
dataset_table).**kwargs – Argumets passed to prepare_variable.
- Returns:
filename – Filepath to cmorized file.
Example
To cmorize a dataset, you can use ,e.g.,:
import cordex as cx from cordex.cmor import cmorize_variable from cordex.tables import cordex_cmor_table ds = cx.domain("EUR-11", dummy="topo").rename(topo="orog") dataset_table = cordex_cmor_table(f"CORDEX-CMIP6_remo_example") filename = cmorize_variable( ds, "orog", cmor_table=cordex_cmor_table("CORDEX-CMIP6_fx"), dataset_table=dataset_table, replace_coords=True, allow_units_convert=True, )