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.
- 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: