|
21 | 21 | import java.util.concurrent.Future; |
22 | 22 | import java.util.concurrent.TimeUnit; |
23 | 23 |
|
| 24 | +import org.apache.commons.math3.util.Precision; |
24 | 25 | import org.jfree.data.Range; |
25 | 26 | import org.opensha.commons.data.CSVFile; |
26 | 27 | import org.opensha.commons.data.Site; |
|
36 | 37 | import org.opensha.commons.geo.LocationUtils; |
37 | 38 | import org.opensha.commons.geo.LocationVector; |
38 | 39 | import org.opensha.commons.geo.Region; |
| 40 | +import org.opensha.commons.gui.plot.GeographicMapMaker; |
39 | 41 | import org.opensha.commons.gui.plot.HeadlessGraphPanel; |
40 | 42 | import org.opensha.commons.gui.plot.PlotCurveCharacterstics; |
41 | 43 | import org.opensha.commons.gui.plot.PlotLineType; |
42 | 44 | import org.opensha.commons.gui.plot.PlotSpec; |
43 | 45 | import org.opensha.commons.gui.plot.PlotUtils; |
| 46 | +import org.opensha.commons.mapping.gmt.elements.GMT_CPT_Files; |
44 | 47 | import org.opensha.commons.param.Parameter; |
45 | 48 | import org.opensha.commons.param.impl.WarningDoubleParameter; |
46 | 49 | import org.opensha.commons.util.ExceptionUtils; |
| 50 | +import org.opensha.commons.util.cpt.CPT; |
47 | 51 | import org.opensha.commons.util.io.archive.ArchiveOutput; |
48 | 52 | import org.opensha.commons.util.io.archive.ArchiveOutput.ParallelZipFileOutput; |
49 | 53 | import org.opensha.sha.calc.HazardCurveCalculator; |
|
61 | 65 | import org.opensha.sha.earthquake.faultSysSolution.FaultSystemRupSet; |
62 | 66 | import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution; |
63 | 67 | import org.opensha.sha.earthquake.faultSysSolution.erf.BaseFaultSystemSolutionERF; |
| 68 | +import org.opensha.sha.earthquake.faultSysSolution.modules.FaultGridAssociations; |
64 | 69 | import org.opensha.sha.earthquake.faultSysSolution.modules.GridSourceProvider; |
65 | 70 | import org.opensha.sha.earthquake.observedEarthquake.ObsEqkRupList; |
66 | 71 | import org.opensha.sha.earthquake.observedEarthquake.ObsEqkRupture; |
|
90 | 95 | import org.opensha.sha.imr.param.SiteParams.DepthTo1pt0kmPerSecParam; |
91 | 96 | import org.opensha.sha.imr.param.SiteParams.DepthTo2pt5kmPerSecParam; |
92 | 97 | import org.opensha.sha.imr.param.SiteParams.Vs30_Param; |
| 98 | +import org.opensha.sha.magdist.IncrementalMagFreqDist; |
93 | 99 |
|
94 | 100 | import com.google.common.base.Preconditions; |
95 | 101 | import com.google.common.base.Stopwatch; |
@@ -428,6 +434,94 @@ public static void main(String[] args) throws IOException { |
428 | 434 | erf.setGriddedSeismicitySettings(origGridSettings); |
429 | 435 | erf.updateForecast(); |
430 | 436 | 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); |
431 | 525 | } else { |
432 | 526 | keptEvents = new ArrayList<>(); |
433 | 527 | keptFractsInReg = new ArrayList<>(); |
|
0 commit comments