Skip to content

Commit

Permalink
Merge pull request #284 from pmpowers-usgs/gmminput-builder-281
Browse files Browse the repository at this point in the history
Gmminput builder improvements
  • Loading branch information
pmpowers-usgs authored Jan 24, 2018
2 parents 10bf970 + 6294405 commit 60acc11
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 126 deletions.
78 changes: 30 additions & 48 deletions src/gov/usgs/earthquake/nshmp/GroundMotions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gov.usgs.earthquake.nshmp;

//....................................... Import ..........................................
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -13,97 +12,80 @@
import gov.usgs.earthquake.nshmp.data.Data;
import gov.usgs.earthquake.nshmp.gmm.Gmm;
import gov.usgs.earthquake.nshmp.gmm.GmmInput;
import gov.usgs.earthquake.nshmp.gmm.GroundMotionModel;
import gov.usgs.earthquake.nshmp.gmm.Imt;
import gov.usgs.earthquake.nshmp.gmm.ScalarGroundMotion;
import gov.usgs.earthquake.nshmp.util.Maths;
//--------------------------------------- End Import --------------------------------------



public class GroundMotions {


//................................ Method: distanceGroundMotion .........................

public static DistanceResult distanceGroundMotions(
Set<Gmm> gmms,
GmmInput inputModel,
Imt imt,
double rMax) {


//.............................. Set Distance and Gmm Inputs ..........................

int round = 5;
double rJB;
double rJB;
double rX;
double rRup;
double rMin = 0.001;
double rPoints = 100.0;
double rStep = (Math.log10(rMax/rMin))/(rPoints-1);
double[] distance = Data.round(round, Data.pow10(Data.buildSequence(
Math.log10(rMin), Math.log10(rMax), rStep, true)));

List<GmmInput> gmmInputs = new ArrayList<>();

for(double r : distance) {
double rStep = (Math.log10(rMax / rMin)) / (rPoints - 1);
double[] distance = Data.round(round, Data.pow10(
Data.buildSequence(Math.log10(rMin), Math.log10(rMax), rStep, true)));

List<GmmInput> gmmInputs = new ArrayList<>();
GmmInput.Builder gmmBuilder = GmmInput.builder().fromCopy(inputModel);

for (double r : distance) {
rJB = r;
rX = r;
rRup = Maths.hypot(r, inputModel.zTop);
GmmInput.Builder gmmBuilder = GmmInput.builder().fromModel(inputModel);
gmmInputs.add(gmmBuilder.distances(rJB, rRup, rX).build());
gmmBuilder.distances(rJB, rRup, rX);
gmmInputs.add(gmmBuilder.build());
}
//-------------------------------------------------------------------------------------


//........................... Calculate Ground Motion .................................

Map<Gmm, List<Double>> distanceMap = Maps.newEnumMap(Gmm.class);
Map<Gmm, List<Double>> meanMap = Maps.newEnumMap(Gmm.class);
Map<Gmm, List<Double>> sigmaMap = Maps.newEnumMap(Gmm.class);
for(Gmm gmm : gmms) {

for (Gmm gmm : gmms) {
ImmutableList.Builder<Double> means = ImmutableList.builder();
ImmutableList.Builder<Double> sigmas = ImmutableList.builder();

for(GmmInput gmmInput : gmmInputs) {
ScalarGroundMotion gm = gmm.instance(imt).calc(gmmInput);

GroundMotionModel model = gmm.instance(imt);
for (GmmInput gmmInput : gmmInputs) {
ScalarGroundMotion gm = model.calc(gmmInput);
means.add(gm.mean());
sigmas.add(gm.sigma());
sigmas.add(gm.sigma());
}

meanMap.put(gmm, means.build());
sigmaMap.put(gmm, sigmas.build());
distanceMap.put(gmm, Doubles.asList(distance));
}
//-------------------------------------------------------------------------------------


return new DistanceResult(
Maps.immutableEnumMap(distanceMap),
Maps.immutableEnumMap(meanMap),
Maps.immutableEnumMap(sigmaMap)
);
Maps.immutableEnumMap(sigmaMap));
}
//------------------------------ End Method: distanceGroundMotion -----------------------



//............................. Class: DistanceResult ...................................

public static class DistanceResult {

public final Map<Gmm, List<Double>> means;
public final Map<Gmm, List<Double>> distance;
public final Map<Gmm, List<Double>> sigmas;

DistanceResult(
Map<Gmm, List<Double>> distance,
Map<Gmm, List<Double>> means,
Map<Gmm, List<Double>> sigmas){
this.distance = distance;
Map<Gmm, List<Double>> sigmas) {
this.distance = distance;
this.means = means;
this.sigmas = sigmas;
}
}
//------------------------------ End Class: DistanceResult ------------------------------



}
//-------------------------------- End Class: GroundMotions -------------------------------
Loading

0 comments on commit 60acc11

Please sign in to comment.