@Override public int[] getShape() { return coordSys.getShape(); }
public void toString(Formatter f, Indent indent) { indent.incr(); f.format("%s CoordSys '%s' type %s", indent, name, type); f.format(" has coordVars:"); for (String v : axisNames) f.format("%s, ", v); f.format(" (shape=[%s])", Misc.showInts(getShape())); if (transformNames != null && !transformNames.isEmpty()) { f.format("; has transforms:"); for (String t : transformNames) f.format("%s, ", t); } indent.decr(); }
public GeoReferencedArray(String coverageName, DataType dataType, Array data, List<CoverageCoordAxis> axes, List<CoverageTransform> transforms, FeatureType type) { this.coverageName = coverageName; this.dataType = dataType; this.data = data; this.axes = axes; this.transforms = transforms; List<String> names = axes.stream().map(CoverageCoordAxis::getName).collect(Collectors.toList()); this.csSubset = new CoverageCoordSys(null, names, null, type); this.csSubset.setDataset(this); this.csSubset.setHorizCoordSys(this.csSubset.makeHorizCoordSys()); // check consistency Section cs = new Section(csSubset.getShape()); Section sdata = new Section(data.getShape()); assert cs.conformal(sdata); // reshape data if needed if (!cs.equalShape(sdata)) this.data = data.reshape(csSubset.getShape()); }
public long getSizeInBytes() { Section section = new Section(coordSys.getShape()); return section.computeSize() * getDataType().getSize(); }
private void checkConformance(Coverage gridSubset, GeoReferencedArray geo, String where) { CoverageCoordSys csys = gridSubset.getCoordSys(); CoverageCoordSys csysData = geo.getCoordSysForData(); //System.out.printf(" csys=%s%n", csys); //System.out.printf("csysData=%s%n", csysData); Section s = new Section(csys.getShape()); Section so = new Section(csysData.getShape()); boolean ok = s.conformal(so); int[] dataShape = geo.getData().getShape(); //System.out.printf("dataShape=%s%n", Misc.showInts(dataShape)); Section sdata = new Section(dataShape); boolean ok2 = s.conformal(sdata); if (!ok || !ok2) logger.warn("CFGridCoverageWriter2 checkConformance fails " +where); } }
private void checkLatLonSubset(CoverageCollection gcs, Coverage coverage, LatLonRect bbox, int[] expectedShape) throws Exception { System.out.printf(" coverage llbb = %s width=%f%n", gcs.getLatlonBoundingBox().toString2(), gcs.getLatlonBoundingBox().getWidth()); System.out.printf(" constrain bbox= %s width=%f%n", bbox.toString2(), bbox.getWidth()); SubsetParams params = new SubsetParams().setLatLonBoundingBox(bbox).setTimePresent(); GeoReferencedArray geo = coverage.readData(params); CoverageCoordSys gcs2 = geo.getCoordSysForData(); Assert.assertNotNull("CoordSysForData", gcs2); System.out.printf(" data cs shape=%s%n", Misc.showInts(gcs2.getShape())); System.out.printf(" data shape=%s%n", Misc.showInts(geo.getData().getShape())); Assert.assertArrayEquals("CoordSys=Data shape", gcs2.getShape(), geo.getData().getShape()); Assert.assertArrayEquals("expected data shape", expectedShape, geo.getData().getShape()); }
@Test public void testFmrcStride() throws IOException, InvalidRangeException { try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC); if (gcs == null) return; // not all datasets have an Fmrc logger.debug("testFmrcStride {}", endpoint); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); CoverageCoordSys csys = cover.getCoordSys(); int[] csysShape = csys.getShape(); logger.debug("csys shape = {}", Misc.showInts(csysShape)); SubsetParams params = new SubsetParams().setHorizStride(2).set(SubsetParams.runtimeAll, true); Optional<CoverageCoordSys> opt = csys.subset(params); if (!opt.isPresent()) { logger.debug("err={}", opt.getErrorMessage()); assert false; } CoverageCoordSys subsetCoordSys = opt.get(); int[] subsetShape = subsetCoordSys.getShape(); logger.debug("csysSubset shape = {}", Misc.showInts(subsetShape)); int n = csysShape.length; csysShape[n-1] = (csysShape[n-1]+1)/2; csysShape[n-2] = (csysShape[n-2]+1)/2; Assert.assertArrayEquals(csysShape, subsetShape); } }
@Test public void testBestStride() throws IOException, InvalidRangeException { logger.debug("testBestStride {}", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); CoverageCoordSys csys = cover.getCoordSys(); int[] csysShape = csys.getShape(); logger.debug("csys shape = {}", Misc.showInts(csysShape)); SubsetParams params = new SubsetParams().setHorizStride(2); Optional<CoverageCoordSys> opt = csys.subset(params); if (!opt.isPresent()) { logger.debug("err={}", opt.getErrorMessage()); assert false; } CoverageCoordSys subsetCoordSys = opt.get(); int[] subsetShape = subsetCoordSys.getShape(); logger.debug("csysSubset shape = {}", Misc.showInts(subsetShape)); int n = csysShape.length; csysShape[n-1] = (csysShape[n-1]+1)/2; csysShape[n-2] = (csysShape[n-2]+1)/2; Assert.assertArrayEquals(csysShape, subsetShape); } }
@Test public void testBestStride() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Ozone_Mixing_Ratio_isobaric"; System.out.printf("Test Dataset %s%n", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); CoverageCoordSys csys = cover.getCoordSys(); int[] csysShape = csys.getShape(); System.out.printf("csys shape = %s%n", Misc.showInts(csysShape)); SubsetParams params = new SubsetParams().setHorizStride(2); Optional<CoverageCoordSys> opt = csys.subset(params); if (!opt.isPresent()) { System.out.printf("err=%s%n", opt.getErrorMessage()); assert false; } CoverageCoordSys subsetCoordSys = opt.get(); int[] subsetShape = subsetCoordSys.getShape(); System.out.printf("csysSubset shape = %s%n", Misc.showInts(subsetShape)); int n = csysShape.length; csysShape[n-1] = (csysShape[n-1]+1)/2; csysShape[n-2] = (csysShape[n-2]+1)/2; Assert.assertArrayEquals(csysShape, subsetShape); } }
@Test @Category(NeedsCdmUnitTest.class) public void testCrossLongitudeSeamGrib() throws Exception { String filename = TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_0p5deg_20100913_0000.grib2"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String gribId = "VAR_2-0-0_L1"; Coverage coverage = gcs.findCoverageByAttribute(Grib.VARIABLE_ID_ATTNAME, gribId); // Land_cover_0__sea_1__land_surface Assert.assertNotNull(gribId, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); System.out.printf(" org coverage shape=%s%n", Misc.showInts(cs.getShape())); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); Assert.assertEquals("rank", 3, cs.getShape().length); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 120.0); writeTestFile(gcs, coverage, bbox, new int[]{1, 21, 241}); } }
@Test @Category(NeedsCdmUnitTest.class) public void testCrossLongitudeSeam() throws Exception { String filename = TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_0p5deg_20100913_0000.grib2"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String gribId = "VAR_2-0-0_L1"; Coverage coverage = gcs.findCoverageByAttribute(Grib.VARIABLE_ID_ATTNAME, gribId); // Land_cover_0__sea_1__land_surface Assert.assertNotNull(gribId, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); System.out.printf(" org coverage shape=%s%n", Misc.showInts(cs.getShape())); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); Assert.assertEquals("rank", 3, cs.getShape().length); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 120.0); checkLatLonSubset(gcs, coverage, bbox, new int[]{1, 21, 241}); } }
@Test @Category(NeedsExternalResource.class) public void testCdmRemoteCoverage() throws Exception { String ds = "http://thredds-test.unidata.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg_ana/latest.xml"; try (DataFactory.Result result = new DataFactory().openFeatureDataset("thredds:resolve:" + ds, null)) { logger.debug("result errlog = {}", result.errLog); assert !result.fatalError; assert result.featureType == FeatureType.GRID; assert result.featureDataset != null; String gridName = "Temperature_isobaric"; FeatureDatasetCoverage dataset = (FeatureDatasetCoverage) result.featureDataset; Assert.assertNotNull(gridName, dataset.getDataVariable(gridName)); Assert.assertEquals(1, dataset.getCoverageCollections().size()); CoverageCollection cc = dataset.getCoverageCollections().get(0); Coverage grid = cc.findCoverage(gridName); Assert.assertNotNull(gridName, grid); CoverageCoordSys gcs = grid.getCoordSys(); Assert.assertNotNull("CoverageCoordSys", gcs); Assert.assertEquals("CoverageCoordSys rank", 5, gcs.getAxes().size()); SubsetParams params = new SubsetParams().set(SubsetParams.timePresent, true).setHorizStride(3); GeoReferencedArray geo = grid.readData(params); CoverageCoordSys geoCoordsys = geo.getCoordSysForData(); Assert.assertNotNull("geoCoordsys", geoCoordsys); int[] shape = geoCoordsys.getShape(); logger.debug("grid_section.getShape = {}", new Section(shape)); int[] expectShape = new int[] {1, 31, 241, 480}; Assert.assertArrayEquals("subset shape", expectShape, shape); } }
@Test @Category(NeedsCdmUnitTest.class) public void testSubsetDt() throws Exception { // try a subset without crossing the seam String filename = TestDir.cdmUnitTestDir + "ft/grid/GFS_Global_onedeg_20081229_1800.grib2.nc"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String covName = "Pressure_surface"; Coverage coverage = gcs.findCoverage(covName); Assert.assertNotNull(covName, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); System.out.printf(" org coverage shape=%s%n", Misc.showInts(cs.getShape())); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(10.0, 40.0), 50.0, 120.0); writeTestFile(gcs, coverage, bbox, new int[]{1, 51, 121}); } }
@Test @Category(NeedsCdmUnitTest.class) public void testCrossLongitudeSeamDt() throws Exception { String filename = TestDir.cdmUnitTestDir + "ft/grid/GFS_Global_onedeg_20081229_1800.grib2.nc"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String covName = "Pressure_surface"; Coverage coverage = gcs.findCoverage(covName); Assert.assertNotNull(covName, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); System.out.printf(" org coverage shape=%s%n", Misc.showInts(cs.getShape())); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 120.0); writeTestFile(gcs, coverage, bbox, new int[]{1, 11, 121}); } }
@Test public void TestGribCurvilinearSubset() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "ft/fmrc/rtofs/ofs.20091122/ofs_atl.t00z.F024.grb.grib2"; // GRIB Curvilinear logger.debug("open {}", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { assert cc != null; Assert.assertEquals(1, cc.getCoverageCollections().size()); CoverageCollection gds = cc.getCoverageCollections().get(0); Assert.assertNotNull(endpoint, gds); Assert.assertEquals(FeatureType.CURVILINEAR, gds.getCoverageType()); Assert.assertEquals(7, gds.getCoverageCount()); HorizCoordSys hcs = gds.getHorizCoordSys(); Assert.assertNotNull(endpoint, hcs); Assert.assertTrue(endpoint, !hcs.isProjection()); Assert.assertNull(endpoint, hcs.getTransform()); String covName = "Mixed_layer_depth_surface"; Coverage coverage = gds.findCoverage(covName); Assert.assertNotNull(covName, coverage); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(64.0, -61.), new LatLonPointImpl(59.0, -52.)); SubsetParams params = new SubsetParams().set(SubsetParams.timePresent, true).set(SubsetParams.latlonBB, bbox); GeoReferencedArray geo = coverage.readData(params); logger.debug("csys shape={}", Misc.showInts(geo.getCoordSysForData().getShape())); Array data = geo.getData(); logger.debug("data shape={}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(geo.getCoordSysForData().getShape(), data.getShape()); int[] expectedShape = new int[] {1, 165, 161}; Assert.assertArrayEquals(expectedShape, data.getShape()); } }
@Test @Category(NeedsExternalResource.class) public void testCdmRemoteSubset() throws Exception { String filename = "cdmremote:http://thredds-dev.unidata.ucar.edu/thredds/cdmremote/grib/NCEP/NAM/CONUS_40km/conduit/best"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String gribId = "Pressure_hybrid"; Coverage coverage = gcs.findCoverage(gribId); Assert.assertNotNull(gribId, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); Assert.assertEquals("rank", 4, cs.getShape().length); LatLonRect llbb_subset = new LatLonRect(new LatLonPointImpl(-15, -140), new LatLonPointImpl(55, 30)); System.out.println("subset lat/lon bbox= " + llbb_subset); checkLatLonSubset(gcs, coverage, llbb_subset, new int[]{1, 1, 129, 185}); } }
@Test @Category(NeedsCdmUnitTest.class) public void testLongitudeSubset() throws Exception { String filename = TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_onedeg_20100913_0000.grib2"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String gribId = "VAR_0-3-0_L1"; Coverage coverage = gcs.findCoverageByAttribute(Grib.VARIABLE_ID_ATTNAME, gribId); // "Pressure_Surface"); Assert.assertNotNull(gribId, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); Assert.assertEquals("rank", 3, cs.getShape().length); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 20.0); checkLatLonSubset(gcs, coverage, bbox, new int[]{1, 11, 21}); } }
@Test @Category(NeedsCdmUnitTest.class) public void testLatLonSubset() throws Exception { String filename = TestDir.cdmUnitTestDir + "conventions/cf/SUPER-NATIONAL_latlon_IR_20070222_1600.nc"; System.out.printf("open %s%n", filename); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull("gcs", gcs); String gribId = "micron11"; Coverage coverage = gcs.findCoverage(gribId); Assert.assertNotNull(gribId, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); Assert.assertEquals("rank", 2, cs.getShape().length); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 20.0); checkLatLonSubset(gcs, coverage, bbox, new int[]{141, 281}); bbox = new LatLonRect(new LatLonPointImpl(-40.0, -180.0), 120.0, 300.0); checkLatLonSubset(gcs, coverage, bbox, new int[]{800, 1300}); } }
int[] shapeCs = geoCs.getShape(); int [] dataShape = geo.getData().getShape();