input.converter.InputConverter#
- class InputConverter(var_lookup_table: str | dict | Path, converter: Callable = None, metadata_info: dict = None)[source]#
Bases:
object
A class for converting input files or xarrays to ValEnsPy complaint xarrays.
- __init__(var_lookup_table: str | dict | Path, converter: Callable = None, metadata_info: dict = None)[source]#
Initialize the InputProcessor
- Parameters:
var_lookup_table (str | dict | Path) – A dictionary, or a Path to a yml file or a string matching the name of one of the yml files in valenspy/ancillary_data, Keys are the CORDEX standard variable names and values are information about the variable in the input file.
converter (function, optional) – A function that deals with unique aspects of the input data when converting to CF convention. Default is None. This function is applied before the units and variable names are converted.
metadata_info (dict, optional) – A dictionary containing the metadata information for the netCDF file. This is added to the global attributes of the netCDF file.
Examples
>>> from valenspy.input.converter import InputConverter >>> ERA5_dict = { ... "tas": { ... "raw_name": "t2m", ... "raw_units": "K"} ... } >>> converter = InputConverter(var_lookup_table=ERA5_dict) >>> ds = converter([paths_to_era5_files])
Or use the pre-defined input converters
>>> from valenspy.input.converter import InputConverter >>> converter = InputConverter("ERA5_lookup") >>> ds = converter([paths_to_era5_files])
Methods
__init__
(var_lookup_table[, converter, ...])Initialize the InputProcessor
convert_input
(data_sources[, metadata_info])Convert the input file(s) or xarray dataset to CF convention.
get_CORDEX_variable
(raw_variable)Get the CORDEX variable name from the raw variable name.
get_raw_variable
(cordex_variable)Get the raw variable name from the CORDEX variable name.
Attributes
Return all the CORDEX variables in the lookup table.
Return all the raw variables in the lookup table.
Return all the raw variables long names in the lookup table.
- convert_input(data_sources: Path | list[Path] | Dataset, metadata_info: dict = {}) Dataset [source]#
Convert the input file(s) or xarray dataset to CF convention.
- Parameters:
data_sources (Path or list(Path) or xarray.Dataset) – The input file or list of input files or an xarray dataset to convert.
metadata_info (dict, optional) – A dictionary containing additional metadata information for the netCDF file.
- Returns:
An xarray dataset in CF convention.
- Return type:
- property cordex_variables: set#
Return all the CORDEX variables in the lookup table.
- get_CORDEX_variable(raw_variable: str) str [source]#
Get the CORDEX variable name from the raw variable name.
- Parameters:
raw_variable (str) – The raw variable name or long name.
- Returns:
The CORDEX variable name.
- Return type:
str
- get_raw_variable(cordex_variable: str) str [source]#
Get the raw variable name from the CORDEX variable name.
- Parameters:
cordex_variable (str) – The CORDEX variable name.
- Returns:
The raw variable name.
- Return type:
str
- property raw_variables: set#
Return all the raw variables in the lookup table.
- property raw_variables_long_names: set#
Return all the raw variables long names in the lookup table.