Skip to content

Commit 7a10be1

Browse files
author
Kevin Milner
committed
updates for PRVI release candidate run
1 parent eee89fb commit 7a10be1

10 files changed

+1334
-41
lines changed

src/main/java/scratch/kevin/BayAreaRegionalGroundMotionCalc.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.concurrent.Future;
2222
import java.util.concurrent.TimeUnit;
2323

24+
import org.apache.commons.math3.util.Precision;
2425
import org.jfree.data.Range;
2526
import org.opensha.commons.data.CSVFile;
2627
import org.opensha.commons.data.Site;
@@ -36,14 +37,17 @@
3637
import org.opensha.commons.geo.LocationUtils;
3738
import org.opensha.commons.geo.LocationVector;
3839
import org.opensha.commons.geo.Region;
40+
import org.opensha.commons.gui.plot.GeographicMapMaker;
3941
import org.opensha.commons.gui.plot.HeadlessGraphPanel;
4042
import org.opensha.commons.gui.plot.PlotCurveCharacterstics;
4143
import org.opensha.commons.gui.plot.PlotLineType;
4244
import org.opensha.commons.gui.plot.PlotSpec;
4345
import org.opensha.commons.gui.plot.PlotUtils;
46+
import org.opensha.commons.mapping.gmt.elements.GMT_CPT_Files;
4447
import org.opensha.commons.param.Parameter;
4548
import org.opensha.commons.param.impl.WarningDoubleParameter;
4649
import org.opensha.commons.util.ExceptionUtils;
50+
import org.opensha.commons.util.cpt.CPT;
4751
import org.opensha.commons.util.io.archive.ArchiveOutput;
4852
import org.opensha.commons.util.io.archive.ArchiveOutput.ParallelZipFileOutput;
4953
import org.opensha.sha.calc.HazardCurveCalculator;
@@ -61,6 +65,7 @@
6165
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemRupSet;
6266
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution;
6367
import org.opensha.sha.earthquake.faultSysSolution.erf.BaseFaultSystemSolutionERF;
68+
import org.opensha.sha.earthquake.faultSysSolution.modules.FaultGridAssociations;
6469
import org.opensha.sha.earthquake.faultSysSolution.modules.GridSourceProvider;
6570
import org.opensha.sha.earthquake.observedEarthquake.ObsEqkRupList;
6671
import org.opensha.sha.earthquake.observedEarthquake.ObsEqkRupture;
@@ -90,6 +95,7 @@
9095
import org.opensha.sha.imr.param.SiteParams.DepthTo1pt0kmPerSecParam;
9196
import org.opensha.sha.imr.param.SiteParams.DepthTo2pt5kmPerSecParam;
9297
import org.opensha.sha.imr.param.SiteParams.Vs30_Param;
98+
import org.opensha.sha.magdist.IncrementalMagFreqDist;
9399

94100
import com.google.common.base.Preconditions;
95101
import com.google.common.base.Stopwatch;
@@ -428,6 +434,94 @@ public static void main(String[] args) throws IOException {
428434
erf.setGriddedSeismicitySettings(origGridSettings);
429435
erf.updateForecast();
430436
hazardMapERF = erf;
437+
438+
// write nucleation files
439+
GridSourceProvider gridProv = erf.getGridSourceProvider();
440+
GriddedRegion nuclRateRegion = new GriddedRegion(reg, 0.1, gridProv.getLocation(0));
441+
double[] nuclMags = {3.5d, 4d, 4.5, 5d, 5.5, 6d, 6.5, 7d, 7.5d};
442+
GriddedGeoDataSet[] nuclXYZs = new GriddedGeoDataSet[nuclMags.length];
443+
for (int m=0; m<nuclMags.length; m++)
444+
nuclXYZs[m] = new GriddedGeoDataSet(nuclRateRegion);
445+
446+
for (int l=0; l<gridProv.getNumLocations(); l++) {
447+
Location loc = gridProv.getLocation(l);
448+
int index = nuclRateRegion.indexForLocation(loc);
449+
if (index >= 0) {
450+
IncrementalMagFreqDist mfd = gridProv.getMFD(l);
451+
// if (mfd == null)
452+
// continue;
453+
for (int m=0; m<nuclMags.length; m++) {
454+
int magIndex = mfd.getClosestXIndex(nuclMags[m]+0.01);
455+
Preconditions.checkState(mfd.getX(magIndex) > nuclMags[m] && mfd.getX(magIndex) < nuclMags[m]+0.1);
456+
nuclXYZs[m].add(index, mfd.getCumRate(magIndex));
457+
}
458+
}
459+
}
460+
461+
// now add fault ruptures
462+
FaultSystemSolution sol = erf.getSolution();
463+
FaultGridAssociations assoc = rupSet.requireModule(FaultGridAssociations.class);
464+
465+
double[] sectAreas = rupSet.getAreaForAllSections();
466+
double[] rupAreas = rupSet.getAreaForAllRups();
467+
for (int rupIndex=0; rupIndex<rupSet.getNumRuptures(); rupIndex++) {
468+
double sumArea = 0d;
469+
List<Integer> sects = rupSet.getSectionsIndicesForRup(rupIndex);
470+
471+
double mag = rupSet.getMagForRup(rupIndex);
472+
double rate = sol.getRateForRup(rupIndex);
473+
for (int sectIndex : sects) {
474+
double fractArea = sectAreas[sectIndex]/rupAreas[rupIndex];
475+
sumArea += sectAreas[sectIndex];
476+
477+
Map<Integer, Double> nodeFracts = assoc.getNodeFractions(rupIndex);
478+
for (int origNodeIndex : nodeFracts.keySet()) {
479+
int index = nuclRateRegion.indexForLocation(gridProv.getLocation(origNodeIndex));
480+
if (index >= 0) {
481+
double nodeFract = nodeFracts.get(origNodeIndex);
482+
double fractNucl = rate * fractArea * nodeFract;
483+
Preconditions.checkState(Double.isFinite(fractNucl));
484+
for (int m=0; m<nuclMags.length; m++)
485+
if ((float)mag >= (float)nuclMags[m])
486+
nuclXYZs[m].add(index, fractNucl);
487+
}
488+
}
489+
}
490+
Preconditions.checkState(Precision.equals(sumArea, rupAreas[rupIndex], 1e-2));
491+
}
492+
493+
CSVFile<String> nuclCSV = new CSVFile<>(true);
494+
List<String> nuclHeader = new ArrayList<>();
495+
nuclHeader.add("Latitude");
496+
nuclHeader.add("Longitude");
497+
for (double nuclMag : nuclMags)
498+
nuclHeader.add("M>"+(float)nuclMag);
499+
nuclCSV.addLine(nuclHeader);
500+
501+
GeographicMapMaker mapMaker = new GeographicMapMaker(nuclRateRegion);
502+
mapMaker.setWriteGeoJSON(false);
503+
504+
for (int m=0; m<nuclMags.length; m++) {
505+
System.out.println("M"+nuclMags[m]+" nucl range: "+nuclXYZs[m].getMinZ()+", "+nuclXYZs[m].getMaxZ());
506+
CPT cpt = GMT_CPT_Files.SEQUENTIAL_BATLOW_UNIFORM.instance().rescale(
507+
Math.floor(Math.log10(nuclXYZs[m].getMinZ())), Math.ceil(Math.log10(nuclXYZs[m].getMaxZ())));
508+
cpt.setLog10(true);
509+
mapMaker.plotXYZData(nuclXYZs[m], cpt, "M>"+nuclMags[m]+" nucleation rate");
510+
511+
mapMaker.plot(outputDir, "nucleation_rates_m"+oDF.format(nuclMags[m]), " ");
512+
}
513+
514+
for (int i=0; i<nuclRateRegion.getNodeCount(); i++) {
515+
List<String> line = new ArrayList<>(nuclHeader.size());
516+
Location loc = nuclRateRegion.locationForIndex(i);
517+
line.add((float)loc.lat+"");
518+
line.add((float)loc.lon+"");
519+
for (int m=0; m<nuclMags.length; m++)
520+
line.add((float)nuclXYZs[m].get(i)+"");
521+
nuclCSV.addLine(line);
522+
}
523+
nuclCSV.writeToFile(new File(outputDir, "nucleation_rates.csv"));
524+
System.exit(0);
431525
} else {
432526
keptEvents = new ArrayList<>();
433527
keptFractsInReg = new ArrayList<>();

0 commit comments

Comments
 (0)