oasislmf.pytools.common.data¶
Attributes¶
Functions¶
|
Generates *_header, *_dtype and *_fmt items given a list of tuples describing some output description |
|
load a file as a numpy ndarray |
|
load file as a single numpy array, |
|
Writes a custom dtype array with headers to csv with the provided row_fmt str |
|
|
|
Resolve file path to open file or use sys.stdin |
Module Contents¶
- 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
- 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.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_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_summary_xref_output = [('item_id', 'i4', '%d'), ('summary_id', 'i4', '%d'), ('summaryset_id', 'i4', '%d')][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.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.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.