GNS-Science/nzshm-model

classmethod for `NshmModel` to build model from logic trees and config rather than files

Closed this issue · 1 comments

Issue 1: User may want to construct a NshmModel object on the fly rather than defining files or using get_model_version().
Issue 2: if a user gets a model and then tries to modify the logic trees this results:

from nzshm_model import get_model_version
model = get_model_version('NSHM_v1.0.4')
slt = model.source_logic_tree
slt.branch_sets = [bs for bs in model.source_logic_tree.branch_sets if bs.short_name=="CRU"]
model.source_logic_tree.branch_sets = [bs for bs in model.source_logic_tree.branch_sets if bs.short_name=="CRU"]
print(len(slt.branch_sets))
print(len(model.source_logic_tree.branch_sets))
$ poetry run python demo/adapters_demo.py 
1
4

The logic tree attribues of an NshmModel object cannot be modified because they are loaded from files every time.

Solution:

  • init NshmModel from objects:
def __init__(self, slt:  gmcmlt: config: Optional[Config], title, etc)
    ...
  • classmethod constructor to biuld from files, as is currently done
@classmethod
def from_files(cls,  self, version: str, title: str,  slt_json: Union[str, Path],  gmm_json: Union[str, Path],  gmm_xml: Union[str, Path],  hazard_config: 'HazardConfig'):
    ...
  • update tests so that we're not jumping though hoops to create a NshmModel instance

all parts are optional. adaptor will need to handle missing parts