private static boolean readRandom(FeatureDatasetCoverage covDataset, PrintWriter pw ) throws IOException, InvalidRangeException { CoverageCollection cc = covDataset.getCoverageCollections().get(0); int ncov = cc.getCoverageCount(); Random r = new Random(System.currentTimeMillis()); int randomIdx = r.nextInt(ncov); int count = 0; Coverage randomCov = null; for (Coverage c : cc.getCoverages()) { if (count == randomIdx) { randomCov = c; break; } count++; } if (randomCov == null) { pw.format("Bad random coverage"); return false; } SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = randomCov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", randomCov.getName(), Misc.showInts(data.getShape())); return true; }
@Test public void testFactory() throws IOException { 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("NGrids", ncoverages, gds.getCoverageCount()); Assert.assertEquals(expectType, gds.getCoverageType()); } }
@Test public void TestGribCurvilinear() 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 cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); GeoReferencedArray geo = cover.readData(new SubsetParams()); TestCoverageSubsetTime.testGeoArray(geo, null, null, null); } }
@Test public void TestNetcdfCurvilinear2D() throws IOException { String endpoint = TestDir.cdmUnitTestDir + "transforms/UTM/artabro_20120425.nc"; // NetCDF Curvilinear 2D only 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(10, gds.getCoverageCount()); String covName = "hs"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); SubsetParams params = new SubsetParams().set(SubsetParams.timePresent, true); GeoReferencedArray geo = cover.readData(params); Array data = geo.getData(); Index ima = data.getIndex(); int[] expectedShape = new int[] {1,151,171}; Assert.assertArrayEquals(expectedShape, data.getShape()); Assert2.assertNearlyEquals(1.782, data.getDouble(ima.set(0, 0, 0)), 1e-6); Assert2.assertNearlyEquals(1.769, data.getDouble(ima.set(0, 11, 0)), 1e-6); } catch (InvalidRangeException e) { e.printStackTrace(); } }
@Test public void TestNetcdfCurvilinear() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "ft/coverage/Run_20091025_0000.nc"; // NetCDF has 2D and 1D 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(20, gds.getCoverageCount()); String covName = "u"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); SubsetParams params = new SubsetParams().setVertCoord(-.05).set(SubsetParams.timePresent, true); GeoReferencedArray geo = cover.readData(params); Array data = geo.getData(); Index ima = data.getIndex(); int[] expectedShape = new int[] {1,1,22,12}; Assert.assertArrayEquals(expectedShape, data.getShape()); Assert2.assertNearlyEquals(0.0036624447, data.getDouble(ima.set(0, 0, 0, 0)), 1e-6); Assert2.assertNearlyEquals(0.20564626, data.getDouble(ima.set(0, 0, 21, 11)), 1e-6); } }
@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()); } }
Assert.assertNotNull(endpoint, gds); Assert.assertEquals(FeatureType.CURVILINEAR, gds.getCoverageType()); Assert.assertEquals(10, gds.getCoverageCount());