diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/CalcConfig.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/CalcConfig.java index 48daad717e65b25cfe428244dd220b9da169ab51..3945369d7dc145929938c43af79328ac9e97a9df 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/CalcConfig.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/CalcConfig.java @@ -802,9 +802,10 @@ public final class CalcConfig { private Output(Builder b) { this.directory = b.directory; - b.dataTypes.add(DataType.TOTAL); - b.dataTypes.add(DataType.MAP); - this.dataTypes = Collections.unmodifiableSet(b.dataTypes); + Set<DataType> dataTypes = EnumSet.copyOf(b.dataTypes); + dataTypes.add(DataType.TOTAL); + dataTypes.add(DataType.MAP); + this.dataTypes = Collections.unmodifiableSet(dataTypes); this.returnPeriods = List.copyOf(b.returnPeriods); } @@ -1028,6 +1029,16 @@ public final class CalcConfig { return this; } + /** + * Set the data types for which results should be calculated. + * + * @see gov.usgs.earthquake.nshmp.calc.CalcConfig.Hazard#imts + */ + public Builder dataTypes(Set<DataType> dataTypes) { + this.output.dataTypes = checkNotNull(dataTypes); + return this; + } + /** * Set the timespan for earthquake probabilities. Calling this method also * sets {@link Rate#valueFormat} to {@link ValueFormat#POISSON_PROBABILITY} diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java index 2561ab96070be39c18f5f366d4d30cb57e7a9e68..8ad506aa2040ea3863432f1a69388c6859c067a0 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java @@ -24,6 +24,9 @@ public enum DataType { MAP, /** Data by {@link SourceType}. */ - SOURCE; + SOURCE, + + /** Disaggregation r-m-ε bin data */ + DISAGG_DATA; } diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java index c2f2ccd7dd89700b5b4190961a444d8103a98a08..0b7bf999048e91b81a9a5fb2c6521cd0a3c328d9 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java @@ -61,18 +61,16 @@ final class DisaggExport { DisaggDataset dd, DisaggConfig dc, String id, - boolean jsonFlag, - boolean εDataFlag, - boolean summaryFlag) { + boolean εDataFlag) { this.ddTotal = ddTotal; this.dd = dd; this.dc = dc; this.id = id; - summary = summaryFlag ? createSummaryElements(ddTotal, dd, dc) : null; + summary = createSummaryElements(ddTotal, dd, dc); + sources = createJsonContributorList(ddTotal, dd, dc.contributorLimit); data = εDataFlag ? createDistanceMagnitudeData(ddTotal, dd) : null; - sources = jsonFlag ? createJsonContributorList(ddTotal, dd, dc.contributorLimit) : null; } @Override diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java index 47a720f499c12299dfc3dbce41993104c9bfe424..100d8081ca2364982d0e999271f030173e52a5b8 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java @@ -186,33 +186,18 @@ public final class Disaggregation { } /** - * Returns an object containing all disaggregation results that is suitable - * for JSON serialization. + * Returns an object containing disaggregation results that is suitable for + * JSON serialization. * * @param imt of the disaggregation to retrieve. - */ - public Object toJson(Imt imt) { - return disaggs.get(imt).toJson(true, true, true, true); - } - - /** - * Returns an object containing custom disaggregation results that is suitable - * for JSON serialization. - * - * @param imt of the disaggregation to retrieve. - * @param summary include summary information, or not * @param gmms include results decomposed by GMM (values are scaled by GMM * logic tree weight) * @param types include results decomposed by source type - * @param epsilons include distance-magnitude-epsilon data that can be used to + * @param rmeData include distance-magnitude-epsilon data that can be used to * build a 3D stem plot */ - public Object toJson(Imt imt, - boolean summary, - boolean gmms, - boolean types, - boolean epsilons) { - return disaggs.get(imt).toJson(summary, gmms, types, epsilons); + public Object toJson(Imt imt, boolean gmms, boolean types, boolean rmeData) { + return disaggs.get(imt).toJson(gmms, types, rmeData); } /** @@ -298,7 +283,7 @@ public final class Disaggregation { public String toString() { StringBuilder sb = new StringBuilder(); sb.append(NEWLINE); - for (DisaggExport export : buildExports(false, true, true, true, true)) { + for (DisaggExport export : buildExports(true, true, false)) { sb.append(export.toString()); sb.append(NEWLINE); } @@ -310,16 +295,14 @@ public final class Disaggregation { * structured object that may be serialized directly or added to some other * object prior to serialization. */ - Object toJson(boolean summary, boolean gmmDisaggs, boolean typeDisaggs, boolean εData) { - return buildExports(true, summary, gmmDisaggs, typeDisaggs, εData); + Object toJson(boolean gmmDisaggs, boolean typeDisaggs, boolean rmεData) { + return buildExports(gmmDisaggs, typeDisaggs, rmεData); } private List<DisaggExport> buildExports( - boolean json, - boolean summary, boolean gmmDisaggs, boolean typeDisaggs, - boolean εData) { + boolean rmεData) { List<DisaggExport> exports = new ArrayList<>(); DisaggExport total = new DisaggExport( @@ -327,9 +310,7 @@ public final class Disaggregation { totalDataset, config, TOTAL_COMPONENT, - json, - εData, - summary); + rmεData); exports.add(total); if (gmmDisaggs) { for (Entry<Gmm, DisaggDataset> gmmEntry : gmmDatasets.entrySet()) { @@ -338,9 +319,7 @@ public final class Disaggregation { gmmEntry.getValue(), config, GMM_COMPONENT + gmmEntry.getKey().toString(), - json, - εData, - summary); + rmεData); exports.add(gmm); } } @@ -351,9 +330,7 @@ public final class Disaggregation { typeEntry.getValue(), config, TYPE_COMPONENT + typeEntry.getKey().toString(), - json, - εData, - summary); + rmεData); exports.add(type); } } diff --git a/src/test/java/gov/usgs/earthquake/nshmp/calc/CalcConfigTests.java b/src/test/java/gov/usgs/earthquake/nshmp/calc/CalcConfigTests.java index eb47edc7335898e77b1fdfaf7a0b4878c44f5aa2..3010f5baa6b29b3ca95453c8d25bc303c1c46649 100644 --- a/src/test/java/gov/usgs/earthquake/nshmp/calc/CalcConfigTests.java +++ b/src/test/java/gov/usgs/earthquake/nshmp/calc/CalcConfigTests.java @@ -1,5 +1,10 @@ package gov.usgs.earthquake.nshmp.calc; +import static gov.usgs.earthquake.nshmp.calc.DataType.DISAGG_DATA; +import static gov.usgs.earthquake.nshmp.calc.DataType.GMM; +import static gov.usgs.earthquake.nshmp.calc.DataType.MAP; +import static gov.usgs.earthquake.nshmp.calc.DataType.SOURCE; +import static gov.usgs.earthquake.nshmp.calc.DataType.TOTAL; import static gov.usgs.earthquake.nshmp.gmm.Imt.PGA; import static gov.usgs.earthquake.nshmp.gmm.Imt.PGV; import static gov.usgs.earthquake.nshmp.gmm.Imt.SA0P01; @@ -106,14 +111,19 @@ class CalcConfigTests { @Test void publicOverrides() throws IOException { Set<Imt> imts = Set.of(PGA, SA0P2, SA1P0); + Set<DataType> dataTypes = EnumSet.of(TOTAL, MAP, GMM, SOURCE, DISAGG_DATA); double distance = 50.0; double timespan = 100.0; CalcConfig config = CalcConfig.defaults() .imts(imts) + .dataTypes(dataTypes) .distance(distance) .timespan(timespan) .build(); assertEquals(imts, config.hazard.imts); + System.out.println(dataTypes); + System.out.println(config.output.dataTypes); + assertEquals(dataTypes, config.output.dataTypes); assertEquals(distance, config.rate.distance); assertEquals(timespan, config.rate.timespan); assertEquals(ValueFormat.POISSON_PROBABILITY, config.rate.valueFormat);