From 7aaee54f66167dbb5074ceb76c1287a97dc61651 Mon Sep 17 00:00:00 2001 From: Peter Powers <pmpowers@usgs.gov> Date: Thu, 21 Nov 2024 15:34:13 -0700 Subject: [PATCH] added static gmm weight map to instance logic tree method --- .../usgs/earthquake/nshmp/gmm/GmmUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/gov/usgs/earthquake/nshmp/gmm/GmmUtils.java b/src/main/java/gov/usgs/earthquake/nshmp/gmm/GmmUtils.java index d32b1b01..d8e8b76d 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/gmm/GmmUtils.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/gmm/GmmUtils.java @@ -8,9 +8,12 @@ import static gov.usgs.earthquake.nshmp.gmm.Imt.PGA; import static gov.usgs.earthquake.nshmp.gmm.Imt.SA0P02; import static java.lang.Math.log; +import java.util.Map; + import com.google.common.primitives.Doubles; import gov.usgs.earthquake.nshmp.gmm.GroundMotionTables.GroundMotionTable; +import gov.usgs.earthquake.nshmp.tree.LogicTree; /** * Ground motion model (Gmm) utilities. @@ -18,6 +21,9 @@ import gov.usgs.earthquake.nshmp.gmm.GroundMotionTables.GroundMotionTable; */ public final class GmmUtils { + /* Name for gmm logic tree; same as in Deserialize. */ + private static final String TREE_NAME = "gmm-tree"; + /* * Base-10 to base-e conversion factor commonly used with ground motion lookup * tables that supply log10 instead of natural log values. This conversion @@ -54,6 +60,22 @@ public final class GmmUtils { : (rake >= -135 && rake <= -45) ? NORMAL : STRIKE_SLIP; } + /** + * Convert a map of GMMs and weights to a logic tree of instances for the + * supplied IMT. + */ + static LogicTree<GroundMotionModel> weightMapToInstanceTree( + Map<Gmm, Double> gmms, + Imt imt) { + + LogicTree.EnumBuilder<Gmm, GroundMotionModel> tree = LogicTree.enumBuilder(TREE_NAME); + gmms.entrySet().forEach(e -> tree.addBranch( + e.getKey(), + e.getKey().instance(imt), + e.getValue())); + return tree.build(); + } + /* Derived from z2p5 via mmoschetti's 2018 ngaw2 db regressions */ static final double BASIN_Z1P0_UPPER = 0.3; static final double BASIN_Z1P0_LOWER = 0.5; -- GitLab