Skip to content

Commit

Permalink
change name of function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdicaprio committed Mar 27, 2024
1 parent 8469f93 commit 2b87e6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nzshm_model/logic_tree/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _validate_names(logic_tree: 'LogicTree') -> None:
def _validate_correlation_weights(logic_tree: 'LogicTree') -> None:
# check that the weights total 1.0
weight_total = 0.0
for branch in logic_tree.composite_branches_fun(filtered=False):
for branch in logic_tree.composite_branches_fn(filtered=False):
weight_total += branch.weight
if not math.isclose(weight_total, 1.0):
raise ValueError("the weights of the logic tree do not sum to 1.0 when correlations are applied")
Expand Down
4 changes: 2 additions & 2 deletions nzshm_model/logic_tree/logic_tree_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _composite_branches(self, filtered=True) -> Generator[CompositeBranch, None,
for branches in product(*[branch_set.branches for branch_set in self.branch_sets]):
yield CompositeBranch(branches=branches)

def composite_branches_fun(self, filtered=True) -> Generator[CompositeBranch, None, None]:
def composite_branches_fn(self, filtered=True) -> Generator[CompositeBranch, None, None]:
"""
Yields all composite (combined) branches of the branch_sets enforcing correlations.
The filtered parameter is set to False during validation of correlation weights to avoid recursion issues. It
Expand Down Expand Up @@ -160,7 +160,7 @@ def composite_branches_fun(self, filtered=True) -> Generator[CompositeBranch, No
composite_branch.weight = reduce(mul, weights, 1.0)
yield composite_branch

composite_branches = property(composite_branches_fun)
composite_branches = property(composite_branches_fn)

@classmethod
def from_json(cls, json_path: Union[Path, str]) -> 'LogicTree':
Expand Down
10 changes: 5 additions & 5 deletions tests/test_logic_tree_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@ def test_check_correlations_validation(fixtures: Fixtures):

def test__composite_branches(fixtures: Fixtures):

assert len(list(fixtures.logic_tree_nocor.composite_branches_fun(filtered=False))) == 4 * 2 * 2
assert len(list(fixtures.logic_tree_nocor.composite_branches_fn(filtered=False))) == 4 * 2 * 2

# branches not filtered by correlation
assert len(list(fixtures.logic_tree._composite_branches(filtered=False))) == 4 * 2

# branches filtered by correlation
assert len(list(fixtures.logic_tree.composite_branches_fun(filtered=False))) == 4
assert len(list(fixtures.logic_tree.composite_branches_fn(filtered=False))) == 4

# can correlate a subset of BranchSets
assert len(list(fixtures.logic_tree2._composite_branches(filtered=False))) == 4 * 2 * 2

assert len(list(fixtures.logic_tree2.composite_branches_fun(filtered=False))) == 4 * 2
assert len(list(fixtures.logic_tree2.composite_branches_fn(filtered=False))) == 4 * 2


def test_composite_weights(fixtures: Fixtures):
# weights sum to 1.0
assert sum(
[branch.weight for branch in fixtures.logic_tree.composite_branches_fun(filtered=False)]
[branch.weight for branch in fixtures.logic_tree.composite_branches_fn(filtered=False)]
) == pytest.approx(1.0)
assert sum(
[branch.weight for branch in fixtures.logic_tree_nocor.composite_branches_fun(filtered=False)]
[branch.weight for branch in fixtures.logic_tree_nocor.composite_branches_fn(filtered=False)]
) == pytest.approx(1.0)

# weights are default from the primary branch
Expand Down

0 comments on commit 2b87e6e

Please sign in to comment.