From 003e4f2f21d42456f06bda63511ac387518ef921 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 10:20:15 -0600
Subject: [PATCH 01/12] test

---
 .gitlab-ci.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e25e1cf..94b5dea 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -99,7 +99,7 @@ Unit Tests:
   rules:
     -
       changes:
-        - 'src/**'
+        - 'src/**/*'
         - '*gradle*'
       when: on_success
     -
@@ -107,6 +107,7 @@ Unit Tests:
       when: manual
   script:
     - ./gradlew check
+    - cat build/reports/tests/test/index.html
     - cat ${JACOCO_HTML_DIR}/index.html
 
 YAML Lint:
-- 
GitLab


From cb0e6c4e304ce9c24acc787d4e3c37678b783054 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 10:47:17 -0600
Subject: [PATCH 02/12] test

---
 .gitlab-ci.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 94b5dea..2436eba 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -107,7 +107,6 @@ Unit Tests:
       when: manual
   script:
     - ./gradlew check
-    - cat build/reports/tests/test/index.html
     - cat ${JACOCO_HTML_DIR}/index.html
 
 YAML Lint:
-- 
GitLab


From 84559763cfa096c30fa604a8b537cf93c3eadf8c Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 11:12:41 -0600
Subject: [PATCH 03/12] test

---
 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2436eba..d15172f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -89,6 +89,7 @@ Unit Tests:
   artifacts:
     paths:
       - ${REPORTS_DIR}
+      - build/reports/tests/test/index.html
     reports:
       junit: ${JUNIT_FILES}
   coverage: '/Total.*?([0-9]{1,3})%/'
-- 
GitLab


From a9bc23cb6248671f92b18bf57e06c869eeef1aa7 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 14:31:06 -0600
Subject: [PATCH 04/12] test

---
 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d15172f..a518091 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -92,6 +92,7 @@ Unit Tests:
       - build/reports/tests/test/index.html
     reports:
       junit: ${JUNIT_FILES}
+  allow_failure: true
   coverage: '/Total.*?([0-9]{1,3})%/'
   extends:
     - .gradle
-- 
GitLab


From 5a3748ae6e149df053d35b175692846800cd3ee9 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 15:07:15 -0600
Subject: [PATCH 05/12] test

---
 .gitlab-ci.yml | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a518091..2299021 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -88,8 +88,7 @@ Markdown Lint:
 Unit Tests:
   artifacts:
     paths:
-      - ${REPORTS_DIR}
-      - build/reports/tests/test/index.html
+      - build/resports
     reports:
       junit: ${JUNIT_FILES}
   allow_failure: true
-- 
GitLab


From 94bee06dd006209f7c7732e907dc5c755445b0df Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 15:08:23 -0600
Subject: [PATCH 06/12] test

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2299021..d8d6056 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -88,7 +88,7 @@ Markdown Lint:
 Unit Tests:
   artifacts:
     paths:
-      - build/resports
+      - ${JACOCO_HTML_DIR}
     reports:
       junit: ${JUNIT_FILES}
   allow_failure: true
-- 
GitLab


From d714da480c112fa3ddb39c44dfbd512950780c04 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 15:09:10 -0600
Subject: [PATCH 07/12] test

---
 .gitlab-ci.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d8d6056..5ae4434 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -103,8 +103,9 @@ Unit Tests:
         - 'src/**/*'
         - '*gradle*'
       when: on_success
+      allow_failure: false
     -
-      allow_failure: true
+      allow_failure: false
       when: manual
   script:
     - ./gradlew check
-- 
GitLab


From 7b6c930d508c867015bd03f9f46a9ba3e16d6adc Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Wed, 11 Aug 2021 16:07:44 -0600
Subject: [PATCH 08/12] test

---
 .gitlab-ci.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5ae4434..a37ec3d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -91,7 +91,6 @@ Unit Tests:
       - ${JACOCO_HTML_DIR}
     reports:
       junit: ${JUNIT_FILES}
-  allow_failure: true
   coverage: '/Total.*?([0-9]{1,3})%/'
   extends:
     - .gradle
-- 
GitLab


From a8bf9f860c67fdc9975896893bf8eff233bb0d33 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 12 Aug 2021 08:54:22 -0600
Subject: [PATCH 09/12] switch to build runner

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a37ec3d..0c58e33 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,7 +28,7 @@ workflow:
   image: ${DEVOPS_REGISTRY}usgs/java:11-jdk
   stage: build
   tags:
-    - development
+    - build
 
 ####
 # Stage: init
-- 
GitLab


From 69e7ea11167e1e3c4a3471f0072f54c27b77432c Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 12 Aug 2021 09:52:01 -0600
Subject: [PATCH 10/12] update publising

---
 build.gradle | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index ad1ea19..6ee694c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@ plugins {
   id "eclipse-wtp"
   id "io.micronaut.application" version "${mnPluginVersion}"
   id "jacoco"
-  id "java"
+  id "java-library"
   id "maven-publish"
 }
 
@@ -21,6 +21,10 @@ configurations {
   nshmp
 }
 
+java {
+  withSourcesJar()
+}
+
 ext {
   libsDir = "libs"
   nshmpLib = "${libsDir}/nshmp-lib-artifacts"
-- 
GitLab


From ea5acf6113d63727787f98cf25896dfad9f3238b Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 12 Aug 2021 13:57:44 -0600
Subject: [PATCH 11/12] add version

---
 gradle/dependencies.gradle | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle
index abf065f..93d3033 100644
--- a/gradle/dependencies.gradle
+++ b/gradle/dependencies.gradle
@@ -5,10 +5,10 @@ dependencies {
   nshmp "ghsc:nshmp-lib:${nshmpLibVersion}@zip"
 
   // Micronaut
-  annotationProcessor platform("io.micronaut:micronaut-bom")
+  annotationProcessor platform("io.micronaut:micronaut-bom:${micronautVersion}")
   annotationProcessor "io.micronaut:micronaut-inject-java"
   annotationProcessor "io.micronaut:micronaut-validation"
-  implementation platform("io.micronaut:micronaut-bom")
+  implementation platform("io.micronaut:micronaut-bom:${micronautVersion}")
   implementation "io.micronaut:micronaut-http-client"
   implementation "io.micronaut:micronaut-inject"
   implementation "io.micronaut:micronaut-validation"
-- 
GitLab


From cf2e66ba5bc23618383f168b87fbacbe8868ec88 Mon Sep 17 00:00:00 2001
From: Peter Powers <pmpowers@usgs.gov>
Date: Tue, 14 Dec 2021 15:21:02 -0700
Subject: [PATCH 12/12] updated lib and other dependencies

---
 build.gradle                                  |  2 +-
 gradle.properties                             |  8 ++---
 gradle/wrapper/gradle-wrapper.properties      |  2 +-
 .../nshmp/www/gmm/GroundMotions.java          | 31 +++++++++++++++++--
 .../nshmp/www/gmm/ResponseSpectra.java        | 11 ++++---
 5 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/build.gradle b/build.gradle
index 6ee694c..2e50899 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,6 @@
 plugins {
   id "application"
-  id "com.diffplug.gradle.spotless" version "${spotlessVersion}"
+  id "com.diffplug.spotless" version "${spotlessVersion}"
   id "com.github.johnrengelman.shadow" version "${shadowVersion}"
   id "com.github.node-gradle.node" version "${nodeVersion}"
   id "com.github.spotbugs" version "${spotbugsVersion}"
diff --git a/gradle.properties b/gradle.properties
index f228ebc..35dc381 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,14 +1,14 @@
 githooksVersion = 1.2.0
 jacksonVersion = 2.9.0
-junitVersion = 5.5.2
+junitVersion = 5.8.2
 logbackVersion = 1.2.3
 micronautVersion = 2.4.1
 mnPluginVersion = 1.4.2
 nodeVersion = 3.0.1
 nshmFaultSectionsTag = v0.1
-nshmpLibVersion = 0.4.2
+nshmpLibVersion = 0.8.0
 nshmpWsUtilsVersion = 0.1.2
 shadowVersion = 6.1.0
-spotbugsVersion = 4.2.4
-spotlessVersion = 4.1.0
+spotbugsVersion = 4.7.0
+spotlessVersion = 6.0.4
 swaggerVersion = 2.1.7
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index be52383..84d1f85 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/GroundMotions.java b/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/GroundMotions.java
index 5c98675..a2b1925 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/GroundMotions.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/GroundMotions.java
@@ -18,11 +18,14 @@ import java.util.stream.Collectors;
 import com.google.common.primitives.Doubles;
 
 import gov.usgs.earthquake.nshmp.Maths;
+import gov.usgs.earthquake.nshmp.data.DoubleData;
 import gov.usgs.earthquake.nshmp.gmm.Gmm;
 import gov.usgs.earthquake.nshmp.gmm.GmmInput;
+import gov.usgs.earthquake.nshmp.gmm.GroundMotion;
 import gov.usgs.earthquake.nshmp.gmm.GroundMotionModel;
 import gov.usgs.earthquake.nshmp.gmm.Imt;
-import gov.usgs.earthquake.nshmp.gmm.ScalarGroundMotion;
+import gov.usgs.earthquake.nshmp.tree.Branch;
+import gov.usgs.earthquake.nshmp.tree.LogicTree;
 
 public class GroundMotions {
 
@@ -115,7 +118,7 @@ public class GroundMotions {
 
       GroundMotionModel model = gmm.instance(imt);
       for (GmmInput gmmInput : gmmInputs) {
-        ScalarGroundMotion gm = model.calc(gmmInput);
+        GroundMotion gm = combine(model.calc(gmmInput));
         means.add(gm.mean());
         sigmas.add(gm.sigma());
       }
@@ -131,6 +134,30 @@ public class GroundMotions {
         xsMap);
   }
 
+  @Deprecated
+  static GroundMotion combine(LogicTree<GroundMotion> tree) {
+    // once GroundMotions in lib is exposed remove this
+    if (tree.size() == 1) {
+      return tree.get(0).value();
+    }
+    double[] means = tree.stream()
+        .map(Branch::value)
+        .mapToDouble(GroundMotion::mean)
+        .toArray();
+    double[] sigmas = tree.stream()
+        .map(Branch::value)
+        .mapToDouble(GroundMotion::sigma)
+        .toArray();
+    double[] weights = tree.stream()
+        .mapToDouble(Branch::weight)
+        .toArray();
+    double mean = DoubleData.weightedSumLn(means, weights);
+    double sigma = DoubleData.weightedSum(sigmas, weights);
+    // TODO update NGA-East test results
+    // double sigma = Maths.srssWeighted(sigmas, weights);
+    return GroundMotion.create(mean, sigma);
+  }
+
   /*
    * Compute distance metrics for a fault.
    */
diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/ResponseSpectra.java b/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/ResponseSpectra.java
index e268119..e1efc86 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/ResponseSpectra.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/www/gmm/ResponseSpectra.java
@@ -12,9 +12,9 @@ import com.google.common.collect.Maps;
 
 import gov.usgs.earthquake.nshmp.gmm.Gmm;
 import gov.usgs.earthquake.nshmp.gmm.GmmInput;
+import gov.usgs.earthquake.nshmp.gmm.GroundMotion;
 import gov.usgs.earthquake.nshmp.gmm.GroundMotionModel;
 import gov.usgs.earthquake.nshmp.gmm.Imt;
-import gov.usgs.earthquake.nshmp.gmm.ScalarGroundMotion;
 
 /**
  * Entry point for computing deterministic response spectra.
@@ -46,8 +46,9 @@ public class ResponseSpectra {
    * @return a two-element double[] containing the natural log of the median
    *         ground motion and its standard deviation
    */
+  @Deprecated
   public static double[] groundMotion(Gmm model, Imt imt, GmmInput source) {
-    ScalarGroundMotion sgm = model.instance(imt).calc(source);
+    GroundMotion sgm = GroundMotions.combine(model.instance(imt).calc(source));
     return new double[] { sgm.mean(), sgm.sigma() };
   }
 
@@ -71,7 +72,7 @@ public class ResponseSpectra {
     Result spectrum = new Result(imts.size());
     int i = 0;
     for (Imt imt : imts) {
-      ScalarGroundMotion sgm = model.instance(imt).calc(input);
+      GroundMotion sgm = GroundMotions.combine(model.instance(imt).calc(input));
       spectrum.periods[i] = imt.period();
       spectrum.means[i] = sgm.mean();
       spectrum.sigmas[i] = sgm.sigma();
@@ -145,12 +146,12 @@ public class ResponseSpectra {
       ImmutableList.Builder<Double> means = ImmutableList.builder();
       ImmutableList.Builder<Double> sigmas = ImmutableList.builder();
 
-      ScalarGroundMotion pgaGm = gmm.instance(Imt.PGA).calc(input);
+      GroundMotion pgaGm = GroundMotions.combine(gmm.instance(Imt.PGA).calc(input));
       means.add(pgaGm.mean());
       sigmas.add(pgaGm.sigma());
 
       for (Imt imt : saImts) {
-        ScalarGroundMotion sgm = gmm.instance(imt).calc(input);
+        GroundMotion sgm = GroundMotions.combine(gmm.instance(imt).calc(input));
         means.add(sgm.mean());
         sigmas.add(sgm.sigma());
       }
-- 
GitLab