Skip to content

Commit 3f32b0f

Browse files
author
Kevin Milner
committed
minor
1 parent 81c0c43 commit 3f32b0f

File tree

5 files changed

+208
-47
lines changed

5 files changed

+208
-47
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.HashSet;
7+
import java.util.List;
8+
9+
import org.opensha.commons.data.function.DiscretizedFunc;
10+
import org.opensha.commons.data.function.LightFixedXFunc;
11+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemRupSet;
12+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution;
13+
import org.opensha.sha.earthquake.faultSysSolution.modules.RupMFDsModule;
14+
import org.opensha.sha.earthquake.faultSysSolution.util.FaultSectionUtils;
15+
import org.opensha.sha.faultSurface.FaultSection;
16+
17+
import com.google.common.base.Preconditions;
18+
19+
public class SeattleFaultRateCalc {
20+
21+
public static void main(String[] args) throws IOException {
22+
double[] minMags = {0d, 6d, 6.5d, 7d, 7.5d};
23+
24+
FaultSystemSolution sol = FaultSystemSolution.load(new File("/home/kevin/OpenSHA/nshm23/batch_inversions/"
25+
+ "2024_02_02-nshm23_branches-WUS_FM_v3/results_WUS_FM_v3_branch_averaged.zip"));
26+
FaultSystemRupSet rupSet = sol.getRupSet();
27+
28+
// int[] parentIDs = {
29+
// FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "seattle", "middle"),
30+
// FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "seattle", "east"),
31+
// FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "seattle", "north"),
32+
// FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "seattle", "south"),
33+
// };
34+
35+
int[] parentIDs = {
36+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Turner", "Mill", "Creek"),
37+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Mount", "Angel"),
38+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Gales", "Chehalem"),
39+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Gales", "Parsons"),
40+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Beaverton"),
41+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Canby"),
42+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Bolton"),
43+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Sylvain", "Oatfield"),
44+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Portland", "Hills", "(south)"),
45+
FaultSectionUtils.findParentSectionID(rupSet.getFaultSectionDataList(), "Portland", "Hills", "(north)"),
46+
};
47+
48+
for (int i=0; i<parentIDs.length; i++)
49+
Preconditions.checkState(parentIDs[i] >= 0, "No parent ID at position %s", i);
50+
51+
HashSet<Integer> rups = new HashSet<>();
52+
for (int parentID : parentIDs) {
53+
String name = null;
54+
for (FaultSection sect : rupSet.getFaultSectionDataList()) {
55+
if (sect.getParentSectionId() == parentID) {
56+
name = sect.getParentSectionName();
57+
break;
58+
}
59+
}
60+
List<Integer> myRups = rupSet.getRupturesForParentSection(parentID);
61+
Preconditions.checkNotNull(myRups, "No ruptures found for %s. %s", parentID, name);
62+
int prevSize = rups.size();
63+
rups.addAll(myRups);
64+
int numAdded = rups.size() - prevSize;
65+
int numDups = myRups.size() - numAdded;
66+
System.out.println("Found "+myRups.size()+" rups for "+name+" (now have "+rups.size()+" total unique; added "+numAdded+", skipped "+numDups+" duplicates)");
67+
}
68+
69+
System.out.println("Found "+rups.size()+" total rups");
70+
71+
RupMFDsModule mfds = sol.requireModule(RupMFDsModule.class);
72+
for (double minMag : minMags) {
73+
double rate = 0d;
74+
for (int rupIndex : rups) {
75+
DiscretizedFunc mfd = mfds.getRuptureMFD(rupIndex);
76+
if (mfd == null)
77+
mfd = new LightFixedXFunc(new double[] {rupSet.getMagForRup(rupIndex)}, new double[] {sol.getRateForRup(rupIndex)});
78+
for (Point2D pt : mfd)
79+
if (pt.getX() >= minMag)
80+
rate += pt.getY();
81+
}
82+
if (minMag > 0d)
83+
System.out.println("M>"+(float)minMag+":\t"+(float)rate+" /year\t(RI: "+(float)(1d/rate)+" years)");
84+
else
85+
System.out.println("Supra-seis:\t"+(float)rate+" /year\t(RI: "+(float)(1d/rate)+" years)");
86+
87+
}
88+
}
89+
90+
}

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

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public static void main(String[] args) throws IOException {
5858

5959
Double vs30 = null;
6060

61-
vs30 = 760d; dirSuffix = "-vs760";
61+
// vs30 = 760d; dirSuffix = "-vs760";
62+
vs30 = 260d; dirSuffix = "-vs260";
6263
Double sigmaTrunc = 3d;
6364
boolean supersample = true;
6465
int erfSamples = -1;
@@ -99,9 +100,9 @@ public static void main(String[] args) throws IOException {
99100
// File sourceDir = SUBDUCTION_DIR;
100101
// File outputDir = new File(sourceDir.getParentFile(), sourceDir.getName()+"-gmTreeCalcs"+dirSuffix);
101102
// // supra-seis only
102-
// File sourceTreeFile = new File(sourceDir, "logic_tree.json");
103-
// int mins = 1440;
104-
// IncludeBackgroundOption bgOp = IncludeBackgroundOption.EXCLUDE;
103+
//// File sourceTreeFile = new File(sourceDir, "logic_tree.json");
104+
//// int mins = 1440;
105+
//// IncludeBackgroundOption bgOp = IncludeBackgroundOption.EXCLUDE;
105106
// // interface gridded only
106107
//// int mins = 1440;
107108
////// File sourceTreeFile = new File(sourceDir, "logic_tree_gridded_only.json");
@@ -115,57 +116,57 @@ public static void main(String[] args) throws IOException {
115116
//// jobSuffix = "_interface";
116117
//// outputSuffix = jobSuffix;
117118
// // interface both (combine only)
118-
//// combineOnly = true;
119-
//// int mins = 1440;
120-
//// forceInputFileName = "results_full_gridded_interface_only.zip";
121-
//// File sourceTreeFile = new File(sourceDir, "logic_tree_full_gridded.json");
122-
//// logicTreeOutputName = "logic_tree_full_gridded_interface_only.json";
123-
//// IncludeBackgroundOption bgOp = IncludeBackgroundOption.INCLUDE;
124-
//// jobSuffix = "_interface";
125-
//// outputSuffix = jobSuffix;
119+
// combineOnly = true;
120+
// int mins = 1440;
121+
// forceInputFileName = "results_full_gridded_interface_only.zip";
122+
// File sourceTreeFile = new File(sourceDir, "logic_tree_full_gridded.json");
123+
// logicTreeOutputName = "logic_tree_full_gridded_interface_only.json";
124+
// IncludeBackgroundOption bgOp = IncludeBackgroundOption.INCLUDE;
125+
// jobSuffix = "_interface";
126+
// outputSuffix = jobSuffix;
126127

127128
/*
128129
* Slab
129130
*
130131
* the logic_tree_gridded_only.json file you need is generated by subduction_slt_split.slurm
131132
*/
132-
// List<LogicTreeLevel<? extends LogicTreeNode>> gmmLevels = PRVI25_LogicTree.levelsSlabGMM;
133-
// File sourceDir = SUBDUCTION_DIR;
134-
// File outputDir = new File(sourceDir.getParentFile(), sourceDir.getName()+"-gmTreeCalcs"+dirSuffix);
135-
// // always slab gridded only
136-
// int mins = 1440;
137-
// File sourceTreeFile = new File(sourceDir, "logic_tree_gridded_only.json");
138-
// logicTreeOutputName = "logic_tree_gridded_slab_only.json";
139-
// IncludeBackgroundOption bgOp = IncludeBackgroundOption.ONLY;
140-
// forceInputFileName = "results_gridded_branches_slab_only.zip";
141-
// jobSuffix = "_slab";
142-
// outputSuffix = jobSuffix;
133+
List<LogicTreeLevel<? extends LogicTreeNode>> gmmLevels = PRVI25_LogicTree.levelsSlabGMM;
134+
File sourceDir = SUBDUCTION_DIR;
135+
File outputDir = new File(sourceDir.getParentFile(), sourceDir.getName()+"-gmTreeCalcs"+dirSuffix);
136+
// always slab gridded only
137+
int mins = 1440;
138+
File sourceTreeFile = new File(sourceDir, "logic_tree_gridded_only.json");
139+
logicTreeOutputName = "logic_tree_gridded_slab_only.json";
140+
IncludeBackgroundOption bgOp = IncludeBackgroundOption.ONLY;
141+
forceInputFileName = "results_gridded_branches_slab_only.zip";
142+
jobSuffix = "_slab";
143+
outputSuffix = jobSuffix;
143144

144145
/*
145146
* Branch averaged (GMM-only)
146147
*/
147-
List<LogicTreeLevel<? extends LogicTreeNode>> gmmLevels = PRVI25_LogicTree.levelsCombinedGMM;
148-
File sourceDir = COMBINED_DIR;
149-
// File sourceDir = new File(INV_DIR, "2025_01_02-prvi25_crustal_subduction_combined_branches");
150-
File outputDir = new File(sourceDir.getParentFile(), sourceDir.getName()+"-ba_only-gmTreeCalcs"+dirSuffix);
151-
// write out a SLT that only contains that node
152-
Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
153-
File sourceTreeFile = new File(outputDir, "fake_erf_logic_tree.json");
154-
FileBackedLevel fakeLevel = new FileBackedLevel("ERF Model", "ERF",
155-
List.of(new FileBackedNode("Branch Averaged ERF", "BranchAveragedERF", 1d, "BA_ERF")));
156-
LogicTree<?> tempTree = LogicTree.buildExhaustive(List.of(fakeLevel), true);
157-
Preconditions.checkState(tempTree.size() == 1);
158-
File sourceFile = new File(outputDir, "fake_erf_slt.zip");
159-
SolutionLogicTree.FileBuilder builder = new SolutionLogicTree.FileBuilder(sourceFile);
160-
builder.setSerializeGridded(true);
161-
builder.solution(FaultSystemSolution.load(new File(sourceDir, COMBINED_SOL.getName())), tempTree.getBranch(0));
162-
builder.close();
163-
forceInputFileName = sourceFile.getName();
164-
tempTree.write(sourceTreeFile);
165-
logicTreeOutputName = "logic_tree.json";
166-
sourceDir = outputDir;
167-
int mins = 1440;
168-
IncludeBackgroundOption bgOp = IncludeBackgroundOption.INCLUDE;
148+
// List<LogicTreeLevel<? extends LogicTreeNode>> gmmLevels = PRVI25_LogicTree.levelsCombinedGMM;
149+
// File sourceDir = COMBINED_DIR;
150+
//// File sourceDir = new File(INV_DIR, "2025_01_02-prvi25_crustal_subduction_combined_branches");
151+
// File outputDir = new File(sourceDir.getParentFile(), sourceDir.getName()+"-ba_only-gmTreeCalcs"+dirSuffix);
152+
// // write out a SLT that only contains that node
153+
// Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
154+
// File sourceTreeFile = new File(outputDir, "fake_erf_logic_tree.json");
155+
// FileBackedLevel fakeLevel = new FileBackedLevel("ERF Model", "ERF",
156+
// List.of(new FileBackedNode("Branch Averaged ERF", "BranchAveragedERF", 1d, "BA_ERF")));
157+
// LogicTree<?> tempTree = LogicTree.buildExhaustive(List.of(fakeLevel), true);
158+
// Preconditions.checkState(tempTree.size() == 1);
159+
// File sourceFile = new File(outputDir, "fake_erf_slt.zip");
160+
// SolutionLogicTree.FileBuilder builder = new SolutionLogicTree.FileBuilder(sourceFile);
161+
// builder.setSerializeGridded(true);
162+
// builder.solution(FaultSystemSolution.load(new File(sourceDir, COMBINED_SOL.getName())), tempTree.getBranch(0));
163+
// builder.close();
164+
// forceInputFileName = sourceFile.getName();
165+
// tempTree.write(sourceTreeFile);
166+
// logicTreeOutputName = "logic_tree.json";
167+
// sourceDir = outputDir;
168+
// int mins = 1440;
169+
// IncludeBackgroundOption bgOp = IncludeBackgroundOption.INCLUDE;
169170

170171

171172
// FOR ALL
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package scratch.kevin.prvi25;
2+
3+
import java.awt.geom.Point2D;
4+
import java.io.File;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import org.opensha.commons.data.CSVFile;
9+
import org.opensha.commons.data.function.XY_DataSet;
10+
import org.opensha.commons.geo.BorderType;
11+
import org.opensha.commons.geo.Location;
12+
import org.opensha.commons.geo.LocationList;
13+
import org.opensha.commons.geo.Region;
14+
import org.opensha.commons.mapping.PoliticalBoundariesData;
15+
import org.opensha.commons.util.DataUtils.MinMaxAveTracker;
16+
import org.opensha.sha.earthquake.rupForecastImpl.prvi25.util.PRVI25_RegionLoader;
17+
18+
import scratch.kevin.prvi25.figures.MapSourceTypeDisagg;
19+
20+
public class QuickHazardLandMask {
21+
22+
public static void main(String[] args) {
23+
// List<Region> landRegions = new ArrayList<>();
24+
// for (XY_DataSet polBound : PoliticalBoundariesData.loadDefaultOutlines(PRVI25_RegionLoader.loadPRVI_MapExtents())) {
25+
// LocationList list = new LocationList();
26+
// for (Point2D pt : polBound)
27+
// list.add(new Location(pt.getY(), pt.getX()));
28+
// Region reg = new Region(list, BorderType.MERCATOR_LINEAR);
29+
// landRegions.add(reg);
30+
// }
31+
//
32+
// CSVFile<String> csv = CSVFile.readFile(new File("/tmp/1.0s_TWO_IN_50.csv"), false);
33+
//
34+
// MinMaxAveTracker covTrack = new MinMaxAveTracker();
35+
// for (int row=1; row<csv.getNumRows(); row++) {
36+
// Location loc = new Location(csv.getDouble(row, 1), csv.getDouble(row, 2));
37+
// boolean inside = false;
38+
// for (Region reg : caRegions) {
39+
// if (reg.contains(loc)) {
40+
// inside = true;
41+
// break;
42+
// }
43+
// }
44+
// if (inside) {
45+
// double cov = csv.getDouble(row, 7);
46+
// covTrack.addValue(cov);
47+
// }
48+
// }
49+
// System.out.println("CA COV: "+covTrack);
50+
}
51+
52+
}

src/main/java/scratch/kevin/simulators/RSQSimCatalog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,9 @@ public int compare(Catalogs o1, Catalogs o2) {
34553455
private static final File[] catalogLocations;
34563456
static {
34573457
catalogLocations = new File[] {
3458-
// USC HPC
3458+
// USC CARC
3459+
new File("/project2/scec_608/rsqsim/catalogs/kmilner"),
3460+
new File("/project2/scec_608/rsqsim/catalogs/shaw"),
34593461
new File("/project/scec_608/rsqsim/catalogs/kmilner"),
34603462
new File("/project/scec_608/rsqsim/catalogs/shaw"),
34613463
new File("/project/scec_608/rsqsim/catalogs/gilchrij"),

src/main/java/scratch/kevin/ucerf3/PureScratch.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3363,13 +3363,29 @@ private static void test346() throws IOException {
33633363
MarkdownUtils.writeHTML(lines, new File("/tmp/md_test.html"));
33643364
}
33653365

3366+
private static void test347() throws IOException {
3367+
File sectsFile = new File("/home/kevin/Downloads/WGUEP2_AllFaults_v5_LL_continishWas_IntersectFix_TaperFix.geojson");
3368+
3369+
String[] args = {
3370+
"--sub-sections",
3371+
sectsFile.getAbsolutePath(),
3372+
"--scale",
3373+
"MEAN_NSHM23",
3374+
"--preset",
3375+
"COULOMB",
3376+
"--output-file",
3377+
"/tmp/wgup_rup_set.zip"
3378+
};
3379+
RuptureSets.main(args);
3380+
}
3381+
33663382
/**
33673383
* @param args
33683384
* @throws Exception
33693385
*/
33703386
public static void main(String[] args) throws Exception {
33713387
try {
3372-
test346();
3388+
test347();
33733389
} catch (Throwable t) {
33743390
t.printStackTrace();
33753391
System.exit(1);

0 commit comments

Comments
 (0)