Skip to content

Commit e394bfe

Browse files
author
field
committed
2 parents de36700 + e547fdf commit e394bfe

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package scratch.kevin.prvi25;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.List;
6+
7+
import org.jfree.chart.ui.RectangleAnchor;
8+
import org.jfree.data.Range;
9+
import org.opensha.commons.data.CSVFile;
10+
import org.opensha.commons.data.Site;
11+
import org.opensha.commons.data.WeightedList;
12+
import org.opensha.commons.data.WeightedValue;
13+
import org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc;
14+
import org.opensha.commons.data.function.DiscretizedFunc;
15+
import org.opensha.commons.geo.Location;
16+
import org.opensha.commons.gui.plot.HeadlessGraphPanel;
17+
import org.opensha.commons.gui.plot.PlotCurveCharacterstics;
18+
import org.opensha.commons.gui.plot.PlotLineType;
19+
import org.opensha.commons.gui.plot.PlotSpec;
20+
import org.opensha.commons.gui.plot.PlotUtils;
21+
import org.opensha.commons.util.FileNameUtils;
22+
import org.opensha.sha.calc.HazardCurveCalculator;
23+
import org.opensha.sha.calc.params.filters.SourceFilterManager;
24+
import org.opensha.sha.calc.params.filters.SourceFilters;
25+
import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution;
26+
import org.opensha.sha.earthquake.faultSysSolution.erf.BaseFaultSystemSolutionERF;
27+
import org.opensha.sha.earthquake.param.IncludeBackgroundOption;
28+
import org.opensha.sha.earthquake.param.IncludeBackgroundParam;
29+
import org.opensha.sha.gui.infoTools.IMT_Info;
30+
import org.opensha.sha.imr.AttenRelRef;
31+
import org.opensha.sha.imr.ScalarIMR;
32+
import org.opensha.sha.imr.attenRelImpl.nshmp.GroundMotionLogicTreeFilter;
33+
import org.opensha.sha.imr.attenRelImpl.nshmp.NSHMP_GMM_Wrapper;
34+
import org.opensha.sha.imr.param.IntensityMeasureParams.SA_Param;
35+
import org.opensha.sha.imr.param.OtherParams.SigmaTruncLevelParam;
36+
import org.opensha.sha.imr.param.OtherParams.SigmaTruncTypeParam;
37+
38+
import com.google.common.base.Preconditions;
39+
40+
import gov.usgs.earthquake.nshmp.gmm.Gmm;
41+
import gov.usgs.earthquake.nshmp.gmm.GroundMotions;
42+
import gov.usgs.earthquake.nshmp.gmm.UsgsPrviBackbone2025;
43+
import net.mahdilamb.colormap.Colors;
44+
45+
public class SiteHazCompNSHMPHaz {
46+
47+
public static void main(String[] args) throws IOException {
48+
File outputDir = new File("/tmp/prvi_site_nshmp_haz_comp");
49+
Preconditions.checkState(outputDir.exists() || outputDir.mkdir(),
50+
"Output directory %s does not exist and could not be created", outputDir.getAbsolutePath());
51+
52+
// NSHMP_GMM_Wrapper gmm = new NSHMP_GMM_Wrapper.Single(Gmm.ASK_14_BASE);
53+
// CSVFile<String> inCSV = CSVFile.readFile(new File("/home/kevin/Downloads/"
54+
// + "prvi-0.2s-ask14base-crustalFaultOnly-PRVI_2025_ACTIVE_CRUST_NO_EPI_SIGMA_NGA.csv"), true);
55+
56+
// NSHMP_GMM_Wrapper gmm = new NSHMP_GMM_Wrapper.Single(Gmm.PRVI_2025_ACTIVE_CRUST);
57+
// CSVFile<String> inCSV = CSVFile.readFile(new File("/home/kevin/Downloads/"
58+
// + "prvi-0.2s-prvi25active-crustalFaultOnly-curves.csv"), true);
59+
60+
NSHMP_GMM_Wrapper gmm = new NSHMP_GMM_Wrapper.WeightedCombination(
61+
WeightedList.of(new WeightedValue<>(Gmm.PRVI_2025_ACTIVE_CRUST, 0.5),
62+
new WeightedValue<>(Gmm.PRVI_2025_ACTIVE_CRUST_ADJUSTED, 0.5)), "Name", "Name");
63+
// gmm.setGroundMotionTreeFilter(new GroundMotionLogicTreeFilter.StringMatching(
64+
// UsgsPrviBackbone2025.SIGMA_NGA_ID,
65+
// GroundMotions.EPI_OFF
66+
// ));
67+
CSVFile<String> inCSV = CSVFile.readFile(new File("/home/kevin/Downloads/"
68+
+ "prvi-0.2s-prvi25activeTotal-crustalFaultOnly-curves.csv"), true);
69+
70+
gmm.setIntensityMeasure(SA_Param.NAME);
71+
gmm.getOtherParams().setValue(SigmaTruncTypeParam.NAME, SigmaTruncTypeParam.SIGMA_TRUNC_TYPE_1SIDED);
72+
gmm.getOtherParams().setValue(SigmaTruncLevelParam.NAME, 3d);
73+
SA_Param.setPeriodInSA_Param(gmm.getIntensityMeasure(), 0.2);
74+
String xName = "0.2s SA (g)";
75+
76+
FaultSystemSolution sol = FaultSystemSolution.load(new File("/home/kevin/OpenSHA/nshm23/batch_inversions/"
77+
+ "2025_08_01-prvi25_crustal_branches-dmSample10x/"
78+
+ "results_PRVI_CRUSTAL_FM_V1p1_branch_averaged_gridded_simplified.zip"));
79+
BaseFaultSystemSolutionERF erf = new BaseFaultSystemSolutionERF();
80+
erf.setSolution(sol);
81+
erf.setParameter(IncludeBackgroundParam.NAME, IncludeBackgroundOption.EXCLUDE);
82+
erf.getTimeSpan().setDuration(1d);
83+
erf.updateForecast();
84+
85+
HazardCurveCalculator calc = new HazardCurveCalculator(new SourceFilterManager(SourceFilters.TRT_DIST_CUTOFFS));
86+
87+
DiscretizedFunc xVals = new IMT_Info().getDefaultHazardCurve(gmm.getIntensityMeasure());
88+
DiscretizedFunc logXvalues = new ArbitrarilyDiscretizedFunc();
89+
for (int i = 0; i < xVals.size(); i++)
90+
logXvalues.set(Math.log(xVals.getX(i)), 1d);
91+
92+
Range xRange = new Range(1e-4, 3e0);
93+
Range yRange = new Range(1e-5, 1e-1);
94+
95+
PlotCurveCharacterstics theirChar = new PlotCurveCharacterstics(PlotLineType.SOLID, 3f, Colors.tab_orange);
96+
PlotCurveCharacterstics ourChar = new PlotCurveCharacterstics(PlotLineType.SOLID, 3f, Colors.tab_blue);
97+
98+
for (int row=1; row<inCSV.getNumRows(); row++) {
99+
String name = inCSV.get(row, 0);
100+
double lat = inCSV.getDouble(row, 2);
101+
double lon = inCSV.getDouble(row, 1);
102+
Site site = new Site(new Location(lat, lon), name);
103+
site.addParameterList(gmm.getSiteParams());
104+
105+
DiscretizedFunc theirs = new ArbitrarilyDiscretizedFunc();
106+
for (int col=3; col<inCSV.getNumCols(); col++) {
107+
double x = inCSV.getDouble(0, col);
108+
double y = inCSV.getDouble(row, col);
109+
y = 1d - Math.exp(-y);
110+
theirs.set(x, y);
111+
}
112+
theirs.setName("NSHMP-Haz");
113+
114+
calc.getHazardCurve(logXvalues, site, gmm, erf);
115+
116+
DiscretizedFunc ours = xVals.deepClone();
117+
for (int i=0; i<xVals.size(); i++)
118+
ours.set(i, logXvalues.getY(i));
119+
ours.setName("OpenSHA");
120+
121+
PlotSpec plot = new PlotSpec(List.of(theirs, ours), List.of(theirChar, ourChar), name, xName, "Annual Probability of Exceedance");
122+
plot.setLegendInset(RectangleAnchor.BOTTOM_LEFT);
123+
124+
HeadlessGraphPanel gp = PlotUtils.initHeadless();
125+
126+
gp.drawGraphPanel(plot, true, true, xRange, yRange);
127+
128+
PlotUtils.writePlots(outputDir, FileNameUtils.simplify(name)+"_hazard_curves", gp, 800, 800, true, true, true);
129+
}
130+
}
131+
132+
}

0 commit comments

Comments
 (0)