Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for grib NaN issue #473

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading