Skip to content

subsection_id_filter

subsection_id_filter

This module provides a class for filtering solution fault sections (subsections).

Classes:

Name Description
FilterSubsectionIds

a chainable filter for fault sections, returning qualifying fault section ids.

Examples:

>>> ham50 = solvis.circle_polygon(50000, -37.78, 175.28)  # 50km radius around Hamilton
<POLYGON ((175.849 -37.779, 175.847 -37.823, 175.839 -37.866, 175.825 -37.90...>
>>> solution = solvis.InversionSolution.from_archive(filename)
>>> rupture_ids = FilterRuptureIds(solution)\
        .for_magnitude(min_mag=5.75, max_mag=6.25)\
        .for_polygon(ham50)

>>> subsection_ids = FilterSubsectionIds(solution)\
>>>     .for_rupture_ids(rupture_ids)

FilterSubsectionIds

Bases: ChainableSetBase

A helper class to filter subsections, returning qualifying section_ids.

Source code in solvis/filter/subsection_id_filter.py
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 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
104
105
106
107
108
109
110
111
112
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
class FilterSubsectionIds(ChainableSetBase):
    """A helper class to filter subsections, returning qualifying section_ids."""

    def __init__(self, solution: 'InversionSolution'):
        """Instantiate a new filter.

        Args:
            solution: The solution instance to filter on.
        """
        self._solution = solution
        self._filter_parent_fault_ids = FilterParentFaultIds(solution)

    def all(self) -> ChainableSetBase:
        """Convenience method returning ids for all solution fault subsections.

        NB the usual `join_prior` argument is not implemented as it doesn't seem useful here.

        Returns:
            A chainable set of all the subsection_ids.
        """
        result = set(self._solution.solution_file.fault_sections.index.to_list())
        return self.new_chainable_set(result, self._solution)

    def tolist(self) -> List[int]:
        """
        Returns the fault subsection id as a list of integers.

        Returns:
            A list of integers representing the filtered fault subsection ids.
        """
        return list(self)

    def for_named_fault_names(
        self,
        named_fault_names: Iterable[str],
        join_prior: Union[SetOperationEnum, str] = 'intersection',
    ) -> ChainableSetBase:
        """Find subsection ids that occur on any of the given named_fault names.

        Args:
            named_fault_names: A list of one or more `named_fault` names.

        Returns:
            The subsection_ids matching the filter.

        Raises:
            ValueError: If any `named_fault_names` argument is not valid.
        """
        parent_fault_ids: Iterable[int] = []
        for nf_name in named_fault_names:
            parent_fault_ids += named_fault.named_fault_table().loc[nf_name].parent_fault_ids
        return self.for_parent_fault_ids(parent_fault_ids, join_prior=join_prior)

    def for_parent_fault_names(
        self, parent_fault_names: Iterable[str], join_prior: Union[SetOperationEnum, str] = 'intersection'
    ) -> ChainableSetBase:
        """Find fault subsection ids for the given parent_fault names.

        Args:
            parent_fault_names: A list of one or more `parent_fault` names.

        Returns:
            The fault_subsection_ids matching the filter.

        Raises:
            ValueError: If any `parent_fault_names` argument is not valid.
        """
        parent_ids = self._filter_parent_fault_ids.for_parent_fault_names(parent_fault_names)
        return self.for_parent_fault_ids(parent_ids, join_prior=join_prior)

    def for_parent_fault_ids(
        self, parent_fault_ids: Iterable[int], join_prior: Union[SetOperationEnum, str] = 'intersection'
    ) -> ChainableSetBase:
        """Find fault subsection ids for the given parent_fault ids.

        Args:
            parent_fault_ids: A list of one or more `parent_fault` ids.

        Returns:
            The fault_subsection_ids matching the filter.
        """
        df0 = self._solution.solution_file.fault_sections
        ids = df0[df0['ParentID'].isin(list(parent_fault_ids))]['FaultID'].tolist()

        result = set([int(id) for id in ids])
        return self.new_chainable_set(result, self._solution, join_prior=join_prior)

    def for_rupture_ids(
        self, rupture_ids: Iterable[int], join_prior: Union[SetOperationEnum, str] = 'intersection'
    ) -> ChainableSetBase:
        """Find fault subsection ids for the given rupture_ids.

        Args:
            rupture_ids: A list of one or more rupture ids.

        Returns:
            The fault_subsection_ids matching the filter.
        """
        df0 = self._solution.model.rupture_sections
        ids = df0[df0.rupture.isin(list(rupture_ids))].section.tolist()
        result = set([int(id) for id in ids])
        return self.new_chainable_set(result, self._solution, join_prior=join_prior)

    def for_polygon(self, polygon, contained=True) -> ChainableSetBase:
        raise NotImplementedError()

__init__(solution: InversionSolution)

Instantiate a new filter.

Parameters:

Name Type Description Default
solution InversionSolution

The solution instance to filter on.

required
Source code in solvis/filter/subsection_id_filter.py
36
37
38
39
40
41
42
43
def __init__(self, solution: 'InversionSolution'):
    """Instantiate a new filter.

    Args:
        solution: The solution instance to filter on.
    """
    self._solution = solution
    self._filter_parent_fault_ids = FilterParentFaultIds(solution)

all() -> ChainableSetBase

Convenience method returning ids for all solution fault subsections.

NB the usual join_prior argument is not implemented as it doesn't seem useful here.

Returns:

Type Description
ChainableSetBase

A chainable set of all the subsection_ids.

Source code in solvis/filter/subsection_id_filter.py
45
46
47
48
49
50
51
52
53
54
def all(self) -> ChainableSetBase:
    """Convenience method returning ids for all solution fault subsections.

    NB the usual `join_prior` argument is not implemented as it doesn't seem useful here.

    Returns:
        A chainable set of all the subsection_ids.
    """
    result = set(self._solution.solution_file.fault_sections.index.to_list())
    return self.new_chainable_set(result, self._solution)

for_named_fault_names(named_fault_names: Iterable[str], join_prior: Union[SetOperationEnum, str] = 'intersection') -> ChainableSetBase

Find subsection ids that occur on any of the given named_fault names.

Parameters:

Name Type Description Default
named_fault_names Iterable[str]

A list of one or more named_fault names.

required

Returns:

Type Description
ChainableSetBase

The subsection_ids matching the filter.

Raises:

Type Description
ValueError

If any named_fault_names argument is not valid.

Source code in solvis/filter/subsection_id_filter.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def for_named_fault_names(
    self,
    named_fault_names: Iterable[str],
    join_prior: Union[SetOperationEnum, str] = 'intersection',
) -> ChainableSetBase:
    """Find subsection ids that occur on any of the given named_fault names.

    Args:
        named_fault_names: A list of one or more `named_fault` names.

    Returns:
        The subsection_ids matching the filter.

    Raises:
        ValueError: If any `named_fault_names` argument is not valid.
    """
    parent_fault_ids: Iterable[int] = []
    for nf_name in named_fault_names:
        parent_fault_ids += named_fault.named_fault_table().loc[nf_name].parent_fault_ids
    return self.for_parent_fault_ids(parent_fault_ids, join_prior=join_prior)

for_parent_fault_ids(parent_fault_ids: Iterable[int], join_prior: Union[SetOperationEnum, str] = 'intersection') -> ChainableSetBase

Find fault subsection ids for the given parent_fault ids.

Parameters:

Name Type Description Default
parent_fault_ids Iterable[int]

A list of one or more parent_fault ids.

required

Returns:

Type Description
ChainableSetBase

The fault_subsection_ids matching the filter.

Source code in solvis/filter/subsection_id_filter.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def for_parent_fault_ids(
    self, parent_fault_ids: Iterable[int], join_prior: Union[SetOperationEnum, str] = 'intersection'
) -> ChainableSetBase:
    """Find fault subsection ids for the given parent_fault ids.

    Args:
        parent_fault_ids: A list of one or more `parent_fault` ids.

    Returns:
        The fault_subsection_ids matching the filter.
    """
    df0 = self._solution.solution_file.fault_sections
    ids = df0[df0['ParentID'].isin(list(parent_fault_ids))]['FaultID'].tolist()

    result = set([int(id) for id in ids])
    return self.new_chainable_set(result, self._solution, join_prior=join_prior)

for_parent_fault_names(parent_fault_names: Iterable[str], join_prior: Union[SetOperationEnum, str] = 'intersection') -> ChainableSetBase

Find fault subsection ids for the given parent_fault names.

Parameters:

Name Type Description Default
parent_fault_names Iterable[str]

A list of one or more parent_fault names.

required

Returns:

Type Description
ChainableSetBase

The fault_subsection_ids matching the filter.

Raises:

Type Description
ValueError

If any parent_fault_names argument is not valid.

Source code in solvis/filter/subsection_id_filter.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def for_parent_fault_names(
    self, parent_fault_names: Iterable[str], join_prior: Union[SetOperationEnum, str] = 'intersection'
) -> ChainableSetBase:
    """Find fault subsection ids for the given parent_fault names.

    Args:
        parent_fault_names: A list of one or more `parent_fault` names.

    Returns:
        The fault_subsection_ids matching the filter.

    Raises:
        ValueError: If any `parent_fault_names` argument is not valid.
    """
    parent_ids = self._filter_parent_fault_ids.for_parent_fault_names(parent_fault_names)
    return self.for_parent_fault_ids(parent_ids, join_prior=join_prior)

for_polygon(polygon, contained=True) -> ChainableSetBase

Source code in solvis/filter/subsection_id_filter.py
136
137
def for_polygon(self, polygon, contained=True) -> ChainableSetBase:
    raise NotImplementedError()

for_rupture_ids(rupture_ids: Iterable[int], join_prior: Union[SetOperationEnum, str] = 'intersection') -> ChainableSetBase

Find fault subsection ids for the given rupture_ids.

Parameters:

Name Type Description Default
rupture_ids Iterable[int]

A list of one or more rupture ids.

required

Returns:

Type Description
ChainableSetBase

The fault_subsection_ids matching the filter.

Source code in solvis/filter/subsection_id_filter.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def for_rupture_ids(
    self, rupture_ids: Iterable[int], join_prior: Union[SetOperationEnum, str] = 'intersection'
) -> ChainableSetBase:
    """Find fault subsection ids for the given rupture_ids.

    Args:
        rupture_ids: A list of one or more rupture ids.

    Returns:
        The fault_subsection_ids matching the filter.
    """
    df0 = self._solution.model.rupture_sections
    ids = df0[df0.rupture.isin(list(rupture_ids))].section.tolist()
    result = set([int(id) for id in ids])
    return self.new_chainable_set(result, self._solution, join_prior=join_prior)

tolist() -> List[int]

Returns the fault subsection id as a list of integers.

Returns:

Type Description
List[int]

A list of integers representing the filtered fault subsection ids.

Source code in solvis/filter/subsection_id_filter.py
56
57
58
59
60
61
62
63
def tolist(self) -> List[int]:
    """
    Returns the fault subsection id as a list of integers.

    Returns:
        A list of integers representing the filtered fault subsection ids.
    """
    return list(self)