Skip to content
Snippets Groups Projects
Commit f72b94df authored by Powers, Peter M.'s avatar Powers, Peter M.
Browse files

allow grid opt distance bin to be null

parent 4b32077f
No related branches found
No related tags found
1 merge request!270Grid optimization update
...@@ -17,6 +17,7 @@ import java.util.List; ...@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalDouble;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -578,7 +579,10 @@ class Deserialize { ...@@ -578,7 +579,10 @@ class Deserialize {
double spacing = obj.get(GRID_SPACING).getAsDouble(); double spacing = obj.get(GRID_SPACING).getAsDouble();
int smoothingDensity = obj.get(SMOOTHING_DENSITY).getAsInt(); int smoothingDensity = obj.get(SMOOTHING_DENSITY).getAsInt();
double smoothingLimit = obj.get(SMOOTHING_LIMIT).getAsDouble(); double smoothingLimit = obj.get(SMOOTHING_LIMIT).getAsDouble();
double distanceBin = obj.get(DISTANCE_BIN).getAsDouble(); JsonElement distanceBinElement = obj.get(DISTANCE_BIN);
OptionalDouble distanceBin = distanceBinElement.isJsonNull()
? OptionalDouble.empty()
: OptionalDouble.of(distanceBinElement.getAsDouble());
String typeStr = obj.get(POINT_SOURCE_TYPE).getAsString(); String typeStr = obj.get(POINT_SOURCE_TYPE).getAsString();
String scalingStr = obj.get(RUPTURE_SCALING).getAsString(); String scalingStr = obj.get(RUPTURE_SCALING).getAsString();
double maxDepth = obj.get(MAX_DEPTH).getAsDouble(); double maxDepth = obj.get(MAX_DEPTH).getAsDouble();
......
...@@ -81,12 +81,12 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -81,12 +81,12 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
private final PointSourceType pointSourceType; private final PointSourceType pointSourceType;
final DepthModel depthModel; final DepthModel depthModel;
final boolean optimizable; // final boolean optimizable;
final double gridSpacing; final double gridSpacing;
final int smoothingDensity; final int smoothingDensity;
final double smoothingLimit; final double smoothingLimit;
final double distanceBin; final OptionalDouble distanceBin;
/* /*
* Enforce expectation that all MFDs are GR* * Enforce expectation that all MFDs are GR*
...@@ -113,11 +113,6 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -113,11 +113,6 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
this.magMaster = builder.magMaster; this.magMaster = builder.magMaster;
this.maxDepth = builder.maxDepth; this.maxDepth = builder.maxDepth;
this.optimizable =
(type() != SourceType.ZONE) &&
(pointSourceType() != FIXED_STRIKE) &&
this.magMaster.isPresent();
double[] depthMags = this.mfds.get(0).data().xValues().toArray(); double[] depthMags = this.mfds.get(0).data().xValues().toArray();
this.depthModel = DepthModel.create( this.depthModel = DepthModel.create(
...@@ -158,7 +153,7 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -158,7 +153,7 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
* circumstances under which a grid optimization table can not be built. * circumstances under which a grid optimization table can not be built.
*/ */
public boolean optimizable() { public boolean optimizable() {
return optimizable; return distanceBin.isPresent();
} }
/** /**
...@@ -274,7 +269,7 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -274,7 +269,7 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
private Double gridSpacing; private Double gridSpacing;
private Integer smoothingDensity; private Integer smoothingDensity;
private Double smoothingLimit; private Double smoothingLimit;
private Double distanceBin; private OptionalDouble distanceBin;
private Builder() { private Builder() {
super(SourceType.GRID); super(SourceType.GRID);
...@@ -776,7 +771,6 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -776,7 +771,6 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
private List<PointSource> initSources(boolean smoothed) { private List<PointSource> initSources(boolean smoothed) {
/* For now, should only be getting here for GR MFDs */ /* For now, should only be getting here for GR MFDs */
Mfd modelMfd = parent.mfds.get(0); Mfd modelMfd = parent.mfds.get(0);
Mfd.Properties props = modelMfd.properties(); // probably INCR
double[] mags = modelMfd.data().xValues().toArray(); double[] mags = modelMfd.data().xValues().toArray();
// Can we get this from the mfd.properties? // Can we get this from the mfd.properties?
...@@ -792,12 +786,13 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -792,12 +786,13 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
// double mMin = parent.magMaster[0] - ΔmBy2; // double mMin = parent.magMaster[0] - ΔmBy2;
// double mMax = parent.magMaster[parent.magMaster.length - 1] + ΔmBy2; // double mMax = parent.magMaster[parent.magMaster.length - 1] + ΔmBy2;
double rMax = parent.groundMotionModels().maxDistance(); double rMax = parent.groundMotionModels().maxDistance();
double distanceBin = parent.distanceBin.orElseThrow();
double[] smoothingOffsets = smoothingOffsets( double[] smoothingOffsets = smoothingOffsets(
parent.smoothingDensity, parent.smoothingDensity,
parent.gridSpacing); parent.gridSpacing);
IntervalTable.Builder tableBuilder = new IntervalTable.Builder() IntervalTable.Builder tableBuilder = new IntervalTable.Builder()
.rows(0.0, rMax, parent.distanceBin) .rows(0.0, rMax, distanceBin)
.columns(mMin, mMax, Δm); .columns(mMin, mMax, Δm);
for (PointSource source : parent.iterableForLocation(origin)) { for (PointSource source : parent.iterableForLocation(origin)) {
...@@ -844,7 +839,6 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -844,7 +839,6 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
/* For now, should only be getting here for GR MFDs */ /* For now, should only be getting here for GR MFDs */
Mfd modelMfd = parent.mfds.get(0); Mfd modelMfd = parent.mfds.get(0);
Mfd.Properties props = modelMfd.properties(); // probably INCR
double[] mags = modelMfd.data().xValues().toArray(); double[] mags = modelMfd.data().xValues().toArray();
double Δm = mags[1] - mags[0]; double Δm = mags[1] - mags[0];
...@@ -857,20 +851,21 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> { ...@@ -857,20 +851,21 @@ public class GridRuptureSet extends AbstractRuptureSet<PointSource> {
// double mMin = parent.magMaster[0] - ΔmBy2; // double mMin = parent.magMaster[0] - ΔmBy2;
// double mMax = parent.magMaster[parent.magMaster.length - 1] + ΔmBy2; // double mMax = parent.magMaster[parent.magMaster.length - 1] + ΔmBy2;
double rMax = parent.groundMotionModels().maxDistance(); double rMax = parent.groundMotionModels().maxDistance();
double distanceBin = parent.distanceBin.orElseThrow();
double[] smoothingOffsets = smoothingOffsets( double[] smoothingOffsets = smoothingOffsets(
parent.smoothingDensity, parent.smoothingDensity,
parent.gridSpacing); parent.gridSpacing);
IntervalTable.Builder ssTableBuilder = new IntervalTable.Builder() IntervalTable.Builder ssTableBuilder = new IntervalTable.Builder()
.rows(0.0, rMax, parent.distanceBin) .rows(0.0, rMax, distanceBin)
.columns(mMin, mMax, Δm); .columns(mMin, mMax, Δm);
IntervalTable.Builder rTableBuilder = new IntervalTable.Builder() IntervalTable.Builder rTableBuilder = new IntervalTable.Builder()
.rows(0.0, rMax, parent.distanceBin) .rows(0.0, rMax, distanceBin)
.columns(mMin, mMax, Δm); .columns(mMin, mMax, Δm);
IntervalTable.Builder nTableBuilder = new IntervalTable.Builder() IntervalTable.Builder nTableBuilder = new IntervalTable.Builder()
.rows(0.0, rMax, parent.distanceBin) .rows(0.0, rMax, distanceBin)
.columns(mMin, mMax, Δm); .columns(mMin, mMax, Δm);
// XySequence srcMfdSum = null; // XySequence srcMfdSum = null;
......
...@@ -8,6 +8,7 @@ import static gov.usgs.earthquake.nshmp.data.DoubleData.checkInRange; ...@@ -8,6 +8,7 @@ import static gov.usgs.earthquake.nshmp.data.DoubleData.checkInRange;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalDouble;
import com.google.common.collect.Range; import com.google.common.collect.Range;
...@@ -178,7 +179,7 @@ abstract class SourceConfig { ...@@ -178,7 +179,7 @@ abstract class SourceConfig {
final double gridSpacing; final double gridSpacing;
final int smoothingDensity; final int smoothingDensity;
final double smoothingLimit; final double smoothingLimit;
final double distanceBin; final OptionalDouble distanceBin;
final PointSourceType pointSourceType; final PointSourceType pointSourceType;
final RuptureScaling ruptureScaling; final RuptureScaling ruptureScaling;
final double maxDepth; final double maxDepth;
...@@ -210,7 +211,7 @@ abstract class SourceConfig { ...@@ -210,7 +211,7 @@ abstract class SourceConfig {
private Double gridSpacing; private Double gridSpacing;
private Integer smoothingDensity; private Integer smoothingDensity;
private Double smoothingLimit; private Double smoothingLimit;
private Double distanceBin; private OptionalDouble distanceBin;
private PointSourceType pointSourceType; private PointSourceType pointSourceType;
private RuptureScaling ruptureScaling; private RuptureScaling ruptureScaling;
private Double maxDepth; private Double maxDepth;
...@@ -242,8 +243,8 @@ abstract class SourceConfig { ...@@ -242,8 +243,8 @@ abstract class SourceConfig {
private static final Range<Double> DISTANCE_RANGE = Range.closed(0.01, 5.0); private static final Range<Double> DISTANCE_RANGE = Range.closed(0.01, 5.0);
Builder distanceBin(double distance) { Builder distanceBin(OptionalDouble distance) {
checkInRange(DISTANCE_RANGE, "Distance bin", distance); distance.ifPresent(d -> checkInRange(DISTANCE_RANGE, "Distance bin", d));
this.distanceBin = distance; this.distanceBin = distance;
return this; return this;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment