Skip to content

Inversion solution model

inversion_solution_model

This module defines the class InversionSolutionModel.

The InversionSolutionModel class provides methods to build pandas dataframes from the raw dataframes available via the InversionSolutionFile class.

Attributes

log = logging.getLogger(__name__) module-attribute

Classes

InversionSolutionModel(solution_file: InversionSolutionFile)

helper methods for analysis of InversionSolutionProtocol subtypes.

Initialize the InversionSolutionModel class.

Parameters:

Name Type Description Default
solution_file InversionSolutionFile

The inversion solution file to use.

required
Source code in solvis/solution/inversion_solution/inversion_solution_model.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def __init__(self, solution_file: InversionSolutionFile) -> None:
    """
    Initialize the `InversionSolutionModel` class.

    Args:
        solution_file (InversionSolutionFile): The inversion solution file to use.
    """
    self._solution_file = solution_file
    self._rs_with_rupture_rates: Optional[pd.DataFrame] = None
    self._ruptures_with_rupture_rates: Optional[pd.DataFrame] = None
    self._rupture_sections: Optional[gpd.GeoDataFrame] = None
    self._fs_with_rates: Optional[pd.DataFrame] = None
    self._fs_with_soln_rates: Optional[pd.DataFrame] = None
    self._fault_sections: Optional[pd.DataFrame] = None
Attributes
solution_file: InversionSolutionFile property

Get the inversion solution file used by this model.

Returns:

Name Type Description
InversionSolutionFile InversionSolutionFile

The inversion solution file.

rupture_sections: DataFrame[dataframe_models.RuptureSectionSchema] property

Calculate and cache the permutations of rupture_id and section_id.

Returns:

Type Description
DataFrame[dataframe_models.RuptureSectionSchema]

pd.DataFrame: A pandas dataframe conforming to the RuptureSectionSchema.

fault_sections_with_rupture_rates: DataFrame[dataframe_models.FaultSectionRuptureRateSchema] cached property

Get the fault sections with rupture rates.

Returns:

Type Description
DataFrame[dataframe_models.FaultSectionRuptureRateSchema]

pd.DataFrame: A pandas dataframe conforming to the FaultSectionRuptureRateSchema.

parent_fault_names: List[str] cached property

Get a sorted list of unique parent fault names.

Returns:

Type Description
List[str]

List[str]: A list of unique parent fault names.

fault_sections_with_solution_slip_rates: DataFrame[dataframe_models.FaultSectionWithSolutionSlipRate] cached property

Calculate and cache fault sections and their solution slip rates.

Solution slip rate combines the inversion inputs (avg slips), and the inversion solution (rupture rates).

Returns:

Type Description
DataFrame[dataframe_models.FaultSectionWithSolutionSlipRate]

a gpd.GeoDataFrame

rs_with_rupture_rates: DataFrame[dataframe_models.RuptureSectionsWithRuptureRatesSchema] cached property

Get the rupture sections with rupture rates.

Returns:

Type Description
DataFrame[dataframe_models.RuptureSectionsWithRuptureRatesSchema]

pd.DataFrame: A pandas dataframe conforming to the RuptureSectionsWithRuptureRatesSchema.

ruptures_with_rupture_rates: DataFrame[dataframe_models.RupturesWithRuptureRatesSchema] cached property

Get the ruptures with rupture rates.

Returns:

Type Description
DataFrame[dataframe_models.RupturesWithRuptureRatesSchema]

pd.DataFrame: A pandas dataframe conforming to the RupturesWithRuptureRatesSchema.

Functions
rate_column_name() -> str

Get the appropriate rate column name.

Returns:

Name Type Description
str str

"Annual Rate" or "rate_weighted_mean"

Source code in solvis/solution/inversion_solution/inversion_solution_model.py
54
55
56
57
58
59
60
61
62
def rate_column_name(self) -> str:
    """Get the appropriate rate column name.

    Returns:
        str: "Annual Rate" or "rate_weighted_mean"
    """
    return (
        "Annual Rate" if self._solution_file.__class__.__name__ == "InversionSolutionFile" else "rate_weighted_mean"
    )
build_rupture_sections() -> DataFrame[dataframe_models.RuptureSectionSchema] cached

Build the rupture sections dataframe.

Returns:

Type Description
DataFrame[dataframe_models.RuptureSectionSchema]

pd.DataFrame: A pandas dataframe conforming to the RuptureSectionSchema.

Source code in solvis/solution/inversion_solution/inversion_solution_model.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@cache
def build_rupture_sections(self) -> 'DataFrame[dataframe_models.RuptureSectionSchema]':
    """
    Build the rupture sections dataframe.

    Returns:
        pd.DataFrame: A pandas dataframe conforming to the RuptureSectionSchema.
    """
    tic = time.perf_counter()

    rs = self.solution_file.indices  # _dataframe_from_csv(self._rupture_sections, 'ruptures/indices.csv').copy()

    # remove "Rupture Index, Num Sections" column
    df_table = rs.drop(rs.iloc[:, :2], axis=1)
    tic0 = time.perf_counter()

    # convert to relational table, turning headings index into plain column
    df2 = df_table.stack().reset_index()

    tic1 = time.perf_counter()
    log.debug('rupture_sections(): time to convert indiced to table: %2.3f seconds' % (tic1 - tic0))

    # remove the headings column
    df2.drop(df2.iloc[:, 1:2], inplace=True, axis=1)
    df2 = df2.set_axis(['rupture', 'section'], axis='columns', copy=False)

    toc = time.perf_counter()
    log.debug('rupture_sections(): time to load and conform rupture_sections: %2.3f seconds' % (toc - tic))
    return cast('DataFrame[dataframe_models.RuptureSectionSchema]', df2)