@Test @Category(NeedsCdmUnitTest.class) public void testBBSubsetVP() throws Exception { String filename = TestDir.cdmUnitTestDir + "transforms/Eumetsat.VerticalPerspective.grb"; try (GridDataset dataset = GridDataset.open(filename)) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_3-0-8"); // "Pixel_scene_type"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox()); ucar.unidata.geoloc.LatLonRect llbb_subset = new LatLonRect(new LatLonPointImpl(), 20.0, 40.0); logger.debug("subset lat/lon bbox = {}", llbb_subset); GeoGrid grid_section = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; logger.debug("result lat/lon bbox = {}", gcs2.getLatLonBoundingBox()); logger.debug("result bbox = {}", gcs2.getBoundingBox()); ProjectionRect pr = gcs2.getProjection().getDefaultMapArea(); logger.debug("projection mapArea = {}", pr); assert (pr.nearlyEquals(gcs2.getBoundingBox())); } }
@Test @Category(NeedsCdmUnitTest.class) public void testLatLonSubset2() throws Exception { try (GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_onedeg_20100913_0000.grib2")) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_0-3-0_L1"); // "Pressure_Surface"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3 : grid.getRank(); logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox().toString2()); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 20.0); logger.debug("constrain bbox = {}", bbox.toString2()); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; assert grid_section.getRank() == grid.getRank(); logger.debug("resulting bbox = {}", gcs2.getLatLonBoundingBox().toString2()); Array data = grid_section.readDataSlice(0, 0, -1, -1); assert data != null; assert data.getRank() == 2; int[] dataShape = data.getShape(); assert dataShape.length == 2; assert dataShape[0] == 11 : data.getShape()[0]; assert dataShape[1] == 21 : data.getShape()[1]; } }
@Test @Category(NeedsCdmUnitTest.class) public void testMSG() throws Exception { String filename = TestDir.cdmUnitTestDir + "transforms/Eumetsat.VerticalPerspective.grb"; try(GridDataset dataset = GridDataset.open(filename)) { logger.debug("open {}", filename); GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_3-0-8"); // "Pixel_scene_type"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3; // bbox = ll: 16.79S 20.5W+ ur: 14.1N 20.09E LatLonRect bbox = new LatLonRect(new LatLonPointImpl(-16.79, -20.5), new LatLonPointImpl(14.1, 20.9)); ProjectionImpl p = gcs.getProjection(); ProjectionRect prect = p.latLonToProjBB(bbox); // must override default implementation logger.debug("{} -> {}", bbox, prect); ProjectionRect expected = new ProjectionRect( new ProjectionPointImpl(-2129.5688, -1793.0041), 4297.8453, 3308.3885); assert prect.nearlyEquals(expected); LatLonRect bb2 = p.projToLatLonBB(prect); logger.debug("{} -> {}", prect, bb2); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getRank() == 3; int[] shape = data.getShape(); assert shape[0] == 1 : shape[0] + " should be 1"; assert shape[1] == 363 : shape[1] + " should be 363"; assert shape[2] == 479 : shape[2] + " should be 479"; } }
@Test @Category(NeedsCdmUnitTest.class) public void testGrib() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "formats/grib1/AVN.wmo")) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_7-0-2-11_L100"); // "Temperature_isobaric"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 3 : data.getShape()[0]; assert data.getShape()[1] == 3 : data.getShape()[1]; assert data.getShape()[2] == 13 : data.getShape()[2]; assert data.getShape()[3] == 15 : data.getShape()[3]; } }
GridDatatype gridDatatype = gridDataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, variableName); assertNotNull(gridDatatype);