Skip to content

branch

branch

Classes for defining logic tree branches

Branch dataclass

Bases: ABC

Abstract baseclass for logic tree branches

Parameters:

Name Type Description Default
name

a name for the branch

required
weight float

a weight for the branch

1.0
Source code in nzshm_model/logic_tree/branch.py
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
@dataclass
class Branch(ABC):
    """
    Abstract baseclass for logic tree branches

    Arguments:
        name: a name for the branch
        weight: a weight for the branch
    """

    branch_id: str = ""
    weight: float = 1.0

    @abstractmethod
    def filtered_branch(self, logic_tree: 'LogicTree', branch_set: 'BranchSet') -> 'FilteredBranch':
        """
        Produce a new filtered branch with the properties of the branch

        Parameters:
            logic_tree: The logic tree that the branch belongs to
            branch_set: The branch est that the branch belongs to

        Returns:
            a filtered branch
        """
        pass

filtered_branch(logic_tree, branch_set) abstractmethod

Produce a new filtered branch with the properties of the branch

Parameters:

Name Type Description Default
logic_tree LogicTree

The logic tree that the branch belongs to

required
branch_set BranchSet

The branch est that the branch belongs to

required

Returns:

Type Description
FilteredBranch

a filtered branch

Source code in nzshm_model/logic_tree/branch.py
30
31
32
33
34
35
36
37
38
39
40
41
42
@abstractmethod
def filtered_branch(self, logic_tree: 'LogicTree', branch_set: 'BranchSet') -> 'FilteredBranch':
    """
    Produce a new filtered branch with the properties of the branch

    Parameters:
        logic_tree: The logic tree that the branch belongs to
        branch_set: The branch est that the branch belongs to

    Returns:
        a filtered branch
    """
    pass

CompositeBranch dataclass

A logic tree branch comprised of combinations of branches from one or more branch sets.

Parameters:

Name Type Description Default
branches Sequence[Branch]

the component branches (branches from branch sets) in the composite branch

list()
weight float

the weight of the composite branch

1.0
Source code in nzshm_model/logic_tree/branch.py
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
@dataclass
class CompositeBranch:
    """
    A logic tree branch comprised of combinations of branches from one or more branch sets.

    Arguments:
        branches: the component branches (branches from branch sets) in the composite branch
        weight: the weight of the composite branch
    """

    branches: Sequence[Branch] = field(default_factory=list)
    weight: float = 1.0

    def __post_init__(self) -> None:
        self.weight = reduce(mul, [branch.weight for branch in self.branches], 1.0)

    def __iter__(self):
        self.__counter = 0
        return self

    def __next__(self):
        if self.__counter >= len(self.branches):
            raise StopIteration
        else:
            self.__counter += 1
            return self.branches[self.__counter - 1]