This spec covers the following user story:
https://www.pivotaltracker.com/story/show/11544573
What needs to be done?
Refactor/Re-implement logic tree class (java/org/gem/engine/logictree.LogicTree.java) to match current data model as specified in nrml_seismic.xsd. The current implementation of the logic tree class dates back to the GEM1 project, and do not exactly reflect the actual data model. Tests are not present.
Logic tree data model
In the context of OpenQuake, a logic tree is a data structure allowing the user to define uncertainties in the input data for hazard calculations. Input data for hazard calculations consist of a source model and a ground motion model. A logic tree therefore allows a user to define one or more source models (and possibly uncertainties on parameters the source model depends on) and one or more ground motion prediction equations (GMPEs) to be used in hazard calculations.
A logic tree (as per schema in nrml_seismic.xsd) is currently structured as an (unbounded) sequence of logic tree branch sets, with a logic tree branch set consisting of an (unbounded) sequence of logic tree branches. A logic tree branch is defined as a sequence (bounded, maxOccurs=1) of an uncertainty model (defined as a string) and an uncertainty weight (non negative double).
A logic tree has currently an id attribute (required), and a tectonic region attribute (optional). The tectonic region attribute is set only when the logic tree describes uncertainties in the ground motion model (that is defines a set of possible GMPEs which needs to be associated to a tectonic region type).
A logic tree branch set has two attributes (both required): branching level and uncertainty type. The branching level defines the position of the branch set in the logic tree (see figure ...). The uncertainty type specifies what type of uncertainty the branch set is describing. The uncertainty type is of string type and restricted to particular values. Currently four possible values are defined: gmpeModel, sourceModel, maxMagnitudeGutenbergRichterRelative, bValueGutenbergRichterRelative. Each of these values allows the logic tree processor (currently implemented in the class org.gem.engine.LogicTreeProcessor.java) to interpret what the uncertainty model in the logic tree branches refers to.
- If uncertainty type == gmpeModel, then the value of the element uncertainty model is interpreted as a string containing the name of a GMPE.
- If uncertainty type == sourceModel, then the value of the element uncertainty model is interpreted as a string containing the name of a file defining a source model
- If uncertainty type == maxMagnitudeGutenbergRichterRelative, then the value of the element uncertainty model is interpreted as a double representing the relative uncertainties on the maximum magnitude of a Gutenberg Richter magnitude frequency distribution.
- If uncertainties type == bValueGutenbergRichterRelative, then the value of the element uncertainty type is interpreted as a double representing the relative uncertainties on the b value of a Gutenberg Richter magnitude frequency distribution.
NOTE
In the current data model, it is expected that the user defines only one branch set for branching level (meaning that a branch set at branching level N is "connected" to all branches defined in branching level N-1, i.e: the logic tree has a symmetric shape). However, it is envisioned to give the possibility to the user to define more than one branch sets per branching level (by for instance differentiating each branch set with an attribute specifying to which particular branch it applies to., which may require defining an index for each branch too.). This a just note about a future possible requirement which may be useful to take into account in the object design.
Usage of logic tree data in OpenQuake
Inside the engine logic tree data are used by the logic tree processor (org.gem.engine.LogicTreeProcessor.java), which is responsible for constructing a model (source model or GMPE) that can then be used for hazard calculation.
"Constructing a model" means looping over the branching levels defined in the logic tree, select an uncertainty model, perform the action corresponding to the selected uncertainty model.
From the usage point of view, a logic tree data object should give access to the defined branching levels (in a ordered way). For each branching level, the associated branch set must be accessible.
Dependencies
Logic tree data are currently used in the logic tree processor (org.gem.engine.LogicTreeProcessor.java) and in the logic tree data reader (org.gem.engine.LogicTreeReader.java) and in the gmpe logic tree data (org.gem.engine.GmpeLogicTreeData.java)