MISO2 Config
Created on Tue Feb 15 14:03:01 2022
@author: jstreeck & bgrammer
- class model.config.MISO2_config.MISO2Config(config_path, data_path, timestamp, mc_batch_size=500)
Class that holds read-only parameters and data for the MISO2 model.
Input data is parsed from .xls files and brought into a format accepted by the ODYM module. Created with a unique identifier to allow for pickling and reloading the config. The config object is necessary to construct survival functions. If injected into a MISO2 model object, it will a pass a copy of the input data for computation. When it parses data with uncertainty, Monte Carlo randomization of the data can be enabled.
- Parameters:
config_path (str) – Default save path when config is pickled.
data_path (str) – Path to input data.
timestamp (str) – Time of config creation. Will be used for default filenames of logs and output.
mc_batch_size (int) – Number of randomized copies of the data that are created when Monte Carlo is active.
- config_path
A str that gives the default save location for config.
- Type:
str
- check_attributes()
Checks if all attributes of the config object are set.
Monte Carlo object is allowed to be None if config was parsed without uncertainty values. Note that this does not check if set objects are of the correct type or sensible value.
- Raises:
AttributeError – If parameter dict or model classifications are empty or an attribute, other than the Monte Carlo object, are not set.
- get_bias(mode)
Returns bias configuration of underlying monte carlo object, if any. Else returns “no uncertainty”.
- Parameters:
mode (str) – One of “next” or “last”. Indicates whether next sample bias is returned, or previous sample bias.
- Return type:
bias(str)
- get_new_scrap_cycle(time)
Returns a copy of the new scrap cycle array. If there is a cutoff value set in the config, will return all zeros (scenario option).
- Parameters:
time (int) – Time index in years that is compared to cutoff value.
- Returns:
Array of new scrap cycle
- Return type:
new_scrap_cycle(np.array)
- get_parameter_dict(nr_start=None, nr_stop=None)
Returns a copy of the ODYM-Parameter dictionary.
If the config contains multiple regions, the method will return a subset copy by the configs nr_start and nr_stop indices. When Monte Carlo randomization is enabled, the underlying MISO2MonteCarlo object will create a queue with randomized versions of the Values. If there is only one region in the config and Monte Carlo randomization is disabled, it will return a reference.
Please note that this method does not support returning randomized parameter dicts of more than one region.
- Parameters:
nr_start (int) – Region start index. Defaults to configs nr_start.
nr_stop (int) – Region stop index. Defaults to configs nr_stop.
- Raises:
WasteRatioError – if the recov and unrecov waste ratio of a process exceed 1.
InputLimitError – if the values violate the specified hard limits.
- get_randomization_state()
Get Monte Carlo state of config.
If a Monte Carlo object exists and any parameter is set to be randomized, returns True. Returns false otherwise.
- Returns:
Monte Carlo state of config.
- Return type:
mc_state(bool)
- initialise_from_excel(config_filename, classification_filename, parse_uncertainty=True, uncertainty_settings_filename='MISO2_uncertainty_distribution_settings.xlsx')
Parses MISO/ODYM data from XLSX files into the config to configure it.
The initialisation makes heavy use of the ODYM file format and parsing routines. See the relevant documentation there for more details.
- Parameters:
config_filename (str) – Name of the config.xls.
classification_filename (str) – Name of the master classification xls.
parse_uncertainty (bool/str) – Try to parse uncertainty data from the parameter files. Defaults to true.
uncertainty_settings_filename (str) – Name of the parameter limits xls. Defaults to “MISO2_uncertainty_settings.xls”.
- Raises:
AttributeError – If any config attribute has not been set to some value.
WasteRateError – If the combined recov and unrecov waste rates of the parsed data exceed 1. This is an error in the input data.
- reload_classification_properties(classification_properties_filename='MISO2_classification_properties.xlsx')
Reload the classification properties from file.
Use this method to reload the classification properties if they have changed after initialisation of the config object.
Warning: Additional props are reset to None before parsing the file again, so any exception in the setting of classifications will leave the miso config in an illegal state.
- Parameters:
classification_properties_filename (str) – configs data path. Defaults to “MISO2_classification_properties.xlsx”
- save_metadata(output_path, additional_data_dir)
Saves metadata to xlsx.
Note that not all metadata is constructed automatically, check the file to make sure it is correct.
- Parameters:
output_path – Path to save output file to.
additional_data_dir – Directory where Metadata template is located.
- save_to_pickle(filename=None, folder=None)
Saves the entire MISO Config object to a pickle.
- Parameters:
filename (str) – Name of the file. Defaults to <UUID>_config.pickle
folder (str) – Folder path. Defaults to config_path variable of MISO config.
- set_global_monte_carlo_state(new_state, parameter_list=None)
Set Monte Carlo randomization of all parameters to the new state.
This will reset the MISO2MonteCarlo objects queue of randomized dicts (if there was one).
- Parameters:
new_state (bool) – Set Monte Carlo to on/off.
parameter_list (list) – Optional: Specify parameters to be set as a list of strings.
- Raises:
AttributeError – when no Monte Carlo object is set in the config.
- set_monte_carlo_mode(mode, **kwargs)
Set monte carlo method to one of “normal”, “systematic_bias”, “systematic_bias_v2” or “sensitivity_by_parametergroup”
- Parameters:
mode (str) – String of mode
- Raises:
AttributeError – If mode is not known.
- set_random_state(random_state)
Set a seed for the Monte Carlo randomization to get reproducible results.
If this is set to any integer value, the Monte Carlo randomization will always return the same results. !!!: This is currently only working for one batch of randomized data inputs.
- Parameters:
random_state (int) – Seed that is passed to the Scipy distributions.
- model.config.MISO2_config.load_configs_from_folder(config_path, key='id')
Tries to load all .pickle files in a directory as MISO2Configs and returns them as a list.
- Parameters:
config_path (str) – A filepath
key (str) – Key of return dict. One of “id”(default) or filename.
- Returns:
A dict of MISO2Config objects.
- Return type:
configs(dict)
- model.config.MISO2_config.save_split_configs_to_folder(path, config_name, config)
Splits a Config object into multiple objects, one per region, and saves them to a folder.
Individual files receive a running index.
- Parameters:
path (str) – Folder path to save to
config_name (str) – Filename of the config.
config (MISO2Config) – Config to split
- model.config.MISO2_config.split_config(miso_config, index)
Returns a subset of the config by region index.
As far as possible, it will give views of the data instead of copies. Split objects receive new ids. This subset config is mainly intended to be passed to another process, by copy.
- Parameters:
miso_config (MISO2Config) – Config to be subset.
index (int) – Regional index number to subset. Must be within the index range of the MISO2Config.
- Returns:
Config subset to one region.
- Return type:
split_config(MISO2Config)