Inversion solution file
inversion_solution_file
¶
An InversionSolution archive file helper.
Supports files in OpenSHA InversionSolution archive format.
It provides conversions from the original file formats to pandas dataframe instances with caching and some error handling.
Attributes¶
ZIP_METHOD = zipfile.ZIP_STORED
module-attribute
¶
Classes¶
InversionSolutionFile()
¶
Class to handle the OpenSHA modular archive file form.
Methods:
Name | Description |
---|---|
to_archive |
serialise an instance to a zip archive. |
Initializes the InversionSolutionFile object.
Source code in solvis/solution/inversion_solution/inversion_solution_file.py
86 87 88 89 90 91 92 93 94 |
|
Attributes¶
RATES_PATH = 'solution/rates.csv'
class-attribute
instance-attribute
¶
description of RATES_PATH
RUPTS_PATH = 'ruptures/properties.csv'
class-attribute
instance-attribute
¶
INDICES_PATH = 'ruptures/indices.csv'
class-attribute
instance-attribute
¶
AVG_SLIPS_PATH = 'ruptures/average_slips.csv'
class-attribute
instance-attribute
¶
FAULTS_PATH = 'ruptures/fault_sections.geojson'
class-attribute
instance-attribute
¶
METADATA_PATH = 'metadata.json'
class-attribute
instance-attribute
¶
LOGIC_TREE_PATH = 'ruptures/logic_tree_branch.json'
class-attribute
instance-attribute
¶
SECT_SLIP_RATES_PATH = 'ruptures/sect_slip_rates.csv'
class-attribute
instance-attribute
¶
DATAFRAMES = [RATES_PATH, RUPTS_PATH, INDICES_PATH, AVG_SLIPS_PATH]
class-attribute
instance-attribute
¶
archive_path: Optional[Path]
property
¶
Get the path to the current archive file.
Returns:
Type | Description |
---|---|
Optional[Path]
|
The path to the archive file, or None if the archive is in a buffer. |
archive: zipfile.ZipFile
property
¶
Open and cache the zip archive.
This property opens the zip archive from the specified path or buffer,
caches it in memory for efficient access, and returns a zipfile.ZipFile
object. If the archive is already cached, it simply returns the cached
version.
Returns:
Type | Description |
---|---|
zipfile.ZipFile
|
A |
fault_sections: DataFrame[FaultSectionSchema]
cached
property
¶
Get the fault sections with target slip rates.
Returns:
Type | Description |
---|---|
DataFrame[FaultSectionSchema]
|
A DataFrame containing fault section data with target slip rates. |
fault_regime: str
cached
property
¶
Get the fault regime from the logic tree branches.
Returns:
Type | Description |
---|---|
str
|
The fault regime name as a string |
rupture_rates: DataFrame[RuptureRateSchema]
property
¶
Get the rupture rates from the archive.
Returns:
Type | Description |
---|---|
DataFrame[RuptureRateSchema]
|
A DataFrame containing rupture rate data. |
ruptures: DataFrame[RuptureSchema]
cached
property
¶
Get the ruptures from the archive.
Returns:
Type | Description |
---|---|
DataFrame[RuptureSchema]
|
A DataFrame containing rupture data. |
indices: gpd.GeoDataFrame
cached
property
¶
Get the rupture indices from the archive.
Returns:
Type | Description |
---|---|
gpd.GeoDataFrame
|
A GeoDataFrame containing rupture index data. |
average_slips: gpd.GeoDataFrame
cached
property
¶
Get the average slips from the archive.
Returns:
Type | Description |
---|---|
gpd.GeoDataFrame
|
A GeoDataFrame containing average slip data. |
section_target_slip_rates: gpd.GeoDataFrame
property
¶
Get the section target slip rates from the archive.
Returns:
Type | Description |
---|---|
gpd.GeoDataFrame
|
A GeoDataFrame containing section target slip rate data. |
Functions¶
to_archive(archive_path_or_buffer: Union[Path, str, io.BytesIO], base_archive_path=None, compat=False)
¶
Write the current solution file to a new zip archive.
Optionally cloning data from a base archive.
In non-compatible mode (the default) rupture ids may not be a contiguous, 0-based sequence, so the archive will not be suitable for use with opensha. Compatible mode will reindex rupture tables, so that the original rutpure ids are lost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
archive_path_or_buffer
|
Union[Path, str, io.BytesIO]
|
path or buffrer to write. |
required |
base_archive_path
|
path to an InversionSolution archive to clone data from. |
None
|
|
compat
|
if True reindex the dataframes so that the archive remains compatible with opensha. |
False
|
Source code in solvis/solution/inversion_solution/inversion_solution_file.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
set_props(rates: pd.DataFrame, ruptures: pd.DataFrame, indices: pd.DataFrame, fault_sections: pd.DataFrame, average_slips: pd.DataFrame)
¶
Set the properties for this object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rates
|
pd.DataFrame
|
A DataFrame containing rupture rate data. |
required |
ruptures
|
pd.DataFrame
|
A DataFrame containing rupture data. |
required |
indices
|
pd.DataFrame
|
A DataFrame containing rupture index data. |
required |
fault_sections
|
pd.DataFrame
|
A DataFrame containing fault section data with target slip rates. |
required |
average_slips
|
pd.DataFrame
|
A GeoDataFrame containing average slip data. |
required |
Source code in solvis/solution/inversion_solution/inversion_solution_file.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
Functions¶
data_to_zip_direct(z, data, name)
¶
Source code in solvis/solution/inversion_solution/inversion_solution_file.py
50 51 52 53 54 |
|
reindex_dataframe(dataframe: pd.DataFrame) -> pd.DataFrame
¶
Source code in solvis/solution/inversion_solution/inversion_solution_file.py
57 58 59 60 61 |
|