Skip to content

Commit 60acc11

Browse files
Merge pull request #284 from pmpowers-usgs/gmminput-builder-281
Gmminput builder improvements
2 parents 10bf970 + 6294405 commit 60acc11

2 files changed

Lines changed: 120 additions & 126 deletions

File tree

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package gov.usgs.earthquake.nshmp;
22

3-
//....................................... Import ..........................................
43
import java.util.ArrayList;
54
import java.util.List;
65
import java.util.Map;
@@ -13,97 +12,80 @@
1312
import gov.usgs.earthquake.nshmp.data.Data;
1413
import gov.usgs.earthquake.nshmp.gmm.Gmm;
1514
import gov.usgs.earthquake.nshmp.gmm.GmmInput;
15+
import gov.usgs.earthquake.nshmp.gmm.GroundMotionModel;
1616
import gov.usgs.earthquake.nshmp.gmm.Imt;
1717
import gov.usgs.earthquake.nshmp.gmm.ScalarGroundMotion;
1818
import gov.usgs.earthquake.nshmp.util.Maths;
19-
//--------------------------------------- End Import --------------------------------------
20-
21-
2219

2320
public class GroundMotions {
24-
25-
26-
//................................ Method: distanceGroundMotion .........................
21+
2722
public static DistanceResult distanceGroundMotions(
2823
Set<Gmm> gmms,
2924
GmmInput inputModel,
3025
Imt imt,
3126
double rMax) {
32-
33-
34-
//.............................. Set Distance and Gmm Inputs ..........................
27+
3528
int round = 5;
36-
double rJB;
29+
double rJB;
3730
double rX;
3831
double rRup;
3932
double rMin = 0.001;
4033
double rPoints = 100.0;
41-
double rStep = (Math.log10(rMax/rMin))/(rPoints-1);
42-
double[] distance = Data.round(round, Data.pow10(Data.buildSequence(
43-
Math.log10(rMin), Math.log10(rMax), rStep, true)));
44-
45-
List<GmmInput> gmmInputs = new ArrayList<>();
46-
47-
for(double r : distance) {
34+
double rStep = (Math.log10(rMax / rMin)) / (rPoints - 1);
35+
double[] distance = Data.round(round, Data.pow10(
36+
Data.buildSequence(Math.log10(rMin), Math.log10(rMax), rStep, true)));
37+
38+
List<GmmInput> gmmInputs = new ArrayList<>();
39+
GmmInput.Builder gmmBuilder = GmmInput.builder().fromCopy(inputModel);
40+
41+
for (double r : distance) {
4842
rJB = r;
4943
rX = r;
5044
rRup = Maths.hypot(r, inputModel.zTop);
51-
GmmInput.Builder gmmBuilder = GmmInput.builder().fromModel(inputModel);
52-
gmmInputs.add(gmmBuilder.distances(rJB, rRup, rX).build());
45+
gmmBuilder.distances(rJB, rRup, rX);
46+
gmmInputs.add(gmmBuilder.build());
5347
}
54-
//-------------------------------------------------------------------------------------
55-
56-
57-
//........................... Calculate Ground Motion .................................
48+
5849
Map<Gmm, List<Double>> distanceMap = Maps.newEnumMap(Gmm.class);
5950
Map<Gmm, List<Double>> meanMap = Maps.newEnumMap(Gmm.class);
6051
Map<Gmm, List<Double>> sigmaMap = Maps.newEnumMap(Gmm.class);
61-
62-
for(Gmm gmm : gmms) {
52+
53+
for (Gmm gmm : gmms) {
6354
ImmutableList.Builder<Double> means = ImmutableList.builder();
6455
ImmutableList.Builder<Double> sigmas = ImmutableList.builder();
65-
66-
for(GmmInput gmmInput : gmmInputs) {
67-
ScalarGroundMotion gm = gmm.instance(imt).calc(gmmInput);
56+
57+
GroundMotionModel model = gmm.instance(imt);
58+
for (GmmInput gmmInput : gmmInputs) {
59+
ScalarGroundMotion gm = model.calc(gmmInput);
6860
means.add(gm.mean());
69-
sigmas.add(gm.sigma());
61+
sigmas.add(gm.sigma());
7062
}
71-
63+
7264
meanMap.put(gmm, means.build());
7365
sigmaMap.put(gmm, sigmas.build());
7466
distanceMap.put(gmm, Doubles.asList(distance));
7567
}
76-
//-------------------------------------------------------------------------------------
77-
68+
7869
return new DistanceResult(
7970
Maps.immutableEnumMap(distanceMap),
8071
Maps.immutableEnumMap(meanMap),
81-
Maps.immutableEnumMap(sigmaMap)
82-
);
72+
Maps.immutableEnumMap(sigmaMap));
8373
}
84-
//------------------------------ End Method: distanceGroundMotion -----------------------
85-
86-
87-
88-
//............................. Class: DistanceResult ...................................
74+
8975
public static class DistanceResult {
90-
76+
9177
public final Map<Gmm, List<Double>> means;
9278
public final Map<Gmm, List<Double>> distance;
9379
public final Map<Gmm, List<Double>> sigmas;
94-
80+
9581
DistanceResult(
9682
Map<Gmm, List<Double>> distance,
9783
Map<Gmm, List<Double>> means,
98-
Map<Gmm, List<Double>> sigmas){
99-
this.distance = distance;
84+
Map<Gmm, List<Double>> sigmas) {
85+
this.distance = distance;
10086
this.means = means;
10187
this.sigmas = sigmas;
10288
}
10389
}
104-
//------------------------------ End Class: DistanceResult ------------------------------
10590

106-
107-
10891
}
109-
//-------------------------------- End Class: GroundMotions -------------------------------

0 commit comments

Comments
 (0)