From 7cb880d76b4085f45a0cc9c6be10b9f08db0c04e Mon Sep 17 00:00:00 2001 From: Peter Powers <pmpowers@usgs.gov> Date: Thu, 3 Feb 2022 20:10:45 -0700 Subject: [PATCH] disagg cleaning --- .../earthquake/nshmp/calc/DisaggExport.java | 23 ---- .../earthquake/nshmp/calc/Disaggregation.java | 29 ----- .../earthquake/nshmp/calc/HazardExport.java | 120 ++++++++---------- 3 files changed, 52 insertions(+), 120 deletions(-) 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 dcde9284..c2f2ccd7 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java @@ -2,12 +2,8 @@ package gov.usgs.earthquake.nshmp.calc; import static gov.usgs.earthquake.nshmp.Text.NEWLINE; import static java.lang.Math.exp; -import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.toList; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.AbstractList; import java.util.ArrayList; import java.util.Comparator; @@ -54,9 +50,6 @@ final class DisaggExport { final SummaryElements summary; final List<JsonContributor> sources; - private static final String DISAGG_DATA = "data.csv"; - private static final String DISAGG_SUMMARY = "summary.txt"; - /* * All component DisaggDatasets require data from the final total * DisaggDataset to correctly calculate contributions and represent summary @@ -82,22 +75,6 @@ final class DisaggExport { sources = jsonFlag ? createJsonContributorList(ddTotal, dd, dc.contributorLimit) : null; } - void toFile(Path dir, String site) throws IOException { - Path siteDir = dir.resolve(site); - Files.createDirectories(siteDir); - Path dataPath = siteDir.resolve(DISAGG_DATA); - Files.write( - dataPath, - data.toString().getBytes(UTF_8)); - Path summaryPath = siteDir.resolve(DISAGG_SUMMARY); - String summaryString = summaryStringBuilder() - .append(DATASET_SEPARATOR) - .toString(); - Files.write( - summaryPath, - summaryString.getBytes(UTF_8)); - } - @Override public String toString() { StringBuilder sb = summaryStringBuilder(); 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 9fc84d9c..47a720f4 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java @@ -5,7 +5,6 @@ import static gov.usgs.earthquake.nshmp.calc.DisaggDataset.SOURCE_CONSOLIDATOR; import static gov.usgs.earthquake.nshmp.calc.DisaggDataset.SOURCE_SET_CONSOLIDATOR; import java.util.ArrayList; -import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -92,34 +91,6 @@ public final class Disaggregation { this.site = site; } - /** - * Disaggregate probabilistic seismic {@code hazard} at the intensity measure - * level corresponding to the supplied {@code returnPeriod} (in years). - * Disaggregation is performed for all IMTs specified in the {@code hazard} - * object. The calculation configuration file accompanying the {@code hazard} - * object is used to configure the disaggregations. - * - * @param hazard to disaggregate - * @param returnPeriod at which to disaggregate (in years) - * @param exec executor service to use for disaggregation - * @return a {@code Disaggregation} object - */ - public static Disaggregation atReturnPeriod( - Hazard hazard, - double returnPeriod, - Executor exec) { - - double rate = 1.0 / returnPeriod; - Map<Imt, Double> imtImls = new EnumMap<>(Imt.class); - for (Entry<Imt, XySequence> entry : hazard.totalCurves.entrySet()) { - double iml = IML_INTERPOLATER.findX(entry.getValue(), rate); - // remove exp below by transforming disagg-epsilon to log earlier - imtImls.put(entry.getKey(), Math.exp(iml)); - } - - return atImls(hazard, imtImls, exec); - } - /** * Disaggregate probabilistic seismic {@code hazard} at a unique intensity * measure level for each IMT. Assumes hazard contains results for each IMT diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java index fc3be340..a782dbd5 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java @@ -20,7 +20,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.logging.Logger; @@ -33,7 +32,6 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import gov.usgs.earthquake.nshmp.Maths; -import gov.usgs.earthquake.nshmp.calc.Disaggregation.ImtDisagg; import gov.usgs.earthquake.nshmp.data.MutableXySequence; import gov.usgs.earthquake.nshmp.data.XySequence; import gov.usgs.earthquake.nshmp.geo.Location; @@ -62,7 +60,6 @@ public final class HazardExport { * model.gmms() methods will only reflect a single model. */ - private static final String DISAGG_DIR = "disagg"; private static final String GMM_DIR = "gmm"; static final String TYPE_DIR = "source"; private static final String CURVE_FILE_ASCII = "curves.csv"; @@ -195,21 +192,8 @@ public final class HazardExport { * @param hazard to write */ public void write(Hazard hazard) throws IOException { - write(hazard, Optional.empty()); - } - - /** - * Write a hazard and disagg result. - * - * @param hazard to write - * @param disagg to write (optional) - */ - public void write(Hazard hazard, Optional<Disaggregation> disagg) throws IOException { checkState(!used, "This result handler is expired"); writeHazard(hazard); - if (disagg.isPresent()) { - writeDisagg(disagg.orElseThrow()); - } resultCount++; if (resultCount % 10 == 0) { batchCount++; @@ -322,50 +306,57 @@ public final class HazardExport { /* * Write the current list of {@code Disaggregation}s to file. */ - private void writeDisagg(Disaggregation disagg) throws IOException { - - /* - * Writing of Hazard results will have already created necessary Imt, Gmm, - * and SourceType directories. - */ - String name = namedSites ? disagg.site.name() : lonLatStr(disagg.site.location()); - for (Entry<Imt, ImtDisagg> imtEntry : disagg.disaggs.entrySet()) { - - /* Write total dataset. */ - ImtDisagg imtDisagg = imtEntry.getValue(); - DisaggDataset ddTotal = imtDisagg.totalDataset; - DisaggConfig dc = imtDisagg.config; - DisaggExport exporter = new DisaggExport(ddTotal, ddTotal, dc, "Total", false, true, true); - Path imtDir = dir.resolve(imtEntry.getKey().name()); - Path totalDir = imtDir.resolve(DISAGG_DIR); - Files.createDirectories(totalDir); - exporter.toFile(totalDir, name); - - if (exportSource) { - for (Entry<SourceType, DisaggDataset> typeEntry : imtDisagg.typeDatasets.entrySet()) { - SourceType type = typeEntry.getKey(); - Path typeDir = imtDir.resolve(TYPE_DIR) - .resolve(type.name()) - .resolve(DISAGG_DIR); - DisaggDataset ddType = typeEntry.getValue(); - exporter = new DisaggExport(ddTotal, ddType, dc, type.toString(), false, true, true); - exporter.toFile(typeDir, name); - } - } - - if (exportGmm) { - for (Entry<Gmm, DisaggDataset> gmmEntry : imtDisagg.gmmDatasets.entrySet()) { - Gmm gmm = gmmEntry.getKey(); - Path gmmDir = imtDir.resolve(GMM_DIR) - .resolve(gmm.name()) - .resolve(DISAGG_DIR); - DisaggDataset ddGmm = gmmEntry.getValue(); - exporter = new DisaggExport(ddTotal, ddGmm, dc, gmm.toString(), false, true, true); - exporter.toFile(gmmDir, name); - } - } - } - } + // @Deprecated + // private void writeDisagg(Disaggregation disagg) throws IOException { + // + // /* + // * Writing of Hazard results will have already created necessary Imt, Gmm, + // * and SourceType directories. + // */ + // String name = namedSites ? disagg.site.name() : + // lonLatStr(disagg.site.location()); + // for (Entry<Imt, ImtDisagg> imtEntry : disagg.disaggs.entrySet()) { + // + // /* Write total dataset. */ + // ImtDisagg imtDisagg = imtEntry.getValue(); + // DisaggDataset ddTotal = imtDisagg.totalDataset; + // DisaggConfig dc = imtDisagg.config; + // DisaggExport exporter = new DisaggExport(ddTotal, ddTotal, dc, "Total", + // false, true, true); + // Path imtDir = dir.resolve(imtEntry.getKey().name()); + // Path totalDir = imtDir.resolve(DISAGG_DIR); + // Files.createDirectories(totalDir); + // exporter.toFile(totalDir, name); + // + // if (exportSource) { + // for (Entry<SourceType, DisaggDataset> typeEntry : + // imtDisagg.typeDatasets.entrySet()) { + // SourceType type = typeEntry.getKey(); + // Path typeDir = imtDir.resolve(TYPE_DIR) + // .resolve(type.name()) + // .resolve(DISAGG_DIR); + // DisaggDataset ddType = typeEntry.getValue(); + // exporter = new DisaggExport(ddTotal, ddType, dc, type.toString(), false, + // true, true); + // exporter.toFile(typeDir, name); + // } + // } + // + // if (exportGmm) { + // for (Entry<Gmm, DisaggDataset> gmmEntry : imtDisagg.gmmDatasets.entrySet()) + // { + // Gmm gmm = gmmEntry.getKey(); + // Path gmmDir = imtDir.resolve(GMM_DIR) + // .resolve(gmm.name()) + // .resolve(DISAGG_DIR); + // DisaggDataset ddGmm = gmmEntry.getValue(); + // exporter = new DisaggExport(ddTotal, ddGmm, dc, gmm.toString(), false, + // true, true); + // exporter.toFile(gmmDir, name); + // } + // } + // } + // } private static String valueStr( XySequence curve, @@ -388,14 +379,6 @@ public final class HazardExport { .collect(joining(",")); } - private static String lonLatStr(Location loc) { - return new StringBuilder() - .append(loc.longitude) - .append("_") - .append(loc.latitude) - .toString(); - } - /* No options will write a new file, supply APPEND to append. */ static void writeLine(Path path, String line, OpenOption... options) throws IOException { @@ -490,6 +473,7 @@ public final class HazardExport { } // Consider Stream (above) + @Deprecated private static Set<Gmm> gmmSet(Iterable<RuptureSet<? extends Source>> ruptureSets) { return Sets.immutableEnumSet( FluentIterable.from(ruptureSets).transformAndConcat( -- GitLab