oasislmf.pytools.gulmc.manager¶
Attributes¶
Functions¶
|
Generate structures needed to store and retrieve vulnerability cdf in the cache. |
|
Generate intensity adjustment array for dynamic footprint models. |
|
Loads vulnerability adjustments from the analysis settings file. |
|
Execute the main gulmc worklow. |
|
|
|
return the cumulative distribution from the probality distribution |
|
calculate the covoluted cumulative distribution between vulnerability damage and hazard probability distribution |
|
|
|
|
|
Compute losses for an event. |
|
Process all the areaperils in the footprint, filtering and retaining only those who have associated vulnerability functions |
|
Register each item to its coverage, with the location of the corresponding hazard intensity cdf |
Module Contents¶
- oasislmf.pytools.gulmc.manager.gen_empty_vuln_cdf_lookup(list_size, compute_info)[source]¶
Generate structures needed to store and retrieve vulnerability cdf in the cache.
- Args:
list_size (int): maximum number of cdfs to be stored in the cache.
- Returns:
- cached_vuln_cdf_lookup (Dict[VULN_LOOKUP_KEY_TYPE, VULN_LOOKUP_VALUE_TYPE]): dict to store
the map between vuln_id and intensity bin id and the location of the cdf in the cache.
cached_vuln_cdf_lookup_keys (List[VULN_LOOKUP_VALUE_TYPE]): list of lookup keys.
- oasislmf.pytools.gulmc.manager.get_dynamic_footprint_adjustments(input_path)[source]¶
Generate intensity adjustment array for dynamic footprint models.
- Args:
input_path (str): location of the generated adjustments file.
- Returns:
numpy array with itemid and adjustment factors
- oasislmf.pytools.gulmc.manager.get_vuln_rngadj(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.gulmc.manager.run(run_dir, ignore_file_type, sample_size, loss_threshold, alloc_rule, debug, random_generator, peril_filter=[], file_in=None, file_out=None, data_server=None, ignore_correlation=False, ignore_haz_correlation=False, effective_damageability=False, max_cached_vuln_cdf_size_MB=200, model_df_engine='oasis_data_manager.df_reader.reader.OasisPandasReader', dynamic_footprint=False, **kwargs)[source]¶
Execute the main gulmc worklow.
- Args:
run_dir (str): the directory of where the process is running ignore_file_type set(str): file extension to ignore when loading sample_size (int): number of random samples to draw. loss_threshold (float): threshold above which losses are printed to the output stream. alloc_rule (int): back-allocation rule. debug (int): for each random sample, print to the output stream the random loss (if 0), the random value used to draw
the hazard intensity sample (if 1), the random value used to draw the damage sample (if 2). Defaults to 0.
random_generator (int): random generator function id. peril_filter (list[int], optional): list of perils to include in the computation (if None, all perils will be included). Defaults to []. file_in (str, optional): filename of input stream. Defaults to None. file_out (str, optional): filename of output stream. Defaults to None. data_server (bool, optional): if True, run the data server. Defaults to None. ignore_correlation (bool, optional): if True, do not compute correlated random samples. Defaults to False. effective_damageability (bool, optional): if True, it uses effective damageability to draw damage samples instead of
using the full monte carlo approach (i.e., to draw hazard intensity first, then damage).
max_cached_vuln_cdf_size_MB (int, optional): size in MB of the in-memory cache to store and reuse vulnerability cdf. Defaults to 200. model_df_engine: (str) The engine to use when loading model dataframes
- Raises:
ValueError: if alloc_rule is not 0, 1, 2, or 3. ValueError: if alloc_rule is 1, 2, or 3 when debug is 1 or 2.
- Returns:
int: 0 if no errors occurred.
- oasislmf.pytools.gulmc.manager.get_haz_cdf(item_event_data, haz_cdf, haz_cdf_ptr, dynamic_footprint, intensity_adjustment, intensity_bin_dict)[source]¶
- oasislmf.pytools.gulmc.manager.pdf_to_cdf(pdf, empty_cdf)[source]¶
return the cumulative distribution from the probality distribution Args:
pdf (np.array[float]): probality distribution empty_cdf (np.array[float]): cumulative distribution buffer for output
- Returns:
cdf (np.array[float]): here we return only the valid part if needed
- oasislmf.pytools.gulmc.manager.calc_eff_damage_cdf(vuln_pdf, haz_pdf, eff_damage_cdf_empty)[source]¶
calculate the covoluted cumulative distribution between vulnerability damage and hazard probability distribution Args:
vuln_pdf (np.array[float]) : vulnerability damage probability distribution haz_pdf (np.array[float]): hazard probability distribution eff_damage_cdf_empty (np.array[float]): output buffer
- Returns:
eff_damage_cdf (np.array[float]): cdf is stored in eff_damage_cdf_empty, here we return only the valid part if needed
- oasislmf.pytools.gulmc.manager.cache_cdf(next_cached_vuln_cdf_i, cached_vuln_cdfs, cached_vuln_cdf_lookup, cached_vuln_cdf_lookup_keys, cdf, cdf_key)[source]¶
- oasislmf.pytools.gulmc.manager.get_gul_from_vuln_cdf(vuln_rval, vuln_cdf, Ndamage_bins, damage_bins, computation_tiv)[source]¶
- oasislmf.pytools.gulmc.manager.compute_event_losses(compute_info, coverages, coverage_ids, items_event_data, items, sample_size, haz_pdf, haz_arr_ptr, vuln_array, damage_bins, cached_vuln_cdf_lookup, cached_vuln_cdf_lookup_keys, cached_vuln_cdfs, agg_vuln_to_vuln_idxs, areaperil_vuln_idx_to_weight, losses, haz_rndms_base, vuln_rndms_base, vuln_adj, haz_eps_ij, damage_eps_ij, norm_inv_parameters, norm_inv_cdf, norm_cdf, vuln_z_unif, haz_z_unif, byte_mv, dynamic_footprint, intensity_bin_dict)[source]¶
Compute losses for an event.
- Args:
compute_info (ndarray): information on the state of the computation coverages (numpy.array[oasis_float]): array with the coverage values for each coverage_id. coverage_ids (numpy.array[int]): array of unique coverage ids used in this event. items_event_data (numpy.array[items_data_type]): items-related data. items (np.ndarray): items table merged with correlation parameters. sample_size (int): number of random samples to draw. haz_pdf (np.array[oasis_float]): hazard intensity cdf. haz_arr_ptr (np.array[int]): array with the indices where each cdf record starts in haz_cdf. vuln_array (np.array[float]): damage pdf for different vulnerability functions, as a function of hazard intensity. damage_bins (List[Union[damagebindictionaryCsv, damagebindictionary]]): loaded data from the damage_bin_dict file. cached_vuln_cdf_lookup (Dict[VULN_LOOKUP_KEY_TYPE, VULN_LOOKUP_VALUE_TYPE]): dict to store
the map between vuln_id and intensity bin id and the location of the cdf in the cache.
cached_vuln_cdf_lookup_keys (List[VULN_LOOKUP_VALUE_TYPE]): list of lookup keys. cached_vuln_cdfs (np.array[oasis_float]): vulnerability cdf cache. agg_vuln_to_vuln_idxs (dict[int, list[int]]): map between aggregate vulnerability id and the list of indices where the individual vulnerability_ids
that compose it are stored in vuln_array.
- areaperil_vuln_idx_to_weight (dict[AGG_VULN_WEIGHTS_KEY_TYPE, AGG_VULN_WEIGHTS_VAL_TYPE]): map between the areaperil id and the index where the vulnerability function
is stored in vuln_array and the vulnerability weight.
losses (numpy.array[oasis_float]): array (to be re-used) to store losses for each item. haz_rndms_base (numpy.array[float64]): 2d array of shape (number of seeds, sample_size) storing the random values
drawn for each seed for the hazard intensity sampling.
- vuln_rndms_base (numpy.array[float64]): 2d array of shape (number of seeds, sample_size) storing the random values
drawn for each seed for the damage sampling.
vuln_adj (np.array): map array between vulnerability_idx and the adjustment factor to be applied to the (random numbers extracted) vulnerability function. haz_eps_ij (np.array[float]): correlated random values of shape (number of seeds, sample_size) for hazard sampling. damage_eps_ij (np.array[float]): correlated random values of shape (number of seeds, sample_size) for damage sampling. norm_inv_parameters (NormInversionParameters): parameters for the Normal (Gaussian) inversion functionality. norm_inv_cdf (np.array[float]): inverse Gaussian cdf. norm_cdf (np.array[float]): Gaussian cdf. vuln_z_unif (np.array[float]): buffer to be re-used to store the correlated random values for vuln. haz_z_unif (np.array[float]): buffer to be re-used to store the correlated random values for haz. byte_mv (numpy.array): byte view of where the output is buffered. dynamic_footprint, intensity_bin_dict
- Returns:
True if processing is done else false
- oasislmf.pytools.gulmc.manager.process_areaperils_in_footprint(event_footprint, present_areaperils, dynamic_footprint)[source]¶
Process all the areaperils in the footprint, filtering and retaining only those who have associated vulnerability functions
- Args:
event_footprint (np.array[Event or EventCSV]): footprint, made of one or more event entries. present_areaperils (dict[int, int]): areaperil to vulnerability index dictionary. dynamic_footprint (boolean): true if there is dynamic_footprint
- Returns:
areaperil_ids (List[int]): list of all areaperil_ids present in the footprint. Nhaz_arr_this_event (int): number of hazard stored for this event. If zero, it means no items have losses in such event. areaperil_to_haz_arr_i (dict[int, int]): map between the areaperil_id and the hazard index in haz_arr_ptr. haz_pdf (np.array[oasis_float]): hazard intensity pdf. haz_arr_ptr (np.array[int]): array with the indices where each hazard intensities record starts in haz arrays (ie, haz_pdf).
- oasislmf.pytools.gulmc.manager.reconstruct_coverages(compute_info, areaperil_ids, areaperil_ids_map, areaperil_to_haz_arr_i, item_map, items, coverages, compute, haz_seeds, haz_peril_correlation_groups, haz_corr_seeds, vuln_seeds, damage_peril_correlation_groups, damage_corr_seeds, dynamic_footprint, byte_mv)[source]¶
Register each item to its coverage, with the location of the corresponding hazard intensity cdf in the footprint, compute the random seeds for the hazard intensity and vulnerability samples.
- Args:
dynamic_compute_info (dynamic_compute_info_type): ndarray that store all dynamic info on computation areaperil_ids (List[int]): list of all areaperil_ids present in the footprint. areaperil_ids_map (Dict[int, Dict[int, int]]) dict storing the mapping between each
areaperil_id and all the vulnerability ids associated with it.
areaperil_to_haz_arr_i (dict[int, int]): map between the areaperil_id and the hazard arr index. item_map (Dict[ITEM_MAP_KEY_TYPE, ITEM_MAP_VALUE_TYPE]): dict storing
the mapping between areaperil_id, vulnerability_id to item.
items (np.ndarray): items table merged with correlation parameters. coverages (numpy.array[oasis_float]): array with the coverage values for each coverage_id. compute (numpy.array[int]): list of coverage ids to be computed. haz_seeds (numpy.array[int]): the random seeds to draw the hazard intensity samples. haz_peril_correlation_groups (numpy.array[int]): unique peril_correlation_groups for hazard haz_corr_seeds (numpy.array[int]): empty buffer to write hazard_corr_seeds vuln_seeds (numpy.array[int]): the random seeds to draw the damage samples. damage_peril_correlation_groups (numpy.array[int]): unique peril_correlation_groups for damage damage_corr_seeds (numpy.array[int]): empty buffer to write damage_corr_seeds dynamic_footprint (bollean): true if dynamic_footprint is on byte_mv : writing buffer
- Returns:
compute_i (int): index of the last coverage id stored in compute. items_data (numpy.array[items_MC_data_type]): item-related data. rng_index (int): number of unique random seeds for damage sampling computed so far. hazard_rng_index (int): number of unique random seeds for hazard intensity sampling computed so far. byte_mv : writing buffer with increased size if needed