Skip to content

ground_motion_logic_tree

logic_tree

Defines ground motion characterisation model logic tree structures used in NSHM.

GMCMBranch dataclass

Bases: Branch

A branch of the GMCM logic tree

Identifies the ground motion model (gsim) and any arguments

Attributes:

Name Type Description
gsim_name str

the name of the ground motion model

gsim_args Dict[str, Any]

a dict of argument names and values

Source code in nzshm_model/logic_tree/gmcm_logic_tree/logic_tree.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@dataclass
class GMCMBranch(Branch):
    """
    A branch of the GMCM logic tree

    Identifies the ground motion model (gsim) and any arguments


    Attributes:
        gsim_name: the name of the ground motion model
        gsim_args: a dict of argument names and values
    """

    gsim_name: str = ""
    gsim_args: Dict[str, Any] = field(default_factory=dict)
    tectonic_region_type: str = ""  # need a default becasue base class has a memeber with a default

    def filtered_branch(self, logic_tree, branch_set) -> 'GMCMFilteredBranch':
        """get a filtered branch containing reference to parent instances.

        Arguments:
            logic_tree: the gmcm logic tree containing the branch
            branch_set: the branch set containing the branch

        Returns:
            a BMCMFilteredBranch instance
        """
        return GMCMFilteredBranch(logic_tree=logic_tree, branch_set=branch_set, **self.__dict__)

    @property
    def registry_identity(self):
        arg_vals = []
        for k, v in self.gsim_args.items():
            arg_vals.append(f"{k}={v}")
        return f"{self.gsim_name}({', '.join(arg_vals)})"

filtered_branch(logic_tree, branch_set)

get a filtered branch containing reference to parent instances.

Parameters:

Name Type Description Default
logic_tree

the gmcm logic tree containing the branch

required
branch_set

the branch set containing the branch

required

Returns:

Type Description
GMCMFilteredBranch

a BMCMFilteredBranch instance

Source code in nzshm_model/logic_tree/gmcm_logic_tree/logic_tree.py
27
28
29
30
31
32
33
34
35
36
37
def filtered_branch(self, logic_tree, branch_set) -> 'GMCMFilteredBranch':
    """get a filtered branch containing reference to parent instances.

    Arguments:
        logic_tree: the gmcm logic tree containing the branch
        branch_set: the branch set containing the branch

    Returns:
        a BMCMFilteredBranch instance
    """
    return GMCMFilteredBranch(logic_tree=logic_tree, branch_set=branch_set, **self.__dict__)

GMCMBranchSet dataclass

Bases: BranchSet[GMCMBranch]

A list of GMCM branches that apply to a particular tectonic region.

Attributes:

Name Type Description
tectonic_region_type str

the tectonic region type TRT that the branch set applies to.

branches List[GMCMBranch]

list of branches.

Source code in nzshm_model/logic_tree/gmcm_logic_tree/logic_tree.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@dataclass
class GMCMBranchSet(BranchSet[GMCMBranch]):
    """A list of GMCM branches that apply to a particular tectonic region.

    Attributes:
        tectonic_region_type: the tectonic region type TRT that the branch set applies to.
        branches: list of branches.
    """

    branches: List[GMCMBranch] = field(default_factory=list)

    def __post_init__(self):
        trts = {branch.tectonic_region_type for branch in self.branches}
        if len(trts) > 1:
            raise ValueError("all tectonic_region_types in a branch set must be the same")

    @property
    def tectonic_region_type(self) -> str:
        return self.branches[0].tectonic_region_type if self.branches else ""

GMCMLogicTree dataclass

Bases: LogicTree['GMCMFilteredBranch']

A dataclass representing the ground motion characterisation model logic tree.

Attributes:

Name Type Description
branch_sets List[GMCMBranchSet]

list of GMCM branch sets that comprise the logic tree.

Source code in nzshm_model/logic_tree/gmcm_logic_tree/logic_tree.py
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
@dataclass
class GMCMLogicTree(LogicTree['GMCMFilteredBranch']):
    """A dataclass representing the ground motion characterisation model logic tree.

    Attributes:
        branch_sets: list of GMCM branch sets that comprise the logic tree.
    """

    # should we enforce that there is only one branch_set per TRT?
    branch_sets: List[GMCMBranchSet] = field(default_factory=list)

    def __post_init__(self):
        self._fix_args()

    def _fix_args(self) -> 'GMCMLogicTree':
        """Replace string representations of numeric arguments with floats"""

        def is_number(value):
            return value.replace("-", "").replace(".", "").replace("e", "").isnumeric()

        for branch_set in self.branch_sets:
            for branch in branch_set.branches:
                for k, v in branch.gsim_args.items():
                    if (isinstance(v, str)) and (is_number(v)):
                        branch.gsim_args[k] = float(v)

        return self