Skip to content

Commit 7d5be01

Browse files
committed
updates for upstream
1 parent bf89e92 commit 7d5be01

13 files changed

+904
-147
lines changed

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

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.text.SimpleDateFormat;
56
import java.util.ArrayList;
7+
import java.util.Date;
68
import java.util.List;
79

10+
import org.opensha.commons.geo.json.Feature;
811
import org.opensha.commons.logicTree.LogicTreeBranch;
912
import org.opensha.commons.logicTree.LogicTreeLevel;
1013
import org.opensha.commons.logicTree.LogicTreeNode;
@@ -20,10 +23,12 @@
2023
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.NSHM23_U3_HybridLogicTreeBranch;
2124
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.prior2018.NSHM18_FaultModels;
2225
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.prior2018.NSHM18_LogicTreeBranch;
26+
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.util.NSHM23_RegionLoader;
2327

2428
import com.google.common.base.Preconditions;
2529

2630
import scratch.UCERF3.enumTreeBranches.FaultModels;
31+
import scratch.ned.nshm23.CEUS_FSS_creator.FaultModelEnum;
2732

2833
public class FakeBALogicTreeGen {
2934

@@ -71,55 +76,55 @@ public static void main(String[] args) throws IOException {
7176
/*
7277
* UCERF3/NSHM18, possibly adding NSHM23 branch averaged
7378
*/
74-
File inputDir = new File("/home/kevin/OpenSHA/UCERF4/batch_inversions/"
75-
// + "2022_12_20-nshm23_u3_hybrid_branches-FM3_1-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR");
76-
// + "2023_01_25-nshm18_branches-new_scale-NSHM18_WUS_PlusU3_FM_3p1-CoulombRupSet-BRANCH_AVERAGED-TotNuclRate-NoRed-ThreshAvgIterRelGR");
77-
// + "2023_04_13-nshm18_branches-new_scale-u3_paleo-NSHM18_WUS_PlusU3_FM_3p1-CoulombRupSet-BRANCH_AVERAGED-TotNuclRate-NoRed-ThreshAvgIterRelGR");
78-
// + "2023_04_14-nshm18_branches-wc_94-u3_paleo-NSHM18_WUS_PlusU3_FM_3p1-CoulombRupSet-BRANCH_AVERAGED-TotNuclRate-NoRed-ThreshAvgIterRelGR");
79-
+ "2023_04_14-nshm23_u3_hybrid_branches-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR");
80-
//// LogicTreeLevel<? extends LogicTreeNode> level = NSHM23_U3_HybridLogicTreeBranch.U3_FM;
81-
//// nodes.add(FaultModels.FM3_1);
82-
// LogicTreeLevel<? extends LogicTreeNode> level = NSHM18_LogicTreeBranch.FM;
83-
// nodes.add(NSHM18_FaultModels.NSHM18_WUS_PlusU3_FM_3p1);
84-
// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "results_FM3_1_CoulombRupSet_branch_averaged.zip"));
85-
//// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "results_NSHM18_WUS_PlusU3_FM_3p1_CoulombRupSet_branch_averaged.zip"));
86-
//// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "node_branch_averaged/SegModel_Classic.zip"));
87-
//// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "results_FM3_1_CoulombRupSet_NoClassic_branch_averaged.zip"));
88-
//// tmpSol.setGridSourceProvider(FaultSystemSolution.load(new File("/home/kevin/OpenSHA/UCERF3/rup_sets/modular/FM3_1_branch_averaged.zip")).getGridSourceProvider());
89-
// tmpSol.setGridSourceProvider(FaultSystemSolution.load(new File("/data/kevin/nshm23/batch_inversions/"
79+
// File inputDir = new File("/home/kevin/OpenSHA/UCERF4/batch_inversions/"
80+
//// + "2022_12_20-nshm23_u3_hybrid_branches-FM3_1-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR");
81+
//// + "2023_01_25-nshm18_branches-new_scale-NSHM18_WUS_PlusU3_FM_3p1-CoulombRupSet-BRANCH_AVERAGED-TotNuclRate-NoRed-ThreshAvgIterRelGR");
82+
//// + "2023_04_13-nshm18_branches-new_scale-u3_paleo-NSHM18_WUS_PlusU3_FM_3p1-CoulombRupSet-BRANCH_AVERAGED-TotNuclRate-NoRed-ThreshAvgIterRelGR");
83+
//// + "2023_04_14-nshm18_branches-wc_94-u3_paleo-NSHM18_WUS_PlusU3_FM_3p1-CoulombRupSet-BRANCH_AVERAGED-TotNuclRate-NoRed-ThreshAvgIterRelGR");
84+
// + "2023_04_14-nshm23_u3_hybrid_branches-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR");
85+
////// LogicTreeLevel<? extends LogicTreeNode> level = NSHM23_U3_HybridLogicTreeBranch.U3_FM;
86+
////// nodes.add(FaultModels.FM3_1);
87+
//// LogicTreeLevel<? extends LogicTreeNode> level = NSHM18_LogicTreeBranch.FM;
88+
//// nodes.add(NSHM18_FaultModels.NSHM18_WUS_PlusU3_FM_3p1);
89+
//// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "results_FM3_1_CoulombRupSet_branch_averaged.zip"));
90+
////// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "results_NSHM18_WUS_PlusU3_FM_3p1_CoulombRupSet_branch_averaged.zip"));
91+
////// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "node_branch_averaged/SegModel_Classic.zip"));
92+
////// FaultSystemSolution tmpSol = FaultSystemSolution.load(new File(inputDir, "results_FM3_1_CoulombRupSet_NoClassic_branch_averaged.zip"));
93+
////// tmpSol.setGridSourceProvider(FaultSystemSolution.load(new File("/home/kevin/OpenSHA/UCERF3/rup_sets/modular/FM3_1_branch_averaged.zip")).getGridSourceProvider());
94+
//// tmpSol.setGridSourceProvider(FaultSystemSolution.load(new File("/data/kevin/nshm23/batch_inversions/"
95+
//// + "2023_09_01-nshm23_branches-mod_pitas_ddw-NSHM23_v2-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR/"
96+
//// + "results_NSHM23_v2_CoulombRupSet_branch_averaged_gridded.zip")).getGridSourceProvider());
97+
//// nodeSols.add(tmpSol);
98+
//////
99+
////// SolutionProcessor processor = null;
100+
//// SolutionProcessor processor = new NSHM23_InvConfigFactory.NSHM23SolProcessor();
101+
////// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only");
102+
////// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-no_classic");
103+
//// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-nshm23_gridded");
104+
////// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-nshm23_gridded-classic_only");
105+
//
106+
// LogicTreeLevel<? extends LogicTreeNode> level = NSHM23_U3_HybridLogicTreeBranch.U3_FM;
107+
// nodes.add(FaultModels.FM3_1);
108+
// nodeSols.add(FaultSystemSolution.load(new File(inputDir, "results_FM3_1_CoulombRupSet_branch_averaged.zip")));
109+
// nodes.add(FaultModels.FM3_2);
110+
// nodeSols.add(FaultSystemSolution.load(new File(inputDir, "results_FM3_2_CoulombRupSet_branch_averaged.zip")));
111+
// SolutionProcessor processor = null;
112+
//
113+
// GridSourceProvider gridProv = FaultSystemSolution.load(new File("/data/kevin/nshm23/batch_inversions/"
90114
// + "2023_09_01-nshm23_branches-mod_pitas_ddw-NSHM23_v2-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR/"
91-
// + "results_NSHM23_v2_CoulombRupSet_branch_averaged_gridded.zip")).getGridSourceProvider());
92-
// nodeSols.add(tmpSol);
93-
////
94-
//// SolutionProcessor processor = null;
95-
// SolutionProcessor processor = new NSHM23_InvConfigFactory.NSHM23SolProcessor();
96-
//// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only");
97-
//// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-no_classic");
115+
// + "results_NSHM23_v2_CoulombRupSet_branch_averaged_gridded.zip")).getGridSourceProvider();
116+
// for (FaultSystemSolution sol : nodeSols)
117+
// sol.setGridSourceProvider(gridProv);
98118
// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-nshm23_gridded");
99-
//// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-nshm23_gridded-classic_only");
100-
101-
LogicTreeLevel<? extends LogicTreeNode> level = NSHM23_U3_HybridLogicTreeBranch.U3_FM;
102-
nodes.add(FaultModels.FM3_1);
103-
nodeSols.add(FaultSystemSolution.load(new File(inputDir, "results_FM3_1_CoulombRupSet_branch_averaged.zip")));
104-
nodes.add(FaultModels.FM3_2);
105-
nodeSols.add(FaultSystemSolution.load(new File(inputDir, "results_FM3_2_CoulombRupSet_branch_averaged.zip")));
106-
SolutionProcessor processor = null;
107-
108-
GridSourceProvider gridProv = FaultSystemSolution.load(new File("/data/kevin/nshm23/batch_inversions/"
109-
+ "2023_09_01-nshm23_branches-mod_pitas_ddw-NSHM23_v2-CoulombRupSet-DsrUni-TotNuclRate-NoRed-ThreshAvgIterRelGR/"
110-
+ "results_NSHM23_v2_CoulombRupSet_branch_averaged_gridded.zip")).getGridSourceProvider();
111-
for (FaultSystemSolution sol : nodeSols)
112-
sol.setGridSourceProvider(gridProv);
113-
File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-nshm23_gridded");
114-
115-
// nodeSols.get(0).setGridSourceProvider(FaultSystemSolution.load(
116-
// new File("/home/kevin/OpenSHA/UCERF3/rup_sets/modular/FM3_1_branch_averaged.zip")).getGridSourceProvider());
117-
// nodeSols.get(1).setGridSourceProvider(FaultSystemSolution.load(
118-
// new File("/home/kevin/OpenSHA/UCERF3/rup_sets/modular/FM3_2_branch_averaged.zip")).getGridSourceProvider());
119-
// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-u3_gridded");
120-
121-
Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
122-
FileBuilder builder = new SolutionLogicTree.FileBuilder(processor, new File(outputDir, "results.zip"));
119+
//
120+
//// nodeSols.get(0).setGridSourceProvider(FaultSystemSolution.load(
121+
//// new File("/home/kevin/OpenSHA/UCERF3/rup_sets/modular/FM3_1_branch_averaged.zip")).getGridSourceProvider());
122+
//// nodeSols.get(1).setGridSourceProvider(FaultSystemSolution.load(
123+
//// new File("/home/kevin/OpenSHA/UCERF3/rup_sets/modular/FM3_2_branch_averaged.zip")).getGridSourceProvider());
124+
//// File outputDir = new File(inputDir.getParentFile(), inputDir.getName()+"-ba_only-u3_gridded");
125+
//
126+
// Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
127+
// FileBuilder builder = new SolutionLogicTree.FileBuilder(processor, new File(outputDir, "results.zip"));
123128

124129
/*
125130
* simple branch averaged
@@ -160,6 +165,32 @@ public static void main(String[] args) throws IOException {
160165
// Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
161166
// FileBuilder builder = new SolutionLogicTree.FileBuilder(processor, new File(outputDir, "results.zip"));
162167

168+
/*
169+
* CEUS FSS tests
170+
*/
171+
File invsDir = new File("/home/kevin/OpenSHA/UCERF4/batch_inversions/");
172+
File inputDir = new File("/data/kevin/nshm23/ceus_converted_fss");
173+
LogicTreeLevel<? extends LogicTreeNode> level = NSHM23_LogicTreeBranch.FM;
174+
nodes.add(NSHM23_FaultModels.NSHM23_v2);
175+
SolutionProcessor processor = null;
176+
177+
// FaultModelEnum fm = FaultModelEnum.BOTH;
178+
// FaultModelEnum fm = FaultModelEnum.ALTERNATE;
179+
FaultModelEnum fm = FaultModelEnum.PREFERRED;
180+
181+
// String dirName = new SimpleDateFormat("yyyy_MM_dd").format(new Date());
182+
String dirName = "2023_11_15";
183+
dirName += "-ceus_fss-"+fm.name();
184+
185+
nodeSols.add(FaultSystemSolution.load(new File(inputDir, "sol_"+fm.name()+"_merged.zip")));
186+
File outputDir = new File(invsDir, dirName);
187+
188+
Feature.write(NSHM23_RegionLoader.AnalysisRegions.CONUS_EAST.load().toFeature(),
189+
new File(outputDir, "ceus_region.geojson"));
190+
191+
Preconditions.checkState(outputDir.exists() || outputDir.mkdir());
192+
FileBuilder builder = new SolutionLogicTree.FileBuilder(processor, new File(outputDir, "results.zip"));
193+
163194
for (int i=0; i<nodes.size(); i++) {
164195
LogicTreeNode node = nodes.get(i);
165196
FaultSystemSolution sol = nodeSols.get(i);

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

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.opensha.commons.logicTree.LogicTreeBranch;
1111
import org.opensha.commons.logicTree.LogicTreeLevel;
1212
import org.opensha.commons.logicTree.LogicTreeNode;
13+
import org.opensha.commons.logicTree.LogicTreeNode.RandomlySampledNode;
1314
import org.opensha.commons.util.modules.OpenSHA_Module;
1415
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemRupSet;
1516
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution;
@@ -35,8 +36,11 @@
3536
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.NSHM23_SingleStates;
3637
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.NSHM23_U3_HybridLogicTreeBranch;
3738
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.RupturePlausibilityModels;
39+
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.SegmentationModelBranchNode;
3840
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.SupraSeisBValues;
3941
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.U3_UncertAddDeformationModels;
42+
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.random.RandomBValSampler;
43+
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.logicTree.random.RandomSegModelSampler;
4044
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.prior2018.NSHM18_DeformationModels;
4145
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.prior2018.NSHM18_FaultModels;
4246
import org.opensha.sha.earthquake.rupForecastImpl.nshm23.prior2018.NSHM18_LogicTreeBranch;
@@ -122,16 +126,50 @@ public static void main(String[] args) throws IOException {
122126
// LogicTreeBranch<U3LogicTreeBranchNode<?>> branch = U3LogicTreeBranch.DEFAULT;
123127
// LogicTreeBranch<LogicTreeNode> branch = NSHM18_LogicTreeBranch.DEFAULT; dirName += "-2018_inputs";
124128
// LogicTreeBranch<LogicTreeNode> branch = NSHM23_U3_HybridLogicTreeBranch.DEFAULT; dirName += "-u3";
125-
LogicTreeBranch<LogicTreeNode> branch = NSHM23_LogicTreeBranch.DEFAULT_ON_FAULT;
126-
branch = branch.copy();
129+
// LogicTreeBranch<LogicTreeNode> branch = NSHM23_LogicTreeBranch.DEFAULT_ON_FAULT;
130+
// branch = branch.copy();
131+
132+
List<LogicTreeLevel<? extends LogicTreeNode>> levels = NSHM23_LogicTreeBranch.levelsOnFault;
133+
levels = new ArrayList<>(levels);
134+
boolean randB = true;
135+
boolean randSeg = true;
136+
int origSize = levels.size();
137+
List<LogicTreeNode> values = new ArrayList<>();
138+
for (LogicTreeNode node : NSHM23_LogicTreeBranch.DEFAULT_ON_FAULT)
139+
values.add(node);
140+
for (int i=levels.size(); --i>=0;) {
141+
if (randB && SupraSeisBValues.class.isAssignableFrom(levels.get(i).getType())) {
142+
levels.remove(i);
143+
values.remove(i);
144+
}
145+
if (randSeg && SegmentationModelBranchNode.class.isAssignableFrom(levels.get(i).getType())) {
146+
levels.remove(i);
147+
values.remove(i);
148+
}
149+
}
150+
Preconditions.checkState(levels.size() < origSize);
151+
if (randB) {
152+
dirName += "-randB";
153+
RandomBValSampler.Level level = new RandomBValSampler.Level(1);
154+
levels.add(level);
155+
values.add(level.getNodes().get(0));
156+
}
157+
if (randSeg) {
158+
dirName += "-randSeg";
159+
RandomSegModelSampler.Level level = new RandomSegModelSampler.Level(1);
160+
levels.add(level);
161+
values.add(level.getNodes().get(0));
162+
}
163+
LogicTreeBranch<LogicTreeNode> branch = new LogicTreeBranch<>(levels, values);
164+
branch.setValue(NSHM23_DeformationModels.EVANS);
127165

128166
// all branch averaged
129-
dirName += "-all_ba";
130-
branch.setValue(NSHM23_DeformationModels.AVERAGE);
131-
branch.setValue(NSHM23_ScalingRelationships.AVERAGE);
132-
branch.setValue(SupraSeisBValues.AVERAGE);
133-
branch.setValue(NSHM23_SegmentationModels.AVERAGE);
134-
branch.setValue(NSHM23_PaleoUncertainties.AVERAGE);
167+
// dirName += "-all_ba";
168+
// branch.setValue(NSHM23_DeformationModels.AVERAGE);
169+
// branch.setValue(NSHM23_ScalingRelationships.AVERAGE);
170+
// branch.setValue(SupraSeisBValues.AVERAGE);
171+
// branch.setValue(NSHM23_SegmentationModels.AVERAGE);
172+
// branch.setValue(NSHM23_PaleoUncertainties.AVERAGE);
135173

136174
// NSHM23_InvConfigFactory.MFD_MIN_FRACT_UNCERT = 0.1;
137175
// dirName += "-mfd_min_uncert_0.1";
@@ -237,7 +275,7 @@ public static void main(String[] args) throws IOException {
237275
for (int i=0; i<branch.size(); i++) {
238276
LogicTreeNode node = branch.getValue(i);
239277
if (node != null) {
240-
if (node.getNodeWeight(branch) > 0d) {
278+
if (!(node instanceof RandomlySampledNode) && node.getNodeWeight(branch) > 0d) {
241279
// only include its name if there are other alternatives (unless we have chosen a zero-weight option)
242280
boolean hasOthers = false;
243281
for (LogicTreeNode oNode : branch.getLevel(i).getNodes()) {
@@ -259,6 +297,8 @@ public static void main(String[] args) throws IOException {
259297
}
260298
}
261299

300+
System.out.println("Logic tree branch: "+branch);
301+
262302
File outputDir = new File(parentDir, dirName);
263303
System.out.println("Will save results in: "+outputDir.getAbsolutePath());
264304

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static void main(String[] args) throws InterruptedException, IOException
185185
boolean adjustForIncompatibleData = true;
186186
boolean randWeight = true;
187187

188-
NSHM23_ConstraintBuilder constrBuilder = new NSHM23_ConstraintBuilder(rupSet, supraBVal,
188+
NSHM23_ConstraintBuilder constrBuilder = new NSHM23_ConstraintBuilder(rupSet, supraBVal, null,
189189
applyDefModelUncertaintiesToNucl, addSectCountUncertaintiesToMFD, adjustForIncompatibleData);
190190
constrBuilder.defaultConstraints();
191191

0 commit comments

Comments
 (0)