Skip to content

Commit 1ffabc3

Browse files
authored
Merge pull request #53 from opensha/2024_09-point_source_dist_corr_refactor
Updates for point source refactor
2 parents a1c0100 + fd6e42c commit 1ffabc3

34 files changed

+1843
-397
lines changed

src/main/java/scratch/kevin/nga/Idriss2013Debug.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import org.opensha.sha.earthquake.param.BackgroundRupType;
1111
import org.opensha.sha.earthquake.param.ProbabilityModelOptions;
1212
import org.opensha.sha.earthquake.rupForecastImpl.FaultRuptureSource;
13-
import org.opensha.sha.earthquake.rupForecastImpl.PointSource13b;
13+
import org.opensha.sha.earthquake.rupForecastImpl.PointSourceNshm;
1414
import org.opensha.sha.earthquake.rupForecastImpl.WGCEP_UCERF_2_Final.griddedSeis.Point2Vert_FaultPoisSource;
1515
import org.opensha.sha.faultSurface.EvenlyGriddedSurface;
1616
import org.opensha.sha.faultSurface.FourPointEvenlyGriddedSurface;
17+
import org.opensha.sha.faultSurface.utils.PointSourceDistanceCorrections;
1718
import org.opensha.sha.imr.attenRelImpl.ngaw2.NGAW2_Wrappers.Idriss_2014_Wrapper;
1819
import org.opensha.sha.imr.param.IntensityMeasureParams.PGA_Param;
1920
import org.opensha.sha.imr.param.SiteParams.DepthTo1pt0kmPerSecParam;
@@ -66,27 +67,26 @@ public static void main(String[] args) {
6667
double fracReverse = 0d;
6768
WC1994_MagLengthRelationship magLenRel = new WC1994_MagLengthRelationship();
6869
double ptSrcCutoff = 6.0;
69-
double[] DEPTHS = new double[] {5.0, 1.0};
7070

7171
ProbEqkSource pointSource;
7272

7373
switch (bgRupType) {
7474
case CROSSHAIR:
7575
pointSource = new Point2Vert_FaultPoisSource(faultLoc, mfd, magLenRel, duration,
7676
ptSrcCutoff, fracStrikeSlip, fracNormal,
77-
fracReverse, true);
77+
fracReverse, true, null);
7878
break;
7979
case FINITE:
8080
pointSource = new Point2Vert_FaultPoisSource(faultLoc, mfd, magLenRel, duration,
8181
ptSrcCutoff, fracStrikeSlip, fracNormal,
82-
fracReverse, false);
82+
fracReverse, false, null);
8383
break;
8484
case POINT:
8585
Map<FocalMech, Double> mechMap = Maps.newHashMap();
8686
mechMap.put(FocalMech.STRIKE_SLIP, fracStrikeSlip);
8787
mechMap.put(FocalMech.REVERSE, fracReverse);
8888
mechMap.put(FocalMech.NORMAL, fracNormal);
89-
pointSource = new PointSource13b(faultLoc, mfd, duration, DEPTHS, mechMap);
89+
pointSource = new PointSourceNshm(faultLoc, mfd, duration, mechMap, PointSourceDistanceCorrections.NONE.get());
9090
break;
9191
default:
9292
throw new IllegalStateException("Unknown Background Rup Type: "+bgRupType);

src/main/java/scratch/nshm23/BValSweepHazardComparison.java renamed to src/main/java/scratch/kevin/nshm23/BValSweepHazardComparison.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scratch.nshm23;
1+
package scratch.kevin.nshm23;
22

33
import java.awt.Color;
44
import java.io.File;

src/main/java/scratch/kevin/nshm23/BranchAveragedHazardScriptWriter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static void main(String[] args) throws IOException {
3333
boolean linkFromBase = true;
3434
Double vs30 = null;
3535
double gridSpacing = 0.1;
36+
boolean supersample = false;
3637

3738
double[] periods = { 0d, 0.2d, 1d, 5d };
3839
AttenRelRef[] gmms = null;
@@ -77,7 +78,9 @@ public static void main(String[] args) throws IOException {
7778
// String solFileName = "results_PRVI_SUB_FM_LARGE_branch_averaged_gridded.zip";
7879

7980
String baseDirName = "2024_11_19-prvi25_crustal_subduction_combined_branches";
80-
String suffix = "ba_only";
81+
// String suffix = "ba_only";
82+
// String suffix = "ba_only-test_grid_branch";
83+
String suffix = "ba_only-test_grid_branch-supersample"; supersample = true;
8184
String solFileName = "combined_branch_averaged_solution.zip";
8285

8386
// String baseDirName = "2024_11_19-prvi25_crustal_branches-dmSample5x";
@@ -158,6 +161,9 @@ public static void main(String[] args) throws IOException {
158161
// remoteTotalMemGB*1024, null);
159162
// BatchScriptWriter pbsWrite = new HovenweepScriptWriter();
160163

164+
if (parallelMPJWrite instanceof FastMPJShellScriptWriter)
165+
((FastMPJShellScriptWriter)parallelMPJWrite).setUseLaunchWrapper(true);
166+
161167
parallelMPJWrite.setEnvVar("MAIN_DIR", remoteMainDir.getAbsolutePath());
162168
singleMPJWrite.setEnvVar("MAIN_DIR", remoteMainDir.getAbsolutePath());
163169
String mainDirPath = "$MAIN_DIR";
@@ -239,6 +245,8 @@ else if (gridReg.getNodeCount() > 5000)
239245
argz += (float)periods[p];
240246
}
241247
}
248+
if (supersample)
249+
argz += " --supersample";
242250
argz += " "+dispatchArgs;
243251

244252
File jobFile = new File(localDir, "batch_hazard_"+bgOp.name()+".slurm");
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package scratch.kevin.nshm23;
2+
3+
import java.awt.geom.Point2D;
4+
import java.io.File;
5+
import java.io.IOException;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import org.opensha.commons.data.CSVFile;
10+
import org.opensha.commons.data.function.ArbDiscrEmpiricalDistFunc;
11+
import org.opensha.commons.data.function.EvenlyDiscretizedFunc;
12+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemRupSet;
13+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution;
14+
import org.opensha.sha.earthquake.faultSysSolution.modules.BranchSectParticMFDs;
15+
import org.opensha.sha.earthquake.faultSysSolution.util.FaultSysTools;
16+
import org.opensha.sha.faultSurface.FaultSection;
17+
import org.opensha.sha.magdist.IncrementalMagFreqDist;
18+
19+
public class SectRIDistCSVWriter {
20+
21+
public static void main(String[] args) throws IOException {
22+
FaultSystemSolution sol = FaultSystemSolution.load(new File("/home/kevin/OpenSHA/nshm23/batch_inversions/"
23+
+ "2024_02_02-nshm23_branches-WUS_FM_v3/results_WUS_FM_v3_branch_averaged.zip"));
24+
FaultSystemRupSet rupSet = sol.getRupSet();
25+
26+
BranchSectParticMFDs sectMFDs = sol.requireModule(BranchSectParticMFDs.class);
27+
28+
double[] mags = {0d, 6d, 6.5d, 7d, 7.5d};
29+
30+
double[] fractiles = {0.025,0.16, 0.84, 0.975};
31+
32+
List<String> riHeader = List.of("Subsection Index", "Parent Section ID", "Subsection Name"
33+
,"Mean RI", "Min RI", "Max RI", "Std. Dev", "p2.5", "p16.0", "p84.0", "p97.5");
34+
List<String> rateHeader = new ArrayList<>(riHeader);
35+
for (int i=0; i<rateHeader.size(); i++)
36+
rateHeader.set(i, rateHeader.get(i).replace("RI", "Rate"));
37+
List<CSVFile<String>> riCSVs = new ArrayList<>(mags.length);
38+
List<CSVFile<String>> rateCSVs = new ArrayList<>(mags.length);
39+
for (int m=0; m<mags.length; m++) {
40+
CSVFile<String> riCSV = new CSVFile<>(true);
41+
riCSV.addLine(riHeader);
42+
riCSVs.add(riCSV);
43+
CSVFile<String> rateCSV = new CSVFile<>(true);
44+
rateCSV.addLine(rateHeader);
45+
rateCSVs.add(rateCSV);
46+
}
47+
48+
EvenlyDiscretizedFunc refMFD = FaultSysTools.initEmptyMFD(5.05, 8.45);
49+
List<String> mfdHeader = new ArrayList<>();
50+
mfdHeader.addAll(riHeader.subList(0, 3));
51+
for (int i=0; i<refMFD.size(); i++)
52+
mfdHeader.add((float)refMFD.getX(i)+"");
53+
CSVFile<String> mfdParticCSV = new CSVFile<>(true);
54+
mfdParticCSV.addLine(mfdHeader);
55+
CSVFile<String> mfdNuclCSV = new CSVFile<>(true);
56+
mfdNuclCSV.addLine(mfdHeader);
57+
58+
for (int s=0; s<rupSet.getNumSections(); s++) {
59+
FaultSection sect = rupSet.getFaultSectionData(s);
60+
IncrementalMagFreqDist particMFD = sol.calcParticipationMFD_forSect(s, refMFD.getMinX(), refMFD.getMaxX(), refMFD.size());
61+
IncrementalMagFreqDist nuclMFD = sol.calcNucleationMFD_forSect(s, refMFD.getMinX(), refMFD.getMaxX(), refMFD.size());
62+
List<String> common = List.of(s+"", sect.getParentSectionId()+"", sect.getSectionName());
63+
List<String> partic = new ArrayList<>(common);
64+
List<String> nucl = new ArrayList<>(common);
65+
for (int i=0; i<refMFD.size(); i++) {
66+
partic.add((float)particMFD.getY(i)+"");
67+
nucl.add((float)nuclMFD.getY(i)+"");
68+
}
69+
mfdParticCSV.addLine(partic);
70+
mfdNuclCSV.addLine(nucl);
71+
72+
for (boolean rate : new boolean[] {false,true}) {
73+
ArbDiscrEmpiricalDistFunc[] dists = new ArbDiscrEmpiricalDistFunc[mags.length];
74+
for (int m=0; m<dists.length; m++)
75+
dists[m] = new ArbDiscrEmpiricalDistFunc();
76+
77+
for (int b=0; b<sectMFDs.getNumBranches(); b++) {
78+
double weight = sectMFDs.getBranchWeight(b);
79+
IncrementalMagFreqDist mfd = sectMFDs.getSectionMFD(b, s);
80+
double[] rates = new double[mags.length];
81+
for (Point2D pt : mfd)
82+
for (int m=0; m<mags.length; m++)
83+
if ((float)pt.getX() >= (float)mags[m])
84+
rates[m] += pt.getY();
85+
if (!rate)
86+
for (int m=0; m<mags.length; m++)
87+
rates[m] = 1d/rates[m];
88+
89+
for (int m=0; m<mags.length; m++)
90+
dists[m].set(rates[m], weight);
91+
}
92+
for (int m=0; m<mags.length; m++) {
93+
List<String> line = new ArrayList<>(common);
94+
line.add((float)dists[m].getMean()+"");
95+
line.add((float)dists[m].getMinX()+"");
96+
line.add((float)dists[m].getMinY()+"");
97+
line.add((float)dists[m].getStdDev()+"");
98+
for (double fract : fractiles)
99+
line.add((float)dists[m].getInterpolatedFractile(fract)+"");
100+
if (rate)
101+
rateCSVs.get(m).addLine(line);
102+
else
103+
riCSVs.get(m).addLine(line);
104+
}
105+
}
106+
}
107+
108+
File outputDir = new File("/tmp");
109+
String prefix = "nshm23_wus";
110+
mfdParticCSV.writeToFile(new File(outputDir, prefix+"_partic_mfds.csv"));
111+
mfdNuclCSV.writeToFile(new File(outputDir, prefix+"_nucl_mfds.csv"));
112+
for (int m=0; m<mags.length; m++) {
113+
String magPrefix;
114+
if (mags[m] == 0)
115+
magPrefix = prefix+"_supra_seis";
116+
else
117+
magPrefix = prefix+"_m"+(float)mags[m];
118+
rateCSVs.get(m).writeToFile(new File(outputDir, magPrefix+"_rate_dists.csv"));
119+
riCSVs.get(m).writeToFile(new File(outputDir, magPrefix+"_ri_dists.csv"));
120+
}
121+
}
122+
123+
}

src/main/java/scratch/kevin/nshm23/SimpleSmoothHazardMapCalc.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.util.NSHM23_RegionLoader;
3636
import org.opensha.sha.faultSurface.PointSurface;
3737
import org.opensha.sha.faultSurface.RuptureSurface;
38-
import org.opensha.sha.faultSurface.utils.PtSrcDistCorr;
3938
import org.opensha.sha.gui.infoTools.IMT_Info;
4039
import org.opensha.sha.imr.AttenRelRef;
4140
import org.opensha.sha.imr.ScalarIMR;
@@ -89,7 +88,6 @@ public static GriddedGeoDataSet[] distKernelSmooth(GriddedGeoDataSet[] momentMap
8988

9089
Location rupLoc = dist == 0d ? siteLoc : LocationUtils.location(siteLoc, 0d, dist);
9190
PointSurface rupSurf = new PointSurface(rupLoc);
92-
rupSurf.setDistCorrMagAndType(Double.NaN, PtSrcDistCorr.Type.NONE);
9391
rupSurf.setAveDip(90d);
9492
rupSurf.setAveStrike(0d);
9593

@@ -319,7 +317,6 @@ public MomentScaledFixedMagERF(GriddedGeoDataSet momentMap, double refMag) {
319317

320318
Location rupLoc = momentMap.getLocation(i);
321319
PointSurface rupSurf = new PointSurface(rupLoc);
322-
rupSurf.setDistCorrMagAndType(Double.NaN, PtSrcDistCorr.Type.NONE);
323320
rupSurf.setAveDip(90d);
324321
rupSurf.setAveStrike(0d);
325322

@@ -370,7 +367,6 @@ public MomentScaledMFDShapeERF(GriddedGeoDataSet momentMap, IncrementalMagFreqDi
370367

371368
Location rupLoc = momentMap.getLocation(i);
372369
PointSurface rupSurf = new PointSurface(rupLoc);
373-
rupSurf.setDistCorrMagAndType(Double.NaN, PtSrcDistCorr.Type.NONE);
374370
rupSurf.setAveDip(90d);
375371
rupSurf.setAveStrike(0d);
376372

@@ -444,7 +440,6 @@ public RateScaledFixedMagERF(GriddedGeoDataSet rateMap, double refMag) {
444440

445441
Location rupLoc = rateMap.getLocation(i);
446442
PointSurface rupSurf = new PointSurface(rupLoc);
447-
rupSurf.setDistCorrMagAndType(Double.NaN, PtSrcDistCorr.Type.NONE);
448443
rupSurf.setAveDip(90d);
449444
rupSurf.setAveStrike(0d);
450445

@@ -495,7 +490,6 @@ public RateScaledMFDShapeERF(GriddedGeoDataSet rateMap, IncrementalMagFreqDist m
495490

496491
Location rupLoc = rateMap.getLocation(i);
497492
PointSurface rupSurf = new PointSurface(rupLoc);
498-
rupSurf.setDistCorrMagAndType(Double.NaN, PtSrcDistCorr.Type.NONE);
499493
rupSurf.setAveDip(90d);
500494
rupSurf.setAveStrike(0d);
501495

src/main/java/scratch/kevin/nshm23/wrapper/MPJ_WrapperHazardCalc.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.cli.Options;
2424
import org.opensha.commons.data.CSVFile;
2525
import org.opensha.commons.data.Site;
26+
import org.opensha.commons.data.WeightedList;
2627
import org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc;
2728
import org.opensha.commons.data.function.DiscretizedFunc;
2829
import org.opensha.commons.data.xyz.GriddedGeoDataSet;
@@ -45,6 +46,9 @@
4546
import org.opensha.sha.earthquake.faultSysSolution.util.SolHazardMapCalc.ReturnPeriods;
4647
import org.opensha.sha.earthquake.param.BackgroundRupType;
4748
import org.opensha.sha.earthquake.param.IncludeBackgroundOption;
49+
import org.opensha.sha.earthquake.util.GriddedSeismicitySettings;
50+
import org.opensha.sha.faultSurface.utils.PointSourceDistanceCorrection;
51+
import org.opensha.sha.faultSurface.utils.PointSourceDistanceCorrections;
4852
import org.opensha.sha.gui.infoTools.IMT_Info;
4953
import org.opensha.sha.imr.AttenRelRef;
5054
import org.opensha.sha.imr.ScalarIMR;
@@ -85,6 +89,9 @@ public class MPJ_WrapperHazardCalc extends MPJTaskCalculator {
8589
private static final IncludeBackgroundOption GRID_SEIS_DEFAULT = IncludeBackgroundOption.INCLUDE;
8690
private IncludeBackgroundOption gridSeisOp = GRID_SEIS_DEFAULT;
8791

92+
// TODO: CLI
93+
private GriddedSeismicitySettings gridSettings = GriddedSeismicitySettings.DEFAULT;
94+
8895
private boolean noSubduction = false;
8996
private boolean noActive = false;
9097
private boolean noStable = false;
@@ -414,7 +421,7 @@ public int getNumSources() {
414421

415422
@Override
416423
public ProbEqkSource getSource(int idx) {
417-
return externalGridProv.getSource(idx, 1d, null, BackgroundRupType.POINT);
424+
return externalGridProv.getSource(idx, 1d, null, gridSettings);
418425
}
419426

420427
@Override

src/main/java/scratch/kevin/nshm23/wrapper/SingleSiteVerificationTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
import org.opensha.sha.earthquake.param.IncludeBackgroundParam;
3737
import org.opensha.sha.earthquake.param.ProbabilityModelOptions;
3838
import org.opensha.sha.earthquake.param.ProbabilityModelParam;
39+
import org.opensha.sha.earthquake.util.GriddedSeismicitySettings;
3940
import org.opensha.sha.faultSurface.RuptureSurface;
41+
import org.opensha.sha.faultSurface.utils.PointSourceDistanceCorrection;
42+
import org.opensha.sha.faultSurface.utils.PointSourceDistanceCorrections;
4043
import org.opensha.sha.gui.infoTools.IMT_Info;
4144
import org.opensha.sha.imr.AttenRelRef;
4245
import org.opensha.sha.imr.ScalarIMR;
@@ -65,6 +68,8 @@ public static void main(String[] args) throws IOException {
6568
boolean subduction = false;
6669
Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
6770

71+
GriddedSeismicitySettings gridSettings = GriddedSeismicitySettings.DEFAULT;
72+
6873
Set<TectonicRegionType> trts = EnumSet.of(TectonicRegionType.ACTIVE_SHALLOW);
6974
if (subduction) {
7075
trts.add(TectonicRegionType.SUBDUCTION_INTERFACE);
@@ -144,7 +149,7 @@ public static void main(String[] args) throws IOException {
144149
calc.getHazardCurve(logXVals, site, gmpe, erf);
145150
DiscretizedFunc wrapperFaultCurve = toLinear(logXVals, xVals);
146151

147-
ProbEqkSource modelTestSrc = gridProv.getSource(testIndex, 1d, null, BackgroundRupType.POINT);
152+
ProbEqkSource modelTestSrc = gridProv.getSource(testIndex, 1d, null, gridSettings);
148153
FaultSystemSolutionERF modelERF = new FaultSystemSolutionERF(baSol);
149154
modelERF.setParameter(ApplyGardnerKnopoffAftershockFilterParam.NAME, false);
150155
modelERF.setParameter(ProbabilityModelParam.NAME, ProbabilityModelOptions.POISSON);

0 commit comments

Comments
 (0)