From 3b98411e9bca259c600325abccc1f7b7595739da Mon Sep 17 00:00:00 2001 From: Peter Powers <pmpowers@usgs.gov> Date: Fri, 18 Feb 2022 08:38:59 -0700 Subject: [PATCH] hazard export takes path instead of optional vs30 --- .../earthquake/nshmp/calc/HazardExport.java | 20 ++++++++++--------- .../earthquake/nshmp/model/LoaderTests.java | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) 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 451012ec..c1f29cee 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java @@ -65,7 +65,7 @@ public final class HazardExport { private static final String CURVE_FILE_ASCII_TRUNCATED = "curves-truncated.csv"; private static final String VALUE_FMT = "%.8e"; - private final Path dir; + private final Path out; private final HazardModel model; private final CalcConfig config; private final boolean exportGmm; @@ -82,9 +82,9 @@ public final class HazardExport { HazardModel model, CalcConfig config, List<Site> sites, - OptionalDouble vs30) throws IOException { + Path out) throws IOException { - this.dir = createOutputDir(config.output.directory, vs30); + this.out = out; this.model = model; this.config = config; this.exportGmm = config.output.dataTypes.contains(DataType.GMM); @@ -107,16 +107,17 @@ public final class HazardExport { * @param model being run * @param config that specifies output options and formats * @param sites reference to the sites to be processed (not retained) - * @param vs30 optional vs30 value used when running multiple site classes + * @param out results directory; this may have been been modified from + * {@code config.output.directory} by calling program * @param log shared logging instance from calling class */ public static HazardExport create( HazardModel model, CalcConfig config, List<Site> sites, - OptionalDouble vs30) throws IOException { + Path out) throws IOException { - return new HazardExport(model, config, sites, vs30); + return new HazardExport(model, config, sites, out); } /* Initialize output directories. */ @@ -124,7 +125,7 @@ public final class HazardExport { for (Imt imt : config.hazard.imts) { - Path imtDir = dir.resolve(imt.name()); + Path imtDir = out.resolve(imt.name()); Files.createDirectory(imtDir); Path totalFile = imtDir.resolve(CURVE_FILE_ASCII); Path totalFileTruncated = imtDir.resolve(CURVE_FILE_ASCII_TRUNCATED); @@ -176,6 +177,7 @@ public final class HazardExport { } if (vs30.isPresent()) { String vs30dir = "vs30-" + ((int) vs30.getAsDouble()); + outDir = outDir.resolve(vs30dir); } Files.createDirectories(outDir); @@ -212,7 +214,7 @@ public final class HazardExport { * The target output directory established by this handler. */ public Path outputDir() { - return dir; + return out; } /* Write the supplied hazard results to file(s). */ @@ -240,7 +242,7 @@ public final class HazardExport { String emptyLine = locStr + "0.0" + ",0.0".repeat(totalCurve.size() - 1); Imt imt = imtEntry.getKey(); - Path imtDir = dir.resolve(imt.name()); + Path imtDir = out.resolve(imt.name()); String totalLine = locStr + valueStr(totalCurve, valueFormatter); String totalLineTrunc = locStr + truncValueStr(totalCurve, valueFormatter, TRUNCATION_LIMIT); diff --git a/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java b/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java index d7518714..dffe8ea8 100644 --- a/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java +++ b/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java @@ -214,7 +214,7 @@ class LoaderTests { List<Site> sites) throws IOException { ExecutorService exec = initExecutor(config.performance.threadCount); - HazardExport handler = HazardExport.create(model, config, sites, OptionalDouble.empty()); + HazardExport handler = HazardExport.create(model, config, sites, config.output.directory); for (Site site : sites) { Hazard hazard = HazardCalcs.hazard(model, config, site, exec); handler.write(hazard); -- GitLab