oasislmf.pytools.lec.manager

Attributes

Functions

read_input_files(run_dir, use_return_period, ...)

Reads all input files and returns a dict of relevant data

get_max_summary_id(file_handles)

Get max summary_id from all summary files

do_lec_output_agg_summary(summary_id, sidx, loss, ...)

Populate outloss_mean and outloss_sample with aggregate and max losses

process_summary_entries(fin, offsets, occ_csr, ...)

Process all indexed event blocks for one (summary_id, file) pair in a single call.

build_merged_idx(idx_handles)

Merge per-file .idx memmaps into one array sorted by summary_id.

process_input_file(fin, outloss_mean, row_used_mean, ...)

Process summary file and populate outloss_mean and outloss_sample with losses

run_lec(file_handles, outloss_mean, row_used_mean, ...)

Process each summary file and populate outloss_mean and outloss_sample

run(run_dir, subfolder[, ept_output_file, ...])

Runs LEC calculations

main([run_dir, subfolder, ept, psept, ...])

Module Contents

oasislmf.pytools.lec.manager.logger[source]
oasislmf.pytools.lec.manager.read_input_files(run_dir, use_return_period, agg_wheatsheaf_mean, occ_wheatsheaf_mean, sample_size)[source]

Reads all input files and returns a dict of relevant data

Parameters:
  • run_dir (str | os.PathLike) – Path to directory containing required files structure

  • use_return_period (bool) – Use Return Period file.

  • agg_wheatsheaf_mean (bool) – Aggregate Wheatsheaf Mean.

  • occ_wheatsheaf_mean (bool) – Occurrence Wheatsheaf Mean.

  • sample_size (int) – Sample Size.

Returns:

A dict of relevent data extracted from files use_return_period (bool): Use Return Period file. agg_wheatsheaf_mean (bool): Aggregate Wheatsheaf Mean. occ_wheatsheaf_mean (bool): Occurrence Wheatsheaf Mean.

Return type:

file_data (Dict[str, Any])

oasislmf.pytools.lec.manager.get_max_summary_id(file_handles)[source]

Get max summary_id from all summary files

Parameters:

file_handles (List[np.memmap]) – List of memmaps for summary files data

Returns:

Max summary ID

Return type:

max_summary_id (int)

oasislmf.pytools.lec.manager.do_lec_output_agg_summary(summary_id, sidx, loss, filtered_occ_map, outloss_mean, row_used_mean, outloss_sample, row_used_sample, num_sidxs, max_summary_id)[source]

Populate outloss_mean and outloss_sample with aggregate and max losses

Parameters:
  • summary_id (oasis_int) – summary_id

  • sidx (oasis_int) – Sample ID

  • loss (oasis_float) – Loss value

  • filtered_occ_map (ndarray[occ_map_dtype]) – Filtered numpy map of event_id, period_no, occ_date_id from the occurrence file_

  • outloss_mean (ndarray[OUTLOSS_DTYPE]) – ndarray indexed by summary_id, period_no containing aggregate and max losses

  • row_used_mean (ndarray[bool]) – bool mask for outloss_mean

  • outloss_sample (ndarray[OUTLOSS_DTYPE]) – ndarray indexed by summary_id, sidx, period_no containing aggregate and max losses

  • row_used_sample (ndarray[bool]) – bool mask for outloss_sample

  • num_sidxs (int) – Number of sidxs to consider for outloss_sample

  • max_summary_id (int) – Max summary ID

oasislmf.pytools.lec.manager.process_summary_entries(fin, offsets, occ_csr, use_return_period, outloss_mean_s, row_used_mean_s, outloss_sample_s, row_used_sample_s, num_sidxs)[source]

Process all indexed event blocks for one (summary_id, file) pair in a single call.

Eliminates per-event Python→numba overhead by looping over all offsets inside numba. offsets should be sorted ascending for best OS page-cache utilisation.

oasislmf.pytools.lec.manager.build_merged_idx(idx_handles)[source]

Merge per-file .idx memmaps into one array sorted by summary_id.

oasislmf.pytools.lec.manager.process_input_file(fin, outloss_mean, row_used_mean, outloss_sample, row_used_sample, occ_csr, use_return_period, num_sidxs, max_summary_id)[source]

Process summary file and populate outloss_mean and outloss_sample with losses

Parameters:
  • fin (np.memmap) – summary binary memmap

  • outloss_mean (ndarray[OUTLOSS_DTYPE]) – ndarray indexed by summary_id, period_no containing aggregate and max losses

  • row_used_mean (ndarray[bool]) – bool mask for outloss_mean

  • outloss_sample (ndarray[OUTLOSS_DTYPE]) – ndarray indexed by summary_id, sidx, period_no containing aggregate and max losses

  • row_used_sample (ndarray[bool]) – bool mask for outloss_sample

  • occ_csr (OccurrenceCSR) – id_index-backed CSR occurrence map

  • use_return_period (bool) – Use Return Period file.

  • num_sidxs (int) – Number of sidxs to consider for outloss_sample

  • max_summary_id (int) – Max summary ID

oasislmf.pytools.lec.manager.run_lec(file_handles, outloss_mean, row_used_mean, outloss_sample, row_used_sample, occ_csr, use_return_period, num_sidxs, max_summary_id)[source]

Process each summary file and populate outloss_mean and outloss_sample

Parameters:
  • file_handles (List[np.memmap]) – List of memmaps for summary files data

  • outloss_mean (ndarray[OUTLOSS_DTYPE]) – ndarray indexed by summary_id, period_no containing aggregate and max losses

  • row_used_mean (ndarray[bool]) – bool mask for outloss_mean

  • outloss_sample (ndarray[OUTLOSS_DTYPE]) – ndarray indexed by summary_id, sidx, period_no containing aggregate and max losses

  • row_used_sample (ndarray[bool]) – bool mask for outloss_sample

  • occ_csr (OccurrenceCSR) – id_index-backed CSR occurrence map

  • use_return_period (bool) – Use Return Period file.

  • num_sidxs (int) – Number of sidxs to consider for outloss_sample

  • max_summary_id (int) – Max summary ID

oasislmf.pytools.lec.manager.run(run_dir, subfolder, ept_output_file=None, psept_output_file=None, agg_full_uncertainty=False, agg_wheatsheaf=False, agg_sample_mean=False, agg_wheatsheaf_mean=False, occ_full_uncertainty=False, occ_wheatsheaf=False, occ_sample_mean=False, occ_wheatsheaf_mean=False, use_return_period=False, noheader=False, output_format='csv')[source]

Runs LEC calculations

Parameters:
  • run_dir (str | os.PathLike) – Path to directory containing required files structure

  • subfolder (str) – Workspace subfolder inside <run_dir>/work/<subfolder>

  • ept_output_file (str, optional) – Path to EPT output file. Defaults to None

  • psept_output_file (str, optional) – Path to PSEPT output file. Defaults to None

  • agg_full_uncertainty (bool, optional) – Aggregate Full Uncertainty. Defaults to False.

  • agg_wheatsheaf (bool, optional) – Aggregate Wheatsheaf. Defaults to False.

  • agg_sample_mean (bool, optional) – Aggregate Sample Mean. Defaults to False.

  • agg_wheatsheaf_mean (bool, optional) – Aggregate Wheatsheaf Mean. Defaults to False.

  • occ_full_uncertainty (bool, optional) – Occurrence Full Uncertainty. Defaults to False.

  • occ_wheatsheaf (bool, optional) – Occurrence Wheatsheaf. Defaults to False.

  • occ_sample_mean (bool, optional) – Occurrence Sample Mean. Defaults to False.

  • occ_wheatsheaf_mean (bool, optional) – Occurrence Wheatsheaf Mean. Defaults to False.

  • use_return_period (bool, optional) – Use Return Period file. Defaults to False.

  • noheader (bool) – Boolean value to skip header in output file

  • output_format (str) – Output format extension. Defaults to “csv”.

oasislmf.pytools.lec.manager.main(run_dir='.', subfolder=None, ept=None, psept=None, agg_full_uncertainty=False, agg_wheatsheaf=False, agg_sample_mean=False, agg_wheatsheaf_mean=False, occ_full_uncertainty=False, occ_wheatsheaf=False, occ_sample_mean=False, occ_wheatsheaf_mean=False, use_return_period=False, noheader=False, ext='csv', **kwargs)[source]