xarray: inputs and outputs
Descriptions of the basic functions are given below.
Function descriptions:
- xarrayIO.convertOptimizationInputToDatasets(esM, useProcessedValues=False)[source]
Takes esM instance input and converts it into xarray datasets.
- Parameters:
esM (EnergySystemModel instance) – EnergySystemModel instance in which the model is held
Default arguments:
- param useProcessedValues:
True if the raw values should be over-written by processed values, False otherwise. A requirement for perfect-foresight and by extension for spatial and technology aggregations
* the default value is False- type useProcessedValues:
bool
- Returns:
xr_ds - esM instance data in xarray dataset format
- Return type:
xarray.dataset
- xarrayIO.convertOptimizationOutputToDatasets(esM, optSumOutputLevel=0)[source]
Takes esM instance output and converts it into an xarray dataset.
- Parameters:
esM (EnergySystemModel instance) – EnergySystemModel instance in which the optimized model is held
optSumOutputLevel (int (0,1,2) or dict) – Output level of the optimization summary (see EnergySystemModel). Either an integer (0,1,2) which holds for all model classes or a dictionary with model class names as keys and an integer (0,1,2) for each key (e.g. {‘StorageModel’:1,’SourceSinkModel’:1,…}
* the default value is 2
- Returns:
xr_ds - EnergySystemModel instance output data in xarray dataset format
- Return type:
xarray.dataset
- xarrayIO.writeDatasetsToNetCDF(datasets, outputFilePath='my_esm.nc', removeExisting=False, mode='a', groupPrefix=None)[source]
Saves dictionary of xarray datasets (with esM instance data) to a netCDF file.
Required arguments:
- Parameters:
datasets (Dict[xr.Dataset]) – The xarray datasets holding all data required to set up an esM instance.
Default arguments:
- Parameters:
outputFilePath (string) – output file name of the netCDF file (can include full path)
* the default value is “my_esm.nc”removeExisting (boolean) – indicates if an existing netCDF file should be removed
* the default value is Falsemode (string) –
Write (‘w’) or append (‘a’) mode.
If mode=’w’, any existing file at this location will be overwritten.
If mode=’a’, existing variables will be overwritten.
* the default value is ‘a’groupPrefix (string) – if specified, multiple xarray datasets (with esM instance data) are saved to the same netcdf file. The dictionary structure is then {group_prefix}/{group}/{…} instead of {group}/{…}
* the default value is None
- xarrayIO.convertDatasetsToEnergySystemModel(datasets)[source]
Takes dictionary of xarray datasets (with esM instance data) and converts it to an esM instance.
- Parameters:
datasets (Dict[xr.Dataset]) – The xarray datasets holding all data required to set up an esM instance.
- Returns:
esM - EnergySystemModel instance
- Return type:
EnergySystemModel instance
- xarrayIO.writeEnergySystemModelToNetCDF(esM, outputFilePath='my_esm.nc', overwriteExisting=False, optSumOutputLevel=0, groupPrefix=None)[source]
Write energySystemModel (input and if exists, output) to netCDF file.
- Parameters:
esM (EnergySystemModel instance) – EnergySystemModel instance in which the model is held
outputFilePath – output file name (can include full path)
* the default value is “my_esm.nc”overwriteExisting – Overwrite existing netCDF file
* the default value is FalseoptSumOutputLevel (int (0,1,2) or dict) – Output level of the optimization summary (see EnergySystemModel). Either an integer (0,1,2) which holds for all model classes or a dictionary with model class names as keys and an integer (0,1,2) for each key (e.g. {‘StorageModel’:1,’SourceSinkModel’:1,…}
* the default value is 2groupPrefix – if specified, multiple xarray datasets (with esM instance data) are saved to the same netcdf file. The dictionary structure is then {group_prefix}/{group}/{…} instead of {group}/{…}
* the default value is None
- Returns:
Nested dictionary containing xr.Dataset with all result values for each component.
- Return type:
- xarrayIO.writeEnergySystemModelToDatasets(esM)[source]
Converts esM instance (input and output) into a xarray dataset.
- Parameters:
esM (EnergySystemModel instance) – EnergySystemModel instance in which the optimized model is held
- Returns:
xr_dss_results - esM instance (input and output) data in xarray dataset format
- Return type:
xr.DataSet
- xarrayIO.readNetCDFToDatasets(filePath='my_esm.nc', groupPrefix=None)[source]
Read optimization results from grouped netCDF file to dictionary of xr.Datasets.
- Parameters:
filePath (string) – output file name of netCDF file (can include full path)
* the default value is “my_esm.nc”groupPrefix (string) – if specified, multiple xarray datasets (with esM instance data) are saved to the same netcdf file. The dictionary structure is then {group_prefix}/{group}/{…} instead of {group}/{…}
* the default value is None
- Returns:
Nested dictionary containing an xr.Dataset with all result values for each component.
- Return type:
Nested dict
- xarrayIO.readNetCDFtoEnergySystemModel(filePath, groupPrefix=None)[source]
Converts netCDF file into an EnergySystemModel instance.
- Parameters:
filePath (string) – file name of netCDF file (can include full path) in which the esM data is stored
* the default value is “my_esm.nc”- Returns:
EnergySystemModel instance
- Return type:
EnergySystemModel instance