Skip to content

Commit a4aab64

Browse files
author
Kevin Milner
committed
Merge branch 'master' into 2024_09-point_source_dist_corr_refactor
2 parents f7382dc + f5222a1 commit a4aab64

16 files changed

+2109
-216
lines changed

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -625,35 +625,35 @@ public static void main(String[] args) throws IOException {
625625
* PRVI25 logic tree
626626
* TODO (this is a just a marker to find this part quickly, not an actual todo)
627627
*/
628-
// List<LogicTreeLevel<? extends LogicTreeNode>> levels = PRVI25_LogicTreeBranch.levelsOnFault;
629-
// dirName += "-prvi25_crustal_branches";
630-
// double avgNumRups = 50000;
631-
// gmpes = new AttenRelRef[] { AttenRelRef.USGS_PRVI_ACTIVE };
632-
//
633-
// // random DM sampling
634-
// levels = new ArrayList<>(levels);
635-
// int origNumLevels = levels.size();
636-
// for (int i=levels.size(); --i>=0;)
637-
// if (levels.get(i).getNodes().get(0) instanceof PRVI25_CrustalDeformationModels)
638-
// levels.remove(i);
639-
// Preconditions.checkState(levels.size() == origNumLevels -1);
640-
// individualRandomLevels.add(new PRVI25_CrustalRandomlySampledDeformationModelLevel());
641-
// samplingBranchCountMultiplier = 5; // 5 for each branch
642-
// dirName += "-dmSample";
643-
// if (samplingBranchCountMultiplier > 1)
644-
// dirName += samplingBranchCountMultiplier+"x";
628+
List<LogicTreeLevel<? extends LogicTreeNode>> levels = PRVI25_LogicTreeBranch.levelsOnFault;
629+
dirName += "-prvi25_crustal_branches";
630+
double avgNumRups = 50000;
631+
gmpes = new AttenRelRef[] { AttenRelRef.USGS_PRVI_ACTIVE };
632+
633+
// random DM sampling
634+
levels = new ArrayList<>(levels);
635+
int origNumLevels = levels.size();
636+
for (int i=levels.size(); --i>=0;)
637+
if (levels.get(i).getNodes().get(0) instanceof PRVI25_CrustalDeformationModels)
638+
levels.remove(i);
639+
Preconditions.checkState(levels.size() == origNumLevels -1);
640+
individualRandomLevels.add(new PRVI25_CrustalRandomlySampledDeformationModelLevel());
641+
samplingBranchCountMultiplier = 5; // 5 for each branch
642+
dirName += "-dmSample";
643+
if (samplingBranchCountMultiplier > 1)
644+
dirName += samplingBranchCountMultiplier+"x";
645645

646-
List<LogicTreeLevel<? extends LogicTreeNode>> levels = PRVI25_LogicTreeBranch.levelsSubduction;
647-
dirName += "-prvi25_subduction_branches";
648-
double avgNumRups = 10000;
649-
gmpes = new AttenRelRef[] { AttenRelRef.USGS_PRVI_INTERFACE, AttenRelRef.USGS_PRVI_SLAB };
646+
// List<LogicTreeLevel<? extends LogicTreeNode>> levels = PRVI25_LogicTreeBranch.levelsSubduction;
647+
// dirName += "-prvi25_subduction_branches";
648+
// double avgNumRups = 10000;
649+
// gmpes = new AttenRelRef[] { AttenRelRef.USGS_PRVI_INTERFACE, AttenRelRef.USGS_PRVI_SLAB };
650650

651651
// levels = new ArrayList<>(levels);
652652
// levels.add(NSHM23_LogicTreeBranch.SUB_SECT_CONSTR);
653653

654654
// dirName += "-proxyGriddedTests";
655655

656-
// Class<? extends InversionConfigurationFactory> factoryClass = PRVI25_InvConfigFactory.class;
656+
Class<? extends InversionConfigurationFactory> factoryClass = PRVI25_InvConfigFactory.class;
657657

658658
// Class<? extends InversionConfigurationFactory> factoryClass = PRVI25_InvConfigFactory.GriddedUseM1Bounds.class;
659659
// dirName += "-grid_bounds_m1";
@@ -670,8 +670,8 @@ public static void main(String[] args) throws IOException {
670670
// Class<? extends InversionConfigurationFactory> factoryClass = PRVI25_InvConfigFactory.RateBalanceAndLimitCrustalBelowObserved_0p9.class;
671671
// dirName += "-limit_below_obs_constraint-grided_rate_balancing";
672672

673-
Class<? extends InversionConfigurationFactory> factoryClass = PRVI25_InvConfigFactory.GriddedForceSlab2Depths.class;
674-
dirName += "-gridded_use_slab2";
673+
// Class<? extends InversionConfigurationFactory> factoryClass = PRVI25_InvConfigFactory.GriddedForceSlab2Depths.class;
674+
// dirName += "-gridded_use_slab2";
675675

676676
if (!factoryClass.equals(PRVI25_InvConfigFactory.class)) {
677677
// try instantiate it to make sure we get any static modifiers that might change branch weights

src/main/java/scratch/kevin/prvi25/FaultSystemLineIntegralCalculator.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,12 @@ public GeographicMapMaker buildMapPlot(boolean labelMagnitudes, boolean plotVect
483483
if (result == integrals.get(0)) {
484484
double integralMiddleLat = 0.5*(result.startLoc.lat + result.endLoc.lat);
485485
double integralMiddleLon = 0.5*(result.startLoc.lon + result.endLoc.lon);
486+
double furthestLeftLon = Math.max(lowerLeft.lon+0.25, lowerLeft.lon + 0.05*(upperRight.lon - lowerLeft.lon));
487+
System.out.println("Furthest left="+furthestLeftLon+", integral left="+integralMiddleLon);
486488
XYTextAnnotation ann = new XYTextAnnotation("Summation Direction", integralMiddleLon, integralMiddleLat);
487489
ann.setFont(textAnnFont);
488-
ann.setTextAnchor(TextAnchor.TOP_CENTER);
489-
ann.setRotationAnchor(TextAnchor.TOP_CENTER);
490+
ann.setTextAnchor(TextAnchor.BOTTOM_CENTER);
491+
ann.setRotationAnchor(TextAnchor.BOTTOM_CENTER);
490492
double vectorAngle = result.azimuth;
491493
while (vectorAngle > 180d)
492494
vectorAngle -= 360d;
@@ -496,6 +498,13 @@ public GeographicMapMaker buildMapPlot(boolean labelMagnitudes, boolean plotVect
496498
ann.setTextAnchor(TextAnchor.BOTTOM_CENTER);
497499
ann.setRotationAnchor(TextAnchor.BOTTOM_CENTER);
498500
}
501+
// } else if (integralMiddleLon < furthestLeftLon) {
502+
//// } else {
503+
// // too far to the left, put it on the other side
504+
//// vectorAngle -= 180;
505+
// ann.setTextAnchor(TextAnchor.BOTTOM_CENTER);
506+
// ann.setRotationAnchor(TextAnchor.BOTTOM_CENTER);
507+
// }
499508
double angleRad = Math.toRadians(vectorAngle + 90);
500509
ann.setRotationAngle(mapMaker.getRotationAngleCorrectedForAspectRatio(angleRad));
501510
mapMaker.addAnnotation(ann);
@@ -587,7 +596,7 @@ public GeographicMapMaker buildMapPlot(boolean labelMagnitudes, boolean plotVect
587596
arrowLen = 0.2*maxVectDist;
588597
arrowThickness = 4f;
589598
} else {
590-
arrowLen = 0.2*maxVectDist;
599+
arrowLen = 0.15*maxVectDist;
591600
arrowThickness = 2f;
592601
}
593602
mapMaker.setFillArrowheads(true);

src/main/java/scratch/kevin/prvi25/PRVI_SubductionTestRupSetBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public static void main(String[] args) throws IOException {
3333
// PRVI25_SubductionFaultModels fm = PRVI25_SubductionFaultModels.PRVI_SUB_FM_SMALL;
3434
PRVI25_SubductionDeformationModels dm = PRVI25_SubductionDeformationModels.FULL;
3535

36-
File outputDir = new File("/home/kevin/Documents/papers/2024_PRVI_Subduction/figures/fault_model");
36+
// File outputDir = new File("/home/kevin/Documents/papers/2024_PRVI_Subduction/figures/fault_model");
37+
File outputDir = new File("/home/kevin/Documents/papers/2024_PRVI_ERF/prvi25-erf-paper/Figures/sub_fm");
3738
Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
3839

3940
// first just write out the fault model

src/main/java/scratch/kevin/prvi25/SubductionDefModConvert.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ public static void main(String[] args) throws IOException {
9595
boolean interpolate = true;
9696
boolean interpSymmetry = true;
9797

98-
File debugDir = new File("/home/kevin/Documents/papers/2024_PRVI_Subduction/figures/def_model");
99-
Preconditions.checkState(debugDir.exists() || debugDir.mkdir());
98+
// File plotOutputDir = new File("/home/kevin/Documents/papers/2024_PRVI_Subduction/figures/def_model");
99+
File plotOutputDir = new File("/home/kevin/Documents/papers/2024_PRVI_ERF/prvi25-erf-paper/Figures/sub_dm");
100+
Preconditions.checkState(plotOutputDir.exists() || plotOutputDir.mkdir());
100101

101102
Table<Boolean, Boolean, String> debugPrefixes = HashBasedTable.create();
102103

@@ -138,7 +139,7 @@ public static void main(String[] args) throws IOException {
138139
String fmTitle = geomTitle;
139140
String fmDmTitle = geomTitle+", "+rateTitle;
140141
debugPrefixes.put(fullRate, largePolys, prefix);
141-
debugWriteSectOrders(inFeatures, debugDir, prefix, fmTitle, fmDmTitle,
142+
debugWriteSectOrders(inFeatures, plotOutputDir, prefix, fmTitle, fmDmTitle,
142143
ratePropName, rateUncertPropName, rakePropName);
143144

144145
Map<String, int[]> stitchInIDs = new HashMap<>();
@@ -447,7 +448,7 @@ public static void main(String[] args) throws IOException {
447448

448449
// plot them
449450
String interpPrefix = prefix+"_interp_"+name.replaceAll("\\W+", "_");
450-
debugWriteInterpFuncsOrders(debugDir, interpPrefix, name,
451+
debugWriteInterpFuncsOrders(plotOutputDir, interpPrefix, name,
451452
dasSlipFunc, dasSlipUncertFunc, dasRakeFunc, sectStartDASs,
452453
sectMidDASs, interpRanges);
453454
}
@@ -531,7 +532,7 @@ public static void main(String[] args) throws IOException {
531532
lines.add(tocIndex, "## Table Of Contents");
532533

533534
// write markdown
534-
MarkdownUtils.writeReadmeAndHTML(lines, debugDir);
535+
MarkdownUtils.writeReadmeAndHTML(lines, plotOutputDir);
535536
}
536537

537538
private static final DecimalFormat moDF = new DecimalFormat("0.00E0");
@@ -652,8 +653,13 @@ private static void debugWriteSectOrders(List<Feature> features, File outputDir,
652653
for (int s=0; s<sects.size(); s++) {
653654
arrows.addAll(PRVI_SubductionSubSectPlots.buildRakeArrows(sects.get(s), slipCPT.getMaxValue()));
654655
}
655-
System.out.println("Plotting "+arrows.size()+" arrow lines");
656-
mapMaker.plotLines(arrows, Color.BLACK, 2f);
656+
System.out.println("Plotting "+arrows.size()+" arrow lines for "+prefix);
657+
// mapMaker.plotLines(arrows, Color.BLACK, 2f);
658+
mapMaker.plotArrows(arrows, 20d, Color.BLACK, 2f);
659+
mapMaker.setFillArrowheads(true);
660+
661+
mapMaker.plotSectScalars(slips, slipCPT, null);
662+
mapMaker.plot(outputDir, prefix+"_slips_no_cpt", fmDmTitle);
657663
}
658664

659665
mapMaker.plotSectScalars(slips, slipCPT, "Slip Rate (mm/yr)");

src/main/java/scratch/kevin/prvi25/figures/CombinedMFDsPlot.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ public static void main(String[] args) throws IOException {
132132
PlotUtils.writePlots(outputDir, "combined_mfds_cml", gp, 800, 750, true, false, false);
133133
}
134134

135-
private static IncrementalMagFreqDist calcFaultMFD(Region region, FaultSystemSolution sol, EvenlyDiscretizedFunc refMFD) {
135+
static IncrementalMagFreqDist calcFaultMFD(Region region, FaultSystemSolution sol, EvenlyDiscretizedFunc refMFD) {
136136
return sol.calcNucleationMFD_forRegion(region, refMFD.getMinX(), refMFD.getMaxX(), refMFD.getDelta(), false);
137137
}
138138

139-
private static IncrementalMagFreqDist calcGriddedMFD(Region region, TectonicRegionType trt,
139+
static IncrementalMagFreqDist calcGriddedMFD(Region region, TectonicRegionType trt,
140140
FaultSystemSolution sol, EvenlyDiscretizedFunc refMFD) {
141141
GridSourceProvider gridProv = sol.getGridSourceProvider();
142142
SummedMagFreqDist ret = new SummedMagFreqDist(refMFD.getMinX(), refMFD.getMaxX(), refMFD.size());
@@ -149,7 +149,7 @@ private static IncrementalMagFreqDist calcGriddedMFD(Region region, TectonicRegi
149149
return ret;
150150
}
151151

152-
private static IncrementalMagFreqDist average(IncrementalMagFreqDist mfd1, IncrementalMagFreqDist mfd2) {
152+
static IncrementalMagFreqDist average(IncrementalMagFreqDist mfd1, IncrementalMagFreqDist mfd2) {
153153
IncrementalMagFreqDist ret = new IncrementalMagFreqDist(mfd1.getMinX(), mfd1.size(), mfd1.getDelta());
154154
for (int i=0; i<ret.size(); i++)
155155
ret.set(i, 0.5*mfd1.getY(i) + 0.5*mfd2.getY(i));
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package scratch.kevin.prvi25.figures;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.HashSet;
6+
import java.util.List;
7+
import java.util.Set;
8+
import java.util.concurrent.TimeUnit;
9+
10+
import org.opensha.commons.geo.Location;
11+
import org.opensha.commons.geo.Region;
12+
import org.opensha.commons.gui.plot.GeographicMapMaker;
13+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemRupSet;
14+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution;
15+
import org.opensha.sha.earthquake.faultSysSolution.modules.ConnectivityClusters;
16+
import org.opensha.sha.earthquake.faultSysSolution.reports.plots.FaultSectionConnectionsPlot;
17+
import org.opensha.sha.earthquake.faultSysSolution.ruptures.util.ConnectivityCluster;
18+
import org.opensha.sha.faultSurface.FaultSection;
19+
20+
import com.google.common.base.Stopwatch;
21+
22+
class ConnectivityClusterPlot {
23+
24+
public static void main(String[] args) throws IOException {
25+
FaultSystemSolution sol = FaultSystemSolution.load(new File("/data/kevin/nshm23/batch_inversions/"
26+
+ "2024_11_19-prvi25_crustal_branches-dmSample5x/results_PRVI_CRUSTAL_FM_V1p1_branch_averaged.zip"));
27+
28+
File outputDir = new File("/home/kevin/Documents/papers/2024_PRVI_ERF/prvi25-erf-paper/Figures/crustal_fm");
29+
30+
FaultSystemRupSet rupSet = sol.getRupSet();
31+
if (!rupSet.hasModule(ConnectivityClusters.class)) {
32+
System.out.println("Calculating connection clusters");
33+
Stopwatch watch = Stopwatch.createStarted();
34+
ConnectivityClusters clusters = ConnectivityClusters.build(rupSet);
35+
watch.stop();
36+
System.out.println("Found "+clusters.size()+" connectivity clusters in "+(float)(watch.elapsed(TimeUnit.MILLISECONDS)/1000)+" s");
37+
rupSet.addModule(clusters);
38+
}
39+
List<ConnectivityCluster> clustersUnsorted = rupSet.requireModule(ConnectivityClusters.class).get();
40+
41+
// see if any clusters rupture completely
42+
System.out.println("Looking for clusters that rupture fully...");
43+
boolean anyFound = false;
44+
for (ConnectivityCluster cluster : clustersUnsorted) {
45+
HashSet<Integer> parents = new HashSet<>(cluster.getParentSectIDs());
46+
if (parents.size() == 1)
47+
continue;
48+
Set<Integer> sects = cluster.getSectIDs();
49+
for (List<Integer> rupSects : rupSet.getSectionIndicesForAllRups()) {
50+
if (rupSects.size() == sects.size() && rupSects.containsAll(sects)) {
51+
System.out.println("Cluster ruptures fully: "+sects);
52+
anyFound = true;
53+
System.out.println("Parents:");
54+
for (int sectID: rupSects) {
55+
FaultSection sect = rupSet.getFaultSectionData(sectID);
56+
if (parents.contains(sect.getParentSectionId())) {
57+
System.out.println("\t"+sect.getParentSectionId()+". "+sect.getParentSectionName());
58+
parents.remove(sect.getParentSectionId());
59+
}
60+
}
61+
}
62+
}
63+
}
64+
if (!anyFound)
65+
System.out.println("No clusters rupture fully");
66+
67+
GeographicMapMaker plotter = FaultSectionConnectionsPlot.buildConnectedClustersPlot(rupSet, sol,
68+
SlipRateFigures.CRUSTAL_FAULT_MAP_REG, null, clustersUnsorted);
69+
70+
plotter.setWritePDFs(true);
71+
plotter.setWriteGeoJSON(false);
72+
73+
plotter.plot(outputDir, "connectivity_clusters", " ");
74+
75+
CrustalFaultNamesFigure.addStandardFaultLabels(plotter, rupSet.getFaultSectionDataList());
76+
77+
plotter.plot(outputDir, "connectivity_clusters_with_fault_names", " ");
78+
}
79+
80+
}

0 commit comments

Comments
 (0)