oasislmf.pytools.common.input_files¶
Attributes¶
Functions¶
|
Get array of amplification IDs from amplifications.bin, where index |
|
Load the correlations from the correlations file. |
|
Load the coverages from the coverages file. |
|
Reads event rates from a CSV file |
|
Generate a quantile interval Dictionary based on sample size and quantile binary file |
|
Read the occurrence binary file and returns an occurrence map |
|
Read the occurrence binary file and returns an occurrence map |
|
Returns date as year, month, day, hour, minute from occ_date_id |
|
Returns the occ_date_id from year, month, day, hour, minute and whether it is a granular date |
|
Returns an array of period weights for each period between 1 and no_of_periods inclusive (with no gaps). |
|
Returns an array of return periods decreasing order with no duplicates. |
Module Contents¶
- oasislmf.pytools.common.input_files.read_amplifications(run_dir='', filename=AMPLIFICATIONS_FILE, use_stdin=False)[source]¶
Get array of amplification IDs from amplifications.bin, where index corresponds to item ID.
- amplifications.bin is binary file with layout:
reserved header (4-byte int), item ID 1 (4-byte int), amplification ID a_1 (4-byte int), … item ID n (4-byte int), amplification ID a_n (4-byte int)
- Args:
run_dir (str): path to amplifications.bin file filename (str | os.PathLike): amplifications file name use_stdin (bool): Use standard input for file data, ignores run_dir/filename. Defaults to False.
- Returns:
- items_amps (numpy.ndarray): array of amplification IDs, where index
corresponds to item ID
- oasislmf.pytools.common.input_files.read_correlations(run_dir, ignore_file_type=set(), filename=CORRELATIONS_FILENAME)[source]¶
Load the correlations from the correlations file. Args:
run_dir (str): path to correlations file ignore_file_type (Set[str]): file extension to ignore when loading. filename (str | os.PathLike): correlations file name
- Returns:
Tuple[Dict[int, int], List[int], Dict[int, int], List[Tuple[int, int]], List[int]] vulnerability dictionary, vulnerability IDs, areaperil to vulnerability index dictionary, areaperil ID to vulnerability index array, areaperil ID to vulnerability array
- oasislmf.pytools.common.input_files.read_coverages(run_dir='', ignore_file_type=set(), filename=COVERAGES_FILE, use_stdin=False)[source]¶
Load the coverages from the coverages file. Args:
run_dir (str): path to coverages file ignore_file_type (Set[str]): file extension to ignore when loading. filename (str | os.PathLike): coverages file name use_stdin (bool): Use standard input for file data, ignores run_dir/filename. Defaults to False.
- Returns:
numpy.array[oasis_float]: array with the coverage values for each coverage_id.
- oasislmf.pytools.common.input_files.read_event_rates(run_dir, filename=EVENTRATES_FILE)[source]¶
Reads event rates from a CSV file Args:
run_dir (str | os.PathLike): Path to input files dir filename (str | os.PathLike): event rates csv file name
- Returns:
unique_event_ids (ndarray[oasis_int]): unique event ids event_rates (ndarray[oasis_float]): event rates
- oasislmf.pytools.common.input_files.read_quantile(sample_size, run_dir, filename=QUANTILE_FILE, return_empty=False)[source]¶
Generate a quantile interval Dictionary based on sample size and quantile binary file Args:
sample_size (int): Sample size run_dir (str | os.PathLike): Path to input files dir filename (str | os.PathLike): quantile binary file name return_empty (bool): return an empty intervals array regardless of the existence of the quantile binary
- Returns:
intervals (quantile_interval_dtype): Numpy array emulating a dictionary for numba
- oasislmf.pytools.common.input_files.read_occurrence_bin(run_dir='', filename=OCCURRENCE_FILE, use_stdin=False)[source]¶
Read the occurrence binary file and returns an occurrence map Args:
run_dir (str | os.PathLike): Path to input files dir filename (str | os.PathLike): occurrence binary file name use_stdin (bool): Use standard input for file data, ignores run_dir/filename. Defaults to False.
- Returns:
occ_map (nb.typed.Dict): numpy map of event_id, period_no, occ_date_id from the occurrence file
- oasislmf.pytools.common.input_files.read_occurrence(run_dir, filename=OCCURRENCE_FILE)[source]¶
Read the occurrence binary file and returns an occurrence map Args:
run_dir (str | os.PathLike): Path to input files dir filename (str | os.PathLike): occurrence binary file name
- Returns:
occ_map (nb.typed.Dict): numpy map of event_id, period_no, occ_date_id from the occurrence file
- oasislmf.pytools.common.input_files.occ_get_date(occ_date_id, granular_date)[source]¶
Returns date as year, month, day, hour, minute from occ_date_id
- Args:
occ_date_id (np.int32 | np.int64): occurrence file date id (int64 for granular dates) granular_date (bool): boolean for whether granular date should be extracted or not
- Returns:
(oasis_int, oasis_int, oasis_int, oasis_int, oasis_int): Returns year, month, date, hour, minute
- oasislmf.pytools.common.input_files.occ_get_date_id(granular_date, occ_year, occ_month, occ_day, occ_hour=0, occ_minute=0)[source]¶
Returns the occ_date_id from year, month, day, hour, minute and whether it is a granular date Args:
granular_date (bool): boolean for whether granular date should be extracted or not occ_year (int): Occurrence Year. occ_month (int): Occurrence Month. occ_day (int): Occurrence Day. occ_hour (int): Occurrence Hour. Defaults to 0. occ_minute (int): Occurrence Minute. Defaults to 0.
- Returns:
occ_date_id (np.int64): occurrence file date id (int64 for granular dates)
- oasislmf.pytools.common.input_files.read_periods(no_of_periods, run_dir, filename=PERIODS_FILE)[source]¶
Returns an array of period weights for each period between 1 and no_of_periods inclusive (with no gaps). Args:
no_of_periods (int): Number of periods run_dir (str | os.PathLike): Path to input files dir filename (str | os.PathLike): periods binary file name
- Returns:
period_weights (ndarray[periods_dtype]): Period weights
- oasislmf.pytools.common.input_files.read_returnperiods(use_return_period_file, run_dir, filename=RETURNPERIODS_FILE)[source]¶
Returns an array of return periods decreasing order with no duplicates. Args:
use_return_period_file (bool): Bool to use Return Period File run_dir (str | os.PathLike): Path to input files dir filename (str | os.PathLike): return periods binary file name
- Returns:
return_periods (ndarray[np.int32]): Return Periods use_return_period_file (bool): Bool to use Return Period File