oasislmf.execution.bin

Python utilities used for setting up the structure of the run directory in which to prepare the inputs to run a model or generate deterministic losses, and store the outputs.

Functions

prepare_run_directory(run_dir, oasis_src_fp, ...[, ...])

Ensures that the model run directory has the correct folder structure in

prepare_run_inputs(analysis_settings, run_dir, ...[, ri])

Sets up binary files in the model inputs directory.

set_footprint_set(setting_val, run_dir)

Create symbolic link to footprint file set that will be used for output

set_vulnerability_set(setting_val, run_dir)

Create symbolic link to vulnerability file set that will be used for output

set_loss_factors_set(setting_val, run_dir)

check_inputs_directory(directory_to_check[, il, ri, ...])

Check that all the required files are present in the directory.

csv_to_bin(csv_directory, bin_directory[, il, ri])

Create the binary files.

check_binary_tar_file(tar_file_path[, check_il])

Checks that all required files are present

create_binary_tar_file(directory)

Package the binaries in a gzipped tar.

check_conversion_tools([il])

Check that the conversion tools are available

cleanup_bin_directory(directory)

Clean the tar and binary files.

Module Contents

oasislmf.execution.bin.prepare_run_directory(run_dir, oasis_src_fp, model_data_fp, analysis_settings_fp, inputs_archive=None, user_data_dir=None, ri=False, copy_model_data=False, model_storage_config_fp=None)[source]

Ensures that the model run directory has the correct folder structure in order for the model run script (ktools) to be executed. Without the RI flag the model run directory will have the following structure

<run_directory>
|-- fifo/
|-- input/
|   `-- csv/
|-- output/
|-- static/
|-- work/
|-- analysis_settings.json
`-- run_ktools.sh

where the direct GUL and/or FM input files exist in the input/csv subfolder and the corresponding binaries exist in the input subfolder.

With the RI flag the model run directory has the following structure

::

<run_directory> |– fifo |– input

|– RI_1 |– RI_2 |– ri_layers.json

|– … |– output |– static |– work |– analysis_settings.json `– run_ktools.sh

where the direct GUL and/or FM input files, and the corresponding binaries exist in the input subfolder, and the RI layer input files and binaries exist in the RI prefixed subfolders.

If any subfolders are missing they are created.

Optionally, if the path to a set of Oasis files is provided then they are copied into the input/csv subfolder.

Optionally, if the path to the analysis settings JSON file is provided then it is copied to the base of the run directory.

Optionally, if the path to model data is provided then the files are symlinked into the static subfolder provided the OS is of type Darwin or Linux, otherwise the source folder tree is recursively copied into the static subfolder.

Parameters:
  • run_dir (str) – the model run directory

  • oasis_src_fp (str) – path to a set of Oasis files

  • ri (bool) – Boolean flag for RI mode

  • analysis_settings_fp (str) – analysis settings JSON file path

  • model_data_fp (str) – model data source path, if this is a file it will be loaded as a custom storage class

  • inputs_archive (str) – path to a tar file containing input files

  • user_data_dir (str) – path to a directory containing additional user-supplied model data

  • model_storage_config_fp (str) – path to the model storage configuration, if not present the model data will be copied to the static directory

oasislmf.execution.bin.prepare_run_inputs(analysis_settings, run_dir, model_storage: oasis_data_manager.filestore.backends.base.BaseStorage, ri=False)[source]

Sets up binary files in the model inputs directory.

Parameters:
  • analysis_settings (dict) – model analysis settings dict

  • run_dir (str) – model run directory

oasislmf.execution.bin.set_footprint_set(setting_val, run_dir)[source]

Create symbolic link to footprint file set that will be used for output calculation.

Parameters:
  • setting_val (string) – identifier for footprint set

  • run_dir (string) – model run directory

oasislmf.execution.bin.set_vulnerability_set(setting_val, run_dir)[source]

Create symbolic link to vulnerability file set that will be used for output calculation.

Parameters:
  • setting_val (string) – identifier for vulnerability set

  • run_dir (string) – model run directory

oasislmf.execution.bin.set_loss_factors_set(setting_val, run_dir)[source]
oasislmf.execution.bin.check_inputs_directory(directory_to_check, il=False, ri=False, check_binaries=True)[source]

Check that all the required files are present in the directory.

Parameters:
  • directory_to_check (string) – directory containing the CSV files

  • il (bool) – check insuured loss files

  • il – check resinsurance sub-folders

  • check_binaries (bool) – check binary files are not present

oasislmf.execution.bin.csv_to_bin(csv_directory, bin_directory, il=False, ri=False)[source]

Create the binary files.

Parameters:
  • csv_directory (str) – the directory containing the CSV files

  • bin_directory (str) – the directory to write the binary files

  • il (bool) – whether to create the binaries required for insured loss calculations

  • ri (bool) – whether to create the binaries required for reinsurance calculations

Raises:

OasisException – If one of the conversions fails

oasislmf.execution.bin.check_binary_tar_file(tar_file_path, check_il=False)[source]

Checks that all required files are present

Parameters:
  • tar_file_path (str) – Path to the tar file to check

  • check_il (bool) – Flag whether to check insured loss files

Raises:

OasisException – If a required file is missing

Returns:

True if all required files are present, False otherwise

Return type:

bool

oasislmf.execution.bin.create_binary_tar_file(directory)[source]

Package the binaries in a gzipped tar.

Parameters:

directory – Path containing the binaries

oasislmf.execution.bin.check_conversion_tools(il=False)[source]

Check that the conversion tools are available

Parameters:

il (bool) – Flag whether to check insured loss tools

Returns:

True if all required tools are present, False otherwise

Return type:

bool

oasislmf.execution.bin.cleanup_bin_directory(directory)[source]

Clean the tar and binary files.