Skip to content

Commit

Permalink
Add test for bug that missing variable in one grib partition caused N…
Browse files Browse the repository at this point in the history
…aNs for all times after (#473)
  • Loading branch information
tdrwenski committed Mar 7, 2024
1 parent ae75b12 commit f87d839
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import ucar.httpservices.HTTPMethod;
import ucar.httpservices.HTTPSession;
import ucar.ma2.Array;
import ucar.ma2.InvalidRangeException;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFiles;
import ucar.nc2.Variable;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.NetcdfDatasets;
import ucar.nc2.dt.grid.GeoGrid;
Expand Down Expand Up @@ -172,4 +174,29 @@ private void checkFileType(String acceptParameter, int expectedResponseCode, Str
}
}
}

@Test
public void shouldNotReturnNaNsForBestGribCollectionVariable() throws IOException, InvalidRangeException {
// precip variable not present in 2024-03-01T19:00:00Z partition
final String varName = "Total_precipitation_Forecast_altitude_above_msl_1_Hour_Accumulation";
final String timeBeforeMissing = "2024-03-01T18:00:00Z";
final String timeAfterMissing = "2024-03-01T21:00:00Z";

final String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/grib/NCEP/RTMA/CONUS_2p5km/Best" + "?var="
+ varName + "&north=40&west=-70&east=-69&south=39&horizStride=1&accept=netcdf3" + "&time_start="
+ timeBeforeMissing + "&time_end=" + timeAfterMissing);

final byte[] content = TestOnLocalServer.getContent(endpoint, HttpServletResponse.SC_OK, ContentType.netcdf);

try (NetcdfFile ncf = NetcdfFiles.openInMemory("test_data.nc", content)) {
final Variable var = ncf.findVariable(varName);
assertThat((Object) var).isNotNull();
// first element for all times
final Array array = var.read(":,0:0,0:0,0:0");
assertThat(array.getSize()).isEqualTo(3);
assertThat(array.getFloat(0)).isNotNaN();
assertThat(array.getFloat(1)).isNotNaN();
assertThat(array.getFloat(2)).isNotNaN();
}
}
}
15 changes: 15 additions & 0 deletions tds/src/test/content/thredds/catalogGrib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,19 @@
<collection name="gfsConus80_file" spec="${cdmUnitTest}/gribCollections/gfs_conus80/**/.*grib1$" timePartition="file"/>
</featureCollection>

<!-- test large grib collection where precipitation variable is missing in one partition -->
<featureCollection name="Real Time Mesoscale Analysis 2.5 km" featureType="GRIB2" harvest="true"
path="grib/NCEP/RTMA/CONUS_2p5km">
<collection name="RTMA-CONUS_2p5km"
spec="${cdmUnitTest}/gribCollections/rtma/.*grib2$"
dateFormatMark="#RTMA_CONUS_2p5km_#yyyyMMdd_HHmm"
timePartition="file"
olderThan="5 min"/>
<update startup="test" trigger="allow"/>
<gribConfig>
<pdsHash>
<useGenType>true</useGenType>
</pdsHash>
</gribConfig>
</featureCollection>
</catalog>

0 comments on commit f87d839

Please sign in to comment.