Skip to content

Commit

Permalink
Handle condition that interval is null
Browse files Browse the repository at this point in the history
Add handling condition for condition that VortexGrid::interval is null in DssDataWriter.

If interval is null or zero set data type to INST-VAL.

Add unit test for TIF to DSS conversion.
  • Loading branch information
Tom Brauer committed Jun 27, 2024
1 parent 44657ed commit 8dec8e5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ public void write() {
options.put("partF", grid.description());
}

if (!cPart.equals("PRECIPITATION")
&& options.getOrDefault("dataType", "").isEmpty()
&& !grid.interval().equals(Duration.ZERO)) {
options.put("dataType", "PER-AVER");
if (!cPart.equals("PRECIPITATION") && options.get("dataType") == null) {
if (!Duration.ZERO.equals(grid.interval()))
options.put("dataType", "PER-AVER");

if (grid.interval() == null || Duration.ZERO.equals(grid.interval()))
options.put("dataType", "INST-VAL");
}

if (cPart.equals("PRECIPITATION") && !grid.interval().isZero()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,62 @@ void irregularSpatialGrid() {
Logger.getAnonymousLogger().log(Level.SEVERE, e, e::getMessage);
}
}

@Test
void tifToDss() {
URL inUrl = Objects.requireNonNull(getClass().getResource("/tif_to_dss/hms_cn_grid.tif"));

String inFile = new File(inUrl.getFile()).toString();

List<String> inFiles = new ArrayList<>();
inFiles.add(inFile);

Path pathToDestination = Paths.get(System.getProperty("java.io.tmpdir"), "hms_cn_grid.dss");

try {
HecDataManager.close(pathToDestination.toString(), false);
Files.deleteIfExists(pathToDestination);
} catch (IOException e) {
Logger.getAnonymousLogger().log(Level.SEVERE, e, e::getMessage);
}

List<String> variables = new ArrayList<>();
variables.add("hms_cn_grid");

BatchImporter importer = BatchImporter.builder()
.inFiles(inFiles)
.variables(variables)
.destination(pathToDestination.toString())
.build();

importer.process();

int[] status = new int[1];
GriddedData griddedData = new GriddedData();
griddedData.setDSSFileName(pathToDestination.toString());
griddedData.setPathname("///////");
GridData gridData = new GridData();
griddedData.retrieveGriddedData(true, gridData, status);
if (status[0] < 0) {
Assertions.fail();
}

GridInfo gridInfo = gridData.getGridInfo();
Assertions.assertEquals("", gridInfo.getStartTime());
Assertions.assertEquals("", gridInfo.getEndTime());
Assertions.assertEquals("UNSPECIF", gridInfo.getDataUnits());
Assertions.assertEquals(DssDataType.INST_VAL.value(), gridInfo.getDataType());
Assertions.assertEquals(98, gridInfo.getMaxValue());
Assertions.assertEquals(21, gridInfo.getMinValue());
Assertions.assertEquals(70.09265, gridInfo.getMeanValue(), 1E-5);

griddedData.done();

try {
HecDataManager.close(pathToDestination.toString(), false);
Files.deleteIfExists(pathToDestination);
} catch (IOException e) {
Logger.getAnonymousLogger().log(Level.SEVERE, e, e::getMessage);
}
}
}
Binary file not shown.

0 comments on commit 8dec8e5

Please sign in to comment.