oasislmf.pytools.gul.manager¶
This file is the entry point for the gul command for the package.
Attributes¶
Functions¶
|
adjust buff size so that the buffer fits the longest coverage |
|
Load the coverages from the coverages file. |
|
Load the items from the items file. |
|
Generate item_map; requires items to be sorted. |
|
Execute the main gulpy worklow. |
|
Compute losses for an event. |
|
Write the computed losses. |
Module Contents¶
- oasislmf.pytools.gul.manager.adjust_byte_mv_size(byte_mv, max_bytes_per_coverage)[source]¶
adjust buff size so that the buffer fits the longest coverage Args:
byte_mv: numpy byte array max_bytes_per_coverage: max size possible to accommodate all the coverage in byte_mv
- Returns:
byte_mv: numpy byte array
- oasislmf.pytools.gul.manager.get_coverages(input_path, ignore_file_type=set())[source]¶
Load the coverages from the coverages file.
- Args:
input_path (str): the path containing the coverage file. ignore_file_type (Set[str]): file extension to ignore when loading.
- Returns:
numpy.array[oasis_float]: array with the coverage values for each coverage_id.
- oasislmf.pytools.gul.manager.gul_get_items(input_path, ignore_file_type=set())[source]¶
Load 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.gul.manager.generate_item_map(items, coverages)[source]¶
Generate item_map; requires items to be sorted.
- Args:
- items (numpy.ndarray[int32, int32, int32]): 1-d structured array storing
item_id, coverage_id, group_id for all items. items need to be sorted by increasing areaperil_id, vulnerability_id in order to output the items in correct order.
- Returns:
- item_map (Dict[ITEM_MAP_KEY_TYPE, ITEM_MAP_VALUE_TYPE]): dict storing
the mapping between areaperil_id, vulnerability_id to item.
- oasislmf.pytools.gul.manager.run(run_dir, ignore_file_type, sample_size, loss_threshold, alloc_rule, debug, random_generator, peril_filter=[], file_in=None, file_out=None, ignore_correlation=False, **kwargs)[source]¶
Execute the main gulpy 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 (bool): if True, for each random sample, print to the output stream the random value
instead of the loss.
random_generator (int): random generator function id. file_in (str, optional): filename of input stream. Defaults to None. file_out (str, optional): filename of output stream. Defaults to None. ignore_correlation (bool): if True, do not compute correlated random samples.
- Raises:
ValueError: if alloc_rule is not 0, 1, or 2.
- Returns:
int: 0 if no errors occurred.
- oasislmf.pytools.gul.manager.compute_event_losses(event_id, coverages, coverage_ids, items_data, last_processed_coverage_ids_idx, sample_size, recs, rec_idx_ptr, damage_bins, loss_threshold, losses, alloc_rule, do_correlation, rndms_base, eps_ij, corr_data_by_item_id, arr_min, arr_max, arr_N, norm_inv_cdf, arr_min_cdf, arr_max_cdf, norm_cdf, z_unif, debug, max_bytes_per_item, byte_mv, cursor)[source]¶
Compute losses for an event.
- Args:
event_id (int32): event id. 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_data (numpy.array[items_data_type]): items-related data. last_processed_coverage_ids_idx (int): index of the last coverage_id stored in coverage_ids that was fully processed
and printed to the output stream.
sample_size (int): number of random samples to draw. recs (numpy.array[ProbMean]): all the cdfs used in event_id. rec_idx_ptr (numpy.array[int]): array with the indices of rec where each cdf record starts. damage_bins (List[Union[damagebindictionaryCsv, damagebindictionary]]): loaded data from the damage_bin_dict file. loss_threshold (float): threshold above which losses are printed to the output stream. losses (numpy.array[oasis_float]): array (to be re-used) to store losses for all item_ids. alloc_rule (int): back-allocation rule. do_correlation (bool): if True, compute correlated random samples. rndms (numpy.array[float64]): 2d array of shape (number of seeds, sample_size) storing the random values
drawn for each seed.
- debug (bool): if True, for each random sample, print to the output stream the random value
instead of the loss.
max_bytes_per_item (int): maximum bytes to be written in the output stream for an item. byte_mv (numpy.array): byte view of where the output is buffered. cursor (int): index of int32_mv where to start writing.
- Returns:
int, int: updated value of cursor, last last_processed_coverage_ids_idx
- oasislmf.pytools.gul.manager.write_losses(event_id, sample_size, loss_threshold, losses, item_ids, alloc_rule, tiv, byte_mv, cursor)[source]¶
Write the computed losses.
- Args:
event_id (int32): event id. sample_size (int): number of random samples to draw. loss_threshold (float): threshold above which losses are printed to the output stream. losses (numpy.array[oasis_float]): losses for all item_ids item_ids (numpy.array[ITEM_ID_TYPE]): ids of items whose losses are in losses. alloc_rule (int): back-allocation rule. tiv (oasis_float): total insured value. byte_mv (numpy.ndarray): byte view of where the output is buffered. cursor (int): index of int32_mv where to start writing.
- Returns:
int: updated values of cursor