MISO2 File manager
Collection of objects and functions for dealing with ODYM/MISO2 input sets.
@author: bgrammer
- class util.MISO2_file_manager.MISO2FileManager(data_dir, config_filename, additional_data_dir=None, uncertainty_values_dir=None, input_sources_dir=None)
Manages paths and filenames associated with a single ODYM/MISO2 input set.
Additional data, uncertainty values and input sources are optional.
- get_filepath(path_type)
Returns filepaths for appropriate MISO2FileType enum.
- Parameters:
path_type (MISO2FileType) – Enum of available file types.
- Returns:
Filepath as string or collection of filepaths as string.
- Return type:
file_path(str/list/dict)
- Raises:
KeyError – When FileType is not available.
- load_parameters(parameters=None, sheet_name='values')
Returns a dictionary of parameter values.
- Parameters:
parameters (list) – List of parameters to read. If None (default), all will be read.
sheet_name (string) – Name of sheet to process.
- Returns:
Dict with parameter name as key and values sheet as pd.DataFrame.
- Return type:
parameter_dict(dict)
- load_sources(sources=None)
Parses all xlsx files from a directory or list of paths to create a dictionary of uncertainty inputs.
- Parameters:
sources (str/list/None) – Path to uncertainty sources or list of paths to uncertainty source files. If None (default), the value will be taken from the input parser.
- Returns:
Dictionary with parameter names as keys and a list of pd.DataFrames as values.
- Return type:
parameter_uncertainty_dataframes(dict)
- load_xls(path_type, sheet=None)
Load XLS of desired path_type.
- Parameters:
path_type (MISO2FileType) – Type of path
sheet (str) – Sheetname
- Returns:
Read in file
- Return type:
pd.DataFrame
- update_filepath(path_type, new_value)
Set new value for filepath.
- Parameters:
path_type (MISO2FileType) – FileType to be specified.
new_value (str) – New path.
- write_uncertainties(material, new_uncertainties_dict, mode)
Write uncertainties back to uncertainty files.
Filepaths are gathered from object class attributes. In mode overwrite, original values (if any) are replaced. In update mode, only values present in the original value will be updated with new values generated from sources. In “update_append”, present values will be updated and those only present in sources are appended.
In update append mode, the number of columns between existing and new values must match.
- Parameters:
material (str) – Name of material.
new_uncertainties_dict (dict) – Dict of pd.DataFrames with parameter name as key.
mode (str) – Update mode, one of “overwrite”, “update” or “update_append.
- write_values(parameter, parameter_dfs, mode, sheet_name='values')
Write values back to parameter files.
Filepaths are gathered from object class attributes.
- Parameters:
parameter (str) – Name of parameter
parameter_dfs (list) – List of pd.DataFrames
mode (str) – Update mode, one of “overwrite”, “update” or “update_append”.
sheet_name (str) – Name of sheet. Defaults to values sheet.
- util.MISO2_file_manager.get_parameter_filenames(data_path, config_file, return_type='list')
Helper function that generates correct parameter filenames from config.
This function uses reworked code from ODYM’s parser function.
- Parameters:
data_path (str) – Path to config file.
config_file (str) – Name of ODYM config file.
return_type (str) – Format to return filenames in. One of “list” (default), “dict” or “all”. “All” returns a dict
values. (with both list and key as)
- Returns:
Parameter input file names. If dict, the parameter name without version number is provided as key.
- Return type:
file_names(list/dict)
- util.MISO2_file_manager.index_check(dfs)
Check dataframes or a list of dataframes if they have a valid REMT / REMGT index.
dfs(pd.DataFrame/list): List of or single pd.DataFrame
- Raises:
ValueError – If index is different than expected.
- util.MISO2_file_manager.regex_material_name(input_string)
Split file path to uncertainty parameter file with .xls ending into the material name. Filenames must be of format uncertainty_<material_name>.xlsx
- Parameters:
input_string (str) – Path to regex for material name.
- Returns:
Material name.
- Return type:
name(str)