oasislmf.preparation.summaries

Attributes

Functions

get_useful_summary_cols(oed_hierarchy)

get_xref_df(il_inputs_df)

get_summary_mapping(inputs_df, oed_hierarchy[, ...])

Create a DataFrame with linking information between Ktools OasisFiles

merge_oed_to_mapping(summary_map_df, exposure_df, ...)

Create a factorized col (summary ids) based on a list of oed column names

write_summary_levels(exposure_df, accounts_df, ...)

Json file with list Available / Recommended columns for use in the summary reporting

write_mapping_file(sum_inputs_df, target_dir[, ...])

Writes a summary map file, used to build summarycalc xref files.

get_ri_inuring_priority_output_levels(run_dir)

Load the mapping from OED InuringPriority to RI output level from the input directory.

generate_summaryxref_files(location_df, account_df, ...)

Top level function for creating the summaryxref files from the manager.py

get_exposure_summary(exposure_df, keys_df[, ...])

Create exposure summary as dictionary of TIVs and number of locations

write_exposure_summary(target_dir, exposure_df, ...[, ...])

Create exposure summary as dictionary of TIVs and number of locations

Module Contents

oasislmf.preparation.summaries.get_useful_summary_cols(oed_hierarchy)[source]
oasislmf.preparation.summaries.calculated_summary_cols[source]
oasislmf.preparation.summaries.get_xref_df(il_inputs_df)[source]
oasislmf.preparation.summaries.get_summary_mapping(inputs_df, oed_hierarchy, is_fm_summary=False)[source]

Create a DataFrame with linking information between Ktools OasisFiles And the Exposure data

Parameters:
  • inputs_df (pandas.DataFrame) – datafame from gul_inputs.get_gul_input_items(..) / il_inputs.get_il_input_items(..)

  • oed_hierarchy (dict) – OED profile hierarchy, used to resolve the acc/loc/pol/port column names to keep

  • is_fm_summary (bool) – Indicates whether an FM summary mapping is required

Returns:

Subset of columns from gul_inputs_df / il_inputs_df

Return type:

pandas.DataFrame

oasislmf.preparation.summaries.merge_oed_to_mapping(summary_map_df, exposure_df, oed_column_join, oed_column_info)[source]

Create a factorized col (summary ids) based on a list of oed column names

{‘Col_A’: 0, ‘Col_B’: 1, ‘Col_C’: 2}

Parameters:
  • summary_map_df (pandas.DataFrame) – dataframe return from get_summary_mapping

  • exposure_df (pandas.DataFrame) – Summary map file path

  • oed_column_join (list) – column to join on

  • oed_column_info (dict) – Dictionary of columns to pick from exposure_df and their default value

Returns:

New DataFrame of summary_map_df + exposure_df merged on exposure index

Return type:

pandas.DataFrame

oasislmf.preparation.summaries.write_summary_levels(exposure_df, accounts_df, exposure_data, target_dir)[source]

Json file with list Available / Recommended columns for use in the summary reporting

Available: Columns which exists in input files and has at least one non-zero / NaN value Recommended: Columns which are available + also in the list of useful groupings SUMMARY_LEVEL_LOC

{
‘GUL’: {
‘available’: [‘AccNumber’,

‘LocNumber’, ‘istenant’, ‘buildingid’, ‘countrycode’, ‘latitude’, ‘longitude’, ‘streetaddress’, ‘postalcode’, ‘occupancycode’, ‘constructioncode’, ‘locperilscovered’, ‘BuildingTIV’, ‘ContentsTIV’, ‘BITIV’, ‘PortNumber’],

‘IL’: {

… etc …

}

}

oasislmf.preparation.summaries.write_mapping_file(sum_inputs_df, target_dir, is_fm_summary=False)[source]

Writes a summary map file, used to build summarycalc xref files.

Parameters:
  • sum_inputs_df (pandas.DataFrame) – dataframe return from get_summary_mapping

  • target_dir (str) – directory the summary map file is written to

  • is_fm_summary (bool) – Indicates whether an FM summary mapping is required

Returns:

Summary xref file path

Return type:

str

oasislmf.preparation.summaries.get_ri_inuring_priority_output_levels(run_dir)[source]

Load the mapping from OED InuringPriority to RI output level from the input directory.

The mapping is created during input generation and records, for each OED InuringPriority value, the index of the last RI layer (output level) that belongs to that priority. When an InuringPriority spans multiple risk levels (e.g. LOC and ACC), its output level is the highest RI layer index among those risk levels.

Parameters:

run_dir (str) – Directory containing ri_inuring_priority_output_levels.json

Returns:

mapping {inuring_priority: output_level} with integer keys/values

Return type:

dict

oasislmf.preparation.summaries.generate_summaryxref_files(location_df, account_df, model_run_fp, analysis_settings, il=False, ri=False, rl=False, intermediary_csv=False)[source]

Top level function for creating the summaryxref files from the manager.py

Parameters:
  • location_df (pandas.DataFrame) – Source locations, joined to the summary map to build the summary groupings and their description files

  • account_df (pandas.DataFrame) – Source accounts, joined the same way. Required for the il, ri and rl summary levels

  • model_run_fp (str) – Model run directory file path

  • analysis_settings (dict) – Model analysis settings file

  • il (bool) – Boolean to indicate the insured loss level mode - false if the source accounts file path not provided to Oasis files gen.

  • ri (bool) – Boolean to indicate the RI loss level mode - false if the source accounts file path not provided to Oasis files gen.

  • rl (bool) – Boolean to indicate the RL loss level mode - false if the source accounts file path not provided to Oasis files gen.

  • intermediary_csv (bool) – If True, also write a csv copy of each summaryxref file alongside the binary

oasislmf.preparation.summaries.get_exposure_summary(exposure_df, keys_df, exposure_profile=get_default_exposure_profile(), additional_fields=[])[source]

Create exposure summary as dictionary of TIVs and number of locations grouped by peril and validity respectively. returns a python dict().

Parameters:
  • exposure_df (pandas.DataFrame) – source exposure dataframe

  • keys_df (pandas.DataFrame) – dataFrame holding keys data (success and errors)

  • exposure_profile (dict) – profile defining exposure file

  • additional_fields (list) – extra exposure columns to group the summary by, on top of loc_id

Returns:

Exposure summary dictionary

Return type:

dict

oasislmf.preparation.summaries.write_exposure_summary(target_dir, exposure_df, keys_fp, keys_errors_fp, exposure_profile, additional_fields=[])[source]

Create exposure summary as dictionary of TIVs and number of locations grouped by peril and validity respectively. Writes dictionary as json file to disk.

Parameters:
  • target_dir (str) – directory on disk to write exposure summary file

  • exposure_df (pandas.DataFrame) – source exposure dataframe

  • keys_fp (str) – file path to keys file

  • keys_errors_fp (str) – file path to keys errors file

  • exposure_profile (dict) – profile defining exposure file

  • additional_fields (list[str]) – list of additional OED fields to add to exposure summary file

Returns:

Exposure summary file path

Return type:

str