oasislmf.pytools.getmodel.manager¶
This file is the entry point for the python get model command for the package
TODO: use selector and select for output
Attributes¶
Functions¶
|
|
|
|
|
Processes the Items loaded from the file extracting meta data around the vulnerability data. |
|
Loads the items from the items file. |
|
Loads the intensity bin dictionary file and creates a dictionary to map intensities to bins |
|
|
|
|
|
Loads the vulnerability binary index file. |
|
Loads the vulnerability binary index file, prioritizing the data in the adjustments file over the data in the |
|
Loads the vulnerability data grouped by the intensity and damage bins. |
|
Loads the vulnerability data grouped by the intensity and damage bins, prioritizing the data |
|
Updates the indexes of the vulnerability IDs (usually used in loading vulnerability data from parquet file). |
|
Update the vulnerability array with adjustment data (used for parquet loading). |
|
Creates a vulnerability array where the index of the array correlates with the index of the vulnerability. |
|
Loads vulnerability adjustments from the analysis settings file. |
|
Loads the vulnerabilities from the file. |
|
Loads the vulnerability adjustment file. |
|
Loads the mean damage bins from the damage_bin_dict file, namely, the interpolation value for each bin. |
|
Loads the damage bins from the damage_bin_dict file. |
|
Calculate the probability of an event happening and then causing damage. |
|
Calculate the result concerning an event ID. |
|
Calculates the cumulative distribution function (cdf) for an event ID. |
|
|
|
Runs the main process of the getmodel process. |
Module Contents¶
- oasislmf.pytools.getmodel.manager.load_items(items, valid_area_peril_id)[source]¶
Processes the Items loaded from the file extracting meta data around the vulnerability data.
- Args:
items: (List[Item]) Data loaded from the vulnerability file valid_area_peril_id: array of area_peril_id to be included (if none, all are included)
- Returns: (Tuple[Dict[int, int], List[int], Dict[int, int], List[Tuple[int, int]], List[int]])
vulnerability dictionary, vulnerability IDs, areaperil to vulnerability index dictionary, areaperil ID to vulnerability index array, areaperil ID to vulnerability array
- oasislmf.pytools.getmodel.manager.get_items(input_path, ignore_file_type=set(), valid_area_peril_id=None)[source]¶
Loads the items from the items file.
- Args:
input_path: (str) the path pointing to the file ignore_file_type: set(str) file extension to ignore when loading
- Returns: (Tuple[Dict[int, int], List[int], Dict[int, int], List[Tuple[int, int]], List[int]])
vulnerability dictionary, vulnerability IDs, areaperil to vulnerability index dictionary, areaperil ID to vulnerability index array, areaperil ID to vulnerability array
- oasislmf.pytools.getmodel.manager.get_intensity_bin_dict(input_path)[source]¶
Loads the intensity bin dictionary file and creates a dictionary to map intensities to bins Used in the dynamic footprint generation as intensitys can be adjusted for defences at runtime
- Args:
input_path: (str) the path pointing to the file
- Returns: (Dict[int, int])
intensity bin dict, with intensity value and bin index
- oasislmf.pytools.getmodel.manager.load_vulns_bin_idx(vulns_bin, vulns_idx_bin, vuln_dict, num_damage_bins, num_intensity_bins, rowsize)[source]¶
Loads the vulnerability binary index file.
- Args:
vulns_bin: (List[VulnerabilityRow]) vulnerability data from the vulnerability file vulns_idx_bin: (List[VulnerabilityIndex]) vulnerability index data from the vulnerability idx file vuln_dict: (Dict[int, int]) maps the vulnerability ID with the index in the vulnerability array num_damage_bins: (int) number of damage bins in the data num_intensity_bins: (int) the number of intensity bins
Returns: (List[List[List[floats]]]) vulnerability data grouped by intensity bin and damage bin
- oasislmf.pytools.getmodel.manager.load_vulns_bin_idx_adjusted(vulns_bin, vulns_idx_bin, vuln_dict, num_damage_bins, num_intensity_bins, rowsize, adj_vuln_data=None)[source]¶
Loads the vulnerability binary index file, prioritizing the data in the adjustments file over the data in the vulnerability file.
- Args:
vulns_bin: (List[VulnerabilityRow]) vulnerability data from the vulnerability file vulns_idx_bin: (List[VulnerabilityIndex]) vulnerability index data from the vulnerability idx file vuln_dict: (Dict[int, int]) maps the vulnerability ID with the index in the vulnerability array num_damage_bins: (int) number of damage bins in the data num_intensity_bins: (int) the number of intensity bins adj_vuln_data: (List[Vulnerability]) vulnerability adjustment data, sorted by vuln_id
Returns: (List[List[List[floats]]]) vulnerability data grouped by intensity bin and damage bin
- oasislmf.pytools.getmodel.manager.load_vulns_bin(vulns_bin, vuln_dict, num_damage_bins, num_intensity_bins)[source]¶
Loads the vulnerability data grouped by the intensity and damage bins.
- Args:
vuln_bin: (List[Vulnerability]) vulnerability data from the vulnerability file vuln_dict: (Dict[int, int]) maps the vulnerability ID with the index in the vulnerability array num_damage_bins: (int) number of damage bins in the data num_intensity_bins: (int) the number of intensity bins
Returns: (List[List[List[floats]]]) vulnerability data grouped by intensity bin and damage bin
- oasislmf.pytools.getmodel.manager.load_vulns_bin_adjusted(vulns_bin, vuln_dict, num_damage_bins, num_intensity_bins, adj_vuln_data=None)[source]¶
Loads the vulnerability data grouped by the intensity and damage bins, prioritizing the data in the adjustments file over the data in the vulnerability file.
- Args:
vuln_bin: (List[Vulnerability]) vulnerability data from the vulnerability file vuln_dict: (Dict[int, int]) maps the vulnerability ID with the index in the vulnerability array num_damage_bins: (int) number of damage bins in the data num_intensity_bins: (int) the number of intensity bins adj_vuln_data: (List[Vulnerability]) vulnerability adjustment data, sorted by vuln_id
Returns: (List[List[List[floats]]]) vulnerability data grouped by intensity bin and damage bin
- oasislmf.pytools.getmodel.manager.update_vulns_dictionary(vuln_dict, vulns_id_array)[source]¶
Updates the indexes of the vulnerability IDs (usually used in loading vulnerability data from parquet file).
- Args:
vuln_dict: (Dict[int, int]) vulnerability dict that maps the vulnerability IDs (key) with the index (value) vulns_id_array: (List[int]) list of vulnerability IDs loaded from the parquet file
- oasislmf.pytools.getmodel.manager.update_vuln_array_with_adj_data(vuln_array, vuln_dict, adj_vuln_data)[source]¶
Update the vulnerability array with adjustment data (used for parquet loading).
- Args:
vuln_array: (3D array) The vulnerability data array. vuln_dict: (Dict[int, int]) Maps vulnerability IDs to indices in vuln_array. adj_vuln_data: (List[Vulnerability]) The vulnerability adjustment data.
Returns: (3D array) The updated vulnerability data array.
- oasislmf.pytools.getmodel.manager.create_vulns_id(vuln_dict)[source]¶
Creates a vulnerability array where the index of the array correlates with the index of the vulnerability.
- Args:
vuln_dict: (Dict) maps the vulnerability of the id (key) with the vulnerability ID (value)
Returns: (List[int]) list of vulnerability IDs
- oasislmf.pytools.getmodel.manager.get_vuln_rngadj_dict(run_dir, vuln_dict)[source]¶
Loads vulnerability adjustments from the analysis settings file.
- Args:
run_dir (str): path to the run directory (used to load the analysis settings)
Returns: (Dict[nb_int32, nb_float64]) vulnerability adjustments dictionary
- oasislmf.pytools.getmodel.manager.get_vulns(storage: oasis_data_manager.filestore.backends.base.BaseStorage, run_dir, vuln_dict, num_intensity_bins, ignore_file_type=set(), df_engine='oasis_data_manager.df_reader.reader.OasisPandasReader')[source]¶
Loads the vulnerabilities from the file.
- Args:
storage: (str) the storage manager for fetching model data run_dir: (str) the path to the run folder (used to load the analysis settings) vuln_dict: (Dict[int, int]) maps the vulnerability ID with the index in the vulnerability array num_intensity_bins: (int) the number of intensity bins ignore_file_type: set(str) file extension to ignore when loading
Returns: (Tuple[List[List[float]], int, np.array[int]) vulnerability data, vulnerabilities id, number of damage bins
- oasislmf.pytools.getmodel.manager.get_vulnerability_replacements(run_dir, vuln_dict)[source]¶
Loads the vulnerability adjustment file.
- Args:
path: (str) the path pointing to the run directory vuln_dict: (Dict[int, int]) list of vulnerability IDs
Returns: (List[Vulnerability]) vulnerability replacement data
- oasislmf.pytools.getmodel.manager.get_mean_damage_bins(storage: oasis_data_manager.filestore.backends.base.BaseStorage, ignore_file_type=set())[source]¶
Loads the mean damage bins from the damage_bin_dict file, namely, the interpolation value for each bin.
- Args:
storage: (BaseStorage) the storage connector for fetching the model data ignore_file_type: set(str) file extension to ignore when loading
Returns: (List[Union[damagebindictionary]]) loaded data from the damage_bin_dict file
- oasislmf.pytools.getmodel.manager.get_damage_bins(storage: oasis_data_manager.filestore.backends.base.BaseStorage, ignore_file_type=set())[source]¶
Loads the damage bins from the damage_bin_dict file.
- Args:
storage: (BaseStorage) the storage connector for fetching the model data ignore_file_type: set(str) file extension to ignore when loading
Returns: (List[Union[damagebindictionary]]) loaded data from the damage_bin_dict file
- oasislmf.pytools.getmodel.manager.damage_bin_prob(p, intensities_min, intensities_max, vulns, intensities)[source]¶
Calculate the probability of an event happening and then causing damage. Note: vulns is a 1-d array containing 1 damage bin of the damage probability distribution as a function of hazard intensity.
- Args:
p: (float) the probability to be updated intensities_min: (int) minimum intensity bin id intensities_max: (int) maximum intensity bin id vulns: (List[float]) slice of damage probability distribution given hazard intensity intensities: (List[float]) intensity probability distribution
Returns: (float) the updated probability
- oasislmf.pytools.getmodel.manager.do_result(vulns_id, vuln_array, mean_damage_bins, int32_mv, num_damage_bins, intensities_min, intensities_max, intensities, event_id, areaperil_id, vuln_i, cursor)[source]¶
Calculate the result concerning an event ID.
- Args:
vulns_id: (List[int]) list of vulnerability IDs vuln_array: (List[List[list]]) list of vulnerabilities and their data mean_damage_bins: (List[float]) the mean of each damage bin (len(mean_damage_bins) == num_damage_bins) int32_mv: (List[int]) FILL IN LATER num_damage_bins: (int) number of damage bins in the data intensities_min: (int) minimum intensity bin id intensities_max: (int) maximum intensity bin id intensities: (List[float]) intensity probability distribution event_id: (int) the event ID that concerns the result being calculated areaperil_id: (List[int]) the areaperil ID that concerns the result being calculated vuln_i: (int) the index concerning the vulnerability inside the vuln_array cursor: (int) PLEASE FILL IN
Returns: (int) PLEASE FILL IN
- oasislmf.pytools.getmodel.manager.doCdf(event_id, num_intensity_bins, footprint, areaperil_to_vulns_idx_dict, areaperil_to_vulns_idx_array, areaperil_to_vulns, vuln_array, vulns_id, num_damage_bins, mean_damage_bins, int32_mv, max_result_relative_size)[source]¶
Calculates the cumulative distribution function (cdf) for an event ID.
- Args:
event_id: (int) the event ID the the CDF is being calculated to. num_intensity_bins: (int) the number of intensity bins for the CDF footprint: (List[Tuple[int, int, float]]) information about the footprint with event_id, areaperil_id,
probability
areaperil_to_vulns_idx_dict: (Dict[int, int]) maps the areaperil ID with the ENTER_HERE areaperil_to_vulns_idx_array: (List[Tuple[int, int]]) the index where the areaperil ID starts and finishes areaperil_to_vulns: (List[int]) maps the areaperil ID to the vulnerability ID vuln_array: (List[list]) FILL IN LATER vulns_id: (List[int]) list of vulnerability IDs num_damage_bins: (int) number of damage bins in the data mean_damage_bins: (List[float]) the mean of each damage bin (len(mean_damage_bins) == num_damage_bins) int32_mv: (List[int]) FILL IN LATER max_result_relative_size: (int) the maximum result size
Returns: (int)
- oasislmf.pytools.getmodel.manager.run(run_dir, file_in, file_out, ignore_file_type, data_server, peril_filter, df_engine='oasis_data_manager.df_reader.reader.OasisPandasReader')[source]¶
Runs the main process of the getmodel process.
- Args:
run_dir: (str) the directory of where the process is running file_in: (Optional[str]) the path to the input directory file_out: (Optional[str]) the path to the output directory ignore_file_type: set(str) file extension to ignore when loading data_server: (bool) if set to True runs the data server peril_filter (list[int]): list of perils to include in the computation (if None, all perils will be included). df_engine: (str) The engine to use when loading dataframes
Returns: None