public GridDatatype makeSubset(Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride) throws InvalidRangeException { return subset(t_range, z_range, bbox, z_stride, y_stride, x_stride); }
public GridDatatype makeSubset(Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride) throws InvalidRangeException { return subset(t_range, z_range, bbox, z_stride, y_stride, x_stride); }
public GridDatatype makeSubset(Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride) throws InvalidRangeException { return subset(t_range, z_range, bbox, z_stride, y_stride, x_stride); }
private void testLatLonSubset(GeoGrid grid, LatLonRect bbox, int[] shape) throws Exception { logger.debug("grid bbox = {}", grid.getCoordinateSystem().getLatLonBoundingBox().toString2()); 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() == 2; logger.debug("resulting bbox = {}", gcs2.getLatLonBoundingBox().toString2()); Array data = grid_section.readDataSlice(0, 0, -1, -1); assert data != null; assert data.getRank() == 2; assert data.getShape()[0] == shape[0] : data.getShape()[0]; assert data.getShape()[1] == shape[1] : data.getShape()[1]; }
@Test @Ignore("Does this file exist in a shared location?") public void testBBSubsetVP2() throws Exception { String filename = "C:/Documents and Settings/caron/My Documents/downloads/MSG2-SEVI-MSGCLAI-0000-0000-20070522114500.000000000Z-582760.grb"; try (GridDataset dataset = GridDataset.open(filename)) { GeoGrid grid = dataset.findGridByName("Pixel_scene_type"); assert null != grid; 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 @Ignore("Does this dataset exist on a public server?") public void testFMRCSubset() throws Exception { try (GridDataset dataset = GridDataset.open("dods://localhost:8080/thredds/dodsC/data/cip/fmrcCase1/CIPFMRCCase1_best.ncd")) { GeoGrid grid = dataset.findGridByName("Latitude__90_to_+90"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; Range timeRange = new Range(2, 2); int bestZIndex = 5; GeoGrid subset = grid.subset(timeRange, new Range(bestZIndex, bestZIndex), null, null); Array yxData = subset.readYXData(0, 0); logger.debug(NCdumpW.toString(yxData, "xyData", null)); } }
@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 testBBSubset() throws Exception { try (GridDataset dataset = GridDataset.open( "dods://localhost:8081/thredds/dodsC/cdmUnitTest/ncss/CONUS_80km_nc/GFS_CONUS_80km_20120419_0000.nc")) { GeoGrid grid = dataset.findGridByName("Pressure"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox()); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); 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 testBBSubsetUnits() throws Exception { try (GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "ncml/testBBSubsetUnits.ncml")) { logger.debug("file = {}", dataset.getLocation()); GeoGrid grid = dataset.findGridByName("pr"); assert null != grid; 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(38, -110), new LatLonPointImpl(42, -90)); 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())); CoordinateAxis xaxis = gcs.getXHorizAxis(); CoordinateAxis yaxis = gcs.getYHorizAxis(); logger.debug("(nx,ny)= {}, {}", xaxis.getSize(), yaxis.getSize()); } }
@Test @Category(NeedsExternalResource.class) public void testScaleOffset() throws Exception { try (GridDataset dataset = GridDataset.open("http://esrl.noaa.gov/psd/thredds/dodsC/Datasets/noaa.oisst.v2/sst.wkmean.1990-present.nc")) { GeoGrid grid = dataset.findGridByName("sst"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {} ({})", gcs.getBoundingBox(), gcs.getLatLonBoundingBox()); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); GeoGrid grid2 = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid2.getCoordinateSystem(); assert null != gcs2; logger.debug("subset bbox = {} ({})", gcs2.getBoundingBox(), gcs2.getLatLonBoundingBox()); logger.debug("original grid var = {}", grid.getVariable()); logger.debug("subset grid var = {}", grid2.getVariable()); Array data = grid.readDataSlice(0, 0, 159, 0); Array data2 = grid2.readDataSlice(0, 0, 0, 0); logger.debug(NCdumpW.toString(data, "org", null)); logger.debug(NCdumpW.toString(data2, "subset", null)); ucar.unidata.util.test.CompareNetcdf.compareData(data, data2); } }
@Test @Category(NeedsCdmUnitTest.class) public void testBBSubset2() throws Exception { try (GridDataset dataset = GridDataset.open(TestOnLocalServer.withDodsPath( "dodsC/cdmUnitTest/ncss/CONUS_80km_nc/GFS_CONUS_80km_20120419_0000.nc"))) { GeoGrid grid = dataset.findGridByName("Pressure"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox()); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(new LatLonPointImpl(-15, -140), new LatLonPointImpl(55, 30)); 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())); } }
LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); GeoGrid grid2 = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid2.getCoordinateSystem(); assert null != gcs2;
@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 testVerticalAxis() throws Exception { String uri = TestDir.cdmUnitTestDir + "ncml/nc/cg/CG2006158_120000h_usfc.nc"; String varName = "CGusfc"; try (GridDataset dataset = GridDataset.open(uri)) { GeoGrid grid = dataset.findGridByName(varName); assert null != grid; GridCoordSystem gcsi = grid.getCoordinateSystem(); assert null != gcsi; assert (gcsi.getVerticalAxis() != null); GridCoordSys gcs = (GridCoordSys) grid.getCoordinateSystem(); assert null != gcs; assert gcs.hasVerticalAxis(); // returns true. // subset geogrid GeoGrid subg = grid.subset(null, null, null, 1, 1, 1); assert null != subg; GridCoordSystem gcsi2 = subg.getCoordinateSystem(); assert null != gcsi2; assert (gcsi2.getVerticalAxis() != null); GridCoordSys gcs2 = (GridCoordSys) subg.getCoordinateSystem(); assert null != gcs2; assert !gcs2.hasVerticalAxis(); // fails } }
assert grid.getRank() == 4; GeoGrid grid_section = grid.subset(null, null, null, 5, 5, 5); assert data.getShape()[3] == 43 : data.getShape()[3]; grid_section = grid.subset(null, new Range(0, 0), null, 0, 2, 2); data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 1 : data.getShape()[0];
public void testSubset() throws Exception { ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmLocalTestDataDir+"rankTest.nc"); GeoGrid grid = dataset.findGridByName("full4"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; doRead4(grid); GeoGrid grid_section = grid.subset(null, new Range(0,3,2), null, null); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis = gcs_section.getVerticalAxis(); assert zaxis.getSize() == 2; assert gcs_section.getXHorizAxis().equals( gcs.getXHorizAxis()); assert gcs_section.getYHorizAxis().equals( gcs.getYHorizAxis()); assert gcs_section.getTimeAxis().equals( gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); logger.debug(NCdumpW.toString( data, "grid_section", null)); dataset.close(); }
@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]; } }
@Test @Category(NeedsCdmUnitTest.class) public void testWRF() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/wrf/wrfout_v2_Lambert.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getSize() == 27; VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; assert vt.getUnitString().equals("Pa"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 13 : data.getShape()[0]; assert data.getShape()[1] == 9 : data.getShape()[1]; assert data.getShape()[2] == 20 : data.getShape()[2]; assert data.getShape()[3] == 25 : data.getShape()[3]; GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 9 : zaxis2.getSize(); assert zaxis2.getUnitsString().equals(zaxis.getUnitsString()); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); VerticalTransform vt_section = gcs_section.getVerticalTransform(); assert vt_section != null; assert vt_section.getUnitString().equals(vt.getUnitString()); } }
@Test @Category(NeedsCdmUnitTest.class) public void testRegular() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/nuwg/03061219_ruc.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getUnitsString().equals("hectopascals"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 7; assert zaxis2.getUnitsString().equals("hectopascals"); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 2 : data.getShape()[0]; assert data.getShape()[1] == 7 : data.getShape()[1]; assert data.getShape()[2] == 22 : data.getShape()[2]; assert data.getShape()[3] == 31 : data.getShape()[3]; // check axes for (CoordinateAxis axis : gcs_section.getCoordinateAxes()) { assert axis.getAxisType() != null; } } }