oasislmf.pytools.lec.aggreports.write_tables¶
Functions¶
|
Get loss based on current and next return period |
|
Populate the Tail with retperiod and tvar values for summary_id |
|
Populate the Tail with retperiod and tvar values for (summary_id, sidx) pair |
|
Processes return periods and computes losses for a given summary, updating TVaR and mean map if required. |
|
Get TVaR values for EPT output from tail |
|
Get TVaR values for PSEPT output from tail |
|
Generate Loss Exceedance Curve values and Tail Value at Risk values based on items and epcalc/eptype/eptype_tvar |
|
Generate Loss Exceedance Curve values and Tail Value at Risk values based on items and epcalc/eptype/eptype_tvar. |
|
Generate Per Sample Exceedance Probability Tables (PSEPT) for each individual sample, producing a separate loss |
|
Generate Per Sample Exceedance Probability Tables (PSEPT) for each individual sample, producing a separate loss |
|
Generate Wheatsheaf Mean Exceedance Probability Table (EPT) by averaging losses for each return period |
Module Contents¶
- oasislmf.pytools.lec.aggreports.write_tables.get_loss(next_retperiod, last_retperiod, last_loss, curr_retperiod, curr_loss)[source]¶
Get loss based on current and next return period
- oasislmf.pytools.lec.aggreports.write_tables.fill_tvar(tail, tail_sizes, tail_offsets, summary_id, next_retperiod, tvar)[source]¶
Populate the Tail with retperiod and tvar values for summary_id
- Parameters:
tail (ndarray[TAIL_valtype]) – Flat array of (return period, tvar) values
tail_sizes (ndarray[int64]) – Array of current fill size per summary_id
tail_offsets (ndarray[int64]) – Array of start positions per summary_id in tail
summary_id (int) – Summary ID
next_retperiod (float) – Next Return Period
tvar (float) – Tail Value at Risk
- Returns:
Flat array of (return period, tvar) values tail_sizes (ndarray[int64]): Array of current fill size per summary_id
- Return type:
tail (ndarray[TAIL_valtype])
- oasislmf.pytools.lec.aggreports.write_tables.fill_tvar_wheatsheaf(tail, tail_sizes, tail_offsets, summary_id, sidx, num_sidxs, next_retperiod, tvar)[source]¶
Populate the Tail with retperiod and tvar values for (summary_id, sidx) pair
- Parameters:
tail (ndarray[TAIL_valtype]) – Flat array of (return period, tvar) values
tail_sizes (ndarray[int64]) – Array of current fill size per (summary_id, sidx) idx
tail_offsets (ndarray[int64]) – Array of start positions per idx in tail
summary_id (int) – Summary ID
sidx (int) – Sample ID
num_sidxs (int) – Number of sidxs to consider
next_retperiod (float) – Next Return Period
tvar (float) – Tail Value at Risk
- Returns:
Flat array of (return period, tvar) values tail_sizes (ndarray[int64]): Array of current fill size per (summary_id, sidx) idx
- Return type:
tail (ndarray[TAIL_valtype])
- oasislmf.pytools.lec.aggreports.write_tables.write_return_period_out(next_returnperiod_idx, last_computed_rp, last_computed_loss, curr_retperiod, curr_loss, summary_id, eptype, epcalc, max_retperiod, counter, tvar, tail, tail_sizes, tail_offsets, returnperiods, mean_map=None, is_wheatsheaf=False, num_sidxs=-1)[source]¶
Processes return periods and computes losses for a given summary, updating TVaR and mean map if required.
- Parameters:
next_returnperiod_idx (int) – Index of the next return period to process.
last_computed_rp (float) – Last computed return period
last_computed_loss (float) – Last computed loss value
curr_retperiod (float) – Current return period being processed.
curr_loss (float) – Loss associated with the current return period.
summary_id (int) – Identifier for the current summary.
eptype (int) – Type of exceedance probability (0 = OEP, 1 = AEP).
epcalc (int) – Type of exceedance probability calculation.
max_retperiod (int) – Maximum return period to be used in calculations
counter (int) – Counter used for updating TVaR
tvar (float) – Tail Value at Risk
tail (ndarray[TAIL_valtype]) – Flat array of (return period, tvar) values
tail_sizes (ndarray[int64]) – Array of current fill size per summary/idx
tail_offsets (ndarray[int64]) – Array of start positions per summary/idx in tail
returnperiods (ndarray[np.int32]) – Return Periods array
mean_map (ndarray[MEANMAP_dtype], optional) – An array mapping used for mean loss calculations per Summary ID. Used for EPT output later. Defaults to None.
is_wheatsheaf (bool, optional) – If True, update the wheatsheaf TVaR structure.
num_sidxs (int, optional) – Number of sidxs to consider. Defaults to -1 if not is_wheatsheaf.
- Returns:
Return period and Loss EPT data tail (ndarray[TAIL_valtype]): Flat array of (return period, tvar) values tail_sizes (ndarray[int64]): Array of current fill size per summary/idx last_computed_rp (float): Last computed return period last_computed_loss (float): Last computed loss value
- Return type:
rets (list[EPT_dtype])
- oasislmf.pytools.lec.aggreports.write_tables.write_tvar(epcalc, eptype_tvar, tail, tail_sizes, tail_offsets, max_summary_id)[source]¶
Get TVaR values for EPT output from tail
- Parameters:
epcalc (int) – Type of exceedance probability calculation.
eptype_tvar (int) – Type of Tail Value-at-Risk (TVAR) to calculate (0 = OEP TVAR, 1 = AEP TVAR).
tail (ndarray[TAIL_valtype]) – Flat array of (return period, tvar) values
tail_sizes (ndarray[int64]) – Array of current fill size per summary_id
tail_offsets (ndarray[int64]) – Array of start positions per summary_id in tail
max_summary_id (int) – Maximum summary ID
- Returns:
Return period and Loss EPT data
- Return type:
rets (ndarray[EPT_dtype])
- oasislmf.pytools.lec.aggreports.write_tables.write_tvar_wheatsheaf(num_sidxs, eptype_tvar, tail, tail_sizes, tail_offsets, total_idxs)[source]¶
Get TVaR values for PSEPT output from tail
- Parameters:
num_sidxs (int) – Number of sidxs to consider.
eptype_tvar (int) – Type of Tail Value-at-Risk (TVAR) to calculate (0 = OEP TVAR, 1 = AEP TVAR).
tail (ndarray[TAIL_valtype]) – Flat array of (return period, tvar) values
tail_sizes (ndarray[int64]) – Array of current fill size per (summary_id, sidx) idx
tail_offsets (ndarray[int64]) – Array of start positions per idx in tail
total_idxs (int) – Total number of (summary_id, sidx) index entries
- Returns:
Return period and Loss PSEPT data
- Return type:
rets (ndarray[PSEPT_dtype])
- oasislmf.pytools.lec.aggreports.write_tables.write_ept(buffer, items, items_start_end, max_retperiod, epcalc, eptype, eptype_tvar, use_return_period, returnperiods, max_summary_id, sample_size=1)[source]¶
Generate Loss Exceedance Curve values and Tail Value at Risk values based on items and epcalc/eptype/eptype_tvar
The loss calculation follows these principles: - For Aggregate Loss Exceedance Curves (AEP): The sum of all losses within a period is calculated. - For Occurrence Loss Exceedance Curves (OEP): The maximum loss within a period is taken. - TVAR (Tail Conditional Expectation): Calculated as the average of losses exceeding a given return period.
- Parameters:
items (ndarray[LOSSVEC2MAP_dtype]) – Array mapping summary_id to loss value (and period_no/period_weighting where applicable)
items_start_end (ndarray[np.int32]) – An array marking where the start and end idxs are for each summary_id in the items array
max_retperiod (int) – Maximum return period to be used in calculations
epcalc (int) – Specifies the calculation method (mean damage loss, full uncertainty, per sample mean, sample mean).
eptype (int) – Type of exceedance probability (0 = OEP, 1 = AEP).
eptype_tvar (int) – Type of Tail Value-at-Risk (TVAR) to calculate (0 = OEP TVAR, 1 = AEP TVAR).
use_return_period (bool) – Use Return Period file.
returnperiods (ndarray[np.int32]) – Return Periods array
max_summary_id (int) – Maximum summary ID
sample_size (int, optional) – Sample Size. Defaults to 1.
buffer (ndarray[EPT_dtype]) – Pre-allocated output buffer that rows are written into and yielded from in chunks
- Yields:
buffer (ndarray[EPT_dtype]) – Buffered chunks of EPT data
- oasislmf.pytools.lec.aggreports.write_tables.write_ept_weighted(buffer, items, items_start_end, cum_weight_constant, epcalc, eptype, eptype_tvar, unused_period_weights, use_return_period, returnperiods, max_summary_id, sample_size=1)[source]¶
Generate Loss Exceedance Curve values and Tail Value at Risk values based on items and epcalc/eptype/eptype_tvar.
This function calculates weighted exceedance probability tables using cumulative period weightings (period_weighting), which impact the calculation of return periods. The weighting allows for more accurate representation of losses when event periods have different probabilities or frequencies of occurrence.
The loss calculation follows these principles: - For Aggregate Loss Exceedance Curves (AEP): The sum of all losses within a period is calculated. - For Occurrence Loss Exceedance Curves (OEP): The maximum loss within a period is taken. - TVAR (Tail Conditional Expectation): Calculated as the average of losses exceeding a given return period.
- Parameters:
items (ndarray[LOSSVEC2MAP_dtype]) – Array mapping summary_id to loss value (and period_no/period_weighting where applicable)
items_start_end (ndarray[np.int32]) – An array marking where the start and end idxs are for each summary_id in the items array
cum_weight_constant (float) – Constant factor for scaling cumulative period weights.
epcalc (int) – Specifies the calculation method (mean damage loss, full uncertainty, per sample mean, sample mean).
eptype (int) – Type of exceedance probability (0 = OEP, 1 = AEP).
eptype_tvar (int) – Type of Tail Value-at-Risk (TVAR) to calculate (0 = OEP TVAR, 1 = AEP TVAR).
unused_period_weights (ndarray[float]) – Array of unused period weights
use_return_period (bool) – Use Return Period file.
returnperiods (ndarray[np.int32]) – Return Periods array
max_summary_id (int) – Maximum summary ID
sample_size (int, optional) – Sample Size. Defaults to 1.
buffer (ndarray[EPT_dtype]) – Pre-allocated output buffer that rows are written into and yielded from in chunks
- Yields:
buffer (ndarray[EPT_dtype]) – Buffered chunks of EPT data
- oasislmf.pytools.lec.aggreports.write_tables.write_psept(buffer, items, items_start_end, max_retperiod, eptype, eptype_tvar, use_return_period, returnperiods, max_summary_id, num_sidxs)[source]¶
Generate Per Sample Exceedance Probability Tables (PSEPT) for each individual sample, producing a separate loss exceedance curve for each sample, eptype, eptype_tvar.
- Parameters:
items (ndarray[WHEATKEYITEMS_dtype]) – Array mapping (summary_id, sidx) to loss value (and period_no/period_weighting where applicable)
items_start_end (ndarray[np.int32]) – An array marking where the start and end idxs are for each (summary_id, sidx) pair in the items array
max_retperiod (int) – Maximum return period to be used in calculations
eptype (int) – Type of exceedance probability (0 = OEP, 1 = AEP).
eptype_tvar (int) – Type of Tail Value-at-Risk (TVAR) to calculate (0 = OEP TVAR, 1 = AEP TVAR).
use_return_period (bool) – Use Return Period file.
returnperiods (ndarray[np.int32]) – Return Periods array
max_summary_id (int) – Maximum summary ID
num_sidxs (int) – Number of sidxs to consider
buffer (ndarray[PSEPT_dtype]) – Pre-allocated output buffer that rows are written into and yielded from in chunks
- Yields:
buffer (ndarray[PSEPT_dtype]) – Buffered chunks of PSEPT data
- oasislmf.pytools.lec.aggreports.write_tables.write_psept_weighted(buffer, items, items_start_end, max_retperiod, eptype, eptype_tvar, unused_period_weights, use_return_period, returnperiods, max_summary_id, num_sidxs, sample_size, mean_map=None)[source]¶
Generate Per Sample Exceedance Probability Tables (PSEPT) for each individual sample, producing a separate loss exceedance curve for each sample, eptype, eptype_tvar.
- Parameters:
items (ndarray[WHEATKEYITEMS_dtype]) – Array mapping (summary_id, sidx) to loss value (and period_no/period_weighting where applicable)
items_start_end (ndarray[np.int32]) – An array marking where the start and end idxs are for each (summary_id, sidx) pair in the items array
max_retperiod (int) – Maximum return period to be used in calculations
eptype (int) – Type of exceedance probability (0 = OEP, 1 = AEP).
eptype_tvar (int) – Type of Tail Value-at-Risk (TVAR) to calculate (0 = OEP TVAR, 1 = AEP TVAR).
unused_period_weights (ndarray[float]) – Array of unused period weights
use_return_period (bool) – Use Return Period file.
returnperiods (ndarray[np.int32]) – Return Periods array
max_summary_id (int) – Maximum summary ID
num_sidxs (int) – Number of sidxs to consider
sample_size (int) – Sample Size. Defaults to 1.
mean_map (ndarray[MEANMAP_dtype], optional) – An array mapping used for mean loss calculations per Summary ID. Used for EPT output later. Defaults to None.
buffer (ndarray[PSEPT_dtype]) – Pre-allocated output buffer that rows are written into and yielded from in chunks
- Yields:
buffer (ndarray[PSEPT_dtype]) – Buffered chunks of PSEPT data
- oasislmf.pytools.lec.aggreports.write_tables.write_wheatsheaf_mean(buffer, mean_map, eptype, epcalc, max_summary_id)[source]¶
Generate Wheatsheaf Mean Exceedance Probability Table (EPT) by averaging losses for each return period from a precomputed mean map.
- Parameters:
mean_map (ndarray[MEANMAP_dtype]) – An array mapping used for mean loss calculations per Summary ID.
epcalc (int) – Specifies the calculation method (mean damage loss, full uncertainty, per sample mean, sample mean).
eptype (int) – Type of exceedance probability (0 = OEP, 1 = AEP).
max_summary_id (int) – Maximum summary ID
buffer (ndarray[EPT_dtype]) – Pre-allocated output buffer that rows are written into and yielded from in chunks
- Yields:
buffer (ndarray[EPT_dtype]) – Buffered chunks of EPT data