Skip to content

Commit

Permalink
Reorg logic tree modules (#38)
Browse files Browse the repository at this point in the history
- organised the logic tree modules with logical hierarchy
- update changelog and bump version
  • Loading branch information
chrisdicaprio authored Jan 24, 2024
1 parent 5709627 commit 72676dd
Show file tree
Hide file tree
Showing 36 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.6.0
current_version = 0.7.0
commit = True
tag = True

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [0.7.0] 2024-01-11
### Added
- logic tree base classes

### Changed
- source logic tree fault systems now named branch sets. API aliases available for backward compatibility with deprecation warning
- source branch tag method changed to property

## [0.6.0] 2023-12-21
### Added
- GMCM logic tree classes for ground motion model serialization and deserialization (as json or xml)
Expand Down
2 changes: 1 addition & 1 deletion nzshm_model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . import nshm_v1_0_0, nshm_v1_0_4

# Python package version is different than the NSHM MODEL version !!
__version__ = '0.6.0'
__version__ = '0.7.0'

CURRENT_VERSION = "NSHM_v1.0.0"

Expand Down
2 changes: 2 additions & 0 deletions nzshm_model/logic_tree/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .gmcm_logic_tree import GMCMBranch, GMCMBranchSet, GMCMLogicTree
from .source_logic_tree import SourceBranch, SourceBranchSet, SourceLogicTree, SourceLogicTreeV1
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from typing import Any, Dict, List, Type

from nzshm_model.logic_tree_base import Branch, BranchSet, FilteredBranch, LogicTree
from nzshm_model.logic_tree.logic_tree_base import Branch, BranchSet, FilteredBranch, LogicTree
from nzshm_model.psha_adapter import PshaAdapterInterface


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .branch_attribute import BranchAttributeSpec, BranchAttributeValue
from .version1.logic_tree import SourceLogicTree as SourceLogicTreeV1
from .version1.logic_tree import SourceLogicTreeCorrelation
from .version2.logic_tree import SourceLogicTree
from .version2.logic_tree import SourceBranch, SourceBranchSet, SourceLogicTree
1 change: 1 addition & 0 deletions nzshm_model/logic_tree/source_logic_tree/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .fault_system_branch_set import BranchSetBase, BranchSetSpec
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from pathlib import Path
from typing import Any, Dict, Generator, Iterable, List, Union

from nzshm_model.source_logic_tree import BranchAttributeValue
from nzshm_model.source_logic_tree.version1 import (
from nzshm_model.logic_tree.source_logic_tree import BranchAttributeValue
from nzshm_model.logic_tree.source_logic_tree.version1 import (
Branch,
FaultSystemLogicTree,
SourceLogicTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclasses import dataclass, field
from typing import Dict, List, Type, Union

from nzshm_model.logic_tree_base import Branch, BranchSet, FilteredBranch, LogicTree
from nzshm_model.logic_tree.logic_tree_base import Branch, BranchSet, FilteredBranch, LogicTree
from nzshm_model.psha_adapter import PshaAdapterInterface

from .. import BranchAttributeValue
Expand Down
4 changes: 3 additions & 1 deletion nzshm_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from pathlib import Path
from typing import TYPE_CHECKING

from nzshm_model.logic_tree import SourceLogicTree
from nzshm_model.logic_tree.source_logic_tree import SourceLogicTreeV1

# from nzshm_model.psha_adapter import NrmlDocument, OpenquakeSimplePshaAdapter
from nzshm_model.psha_adapter.openquake import NrmlDocument, OpenquakeSimplePshaAdapter
from nzshm_model.source_logic_tree import SourceLogicTree, SourceLogicTreeV1

if TYPE_CHECKING:
from nzshm_model.psha_adapter.openquake.logic_tree import LogicTree
Expand Down
2 changes: 1 addition & 1 deletion nzshm_model/nshm_v1_0_0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! nshm_v1_0_0.py

import nzshm_model.source_logic_tree.SLT_v8_gmm_v2_final as slt_config
import nzshm_model.logic_tree.source_logic_tree.SLT_v8_gmm_v2_final as slt_config

from .model import NshmModel

Expand Down
2 changes: 1 addition & 1 deletion nzshm_model/nshm_v1_0_4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! nshm_v1_0_4.py

# Is this only used for the correlations ??
import nzshm_model.source_logic_tree.SLT_v9p0p0 as slt_config
import nzshm_model.logic_tree.source_logic_tree.SLT_v9p0p0 as slt_config

from .model import NshmModel

Expand Down
3 changes: 1 addition & 2 deletions nzshm_model/psha_adapter/openquake/simple_nrml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from lxml import etree
from lxml.builder import ElementMaker

from nzshm_model.gmcm_logic_tree import GMCMBranch, GMCMBranchSet, GMCMLogicTree
from nzshm_model.logic_tree import GMCMBranch, GMCMBranchSet, GMCMLogicTree, SourceLogicTree
from nzshm_model.psha_adapter.openquake.logic_tree import NrmlDocument
from nzshm_model.psha_adapter.psha_adapter_interface import PshaAdapterInterface
from nzshm_model.source_logic_tree import SourceLogicTree

try:
from .toshi import API_KEY, API_URL, SourceSolution
Expand Down
1 change: 0 additions & 1 deletion nzshm_model/source_logic_tree/core/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nzshm-model"
version = "0.6.0"
version = "0.7.0"
description = "The logic tree definitions, final configurations, and versioning of the New Zealand | Aotearoa National Seismic Hazard Model"
authors = ["Chris DiCaprio <[email protected]>", "Chris Chamberlain <[email protected]>"]
license = "AGPL3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import pytest

from nzshm_model.gmcm_logic_tree import GMCMLogicTree
from nzshm_model.logic_tree import GMCMLogicTree, SourceLogicTree
from nzshm_model.psha_adapter.openquake import OpenquakeSimplePshaAdapter
from nzshm_model.source_logic_tree.version2 import SourceLogicTree

FIXTURE_PATH = Path(__file__).parent.parent.parent / "fixtures"

Expand Down
6 changes: 5 additions & 1 deletion tests/test_correlation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import unittest

from nzshm_model.source_logic_tree import BranchAttributeSpec, BranchAttributeValue, SourceLogicTreeCorrelation
from nzshm_model.logic_tree.source_logic_tree import (
BranchAttributeSpec,
BranchAttributeValue,
SourceLogicTreeCorrelation,
)


class TestFlattenedSourceLogicTree(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gmcm_filtering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from nzshm_model.gmcm_logic_tree import GMCMBranch, GMCMLogicTree
from nzshm_model.logic_tree import GMCMBranch, GMCMLogicTree

gmcm_json_filepath = Path(__file__).parent / 'fixtures' / 'gmcm_logic_tree_example.json'

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gmcm_logic_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from nzshm_model.gmcm_logic_tree.logic_tree import GMCMLogicTree
from nzshm_model.logic_tree import GMCMLogicTree
from nzshm_model.psha_adapter.openquake import NrmlDocument
from nzshm_model.psha_adapter.openquake.simple_nrml import OpenquakeSimplePshaAdapter

Expand Down
10 changes: 6 additions & 4 deletions tests/test_logic_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import pytest

from nzshm_model.source_logic_tree.branch_attribute import BranchAttributeSpec
from nzshm_model.source_logic_tree.version1.logic_tree import (
from nzshm_model.logic_tree.source_logic_tree.branch_attribute import BranchAttributeSpec
from nzshm_model.logic_tree.source_logic_tree.version1.logic_tree import (
Branch,
BranchAttributeValue,
CompositeBranch,
Expand All @@ -16,7 +16,7 @@
SourceLogicTree,
SourceLogicTreeCorrelation,
)
from nzshm_model.source_logic_tree.version1.slt_config import from_config
from nzshm_model.logic_tree.source_logic_tree.version1.slt_config import from_config


def test_composite_branch():
Expand Down Expand Up @@ -120,7 +120,9 @@ def test_serialise_slt():

class TestSourceLogicTreeSpecification:
def test_slt_v8(self):
config = Path(__file__).parent.parent / 'nzshm_model' / 'source_logic_tree' / 'SLT_v8_gmm_v2_final.py'
config = (
Path(__file__).parent.parent / 'nzshm_model' / 'logic_tree' / 'source_logic_tree' / 'SLT_v8_gmm_v2_final.py'
)
slt = from_config(config)

slt_spec = slt.derive_spec()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_logic_tree_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# import itertools
from pathlib import Path

from nzshm_model.source_logic_tree.version2 import SourceLogicTree
from nzshm_model.logic_tree import SourceLogicTree

# import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_slt_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from nzshm_model.source_logic_tree.version2 import SourceLogicTree
from nzshm_model.logic_tree import SourceLogicTree

# import pytest

Expand Down
12 changes: 7 additions & 5 deletions tests/test_slt_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import pytest

import nzshm_model
from nzshm_model.source_logic_tree.version1 import Branch, FaultSystemLogicTree, SourceLogicTree
from nzshm_model.source_logic_tree.version1.slt_config import (
from nzshm_model.logic_tree.source_logic_tree.version1 import Branch, FaultSystemLogicTree, SourceLogicTree
from nzshm_model.logic_tree.source_logic_tree.version1.slt_config import (
decompose_crustal_tag,
decompose_subduction_tag,
from_config,
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_assemble_puy(self):
class TestConfigSerialisation:
@pytest.mark.parametrize("python_module", ['SLT_v9p0p0.py', 'SLT_v8_gmm_v2_final.py'])
def test_slt_dict_to_json(self, python_module):
config = Path(__file__).parent.parent / 'nzshm_model' / 'source_logic_tree' / python_module
config = Path(__file__).parent.parent / 'nzshm_model' / 'logic_tree' / 'source_logic_tree' / python_module
slt = from_config(config)
obj = dataclasses.asdict(slt)
jsonish = json.dumps(obj, indent=2)
Expand All @@ -96,7 +96,7 @@ def test_slt_dict_to_json(self, python_module):
@pytest.mark.parametrize("python_module", ['SLT_v9p0p0.py', 'SLT_v8_gmm_v2_final.py'])
def test_slt_v8_round_trip(self, python_module):

config = Path(__file__).parent.parent / 'nzshm_model' / 'source_logic_tree' / python_module
config = Path(__file__).parent.parent / 'nzshm_model' / 'logic_tree' / 'source_logic_tree' / python_module
slt = from_config(config)
obj = dataclasses.asdict(slt)
jsonish = json.dumps(obj, indent=2)
Expand All @@ -118,7 +118,9 @@ def test_slt_v8_round_trip(self, python_module):

class TestFromConfig:
def test_slt_v8(self):
config = Path(__file__).parent.parent / 'nzshm_model' / 'source_logic_tree' / 'SLT_v8_gmm_v2_final.py'
config = (
Path(__file__).parent.parent / 'nzshm_model' / 'logic_tree' / 'source_logic_tree' / 'SLT_v8_gmm_v2_final.py'
)
slt = from_config(config)
print(slt)
assert slt.fault_system_lts[0].branches[-1].values[0].name == 'dm'
Expand Down
3 changes: 1 addition & 2 deletions tests/test_slt_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pytest

import nzshm_model
from nzshm_model.source_logic_tree import SourceLogicTree
from nzshm_model.source_logic_tree.version2 import SourceBranch
from nzshm_model.logic_tree import SourceBranch, SourceLogicTree


## three example filter functions
Expand Down
4 changes: 2 additions & 2 deletions tests/test_slt_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import pytest

import nzshm_model
from nzshm_model.source_logic_tree import SourceLogicTree, SourceLogicTreeV1
from nzshm_model.source_logic_tree.version2 import SourceBranch, SourceBranchSet
from nzshm_model.logic_tree import SourceBranch, SourceBranchSet
from nzshm_model.logic_tree.source_logic_tree import SourceLogicTree, SourceLogicTreeV1


@pytest.fixture(scope='module')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_slt_version_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

import nzshm_model
from nzshm_model.source_logic_tree import SourceLogicTree, SourceLogicTreeV1
from nzshm_model.logic_tree.source_logic_tree import SourceLogicTree, SourceLogicTreeV1


@pytest.fixture(scope='module')
Expand Down

0 comments on commit 72676dd

Please sign in to comment.