oasislmf.preparation.summaries ============================== .. py:module:: oasislmf.preparation.summaries Functions --------- .. autoapisummary:: oasislmf.preparation.summaries.get_useful_summary_cols oasislmf.preparation.summaries.get_xref_df oasislmf.preparation.summaries.get_summary_mapping oasislmf.preparation.summaries.merge_oed_to_mapping oasislmf.preparation.summaries.write_summary_levels oasislmf.preparation.summaries.write_mapping_file oasislmf.preparation.summaries.generate_summaryxref_files oasislmf.preparation.summaries.get_exposure_summary oasislmf.preparation.summaries.write_exposure_summary Module Contents --------------- .. py:function:: get_useful_summary_cols(oed_hierarchy) .. py:function:: get_xref_df(il_inputs_df) .. py:function:: get_summary_mapping(inputs_df, oed_hierarchy, is_fm_summary=False) Create a DataFrame with linking information between Ktools `OasisFiles` And the Exposure data :param inputs_df: datafame from gul_inputs.get_gul_input_items(..) / il_inputs.get_il_input_items(..) :type inputs_df: pandas.DataFrame :param is_fm_summary: Indicates whether an FM summary mapping is required :type is_fm_summary: bool :return: Subset of columns from gul_inputs_df / il_inputs_df :rtype: pandas.DataFrame .. py:function:: merge_oed_to_mapping(summary_map_df, exposure_df, oed_column_join, oed_column_info) Create a factorized col (summary ids) based on a list of oed column names :param :summary_map_df dataframe return from get_summary_mapping :type summary_map_df: pandas.DataFrame :param exposure_df: Summary map file path :type exposure_df: pandas.DataFrame :param oed_column_join: column to join on :type oed_column_join: list :param oed_column_info: Dictionary of columns to pick from exposure_df and their default value :type oed_column_info: dict {'Col_A': 0, 'Col_B': 1, 'Col_C': 2} :return: New DataFrame of summary_map_df + exposure_df merged on exposure index :rtype: pandas.DataFrame .. py:function:: write_summary_levels(exposure_df, accounts_df, exposure_data, target_dir) 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 ... } } .. py:function:: write_mapping_file(sum_inputs_df, target_dir, is_fm_summary=False) Writes a summary map file, used to build summarycalc xref files. :param summary_mapping: dataframe return from get_summary_mapping :type summary_mapping: pandas.DataFrame :param sum_mapping_fp: Summary map file path :type sum_mapping_fp: str :param is_fm_summary: Indicates whether an FM summary mapping is required :type is_fm_summary: bool :return: Summary xref file path :rtype: str .. py:function:: generate_summaryxref_files(location_df, account_df, model_run_fp, analysis_settings, il=False, ri=False, rl=False, gul_item_stream=False, fmpy=False) Top level function for creating the summaryxref files from the manager.py :param model_run_fp: Model run directory file path :type model_run_fp: str :param analysis_settings: Model analysis settings file :type analysis_settings: dict :param il: Boolean to indicate the insured loss level mode - false if the source accounts file path not provided to Oasis files gen. :type il: bool :param ri: Boolean to indicate the RI loss level mode - false if the source accounts file path not provided to Oasis files gen. :type ri: bool :param rl: Boolean to indicate the RL loss level mode - false if the source accounts file path not provided to Oasis files gen. :type rl: bool :param gul_items: Boolean to gul to use item_id instead of coverage_id :type gul_items: bool :param fmpy: Boolean to indicate whether fmpy python version will be used :type fmpy: bool .. py:function:: get_exposure_summary(exposure_df, keys_df, exposure_profile=get_default_exposure_profile()) Create exposure summary as dictionary of TIVs and number of locations grouped by peril and validity respectively. returns a python dict(). :param exposure_df: source exposure dataframe :type exposure df: pandas.DataFrame :param keys_df: dataFrame holding keys data (success and errors) :type keys_errors_df: pandas.DataFrame :param exposure_profile: profile defining exposure file :type exposure_profile: dict :return: Exposure summary dictionary :rtype: dict .. py:function:: write_exposure_summary(target_dir, exposure_df, keys_fp, keys_errors_fp, exposure_profile) Create exposure summary as dictionary of TIVs and number of locations grouped by peril and validity respectively. Writes dictionary as json file to disk. :param target_dir: directory on disk to write exposure summary file :type target_dir: str :param exposure_df: source exposure dataframe :type exposure df: pandas.DataFrame :param keys_fp: file path to keys file :type keys_fp: str :param keys_errors_fp: file path to keys errors file :type keys_errors_fp: str :param exposure_profile: profile defining exposure file :type exposure_profile: dict :return: Exposure summary file path :rtype: str