Skip to content
Snippets Groups Projects
Commit 3923bee9 authored by Powers, Peter M.'s avatar Powers, Peter M.
Browse files

Merge branch 'haz-export-vs30-140' into 'main'

Hazard export updates

Closes #140

See merge request !250
parents cd82480a 5b669468
No related branches found
No related tags found
1 merge request!250Hazard export updates
Pipeline #115848 passed
......@@ -7,6 +7,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.OptionalDouble;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;
......@@ -63,7 +64,7 @@ public final class EqRateExport {
boolean rates = config.rate.valueFormat == ValueFormat.ANNUAL_RATE;
this.log = log;
this.dir = HazardExport.createOutputDir(config.output.directory);
this.dir = HazardExport.createOutputDir(config.output.directory, OptionalDouble.empty());
this.file = rates ? RATE_FILE : PROB_FILE;
this.valueFormat = rates ? RATE_FORMAT : PROB_FORMAT;
this.model = model;
......
......@@ -20,6 +20,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.OptionalDouble;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.IntStream;
......@@ -80,9 +81,10 @@ public final class HazardExport {
private HazardExport(
HazardModel model,
CalcConfig config,
List<Site> sites) throws IOException {
List<Site> sites,
OptionalDouble vs30) throws IOException {
this.dir = createOutputDir(config.output.directory);
this.dir = createOutputDir(config.output.directory, vs30);
this.model = model;
this.config = config;
this.exportGmm = config.output.dataTypes.contains(DataType.GMM);
......@@ -105,14 +107,16 @@ 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 log shared logging instance from calling class
*/
public static HazardExport create(
HazardModel model,
CalcConfig config,
List<Site> sites) throws IOException {
List<Site> sites,
OptionalDouble vs30) throws IOException {
return new HazardExport(model, config, sites);
return new HazardExport(model, config, sites, vs30);
}
/* Initialize output directories. */
......@@ -163,15 +167,19 @@ public final class HazardExport {
}
/* Avoid clobbering exsting result directories via incrementing. */
static Path createOutputDir(Path dir) throws IOException {
static Path createOutputDir(Path dir, OptionalDouble vs30) throws IOException {
int i = 1;
Path incrementedDir = dir;
while (Files.exists(incrementedDir)) {
incrementedDir = incrementedDir.resolveSibling(dir.getFileName() + "-" + i);
Path outDir = dir;
while (Files.exists(outDir)) {
outDir = outDir.resolveSibling(dir.getFileName() + "-" + i);
i++;
}
Files.createDirectories(incrementedDir);
return incrementedDir;
if (vs30.isPresent()) {
String vs30dir = "vs30-" + ((int) vs30.getAsDouble());
outDir = outDir.resolve(vs30dir);
}
Files.createDirectories(outDir);
return outDir;
}
/**
......
......@@ -214,7 +214,7 @@ class LoaderTests {
List<Site> sites) throws IOException {
ExecutorService exec = initExecutor(config.performance.threadCount);
HazardExport handler = HazardExport.create(model, config, sites);
HazardExport handler = HazardExport.create(model, config, sites, OptionalDouble.empty());
for (Site site : sites) {
Hazard hazard = HazardCalcs.hazard(model, config, site, exec);
handler.write(hazard);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment