Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

apply plugin: 'java-library'
apply plugin: 'eclipse'

ext {
parentProject = 'opensha'
Expand All @@ -12,7 +13,7 @@ apply from: '../opensha/build-common.gradle'

dependencies {

api "ghsc:nshmp-lib:1.8.4"
api 'org.opensha:opensha-nshmp-lib:1.8.4-opensha.1'

implementation 'org.apache.pdfbox:pdfbox:2.0.6'
implementation 'org.apache.commons:commons-collections4:4.1'
Expand Down
61 changes: 0 additions & 61 deletions src/main/java/gov/usgs/earthquake/nshmp/model/NshmUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.usgs.earthquake.nshmp.model;
package org.opensha.nshmp.shaded.model;

import static java.util.stream.Collectors.toList;
import static org.opensha.sha.util.TectonicRegionType.ACTIVE_SHALLOW;
Expand Down Expand Up @@ -26,13 +26,13 @@
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;

import gov.usgs.earthquake.nshmp.data.Indexing;
import gov.usgs.earthquake.nshmp.model.SystemRuptureSet.SystemRupture;
import gov.usgs.earthquake.nshmp.tree.Branch;
import org.opensha.nshmp.shaded.data.NshmpIndexing;
import org.opensha.nshmp.shaded.model.NshmpSystemRuptureSet.SystemRupture;
import org.opensha.nshmp.shaded.tree.NshmpBranch;

public class NshmErf extends AbstractERF {

private final HazardModel model;
private final NshmpHazardModel model;
private final List<NshmSource> allSources;
private final Multimap<TectonicRegionType, NshmSource> sourceMap;

Expand All @@ -46,10 +46,10 @@ public class NshmErf extends AbstractERF {

public NshmErf(Path path, Set<TectonicRegionType> trts,
IncludeBackgroundOption gridOption) {
this(HazardModel.load(path), trts, gridOption);
this(NshmpHazardModel.load(path), trts, gridOption);
}

public NshmErf(HazardModel model, Set<TectonicRegionType> trts,
public NshmErf(NshmpHazardModel model, Set<TectonicRegionType> trts,
IncludeBackgroundOption gridOption) {
this.model = model;
allSources = new ArrayList<>();
Expand Down Expand Up @@ -78,29 +78,29 @@ private void init() {
setTimeSpan(timeSpan);

// nshmp-haz initializers
Multimap<TectonicSetting, SourceTree> trees = model.trees();
for (Entry<TectonicSetting, SourceTree> entry : trees.entries()) {
Multimap<NshmpTectonicSetting, NshmpSourceTree> trees = model.trees();
for (Entry<NshmpTectonicSetting, NshmpSourceTree> entry : trees.entries()) {

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

if (setting == TectonicSetting.SUBDUCTION) {
if ((type == SourceType.INTERFACE || type == SourceType.INTERFACE_CLUSTER
|| type == SourceType.INTERFACE_GRID || type == SourceType.INTERFACE_SYSTEM) && !subInterface) {
if (setting == NshmpTectonicSetting.SUBDUCTION) {
if ((type == NshmpSourceType.INTERFACE || type == NshmpSourceType.INTERFACE_CLUSTER
|| type == NshmpSourceType.INTERFACE_GRID || type == NshmpSourceType.INTERFACE_SYSTEM) && !subInterface) {
continue;
}
if ((type == SourceType.SLAB || type == SourceType.INTRASLAB_GRID) && !subSlab) {
if ((type == NshmpSourceType.SLAB || type == NshmpSourceType.INTRASLAB_GRID) && !subSlab) {
continue;
}
}
if (setting == TectonicSetting.STABLE_CRUST && !stableCrust) {
if (setting == NshmpTectonicSetting.STABLE_CRUST && !stableCrust) {
continue;
}
if (setting == TectonicSetting.ACTIVE_CRUST && !activeCrust) {
if (setting == NshmpTectonicSetting.ACTIVE_CRUST && !activeCrust) {
continue;
}
if (setting == TectonicSetting.VOLCANIC && !volcanic) {
if (setting == NshmpTectonicSetting.VOLCANIC && !volcanic) {
continue;
}

Expand All @@ -120,7 +120,7 @@ public Multimap<TectonicRegionType, NshmSource> sourceMap() {
return sourceMap;
}

private List<NshmSource> initTree(SourceTree tree) {
private List<NshmSource> initTree(NshmpSourceTree tree) {
List<NshmSource> sources = new ArrayList<>();
double duration = getTimeSpan().getDuration();
tree.stream()
Expand Down Expand Up @@ -153,117 +153,117 @@ public int compare(NshmSource o1, NshmSource o2) {
}

private List<NshmSource> sourcesFromBranch(
Branch<RuptureSet> branch,
NshmpBranch<NshmpRuptureSet> branch,
double duration) {

RuptureSet ruptureSet = branch.value();
NshmpRuptureSet ruptureSet = branch.value();
double weight = branch.weight();

switch (ruptureSet.type()) {

case GRID:
GriddedRuptureSet grs = (GriddedRuptureSet) ruptureSet;
NshmpGriddedRuptureSet grs = (NshmpGriddedRuptureSet) ruptureSet;
return (grid)
? gridRuptureSetToSources(grs, weight, duration)
: List.of();

case ZONE:
GriddedRuptureSet zrs = (GriddedRuptureSet) ruptureSet;
NshmpGriddedRuptureSet zrs = (NshmpGriddedRuptureSet) ruptureSet;
return (faults)
? gridRuptureSetToSources(zrs, weight, duration)
: List.of();

case INTERFACE_GRID:
GriddedRuptureSet igrs = (GriddedRuptureSet) ruptureSet;
NshmpGriddedRuptureSet igrs = (NshmpGriddedRuptureSet) ruptureSet;
return (subInterface && grid)
? gridRuptureSetToSources(igrs, weight, duration)
: List.of();

case INTRASLAB_GRID:
GriddedRuptureSet isgrs = (GriddedRuptureSet) ruptureSet;
NshmpGriddedRuptureSet isgrs = (NshmpGriddedRuptureSet) ruptureSet;
return (subSlab && grid)
? gridRuptureSetToSources(isgrs, weight, duration)
: List.of();

case SLAB:
GriddedRuptureSet slabRuptures = (GriddedRuptureSet) ruptureSet;
NshmpGriddedRuptureSet slabRuptures = (NshmpGriddedRuptureSet) ruptureSet;
return (subSlab && grid)
? gridRuptureSetToSources(slabRuptures, weight, duration)
: List.of();

case FAULT_CLUSTER:
ClusterRuptureSet crs = (ClusterRuptureSet) ruptureSet;
NshmpClusterRuptureSet crs = (NshmpClusterRuptureSet) ruptureSet;
return (faults)
? clusterRuptureSetToSources(crs, weight, duration)
: List.of();

case FAULT_SYSTEM:
SystemRuptureSet srs = (SystemRuptureSet) ruptureSet;
NshmpSystemRuptureSet srs = (NshmpSystemRuptureSet) ruptureSet;
return (faults)
? systemRuptureSetToSources(srs, weight, duration)
: List.of();

case INTERFACE:
return (subInterface && faults)
? iterableRuptureSetToSources((IterableRuptureSet) ruptureSet, weight, duration)
? iterableRuptureSetToSources((NshmpIterableRuptureSet) ruptureSet, weight, duration)
: List.of();

case INTERFACE_CLUSTER:
ClusterRuptureSet icrs = (ClusterRuptureSet) ruptureSet;
NshmpClusterRuptureSet icrs = (NshmpClusterRuptureSet) ruptureSet;
return (subInterface && faults)
? clusterRuptureSetToSources(icrs, weight, duration)
: List.of();

case INTERFACE_SYSTEM:
SystemRuptureSet isrs = (SystemRuptureSet) ruptureSet;
NshmpSystemRuptureSet isrs = (NshmpSystemRuptureSet) ruptureSet;
return (faults)
? systemRuptureSetToSources(isrs, weight, duration)
: List.of();

default:
return (faults)
? iterableRuptureSetToSources((IterableRuptureSet) ruptureSet, weight, duration)
? iterableRuptureSetToSources((NshmpIterableRuptureSet) ruptureSet, weight, duration)
: List.of();
}
}

private static List<NshmSource> gridRuptureSetToSources(
GriddedRuptureSet ruptureSet,
NshmpGriddedRuptureSet ruptureSet,
double weight,
double duration) {

List<NshmSource> sources = new ArrayList<>();
for (GridSource gridSource : ruptureSet) {
for (NshmpGridSource gridSource : ruptureSet) {
sources.add(new NshmSource.Point(gridSource, weight, duration));
}
return sources;
}

private static List<NshmSource> iterableRuptureSetToSources(
IterableRuptureSet ruptureSet,
NshmpIterableRuptureSet ruptureSet,
double weight,
double duration) {

return List.of(new NshmSource.Fault(ruptureSet, weight, duration));
}

private static List<NshmSource> systemRuptureSetToSources(
SystemRuptureSet srs,
NshmpSystemRuptureSet srs,
double weight,
double duration) {

List<NshmSurface> surfaces = Arrays.stream(srs.sections)
.map(section -> new NshmSurface(section))
.collect(Collectors.toList());

// SystemRuptureSet.stream() not supported but should be.
// NshmpSystemRuptureSet.stream() not supported but should be.
// Iterator should work, even if it isn't used in nshm calc
// pathways

List<NshmSource> sources = new ArrayList<>(srs.size());
for (int i = 0; i < srs.size(); i++) {
SystemRupture source = (SystemRupture) srs.get(i);
int[] sectionIndices = Indexing.bitsToIndices(source.bitset());
int[] sectionIndices = NshmpIndexing.bitsToIndices(source.bitset());
List<NshmSurface> ruptureSurfaces = IntStream.of(sectionIndices)
.mapToObj(surfaces::get)
.collect(Collectors.toList());
Expand All @@ -273,7 +273,7 @@ private static List<NshmSource> systemRuptureSetToSources(
}

private static List<NshmSource> clusterRuptureSetToSources(
ClusterRuptureSet crs,
NshmpClusterRuptureSet crs,
double weight,
double duration) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.usgs.earthquake.nshmp.model;
package org.opensha.nshmp.shaded.model;

import java.awt.geom.Point2D;
import java.nio.file.Path;
Expand Down Expand Up @@ -30,30 +30,30 @@ public class NshmErfTest {
// private static final Path MODEL = Path.of("../nshm-conus-2018-5.x-maint");
private static final Path MODEL = Path.of("../nshm-prvi");

static gov.usgs.earthquake.nshmp.geo.Location testLoc =
gov.usgs.earthquake.nshmp.geo.Location.create(-66.117, 18.465);
// static gov.usgs.earthquake.nshmp.geo.Location testLoc =
// gov.usgs.earthquake.nshmp.geo.Location.create(-80, 33.2);
static org.opensha.nshmp.shaded.geo.NshmpLocation testLoc =
org.opensha.nshmp.shaded.geo.NshmpLocation.create(-66.117, 18.465);
// static org.opensha.nshmp.shaded.geo.NshmpLocation testLoc =
// org.opensha.nshmp.shaded.geo.NshmpLocation.create(-80, 33.2);

// static gov.usgs.earthquake.nshmp.geo.Location testLoc =
// gov.usgs.earthquake.nshmp.geo.Location.create(-110, 37.5);
// static org.opensha.nshmp.shaded.geo.NshmpLocation testLoc =
// org.opensha.nshmp.shaded.geo.NshmpLocation.create(-110, 37.5);

public static void main(String[] args) {

// Set<TectonicRegionType> trts =
// EnumSet.of(TectonicRegionType.STABLE_SHALLOW);
Set<TectonicRegionType> trts = EnumSet.noneOf(TectonicRegionType.class);

HazardModel model = HazardModel.load(MODEL);
NshmpHazardModel model = NshmpHazardModel.load(MODEL);
NshmErf erf = new NshmErf(model, trts, IncludeBackgroundOption.INCLUDE);
System.out.println("NSHM ERF size: " + erf.getNumSources());
erf.getTimeSpan().setDuration(1.0);
erf.updateForecast();

System.out.println(Models.mfd(
System.out.println(NshmpModels.mfd(
model,
TectonicSetting.SUBDUCTION,
Optional.of(SourceType.INTERFACE)));
NshmpTectonicSetting.SUBDUCTION,
Optional.of(NshmpSourceType.INTERFACE)));

// for (ProbEqkSource src : erf) {
//
Expand All @@ -66,7 +66,7 @@ public static void main(String[] args) {
// if (ptSrc.loc.equals(testLoc)) {
// System.out.println(testLoc);
// System.out.println(ptSrc.mfd);
// for (Rupture rup : ptSrc) {
// for (NshmpRupture rup : ptSrc) {
// PointSourceFinite.FiniteSurface surf =
// (PointSourceFinite.FiniteSurface) rup.surface();
// System.out.println(surf.mag + " " + surf.zTor + " " + surf.dip());
Expand All @@ -87,7 +87,7 @@ public static void main(String[] args) {
System.out.println(true);

NshmSource.Point ptSrc = (NshmSource.Point) nshmSrc;
GridSource nhPtSrc = (GridSource) nshmSrc.delegate();
NshmpGridSource nhPtSrc = (NshmpGridSource) nshmSrc.delegate();

// PointSourceFixedStrike ptSrc = (PointSourceFixedStrike) nshmSrc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gov.usgs.earthquake.nshmp.model;
package org.opensha.nshmp.shaded.model;

import org.opensha.sha.earthquake.ProbEqkRupture;
import org.opensha.sha.faultSurface.RuptureSurface;

import gov.usgs.earthquake.nshmp.Maths;
import org.opensha.nshmp.shaded.NshmpMaths;

class NshmRupture extends ProbEqkRupture {

Expand All @@ -20,7 +20,7 @@ class NshmRupture extends ProbEqkRupture {

super(
mag, rake,
Maths.rateToProbability(rate * weight, duration),
NshmpMaths.rateToProbability(rate * weight, duration),
surface, null);

this.rate = rate;
Expand Down
Loading
Loading