Skip to content

Commit

Permalink
Merge pull request #213 from pmpowers-usgs/export-updates-51
Browse files Browse the repository at this point in the history
Export updates 51
  • Loading branch information
pmpowers-usgs authored Apr 30, 2017
2 parents 7a861ef + 5ef50c2 commit e8340f5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
20 changes: 16 additions & 4 deletions src/org/opensha2/calc/DeaggContributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ List<JsonContributor> toJson(ContributionFilter filter) {
ArrayList<JsonContributor> jsonList = new ArrayList<>();
JsonContributor jc = JsonContributor.createMulti(
sourceSet.name(),
sourceSet.type(),
Maths.round(filter.toPercent(total()), 2));
jsonList.add(jc);
for (DeaggContributor child : children) {
Expand Down Expand Up @@ -301,6 +302,7 @@ List<JsonContributor> toJson(ContributionFilter filter) {
double εBar = εScaled / total;
JsonContributor jc = JsonContributor.createSingle(
source.name(),
source.type(),
Maths.round(filter.toPercent(total()), 2),
-1,
rBar,
Expand Down Expand Up @@ -436,6 +438,7 @@ List<JsonContributor> toJson(ContributionFilter filter) {
double εBar = εScaled / total;
JsonContributor jc = JsonContributor.createSingle(
cluster.name(),
cluster.type(),
Maths.round(filter.toPercent(total()), 2),
-2,
rBar,
Expand Down Expand Up @@ -559,6 +562,7 @@ List<JsonContributor> toJson(ContributionFilter filter) {
double εBar = εScaled / total;
JsonContributor jc = JsonContributor.createSingle(
section.name(),
section.type(),
Maths.round(filter.toPercent(total()), 2),
-3,
rBar,
Expand Down Expand Up @@ -704,6 +708,7 @@ public Iterator<Rupture> iterator() {
/* Wrapper of contributor data suitable for JSON serialization. */
static final class JsonContributor {
String name;
String source;
JsonContributorType type;
Double contribution;
Integer id;
Expand All @@ -715,17 +720,23 @@ static final class JsonContributor {
Double longitude;

/* Use for SourceSets. */
static JsonContributor createMulti(String name, double contribution) {
static JsonContributor createMulti(
String name,
SourceType source,
double contribution) {

JsonContributor jc = new JsonContributor();
jc.name = name;
jc.type = JsonContributorType.MULTI;
jc.source = source.toString();
jc.type = JsonContributorType.SET;
jc.contribution = contribution;
return jc;
}

/* Use for more detailed individual sources. */
static JsonContributor createSingle(
String name,
SourceType source,
double contribution,
int id,
double r,
Expand All @@ -737,6 +748,7 @@ static JsonContributor createSingle(

JsonContributor jc = new JsonContributor();
jc.name = name;
jc.source = source.toString();
jc.type = JsonContributorType.SINGLE;
jc.contribution = contribution;
jc.id = id;
Expand All @@ -751,8 +763,8 @@ static JsonContributor createSingle(
}

private static enum JsonContributorType {
SINGLE,
MULTI;
SET,
SINGLE;
}

/* Convert a builder list to immutable sorted contributor list. */
Expand Down
6 changes: 3 additions & 3 deletions src/org/opensha2/calc/DeaggExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private static SummaryElements createSummaryElements(

private static double traceContribution(DeaggDataset dd) {
double toPercent = percentScalar(dd);
double traceConribution = 0.0;
double traceContribution = 0.0;
for (int ri = 0; ri < dd.rmε.rows().size(); ri++) {
for (int mi = 0; mi < dd.rmε.columns().size(); mi++) {
if (dd.rmWeights.get(ri, mi) <= 0.0) {
Expand All @@ -406,12 +406,12 @@ private static double traceContribution(DeaggDataset dd) {
for (double εValue : dd.rmε.column(ri, mi).yValues()) {
double rmεBinContribution = εValue * toPercent;
if (rmεBinContribution < TRACE_LIMIT) {
traceConribution += rmεBinContribution;
traceContribution += rmεBinContribution;
}
}
}
}
return traceConribution;
return traceContribution;
}

private static double percentScalar(DeaggDataset dd) {
Expand Down
15 changes: 12 additions & 3 deletions src/org/opensha2/calc/Deaggregation.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,27 @@ public String toString() {

/*
* Method does not return a JSON String, but rather an appropriately
* structured object that may be serialized directly or added to soem other
* structured object that may be serialized directly or added to some other
* object prior to serialization.
*/
Object toJson() {
List<DeaggExport> jsonDeaggs = new ArrayList<>();
DeaggExport export = new DeaggExport(
DeaggExport total = new DeaggExport(
totalDataset,
totalDataset,
config,
"Total",
true);
jsonDeaggs.add(export);
jsonDeaggs.add(total);
for (Entry<Gmm, DeaggDataset> ddEntry : gmmDatasets.entrySet()) {
DeaggExport gmm = new DeaggExport(
totalDataset,
ddEntry.getValue(),
config,
ddEntry.getKey().toString(),
true);
jsonDeaggs.add(gmm);
}
return jsonDeaggs;
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/org/opensha2/eq/model/PointSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ class PointSource implements Source {

@Override
public String name() {
return "PointSource: " + loc;
return "PointSource: " + formatLocation(loc);
}

static final String FORMAT = "%.3f, %.3f";
static String formatLocation(Location loc) {
return String.format(FORMAT, loc.lon(), loc.lat());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/org/opensha2/eq/model/PointSourceFinite.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PointSourceFinite extends PointSource {

@Override
public String name() {
return "PointSourceFinite: " + loc;
return "PointSourceFinite: " + formatLocation(loc);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/org/opensha2/eq/model/PointSourceFixedStrike.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PointSourceFixedStrike extends PointSourceFinite {

@Override
public String name() {
return "PointSourceFixedStrike: " + loc;
return "PointSourceFixedStrike: " + formatLocation(loc);
}

/*
Expand Down

0 comments on commit e8340f5

Please sign in to comment.