From a2f4ed9f573e38d5468e64178e78b7eeb75990f6 Mon Sep 17 00:00:00 2001
From: Jason Altekruse <jaltekruse@usgs.gov>
Date: Fri, 23 Sep 2022 10:06:38 -0600
Subject: [PATCH] only add index for site class to origin and shape vectors if
 there is more than one site class

---
 .../reader/BoundingReaderHazardCurves.java    | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderHazardCurves.java b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderHazardCurves.java
index 4257bc9..f03a236 100644
--- a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderHazardCurves.java
+++ b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderHazardCurves.java
@@ -124,21 +124,24 @@ public class BoundingReaderHazardCurves extends BoundingReader<StaticDataHazardC
       for (int iImt = 0; iImt < netcdfData.imts().size(); iImt++) {
         var imt = netcdfData.imts().get(iImt);
 
-        // Build origin array, e.g [0, imt, siteClass]
-        var origin = netcdf.netcdfShape().buildShape()
+        // origin array builder, e.g [0, imt, siteClass]
+        var origin_builder = netcdf.netcdfShape().buildShape()
             .add(IndexKey.IML, 0)
-            .add(IndexKey.IMT, iImt)
-            .add(IndexKey.SITE_CLASS, iSiteClass)
-            .reduce()
-            .build();
+            .add(IndexKey.IMT, iImt);
 
-        // Build shape array, e.g. [nIML, 1, 1]
-        var shape = netcdf.netcdfShape().buildShape()
+        // shape array builder, e.g. [nIML, 1, 1]
+        var shape_builder = netcdf.netcdfShape().buildShape()
             .add(IndexKey.IML, netcdfData.nIml())
-            .add(IndexKey.IMT, 1)
-            .add(IndexKey.SITE_CLASS, 1)
-            .reduce()
-            .build();
+            .add(IndexKey.IMT, 1);
+
+        // Only add index for siteClass if this is not a singleton dimension
+        if (netcdfData.siteClasses().size() > 1) {
+          origin_builder.add(IndexKey.SITE_CLASS, iSiteClass);
+          shape_builder.add(IndexKey.SITE_CLASS, 1);
+        }
+
+        var origin = origin_builder.reduce().build();
+        var shape = shape_builder.reduce().build();
 
         try {
           var xySequence = XySequence.create(
-- 
GitLab