Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
c0b45e3
tests for upstream
kevinmilner Mar 10, 2026
c776446
for upstream logic tree refactor
kevinmilner Mar 13, 2026
1833065
updated random level/node classes & serialization
kevinmilner Mar 17, 2026
01f0251
Merge branch 'master' into model/nshm26-dev
kevinmilner Mar 17, 2026
d974354
WIP on random sampling and branch/level serialization
kevinmilner Mar 17, 2026
9e42293
refactored to use json element data and skipping custom adapter logic
kevinmilner Mar 18, 2026
e187739
more serialization/sampling improvements
kevinmilner Mar 18, 2026
9c62882
serialization cleanup progress
kevinmilner Mar 19, 2026
60a0824
for upstream
kevinmilner Mar 21, 2026
882ef51
now uses MergedSolutionCreator
kevinmilner Mar 23, 2026
e6c013b
updates for upstream
kevinmilner Mar 23, 2026
cc34ffe
misc/diagnostics for upstream
kevinmilner Mar 26, 2026
07f95fc
upstream and tests
kevinmilner Mar 27, 2026
3d904ce
minor
kevinmilner Mar 30, 2026
aea5696
logic tree figure
kevinmilner Mar 31, 2026
03648b8
scaling update
kevinmilner Mar 31, 2026
1edae47
rename package to gov and nshm27
kevinmilner Mar 31, 2026
1e28713
rename package to gov and nshm27
kevinmilner Mar 31, 2026
f217683
renamed NSHM26 -> NSHM27
kevinmilner Apr 1, 2026
1b631e2
more nshm26-27 refactoring/cleanup
kevinmilner Apr 1, 2026
806e36a
figures and bathymetry data
kevinmilner Apr 2, 2026
f4a9525
new latin hypercube sampling option
kevinmilner Apr 2, 2026
0f848da
now tracks sampling metadata
kevinmilner Apr 6, 2026
0e58c31
obs mfd plots
kevinmilner Apr 6, 2026
9ab359b
LHS-pairwise figures and tests
kevinmilner Apr 13, 2026
d24066e
minor
kevinmilner Apr 20, 2026
cbe3e50
Merge branch 'master' into model/nshm27-dev
kevinmilner Apr 23, 2026
f564275
inversion slurm submit script reorg
kevinmilner Apr 24, 2026
979a5c5
bump comm-stat-dist to 1.3 with truncN fixes, remove local temp version
kevinmilner May 15, 2026
08274ab
updated grid seis and other tests
kevinmilner May 27, 2026
35587ac
minor
kevinmilner Jun 4, 2026
3a58b53
Merge branch 'master' into model/nshm27-dev
kevinmilner Jun 15, 2026
c66bed9
for upstream
kevinmilner Jun 22, 2026
675fc8b
tests and upstream
kevinmilner Jun 23, 2026
1f4a8ff
for upstream
kevinmilner Jun 23, 2026
f616040
upstream
kevinmilner Jun 25, 2026
a7935cb
beta model updates
kevinmilner Jun 30, 2026
8e6319d
for upstream
kevinmilner Jul 13, 2026
c994ff0
new MFD exploration plots
kevinmilner Jul 14, 2026
71d74f7
plots and investigations
kevinmilner Jul 15, 2026
bb488d5
persistent output dir
kevinmilner Jul 15, 2026
4d3c4b5
lots of new plots and updates for upstream
kevinmilner Jul 22, 2026
8e5f123
figure updates
kevinmilner Jul 24, 2026
231f66d
fixes for rate model sampling on b-value plot
kevinmilner Jul 27, 2026
a568180
comp/diagnostics
kevinmilner Jul 27, 2026
b6f4a25
Merge branch 'master' into model/nshm27-dev
kevinmilner Jul 27, 2026
bfc4d0d
comparison updates
kevinmilner Jul 28, 2026
5fdd687
rake rounding
kevinmilner Jul 28, 2026
e84224f
comparison updates
kevinmilner Jul 28, 2026
f0ac591
Merge branch 'master' into model/nshm27-dev
kevinmilner Jul 28, 2026
e98ce40
now works with point source optimizations
kevinmilner Jul 31, 2026
0941d44
new tests and plots
kevinmilner Jul 31, 2026
68763a8
minor
kevinmilner Aug 1, 2026
dda9947
Merge branch 'master' into model/nshm27-dev
kevinmilner Aug 4, 2026
052c416
Merge branch 'master' into model/nshm27-dev
kevinmilner Aug 5, 2026
93a3b94
Refactored nshm packages back into opensha namespace
kevinmilner Aug 5, 2026
7ea2b93
Merge branch 'chore/nshmp_lib_shading' into model/nshm27-dev
kevinmilner Aug 6, 2026
19b02cc
updates for shaded jar
kevinmilner Aug 6, 2026
fffc00e
now detects and handles sources with TRT-specific-GMM overrides
kevinmilner Aug 6, 2026
3a2fabd
there's already a ton of STDOUT upstream, might as well make it useful
kevinmilner Aug 7, 2026
356530f
region tests
kevinmilner Aug 7, 2026
2fbdc40
for upstream
kevinmilner Aug 7, 2026
863d4ad
Merge branch 'chore/nshmp_lib_shading' into model/nshm27-dev
kevinmilner Aug 8, 2026
969ffd6
refactored to generic sect dist sampling api
kevinmilner Aug 10, 2026
6b87ed3
Merge branch 'master' into model/nshm27-dev
kevinmilner Aug 11, 2026
76c6a83
Merge branch 'master' into model/nshm27-dev
kevinmilner Aug 17, 2026
40e7f08
Merge branch 'master' into model/nshm27-dev
kevinmilner Aug 17, 2026
cecd4a2
sampled tree examples for Ian
kevinmilner Aug 19, 2026
d325841
upstream refactors and new figures
kevinmilner Aug 27, 2026
fcdba04
faster calcs
kevinmilner Sep 2, 2026
7e7cbdb
Merge branch 'master' into model/nshm27-dev
kevinmilner Sep 2, 2026
8f5a9f7
new models
kevinmilner Sep 3, 2026
7cc8bd6
plot/calc updates
kevinmilner Sep 8, 2026
e434613
removed legacy pairwise-optimization code
kevinmilner Sep 8, 2026
2e46107
scoring interface cleanup
kevinmilner Sep 9, 2026
0cb9352
optimization cleanup/generalization
kevinmilner Sep 9, 2026
8366305
better plots and now with maps
kevinmilner Sep 10, 2026
05780e4
updated convergence calcs/plots
kevinmilner Sep 14, 2026
239ceeb
Merge branch 'master' into model/nshm27-dev
kevinmilner Sep 14, 2026
e61efe6
for upstream
kevinmilner Sep 14, 2026
29df3dd
Merge branch 'master' into model/nshm27-dev
kevinmilner Sep 14, 2026
03bca7f
new plots and calcs
kevinmilner Sep 16, 2026
57802c6
new runs
kevinmilner Sep 18, 2026
00a510e
new ColorUtils with consolidated transparent/saturate methods
kevinmilner Sep 18, 2026
ee1e375
consolidated additional color utility methods
kevinmilner Sep 18, 2026
6c5be43
option for std dev range in signed bias plots
kevinmilner Sep 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 136 additions & 21 deletions src/main/java/org/opensha/nshmp/shaded/model/NshmErf.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.apache.commons.numbers.core.Precision;
import org.opensha.commons.data.TimeSpan;
import org.opensha.sha.earthquake.AbstractERF;
import org.opensha.sha.earthquake.ProbEqkSource;
import org.opensha.sha.earthquake.param.IncludeBackgroundOption;
import org.opensha.sha.imr.attenRelImpl.nshmp.NSHMP_GMM_Wrapper;
import org.opensha.sha.util.TectonicRegionType;

import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;

import org.opensha.nshmp.shaded.data.NshmpIndexing;
import org.opensha.nshmp.shaded.gmm.NshmpGmm;
import org.opensha.nshmp.shaded.model.NshmpSystemRuptureSet.SystemRupture;
import org.opensha.nshmp.shaded.tree.NshmpBranch;

Expand All @@ -43,6 +49,7 @@ public class NshmErf extends AbstractERF {
private final boolean volcanic;
private final boolean grid;
private final boolean faults;
private Set<TectonicRegionType> trts;

public NshmErf(Path path, Set<TectonicRegionType> trts,
IncludeBackgroundOption gridOption) {
Expand All @@ -52,6 +59,7 @@ public NshmErf(Path path, Set<TectonicRegionType> trts,
public NshmErf(NshmpHazardModel model, Set<TectonicRegionType> trts,
IncludeBackgroundOption gridOption) {
this.model = model;
this.trts = trts;
allSources = new ArrayList<>();
sourceMap = MultimapBuilder
.enumKeys(TectonicRegionType.class)
Expand All @@ -69,6 +77,8 @@ public NshmErf(NshmpHazardModel model, Set<TectonicRegionType> trts,

init();
}

private static final boolean PROCESS_TRT_OVERRIDES = true;

private void init() {

Expand All @@ -79,37 +89,134 @@ private void init() {

// nshmp-haz initializers
Multimap<NshmpTectonicSetting, NshmpSourceTree> trees = model.trees();
if (PROCESS_TRT_OVERRIDES) {
List<NshmpTRTBranch> trtMappedRuptureSets = parseTRTOverrides(trees);
for (NshmpTRTBranch trtBranch : trtMappedRuptureSets) {
if (!trts.isEmpty() && !trts.contains(trtBranch.trt))
continue;
List<NshmSource> sources = initBranch(trtBranch.branch);
sources.forEach(s -> s.setTectonicRegionType(trtBranch.trt));
allSources.addAll(sources);
sourceMap.putAll(trtBranch.trt, sources);
}
allSources.sort(new Comparator<NshmSource>() {
@Override
public int compare(NshmSource o1, NshmSource o2) {
return Integer.compare(o1.getNSHM_ID(), o2.getNSHM_ID());
}
});
} else {
for (Entry<NshmpTectonicSetting, NshmpSourceTree> entry : trees.entries()) {
NshmpTectonicSetting setting = entry.getKey();
NshmpSourceTree tree = entry.getValue();
NshmpSourceType type = tree.type();

TectonicRegionType trt = NshmUtil.tectonicSettingToType(setting, type);
if (!trts.isEmpty() && !trts.contains(trt))
continue;
List<NshmSource> sources = initTree(tree);
sources.forEach(s -> s.setTectonicRegionType(trt));
allSources.addAll(sources);
sourceMap.putAll(trt, sources);
}
}
}

private record NshmpTRTBranch(TectonicRegionType trt, NshmpBranch<NshmpRuptureSet> branch) {}

/**
* Map each branch to a tectonic region type, also processing any GMM-overrides that Peter might sneak in there
* to change the TRT within a different NshmpTectonicSetting
* @param trees
* @return
*/
private static List<NshmpTRTBranch> parseTRTOverrides(
Multimap<NshmpTectonicSetting, NshmpSourceTree> trees) {
List<NshmpTRTBranch> ret = new ArrayList<>();

for (Entry<NshmpTectonicSetting, NshmpSourceTree> entry : trees.entries()) {

NshmpTectonicSetting setting = entry.getKey();
NshmpSourceTree tree = entry.getValue();
NshmpSourceType type = tree.type();

if (setting == NshmpTectonicSetting.SUBDUCTION) {
if ((type == NshmpSourceType.INTERFACE || type == NshmpSourceType.INTERFACE_CLUSTER
|| type == NshmpSourceType.INTERFACE_GRID || type == NshmpSourceType.INTERFACE_SYSTEM) && !subInterface) {
TectonicRegionType origTRT = NshmUtil.tectonicSettingToType(setting, type);

System.out.println("Processing tree "+tree.id()+". "+tree.name()+" ("+origTRT.name()+")");

for (NshmpBranch<NshmpRuptureSet> branch : tree) {
if (origTRT == VOLCANIC) {
// copy over as is, no current GMM type for volcanic
ret.add(new NshmpTRTBranch(origTRT, branch));
continue;
}
if ((type == NshmpSourceType.SLAB || type == NshmpSourceType.INTRASLAB_GRID) && !subSlab) {
continue;
NshmpRuptureSet rs = branch.value();
System.out.println("\tProcessing RS "+rs.id()+". "+rs.name()+" ("+origTRT.name()+")");
NshmpGmmTree gmmTree = rs.gmmTree();
double weightOrig = 0d;
double weightOverrideSum = 0d;
Map<TectonicRegionType, Double> overrideWeights = new EnumMap<>(TectonicRegionType.class);
for (NshmpBranch<NshmpGmm> gmm : gmmTree.tree()) {
TectonicRegionType gmmTRT = NSHMP_GMM_Wrapper.trtForType(gmm.value().type());
if (gmmTRT != origTRT) {
// we have a GMM TRT override
weightOverrideSum += gmm.weight();
if (overrideWeights.containsKey(gmmTRT))
overrideWeights.put(gmmTRT, overrideWeights.get(gmmTRT)+gmm.weight());
else
overrideWeights.put(gmmTRT, gmm.weight());
} else {
weightOrig += gmm.weight();
}
}
if (weightOverrideSum > 0d) {
// we have overrides to process
Preconditions.checkState(Precision.equals(weightOverrideSum + weightOrig, 1d, 1e-4));
System.err.println("Detected a GMM TRT override for source "+rs.id()+". "+rs.name()+" with original TRT="+origTRT.name());
if (weightOrig > 0d) {
System.err.println("\t"+origTRT.name()+":\t"+weightOrig);
ret.add(new NshmpTRTBranch(origTRT, new WeightScaledBranch(branch, weightOrig, origTRT)));
}
for (TectonicRegionType trt : overrideWeights.keySet()) {
double weight = overrideWeights.get(trt);
System.err.println("\t"+trt.name()+":\t"+weight);
ret.add(new NshmpTRTBranch(trt, new WeightScaledBranch(branch, weight, trt)));
}
} else {
// copy over as is
ret.add(new NshmpTRTBranch(origTRT, branch));
}
}
if (setting == NshmpTectonicSetting.STABLE_CRUST && !stableCrust) {
continue;
}
if (setting == NshmpTectonicSetting.ACTIVE_CRUST && !activeCrust) {
continue;
}
if (setting == NshmpTectonicSetting.VOLCANIC && !volcanic) {
continue;
}
}

return ret;
}

private static class WeightScaledBranch implements NshmpBranch<NshmpRuptureSet> {

private NshmpBranch<NshmpRuptureSet> upstream;
private double scale;
private TectonicRegionType trt;

public WeightScaledBranch(NshmpBranch<NshmpRuptureSet> upstream, double scale, TectonicRegionType trt) {
this.upstream = upstream;
this.scale = scale;
this.trt = trt;
}

@Override
public String id() {
return upstream.id()+"-"+trt.name();
}

@Override
public NshmpRuptureSet value() {
return upstream.value();
}

TectonicRegionType trt = NshmUtil.tectonicSettingToType(setting, type);
List<NshmSource> sources = initTree(tree);
sources.forEach(s -> s.setTectonicRegionType(trt));
allSources.addAll(sources);
sourceMap.putAll(trt, sources);
@Override
public double weight() {
return upstream.weight()*scale;
}

}

public List<NshmSource> allSources() {
Expand Down Expand Up @@ -152,6 +259,14 @@ public int compare(NshmSource o1, NshmSource o2) {
return sources;
}

private List<NshmSource> initBranch(NshmpBranch<NshmpRuptureSet> branch) {
List<NshmSource> sources = new ArrayList<>();
double duration = getTimeSpan().getDuration();
sources.addAll(sourcesFromBranch(branch, duration));

return sources;
}

private List<NshmSource> sourcesFromBranch(
NshmpBranch<NshmpRuptureSet> branch,
double duration) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/org/opensha/nshmp/shaded/model/NshmSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public RuptureSurface getSourceSurface() {
throw new UnsupportedOperationException();
}

public Object getDelegate() {
return delegate;
}

static class Fault extends NshmSource<NshmpIterableRuptureSet> {
public static class Fault extends NshmSource<NshmpIterableRuptureSet> {

private final List<NshmRupture> ruptures;

Expand Down Expand Up @@ -99,7 +95,7 @@ public void setDuration(double duration) {
}
}

static class Point extends NshmSource<NshmpGridSource> {
public static class Point extends NshmSource<NshmpGridSource> {

final double weight;
double duration;
Expand Down Expand Up @@ -142,7 +138,7 @@ public void setDuration(double duration) {
}
}

static class System extends NshmSource<SystemRupture> {
public static class System extends NshmSource<SystemRupture> {

final List<NshmSurface> surfaces;
final NshmRupture rupture;
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/org/opensha/nshmp/shaded/model/NshmSurface.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.opensha.sha.faultSurface.RuptureSurface;
import org.opensha.sha.faultSurface.cache.CacheEnabledSurface;
import org.opensha.sha.faultSurface.cache.SurfaceDistances;
import org.opensha.sha.faultSurface.utils.ptSrcCorr.PointSourceDistanceCorrection;
import org.opensha.sha.util.TectonicRegionType;

import org.opensha.nshmp.shaded.fault.surface.NshmpDefaultGriddedSurface;
import org.opensha.nshmp.shaded.fault.surface.NshmpGriddedSurface;
Expand All @@ -36,6 +38,64 @@ public class NshmSurface implements CacheEnabledSurface {
public NshmSurface(org.opensha.nshmp.shaded.fault.surface.NshmpRuptureSurface delegate) {
this.delegate = delegate;
}

/**
* This creates a point surface that will work with existing OpenSHA point-source optimizations
* @param delegate
* @return
*/
public static org.opensha.sha.faultSurface.PointSurface buildPointSurface(
org.opensha.nshmp.shaded.fault.surface.NshmpRuptureSurface delegate) {
// this is the point surface
double len = 0d;
try {
len = delegate.length();
} catch (Exception e) {}
org.opensha.sha.faultSurface.PointSurface surf = new org.opensha.sha.faultSurface.PointSurface(
NshmUtil.toOpenShaLocation(delegate.centroid()), delegate.dip(), delegate.depth(),
delegate.depth() + delegate.width()*Math.sin(Math.toRadians(delegate.dip())), len);
return new org.opensha.sha.faultSurface.PointSurface.DistanceCorrecting(
surf, new DelegatePointSourceCorrection(delegate), null, Double.NaN);
}

/**
* Delegate point source correction that passes through to NSHMP-haz. This is required for point source
* optimizations to work with wrapped point sources. As part of that, equals/hashCode have to be constant
* for all delegate corrections.
*/
private static class DelegatePointSourceCorrection implements PointSourceDistanceCorrection.Single {

private org.opensha.nshmp.shaded.fault.surface.NshmpRuptureSurface delegate;

private DelegatePointSourceCorrection(org.opensha.nshmp.shaded.fault.surface.NshmpRuptureSurface delegate) {
this.delegate = delegate;
}

@Override
public SurfaceDistances getCorrectedDistance(Location location, org.opensha.sha.faultSurface.PointSurface surf,
TectonicRegionType trt, double mag, double horzDist) {
NshmpDistance distance = delegate.distanceTo(NshmUtil.fromOpenShaLocation(location));
return new SurfaceDistances.Precomputed(location, distance.rRup, distance.rJB, distance.rX);
}

private static final int hashCode = DelegatePointSourceCorrection.class.hashCode();

@Override
public int hashCode() {
return hashCode;
}

@Override
public boolean equals(Object obj) {
// return obj instanceof DelegatePointSourceCorrection;
if (!(obj instanceof DelegatePointSourceCorrection))
return false;
DelegatePointSourceCorrection other = (DelegatePointSourceCorrection)obj;
// System.out.println("Delegate classes:\t"+delegate.getClass()+"\t"+other.delegate.getClass());
return other.delegate.getClass().equals(delegate.getClass());
}

}

// return nshmp-haz rupture centroid as OpenSHA location for
// use in computing min distance to a fault system subsection
Expand Down
Loading
Loading