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 items from the items file. |
|
Generate item_map as a hashmap + jagged array; 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
- Parameters:
byte_mv – numpy byte array
max_bytes_per_coverage – max size possible to accommodate all the coverage in byte_mv
- Returns:
numpy byte array
- Return type:
byte_mv
- oasislmf.pytools.gul.manager.gul_get_items(input_path, ignore_file_type=set())[source]¶
Load the items from the items file.
- Parameters:
- 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 as a hashmap + jagged array; requires items to be sorted.
- Items must be sorted by (areaperil_id, vulnerability_id). Builds:
hashmap: (areaperil_id, vulnerability_id) → pair_index
jagged: pair_index → item indices via ja_offsets / ja_item_idxs
- Parameters:
items (numpy.ndarray) – 1-d structured array sorted by (areaperil_id, vulnerability_id).
coverages (numpy.ndarray) – coverage id to information on items.
- Returns:
packed hashmap table. item_map_hm_keys (np.array[item_map_key_dtype]): key storage for the hashmap. item_map_ja_offsets (np.array[oasis_int]): CSR offsets (N_pairs + 1).
- Return type:
item_map_hm (np.array[uint8])
- 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.
- Parameters:
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.
peril_filter (list[int], optional) – list of perils to include in the computation (all included if empty). Defaults to [].
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.
**kwargs – additional keyword arguments, accepted and ignored so that callers can forward a wider parameter dict.
- Raises:
ValueError – if alloc_rule is not 0, 1, or 2.
- Returns:
0 if no errors occurred.
- Return type:
- 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_inv_factor, norm_inv_cdf, arr_min_cdf, arr_norm_factor, norm_cdf, z_unif, debug, max_bytes_per_item, byte_mv, cursor)[source]¶
Compute losses for an event.
- Parameters:
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_base (numpy.array[float64]) – 2d array of shape (number of seeds, sample_size) storing the random values drawn for each seed.
eps_ij (np.array[float]) – correlated random values for damage sampling.
corr_data_by_item_id (np.array[correlations_dtype]) – correlation values by item id.
arr_min (float) – minimum value of the inverse Gaussian cdf lookup table.
arr_inv_factor (float) – scaling factor to index the inverse Gaussian cdf lookup table.
norm_inv_cdf (np.array[float]) – inverse Gaussian cdf lookup table.
arr_min_cdf (float) – minimum value of the Gaussian cdf lookup table.
arr_norm_factor (float) – scaling factor to index the Gaussian cdf lookup table.
norm_cdf (np.array[float]) – Gaussian cdf lookup table.
z_unif (np.array[float]) – reusable buffer for correlated random values.
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:
updated value of cursor, last last_processed_coverage_ids_idx
- Return type:
- 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.
- Parameters:
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:
updated values of cursor
- Return type: