From d0496842bf7efc9eb67068b33b74cc5e42d526be Mon Sep 17 00:00:00 2001 From: Peter Powers <pmpowers@usgs.gov> Date: Mon, 21 Mar 2016 17:25:11 -0600 Subject: [PATCH] special cased rectangular map polygons to use Regions.createRectangular() --- etc/examples/5-complex-model/README.md | 2 +- src/org/opensha2/calc/Sites.java | 23 ++++++--- src/org/opensha2/calc/Transforms.java | 67 ++++++++++++++++---------- 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/etc/examples/5-complex-model/README.md b/etc/examples/5-complex-model/README.md index 3acaf6517..72e498dd8 100644 --- a/etc/examples/5-complex-model/README.md +++ b/etc/examples/5-complex-model/README.md @@ -25,6 +25,6 @@ To compute a small, low-resolution map for the central San Francisco bay area, e hazard ../../../../nshmp-model-cous-2008/Western\ US map.geojson config-map.json ``` -This computes 121 curves over a 2° by 2° area and will give you a sense of how long a larger map might take. Note that in the above two examples we specified different output directories for each calculation. +This computes 121 curves over a 2° by 2° area and will give you a sense of how long a larger map might take. Note that in the above two examples we specified different output directories in the config files for each calculation. #### Next: [Example 6 – Enhanced output](../6-enhanced-output) diff --git a/src/org/opensha2/calc/Sites.java b/src/org/opensha2/calc/Sites.java index 479fb283e..f8cb483bf 100644 --- a/src/org/opensha2/calc/Sites.java +++ b/src/org/opensha2/calc/Sites.java @@ -7,7 +7,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.opensha2.geo.BorderType.MERCATOR_LINEAR; import static org.opensha2.util.GeoJson.validateProperty; import static org.opensha2.util.Parsing.splitToList; -import static org.opensha2.util.Parsing.trimEnds; import static org.opensha2.util.TextUtils.ALIGN_COL; import static org.opensha2.util.TextUtils.format; @@ -329,7 +328,19 @@ public final class Sites { JsonObject properties = sitesFeature.getAsJsonObject(GeoJson.Key.PROPERTIES); String mapName = readName(properties, "Unnamed Map"); - Region calcRegion = Regions.create(mapName, border, MERCATOR_LINEAR); + /* + * We special case a 5-coordinate border that defines a mercator + * recangle so as to create a region that includes sites on the + * north and east borders. + */ + + Region calcRegion = null; + try { + Bounds b = validateExtents(border).bounds(); + calcRegion = Regions.createRectangular(mapName, b.min(), b.max()); + } catch (IllegalArgumentException iae) { + calcRegion = Regions.create(mapName, border, MERCATOR_LINEAR); + } checkState( properties.has(GeoJson.Properties.Key.SPACING), "A \"spacing\" : value (in degrees) must be defined in \"properties\""); @@ -378,12 +389,12 @@ public final class Sites { JsonArray coords = geometry.getAsJsonArray(GeoJson.Key.COORDINATES); LocationList border = GeoJson.fromCoordinates(coords); - checkState( + checkArgument( border.size() > 2, "A GeoJSON polygon must have at least 3 coordinates:%s", border); - checkState( + checkArgument( border.first().equals(border.last()), "The first and last points in a GeoJSON polygon must be the same:%s", border); @@ -397,7 +408,7 @@ public final class Sites { } private static LocationList validateExtents(LocationList locs) { - checkState(locs.size() == 5, + checkArgument(locs.size() == 5, "Extents polygon must contain 5 coordinates:%s", locs); Location p1 = locs.get(0); Location p2 = locs.get(1); @@ -411,7 +422,7 @@ public final class Sites { p2.latRad() == p3.latRad() && p1.lonRad() == p2.lonRad() && p3.lonRad() == p4.lonRad()); - checkState(rectangular, + checkArgument(rectangular, "Extents polygon does not define a lat-lon Mercator rectangle:%s", locs); return locs; } diff --git a/src/org/opensha2/calc/Transforms.java b/src/org/opensha2/calc/Transforms.java index 1c271139f..6c27d5c22 100644 --- a/src/org/opensha2/calc/Transforms.java +++ b/src/org/opensha2/calc/Transforms.java @@ -68,7 +68,8 @@ final class Transforms { this.site = site; } - @Override public SourceInputList apply(Source source) { + @Override + public SourceInputList apply(Source source) { SourceInputList hazardInputs = new SourceInputList(source); for (Rupture rup : source) { @@ -116,7 +117,8 @@ final class Transforms { this.gmmTable = gmmTable; } - @Override public GroundMotions apply(InputList inputs) { + @Override + public GroundMotions apply(InputList inputs) { Set<Imt> imtKeys = gmmTable.keySet(); Set<Gmm> gmmKeys = gmmTable.get(imtKeys.iterator().next()).keySet(); @@ -155,7 +157,8 @@ final class Transforms { this.truncationLevel = config.truncationLevel; } - @Override public HazardCurves apply(GroundMotions groundMotions) { + @Override + public HazardCurves apply(GroundMotions groundMotions) { HazardCurves.Builder curveBuilder = HazardCurves.builder(groundMotions); @@ -212,7 +215,8 @@ final class Transforms { this.truncationLevel = config.truncationLevel; } - @Override public HazardCurves apply(GroundMotions groundMotions) { + @Override + public HazardCurves apply(GroundMotions groundMotions) { HazardCurves.Builder curveBuilder = HazardCurves.builder(groundMotions); @@ -259,7 +263,9 @@ final class Transforms { return curveBuilder.build(); } - /* Construct an exceedance curve considering uncertain ground motions. */ + /* + * Construct an exceedance curve considering uncertain ground motions. + */ private XySequence exceedanceCurve( final double[] means, final double sigma, @@ -306,12 +312,13 @@ final class Transforms { this.sourceToInputs = new SourceToInputs(site); this.inputsToGroundMotions = new InputsToGroundMotions(gmmTable); - this.groundMotionsToCurves = config.gmmUncertainty && gmmSet.epiUncertainty() ? - new GroundMotionsToCurvesWithUncertainty(gmmSet, config) : - new GroundMotionsToCurves(config); + this.groundMotionsToCurves = config.gmmUncertainty && gmmSet.epiUncertainty() + ? new GroundMotionsToCurvesWithUncertainty(gmmSet, config) + : new GroundMotionsToCurves(config); } - @Override public HazardCurves apply(Source source) { + @Override + public HazardCurves apply(Source source) { return groundMotionsToCurves.apply( inputsToGroundMotions.apply( sourceToInputs.apply(source))); @@ -336,7 +343,8 @@ final class Transforms { this.modelCurves = config.logModelCurves(); } - @Override public HazardCurveSet apply(List<HazardCurves> curvesList) { + @Override + public HazardCurveSet apply(List<HazardCurves> curvesList) { if (curvesList.isEmpty()) return HazardCurveSet.empty(sources); @@ -380,7 +388,8 @@ final class Transforms { this.config = config; } - @Override public HazardCurveSet apply(SystemSourceSet sources) { + @Override + public HazardCurveSet apply(SystemSourceSet sources) { InputList inputs = SystemSourceSet.toInputsFunction(site).apply(sources); if (inputs.isEmpty()) return HazardCurveSet.empty(sources); @@ -394,9 +403,9 @@ final class Transforms { GroundMotions gms = inputsToGm.apply(inputs); Function<GroundMotions, HazardCurves> gmToCurves = - config.gmmUncertainty && gmmSet.epiUncertainty() ? - new GroundMotionsToCurvesWithUncertainty(gmmSet, config) : - new GroundMotionsToCurves(config); + config.gmmUncertainty && gmmSet.epiUncertainty() + ? new GroundMotionsToCurvesWithUncertainty(gmmSet, config) + : new GroundMotionsToCurves(config); HazardCurves curves = gmToCurves.apply(gms); CurveConsolidator consolidator = new CurveConsolidator(sources, config); @@ -428,7 +437,8 @@ final class Transforms { this.config = config; } - @Override public HazardCurveSet apply(SystemSourceSet sources) { + @Override + public HazardCurveSet apply(SystemSourceSet sources) { // create input list InputList master = SystemSourceSet.toInputsFunction(site).apply(sources); @@ -475,12 +485,13 @@ final class Transforms { gmmSet.gmms()); this.inputsToGroundMotions = new InputsToGroundMotions(gmmTable); - this.groundMotionsToCurves = config.gmmUncertainty && gmmSet.epiUncertainty() ? - new GroundMotionsToCurvesWithUncertainty(gmmSet, config) : - new GroundMotionsToCurves(config); + this.groundMotionsToCurves = config.gmmUncertainty && gmmSet.epiUncertainty() + ? new GroundMotionsToCurvesWithUncertainty(gmmSet, config) + : new GroundMotionsToCurves(config); } - @Override public HazardCurves apply(InputList inputs) { + @Override + public HazardCurves apply(InputList inputs) { return groundMotionsToCurves.apply(inputsToGroundMotions.apply(inputs)); } } @@ -498,7 +509,8 @@ final class Transforms { transform = new SourceToInputs(site); } - @Override public ClusterInputs apply(ClusterSource clusterSource) { + @Override + public ClusterInputs apply(ClusterSource clusterSource) { ClusterInputs clusterInputs = new ClusterInputs(clusterSource); for (FaultSource faultSource : clusterSource.faults()) { clusterInputs.add(transform.apply(faultSource)); @@ -521,7 +533,8 @@ final class Transforms { transform = new InputsToGroundMotions(gmmTable); } - @Override public ClusterGroundMotions apply(ClusterInputs clusterInputs) { + @Override + public ClusterGroundMotions apply(ClusterInputs clusterInputs) { ClusterGroundMotions clusterGroundMotions = new ClusterGroundMotions( clusterInputs.parent); for (SourceInputList hazardInputs : clusterInputs) { @@ -552,7 +565,8 @@ final class Transforms { this.truncationLevel = config.truncationLevel; } - @Override public ClusterCurves apply(ClusterGroundMotions clusterGroundMotions) { + @Override + public ClusterCurves apply(ClusterGroundMotions clusterGroundMotions) { Builder builder = ClusterCurves.builder(clusterGroundMotions); @@ -628,7 +642,8 @@ final class Transforms { this.groundMotionsToCurves = new ClusterGroundMotionsToCurves(config); } - @Override public ClusterCurves apply(ClusterSource source) { + @Override + public ClusterCurves apply(ClusterSource source) { return groundMotionsToCurves.apply( inputsToGroundMotions.apply( sourceToInputs.apply(source))); @@ -654,7 +669,8 @@ final class Transforms { this.modelCurves = config.logModelCurves(); } - @Override public HazardCurveSet apply(List<ClusterCurves> curvesList) { + @Override + public HazardCurveSet apply(List<ClusterCurves> curvesList) { if (curvesList.isEmpty()) return HazardCurveSet.empty(sources); @@ -690,7 +706,8 @@ final class Transforms { this.site = site; } - @Override public Hazard apply(List<HazardCurveSet> curveSetList) { + @Override + public Hazard apply(List<HazardCurveSet> curveSetList) { Hazard.Builder resultBuilder = Hazard.builder(config) .model(model) -- GitLab