Skip to content

Commit

Permalink
[GEOS-7602] Add tests of NetCDF output from rotated pole GRIB2 data
Browse files Browse the repository at this point in the history
  • Loading branch information
bencaradocdavies committed Jun 25, 2016
1 parent c438a9a commit 73509f5
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/extension/netcdf-out/pom.xml
Expand Up @@ -85,7 +85,13 @@
<dependency>
<groupId>org.geoserver.extension</groupId>
<artifactId>gs-netcdf</artifactId>
<version>${project.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.geoserver.extension</groupId>
<artifactId>gs-grib</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
Expand Down
Expand Up @@ -38,10 +38,16 @@
*/
public class WCSNetCDFTest extends WCSNetCDFBaseTest {

public static final double DELTA = 1e-6;

public static QName POLYPHEMUS = new QName(CiteTestData.WCS_URI, "polyphemus", CiteTestData.WCS_PREFIX);
public static QName NO2 = new QName(CiteTestData.WCS_URI, "NO2", CiteTestData.WCS_PREFIX);
public static QName TEMPERATURE_SURFACE = new QName(CiteTestData.WCS_URI, "Temperature_surface",
CiteTestData.WCS_PREFIX);
public static QName TEMPERATURE_SURFACE_NETCDF = new QName(CiteTestData.WCS_URI,
"Temperature_surface_NetCDF", CiteTestData.WCS_PREFIX);
public static QName TEMPERATURE_SURFACE_GRIB = new QName(CiteTestData.WCS_URI,
"Temperature_surface", CiteTestData.WCS_PREFIX);
public static QName SNOW_DEPTH_GRIB = new QName(CiteTestData.WCS_URI,
"Snow_depth_water_equivalent_surface", CiteTestData.WCS_PREFIX);

/**
* Only setup coverages
Expand All @@ -65,7 +71,11 @@ protected void onSetUp(SystemTestData testData) throws Exception {
testData.addRasterLayer(POLYPHEMUS, "pol.zip", null, null, this.getClass(), getCatalog());
setupRasterDimension(getLayerId(NO2), ResourceInfo.TIME, DimensionPresentation.LIST, null);
setupRasterDimension(getLayerId(NO2), ResourceInfo.ELEVATION, DimensionPresentation.LIST, null);
testData.addRasterLayer(TEMPERATURE_SURFACE, "rotated-pole.nc", null, null, this.getClass(),
testData.addRasterLayer(TEMPERATURE_SURFACE_NETCDF, "rotated-pole.nc", null, null,
this.getClass(), getCatalog());
testData.addRasterLayer(TEMPERATURE_SURFACE_GRIB, "rap-native.grib2", null, null,
this.getClass(), getCatalog());
testData.addRasterLayer(SNOW_DEPTH_GRIB, "cosmo-eu.grib2", null, null, this.getClass(),
getCatalog());
}

Expand Down Expand Up @@ -146,18 +156,18 @@ public void testInputMemoryExceeded() throws Exception {
}

/**
* Test NetCDF output for a rotated pole projection.
* Test NetCDF output from a NetCDF file with a rotated pole projection.
*/
@Test
public void testRotatedPole() throws Exception {
public void testNetcdfRotatedPole() throws Exception {
MockHttpServletResponse response = getAsServletResponse(
"ows?request=GetCoverage&service=WCS&version=2.0.1"
+ "&coverageid=wcs__Temperature_surface&format=application/x-netcdf");
+ "&coverageid=wcs__Temperature_surface_NetCDF&format=application/x-netcdf");
assertEquals(200, response.getStatus());
assertEquals("application/x-netcdf", response.getContentType());
byte[] responseBytes = getBinary(response);
File file = File.createTempFile("netcdf-rotated-pole-", "-wcs__Temperature_surface.nc",
new File("./target"));
File file = File.createTempFile("netcdf-rotated-pole-",
"-wcs__Temperature_surface_NetCDF.nc", new File("./target"));
FileUtils.writeByteArrayToFile(file, responseBytes);
try (NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath())) {
assertNotNull(dataset);
Expand All @@ -177,7 +187,7 @@ public void testRotatedPole() throws Exception {
assertEquals("grid_longitude", rlonVar.findAttribute("standard_name").getStringValue());
assertEquals("degrees", rlonVar.findAttribute("units").getStringValue());
assertArrayEquals(new float[] { -30, -20, -10, 0, 10, 20, 30 },
(float[]) rlonVar.read().copyTo1DJavaArray(), 0.0f);
(float[]) rlonVar.read().copyTo1DJavaArray(), (float) DELTA);
Variable rlatVar = dataset.findVariable("rlat");
assertNotNull(rlatVar);
assertEquals(1, rlatVar.getDimensions().size());
Expand All @@ -186,17 +196,18 @@ public void testRotatedPole() throws Exception {
assertEquals("grid_latitude", rlatVar.findAttribute("standard_name").getStringValue());
assertEquals("degrees", rlatVar.findAttribute("units").getStringValue());
assertArrayEquals(new float[] { -20, -10, 0, 10, 20 },
(float[]) rlatVar.read().copyTo1DJavaArray(), 0.0f);
(float[]) rlatVar.read().copyTo1DJavaArray(), (float) DELTA);
// check projection variable
Variable projVar = dataset.findVariable("rotated_latitude_longitude");
assertNotNull(projVar);
assertEquals("rotated_latitude_longitude",
projVar.findAttribute("grid_mapping_name").getStringValue());
assertEquals(74.0,
projVar.findAttribute("grid_north_pole_longitude").getNumericValue());
assertEquals(36.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue());
Variable tempVar = dataset.findVariable("Temperature_surface");
// check Temperature_surface variable
assertEquals(74.0, projVar.findAttribute("grid_north_pole_longitude").getNumericValue()
.doubleValue(), DELTA);
assertEquals(36.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue()
.doubleValue(), DELTA);
// check data variable
Variable tempVar = dataset.findVariable("Temperature_surface_NetCDF");
assertNotNull(tempVar);
assertEquals("rotated_latitude_longitude",
tempVar.findAttribute("grid_mapping").getStringValue());
Expand All @@ -208,7 +219,145 @@ public void testRotatedPole() throws Exception {
new float[] { 300, 299, 298, 297, 296, 295, 294, 299, 300, 299, 298, 297, 296,
295, 298, 299, 300, 299, 298, 297, 296, 297, 298, 299, 300, 299, 298,
297, 296, 297, 298, 299, 300, 299, 298 },
(float[]) tempVar.read().copyTo1DJavaArray(), 0.0f);
(float[]) tempVar.read().copyTo1DJavaArray(), (float) DELTA);
} finally {
FileUtils.deleteQuietly(file);
}
}

/**
* Test NetCDF output from an RAP native GRIB2 file with a GDS template 32769 rotated pole projection.
*/
@Test
public void testRapNativeGribRotatedPole() throws Exception {
MockHttpServletResponse response = getAsServletResponse(
"ows?request=GetCoverage&service=WCS&version=2.0.1"
+ "&coverageid=wcs__Temperature_surface&format=application/x-netcdf");
assertEquals(200, response.getStatus());
assertEquals("application/x-netcdf", response.getContentType());
byte[] responseBytes = getBinary(response);
File file = File.createTempFile("rap-native-grib-rotated-pole-",
"-wcs__Temperature_surface.nc", new File("./target"));
FileUtils.writeByteArrayToFile(file, responseBytes);
try (NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath())) {
assertNotNull(dataset);
// check dimensions
Dimension rlonDim = dataset.findDimension("rlon");
assertNotNull(rlonDim);
assertEquals(7, rlonDim.getLength());
Dimension rlatDim = dataset.findDimension("rlat");
assertNotNull(rlatDim);
assertEquals(5, rlatDim.getLength());
// check coordinate variables
Variable rlonVar = dataset.findVariable("rlon");
assertNotNull(rlonVar);
assertEquals(1, rlonVar.getDimensions().size());
assertEquals(rlonDim, rlonVar.getDimensions().get(0));
assertEquals("grid_longitude", rlonVar.findAttribute("long_name").getStringValue());
assertEquals("grid_longitude", rlonVar.findAttribute("standard_name").getStringValue());
assertEquals("degrees", rlonVar.findAttribute("units").getStringValue());
assertArrayEquals(new float[] { -30, -20, -10, 0, 10, 20, 30 },
(float[]) rlonVar.read().copyTo1DJavaArray(), (float) DELTA);
Variable rlatVar = dataset.findVariable("rlat");
assertNotNull(rlatVar);
assertEquals(1, rlatVar.getDimensions().size());
assertEquals(rlatDim, rlatVar.getDimensions().get(0));
assertEquals("grid_latitude", rlatVar.findAttribute("long_name").getStringValue());
assertEquals("grid_latitude", rlatVar.findAttribute("standard_name").getStringValue());
assertEquals("degrees", rlatVar.findAttribute("units").getStringValue());
assertArrayEquals(new float[] { -20, -10, 0, 10, 20 },
(float[]) rlatVar.read().copyTo1DJavaArray(), (float) DELTA);
// check projection variable
Variable projVar = dataset.findVariable("rotated_latitude_longitude");
assertNotNull(projVar);
assertEquals("rotated_latitude_longitude",
projVar.findAttribute("grid_mapping_name").getStringValue());
assertEquals(74.0, projVar.findAttribute("grid_north_pole_longitude").getNumericValue()
.doubleValue(), DELTA);
assertEquals(36.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue()
.doubleValue(), DELTA);
// check data variable
Variable dataVar = dataset.findVariable("Temperature_surface");
assertNotNull(dataVar);
assertEquals("rotated_latitude_longitude",
dataVar.findAttribute("grid_mapping").getStringValue());
assertEquals("K", dataVar.findAttribute("units").getStringValue());
assertEquals(2, dataVar.getDimensions().size());
assertEquals(rlatDim, dataVar.getDimensions().get(0));
assertEquals(rlonDim, dataVar.getDimensions().get(1));
assertArrayEquals(
new float[] { 300, 299, 298, 297, 296, 295, 294, 299, 300, 299, 298, 297, 296,
295, 298, 299, 300, 299, 298, 297, 296, 297, 298, 299, 300, 299, 298,
297, 296, 297, 298, 299, 300, 299, 298 },
(float[]) dataVar.read().copyTo1DJavaArray(), (float) DELTA);
} finally {
FileUtils.deleteQuietly(file);
}
}

/**
* Test NetCDF output from a COSMO EU GRIB2 file with a GDS template 1 rotated pole projection.
*/
@Test
public void testCosmoEuGribRotatedPole() throws Exception {
MockHttpServletResponse response = getAsServletResponse(
"ows?request=GetCoverage&service=WCS&version=2.0.1"
+ "&coverageid=wcs__Snow_depth_water_equivalent_surface&format=application/x-netcdf");
assertEquals(200, response.getStatus());
assertEquals("application/x-netcdf", response.getContentType());
byte[] responseBytes = getBinary(response);
File file = File.createTempFile("cosmo-eu-grib-rotated-pole-",
"-wcs__Snow_depth_water_equivalent_surface.nc", new File("./target"));
FileUtils.writeByteArrayToFile(file, responseBytes);
try (NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath())) {
assertNotNull(dataset);
// check dimensions
Dimension rlonDim = dataset.findDimension("rlon");
assertNotNull(rlonDim);
assertEquals(5, rlonDim.getLength());
Dimension rlatDim = dataset.findDimension("rlat");
assertNotNull(rlatDim);
assertEquals(5, rlatDim.getLength());
// check coordinate variables
Variable rlonVar = dataset.findVariable("rlon");
assertNotNull(rlonVar);
assertEquals(1, rlonVar.getDimensions().size());
assertEquals(rlonDim, rlonVar.getDimensions().get(0));
assertEquals("grid_longitude", rlonVar.findAttribute("long_name").getStringValue());
assertEquals("grid_longitude", rlonVar.findAttribute("standard_name").getStringValue());
assertEquals("degrees", rlonVar.findAttribute("units").getStringValue());
assertArrayEquals(new float[] { -18, -8, 2, 12, 22 },
(float[]) rlonVar.read().copyTo1DJavaArray(), (float) DELTA);
Variable rlatVar = dataset.findVariable("rlat");
assertNotNull(rlatVar);
assertEquals(1, rlatVar.getDimensions().size());
assertEquals(rlatDim, rlatVar.getDimensions().get(0));
assertEquals("grid_latitude", rlatVar.findAttribute("long_name").getStringValue());
assertEquals("grid_latitude", rlatVar.findAttribute("standard_name").getStringValue());
assertEquals("degrees", rlatVar.findAttribute("units").getStringValue());
assertArrayEquals(new float[] { -20, -10, 0, 10, 20 },
(float[]) rlatVar.read().copyTo1DJavaArray(), (float) DELTA);
// check projection variable
Variable projVar = dataset.findVariable("rotated_latitude_longitude");
assertNotNull(projVar);
assertEquals("rotated_latitude_longitude",
projVar.findAttribute("grid_mapping_name").getStringValue());
assertEquals(-170.0, projVar.findAttribute("grid_north_pole_longitude")
.getNumericValue().doubleValue(), DELTA);
assertEquals(40.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue()
.doubleValue(), DELTA);
// check data variable
Variable dataVar = dataset.findVariable("Snow_depth_water_equivalent_surface");
assertNotNull(dataVar);
assertEquals("rotated_latitude_longitude",
dataVar.findAttribute("grid_mapping").getStringValue());
assertEquals(2, dataVar.getDimensions().size());
assertEquals(rlatDim, dataVar.getDimensions().get(0));
assertEquals(rlonDim, dataVar.getDimensions().get(1));
assertArrayEquals(
new float[] { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124 },
(float[]) dataVar.read().copyTo1DJavaArray(), (float) DELTA);
} finally {
FileUtils.deleteQuietly(file);
}
Expand Down
Binary file not shown.
Expand Up @@ -2,3 +2,4 @@
971802=PROJCS["lambert_conformal_conic_2SP", GEOGCS["unknown", DATUM["unknown", SPHEROID["unknown", 6377397.0, 299.15550239234693]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]], PROJECTION["Lambert_Conformal_Conic_2SP"], PARAMETER["central_meridian", 13.333333015441895], PARAMETER["latitude_of_origin", 46.0], PARAMETER["standard_parallel_1", 46.0], PARAMETER["standard_parallel_2", 49], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","971802"]]
971805=PROJCS["albers_conical_equal_area", GEOGCS["unknown", DATUM["unknown", SPHEROID["unknown", 6378137.0, 298.2572221010042]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]], PROJECTION["Albers_Conic_Equal_Area"], PARAMETER["central_meridian", -126.0], PARAMETER["latitude_of_origin", 45.0], PARAMETER["standard_parallel_1", 50.0], PARAMETER["false_easting", 1000000.0], PARAMETER["false_northing", 0.0], PARAMETER["standard_parallel_2", 58.5], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","971805"]]
971806=PROJCS["rotated_latitude_longitude", GEOGCS["unknown", DATUM["unknown", SPHEROID["unknown", 6371229.0, 0.0]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]], PROJECTION["Rotated_Pole"], PARAMETER["central_meridian", -106.0], PARAMETER["latitude_of_origin", 54.0], PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","971806"]]
971807=PROJCS["rotated_latitude_longitude", GEOGCS["unknown", DATUM["unknown", SPHEROID["unknown", 6371229.0, 0.0]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]], PROJECTION["Rotated_Pole"], PARAMETER["central_meridian", 10.0], PARAMETER["latitude_of_origin", 50.0], PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","971807"]]
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions src/pom.xml
Expand Up @@ -1258,6 +1258,7 @@
<include>**/*.zip</include>
<include>**/*.json</include>
<include>**/*.nc</include>
<include>**/*.grib2</include>
</includes>
<excludes>
<exclude>**/doc-files/**</exclude>
Expand Down

0 comments on commit 73509f5

Please sign in to comment.