From 18cc46a1b33c35c18549e7ca3168c30ecd657611 Mon Sep 17 00:00:00 2001 From: bclayton-usgs <bclayton@usgs.gov> Date: Thu, 12 Mar 2020 11:38:59 -0600 Subject: [PATCH] update bounding hazards --- .../netcdf/reader/BoundingHazardsReader.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingHazardsReader.java b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingHazardsReader.java index c8f1b4e..5a30ebe 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingHazardsReader.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingHazardsReader.java @@ -82,33 +82,36 @@ public class BoundingHazardsReader { var latLower = latitudes[idxLatLL]; var latUpper = latitudes[idxLatLL + 1]; - boundingLocations.add(new BoundingLocation(latLower, lonLeft, 0, 0)); - boundingLocations.add(new BoundingLocation(latUpper, lonLeft, 1, 0)); - boundingLocations.add(new BoundingLocation(latUpper, lonRight, 1, 1)); - boundingLocations.add(new BoundingLocation(latLower, lonRight, 0, 1)); + boundingLocations.add(new BoundingLocation(lonLeft, latLower, 0, 0)); + boundingLocations.add(new BoundingLocation(lonLeft, latUpper, 0, 1)); + boundingLocations.add(new BoundingLocation(lonRight, latUpper, 1, 1)); + boundingLocations.add(new BoundingLocation(lonRight, latLower, 1, 0)); - var boundingHazardsBuilder = extractHazardsAt(idxLonLL, idxLatLL); + var hazards = extractHazardsAt(idxLonLL, idxLatLL); var fracLon = NetcdfUtils.calcGridFrac(longitudes, idxLonLL, site.longitude); var fracLat = NetcdfUtils.calcGridFrac(latitudes, idxLatLL, site.latitude); - boundingHazards = boundingHazardsBuilder.put( + var builder = BoundingHazards.builder(); + hazards.forEach(entry -> builder.put(entry.getKey(), entry.getValue())); + builder.put( site, - calcTargetHazards(fracLon, fracLat)) + calcTargetHazards(hazards, fracLon, fracLat)) .build(); + boundingHazards = builder.build(); NetcdfUtils.checkBoundingHazards(boundingHazards, boundingLocations.get(0).location); } - private StaticHazards calcTargetHazards(double fracLon, double fracLat) { + private StaticHazards calcTargetHazards(BoundingHazards hazards, double fracLon, double fracLat) { var westTarget = getTargetData( - boundingHazards.get(boundingLocations.get(0).location), - boundingHazards.get(boundingLocations.get(1).location), + hazards.get(boundingLocations.get(0).location), + hazards.get(boundingLocations.get(1).location), fracLat); var eastTarget = getTargetData( - boundingHazards.get(boundingLocations.get(3).location), - boundingHazards.get(boundingLocations.get(2).location), + hazards.get(boundingLocations.get(3).location), + hazards.get(boundingLocations.get(2).location), fracLat); return getTargetData(westTarget, eastTarget, fracLon); @@ -121,10 +124,9 @@ public class BoundingHazardsReader { * List order is clockwise from lower left corner: LL, UL, UR, LR, [T] with an * empty slot for the interpolated target hazards */ - private BoundingHazards.Builder extractHazardsAt( + private BoundingHazards extractHazardsAt( int idxLonLL, int idxLatLL) { - try (NetcdfDataset ncd = NetcdfDataset.openDataset(netcdf.path().toString())) { var boundingHazardMaps = BoundingHazards.builder(); var targetGroup = ncd.findGroup(netcdf.nshmGroup().baseGroup()); @@ -156,7 +158,7 @@ public class BoundingHazardsReader { mapHazardsFromArray(aHazards.section(boundingLocation.origin, shape))); } - return boundingHazardMaps; + return boundingHazardMaps.build(); } catch (IOException | InvalidRangeException e) { throw new RuntimeException("Could not read Netcdf file [" + netcdf.path() + "]"); } -- GitLab