oasislmf.pytools.common.data

Attributes

Functions

generate_output_metadata(output)

Generates *_header, *_dtype and *_fmt items given a list of tuples describing some output description

load_as_ndarray(dir_path, name, _dtype[, must_exist, ...])

load a file as a numpy ndarray

load_as_array(dir_path, name, _dtype[, must_exist])

load file as a single numpy array,

write_ndarray_to_fmt_csv(output_file, data, headers, ...)

Writes a custom dtype array with headers to csv with the provided row_fmt str

almost_equal(a, b)

resolve_file(path, mode, stack)

Resolve file path to open file or use sys.stdin

Module Contents

oasislmf.pytools.common.data.oasis_int[source]
oasislmf.pytools.common.data.nb_oasis_int[source]
oasislmf.pytools.common.data.oasis_int_size[source]
oasislmf.pytools.common.data.oasis_float[source]
oasislmf.pytools.common.data.nb_oasis_float[source]
oasislmf.pytools.common.data.oasis_float_size[source]
oasislmf.pytools.common.data.areaperil_int[source]
oasislmf.pytools.common.data.nb_areaperil_int[source]
oasislmf.pytools.common.data.areaperil_int_size[source]
oasislmf.pytools.common.data.null_index[source]
oasislmf.pytools.common.data.DEFAULT_BUFFER_SIZE = 1000000[source]
oasislmf.pytools.common.data.MEAN_TYPE_ANALYTICAL = 1[source]
oasislmf.pytools.common.data.MEAN_TYPE_SAMPLE = 2[source]
oasislmf.pytools.common.data.generate_output_metadata(output)[source]

Generates *_header, *_dtype and *_fmt items given a list of tuples describing some output description output description has type List(Tuple({name: str}, {type: Any}, {format: str})) Args:

output_map (list(tuple(str, Any, str))): Dictionary mapping string name to {output description}_output list

Returns:

result (tuple(list[str], np.dtype, str)): Tuple containing the generated *_header list, *_dtype np.dtype, *_fmt csv format string

oasislmf.pytools.common.data.aggregatevulnerability_output = [('aggregate_vulnerability_id', 'i4', '%d'), ('vulnerability_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.amplifications_output = [('item_id', 'i4', '%d'), ('amplification_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.cdf_output = [('event_id', 'i4', '%d'), ('areaperil_id', 'i4', '%d'), ('vulnerability_id', 'i4', '%d'),...[source]
oasislmf.pytools.common.data.complex_items_meta_output = [('item_id', 'u4', '%u'), ('coverage_id', 'u4', '%u'), ('group_id', 'u4', '%u'),...[source]
oasislmf.pytools.common.data.correlations_output[source]
oasislmf.pytools.common.data.coverages_output[source]
oasislmf.pytools.common.data.damagebin_output[source]
oasislmf.pytools.common.data.eve_output[source]
oasislmf.pytools.common.data.footprint_event_output[source]
oasislmf.pytools.common.data.fm_output[source]
oasislmf.pytools.common.data.fm_policytc_output = [('level_id', 'i4', '%d'), ('agg_id', 'i4', '%d'), ('layer_id', 'i4', '%d'), ('profile_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.fm_profile_output[source]
oasislmf.pytools.common.data.fm_profile_step_output[source]
oasislmf.pytools.common.data.fm_programme_output = [('from_agg_id', 'i4', '%d'), ('level_id', 'i4', '%d'), ('to_agg_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.fm_summary_xref_output = [('output', 'i4', '%d'), ('summary_id', 'i4', '%d'), ('summaryset_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.fm_xref_output = [('output', 'i4', '%d'), ('agg_id', 'i4', '%d'), ('layer_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.gul_output[source]
oasislmf.pytools.common.data.gul_summary_xref_output = [('item_id', 'i4', '%d'), ('summary_id', 'i4', '%d'), ('summaryset_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.items_output[source]
oasislmf.pytools.common.data.lossfactors_output = [('event_id', 'i4', '%d'), ('amplification_id', 'i4', '%d'), ('factor', 'f4', '%.2f')][source]
oasislmf.pytools.common.data.occurrence_output = [('event_id', 'i4', '%d'), ('period_no', 'i4', '%d'), ('occ_date_id', 'i4', '%d')][source]
oasislmf.pytools.common.data.occurrence_granular_output = [('event_id', 'i4', '%d'), ('period_no', 'i4', '%d'), ('occ_date_id', 'i8', '%d')][source]
oasislmf.pytools.common.data.periods_output = [('period_no', 'i4', '%d'), ('weighting', 'f8', '%0.9lf')][source]
oasislmf.pytools.common.data.quantile_output = [('quantile', 'f4', '%f')][source]
oasislmf.pytools.common.data.quantile_interval_output[source]
oasislmf.pytools.common.data.random_output = [('random_no', 'f4', '%f')][source]
oasislmf.pytools.common.data.returnperiods_output = [('return_period', 'i4', '%d')][source]
oasislmf.pytools.common.data.vulnerability_output[source]
oasislmf.pytools.common.data.vulnerability_weight_output[source]
oasislmf.pytools.common.data.load_as_ndarray(dir_path, name, _dtype, must_exist=True, col_map=None)[source]

load a file as a numpy ndarray useful for multi-columns files Args:

dir_path: path to the directory where the binary or csv file is stored name: name of the file _dtype: np.dtype must_exist: raise FileNotFoundError if no file is present col_map: name re-mapping to change name of csv columns

Returns:

numpy ndarray

oasislmf.pytools.common.data.load_as_array(dir_path, name, _dtype, must_exist=True)[source]
load file as a single numpy array,

useful for files with a binary version with only one type of value where their index correspond to an id. For example coverage.bin only contains tiv value for each coverage id coverage_id n correspond to index n-1

Args:

dir_path: path to the directory where the binary or csv file is stored name: name of the file _dtype: numpy dtype of the required array must_exist: raise FileNotFoundError if no file is present

Returns:

numpy array of dtype type

oasislmf.pytools.common.data.write_ndarray_to_fmt_csv(output_file, data, headers, row_fmt)[source]

Writes a custom dtype array with headers to csv with the provided row_fmt str

This function is a faster replacement for np.savetxt as it formats each row one at a time before writing to csv. We create one large string, and formats all the data at once, and writes all the data at once.

WARNING: untested with string types in custom data.

Args:

output_file (io.TextIOWrapper): CSV file data (ndarray[<custom dtype>]): Custom dtype ndarray with column names headers (list[str]): Column names for custom ndarray row_fmt (str): Format for each row in csv

oasislmf.pytools.common.data.float_equal_precision[source]
oasislmf.pytools.common.data.almost_equal(a, b)[source]
oasislmf.pytools.common.data.resolve_file(path, mode, stack)[source]

Resolve file path to open file or use sys.stdin

Args:

path (str | os.PathLike): File path or “-” indicationg standard input/output. mode (str): Mode to open file (“r”, “rb, “w”, “wb”). stack (ExitStack): Context manager stack used to manage file lifecycle.

Returns:

file (IO): A file-like object opened in the specified mode.