public CoverageCollection findCoverageDataset( FeatureType type) { for (CoverageCollection cd : covCollections) if (cd.getCoverageType() == type) return cd; return null; }
public FeatureDatasetCoverage(String location, Closeable closer, CoverageCollection covCollection) { this.location = location; this.gatts = new AttributeContainerHelper(location, covCollection.getGlobalAttributes()); this.closer = closer; this.covCollections = Lists.newArrayList(covCollection); this.featureType = covCollection.getCoverageType(); this.calendarDateRange = covCollection.getCalendarDateRange(); }
public FeatureDatasetCoverage(String location, AttributeContainer gatts, Closeable closer, List<CoverageCollection> covCollections) { this.location = location; this.gatts = gatts; this.closer = closer; this.covCollections = covCollections; CalendarDateRange cdr = null; FeatureType ft = null; for (CoverageCollection cc : covCollections) { FeatureType ftCheck = cc.getCoverageType(); if (ft == null) ft = ftCheck; else if (ftCheck != ft) ft = FeatureType.COVERAGE; CalendarDateRange cdrCheck = cc.getCalendarDateRange(); if (cdr == null) cdr = cdrCheck; else if (cdrCheck != null) cdr = cdr.extend( cdrCheck); } this.featureType = ft; this.calendarDateRange = cdr; }
void testCoverage(String endpoint) throws IOException, InvalidRangeException { System.out.printf("open CoverageDatasetFactory %s%n", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { assert cc != null; CoverageCollection gds = cc.findCoverageDataset(what); Assert.assertEquals(what, gds.getCoverageType()); } }
@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 TestCFWriterCoverageSize() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1"; logger.info("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.GRID, gds.getCoverageType()); // CFGridCoverageWriter2 adds another (dependent) time coordinate, so we need to test this case ucar.nc2.util.Optional<Long> opt = CFGridCoverageWriter2.writeOrTestSize(gds, Lists.newArrayList("Temperature_isobaric"), new SubsetParams(), false, true, null); Assert.assertTrue(opt.isPresent()); long size = opt.get(); Assert.assertEquals(25245084, size); // Includes sizes of non-coverage variables. } }
@Test public void testGridCoverageDatasetRdavm() throws IOException, InvalidRangeException { if (showDetails) System.out.printf("%s%n", filename); try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, fdc); for (CoverageCollection cc : fdc.getCoverageCollections()) { System.out.printf(" %s type=%s%n", cc.getName(), cc.getCoverageType()); //for (CoverageCoordSys coordSys : cc.getCoordSys()) { //Assert.assertTrue( coordSys.isTime2D(coordSys.getAxis(AxisType.RunTime))); //Assert.assertTrue( coordSys.isTime2D(coordSys.getTimeAxis())); //} if (showDetails) for (CoverageCoordAxis axis : cc.getCoordAxes()) { if (axis.getAxisType().isTime()) System.out.printf(" %12s %10s %5d %10s %s%n", axis.getName(), axis.getAxisType(), axis.getNcoords(), axis.getDependenceType(), axis.getSpacing()); } } } }
@Test public void TestCoverageSize() throws IOException { String endpoint = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1"; logger.info("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.GRID, gds.getCoverageType()); String covName = "Temperature_isobaric"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(25243920, size); covName = "Relative_humidity_layer_between_two_sigmas_layer"; cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); size = cover.getSizeInBytes(); Assert.assertEquals(870480, size); } }
@Test public void TestCFWriterCoverageRead() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "ncss/test/GFS_CONUS_80km_20120227_0000.grib1.nc4"; logger.info("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.FMRC, gds.getCoverageType()); String covName = "Temperature_isobaric"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(25243920, size); SubsetParams subset = new SubsetParams().setVertCoord(300.0).setTimeOffset(42.0); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData(); logger.info("{}", Misc.showInts(data.getShape())); } } }
@Test public void TestMRUTPRead() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/tp/GFSonedega.ncx4"; 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.assertEquals(FeatureType.GRID, gds.getCoverageType()); String covName = "Relative_humidity_sigma"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(2*181*360*4, size); SubsetParams subset = new SubsetParams().setTimeOffset(6); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData(); logger.debug("{}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(new int[]{1, 1, 181, 360}, data.getShape()); float val = data.getFloat(3179); logger.debug("data val at {} = {}", 3179, val); Assert2.assertNearlyEquals(98.0, val); val = data.getFloat(5020); logger.debug("data val at {} = {}", 5020, val); Assert2.assertNearlyEquals(60.0, val); } }
@Test public void TestMRUTCRead() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/anal/HRRRanalysis.ncx4"; 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.assertEquals(FeatureType.GRID, gds.getCoverageType()); String covName = "Temperature_isobaric"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(4*5*1377*2145*4, size); SubsetParams subset = new SubsetParams().setVertCoord(70000).setTimeOffset(2); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData(); logger.debug("{}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(new int[]{1, 1, 1377, 2145}, data.getShape()); float val = data.getFloat(40600); logger.debug("data val at {} = {}", 40600, val); Assert2.assertNearlyEquals(281.627563, val); val = data.getFloat(55583); logger.debug("data val at {} = {}", 55583, val); Assert2.assertNearlyEquals(281.690063, val); } }
Assert.assertEquals(2, cc.getCoverageCollections().size()); CoverageCollection gds = cc.getCoverageCollections().get(0); Assert.assertEquals(FeatureType.FMRC, gds.getCoverageType());
@Test public void TestBestRead() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_conus80/gfsConus80_file.ncx4"; logger.debug("open {}", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { assert cc != null; Assert.assertEquals(2, cc.getCoverageCollections().size()); CoverageCollection gds = cc.getCoverageCollections().get(1); Assert.assertEquals(FeatureType.GRID, gds.getCoverageType()); String covName = "Temperature_isobaric"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(41*29*65*93*4, size); SubsetParams subset = new SubsetParams().setVertCoord(300.0).setTime(useDate); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData(); logger.debug("{}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(new int[] {1,1,65,93}, data.getShape()); float first = data.getFloat(0); float last = data.getFloat((int)data.getSize()-1); logger.debug("data first = {} last = {}", first, last); Assert2.assertNearlyEquals(241.699997, first); Assert2.assertNearlyEquals(225.099991, last); } }
@Test public void TestSRCRead() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_conus80/20141025/GFS_CONUS_80km_20141025_0000.grib1.ncx4"; 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.assertEquals(FeatureType.GRID, gds.getCoverageType()); String covName = "Temperature_isobaric"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(25243920, size); SubsetParams subset = new SubsetParams().setVertCoord(200.0).setTimeOffset(42.0); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData(); logger.debug("{}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(new int[] {1,1,65,93}, data.getShape()); float first = data.getFloat(0); float last = data.getFloat((int)data.getSize()-1); logger.debug("data first = {} last = {}", first, last); Assert2.assertNearlyEquals(219.5f, first); Assert2.assertNearlyEquals(218.6f, last); } }
@Test public void TestTwoDRead() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_conus80/gfsConus80_file.ncx4"; logger.debug("open {}", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { assert cc != null; Assert.assertEquals(2, cc.getCoverageCollections().size()); CoverageCollection gds = cc.getCoverageCollections().get(0); Assert.assertEquals(FeatureType.FMRC, gds.getCoverageType()); String covName = "Temperature_isobaric"; Coverage cover = gds.findCoverage(covName); Assert.assertNotNull(covName, cover); long size = cover.getSizeInBytes(); Assert.assertEquals(6*36*29*65*93*4, size); // LOOK if we dont set the runtime, assume latest. driven by Cdmrf spec. could be different. SubsetParams subset = new SubsetParams().setVertCoord(300.0).setTime(useDate); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData(); logger.debug("{}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(new int[] {1,1,1,65,93}, data.getShape()); float first = data.getFloat(0); float last = data.getFloat((int)data.getSize()-1); logger.debug("data first = {} last = {}", first, last); Assert2.assertNearlyEquals(241.699997, first); Assert2.assertNearlyEquals(225.099991, last); } }
@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); } }
@Ignore("files not present") @Test public void testGridCoverageDatasetFmrc() throws IOException, InvalidRangeException { System.out.printf("%s%n", filename); try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.GRID.toString(), cc); System.out.printf(" %s type=%s%n", cc.getName(), cc.getCoverageType()); for (CoverageCoordSys coordSys : cc.getCoordSys()) { Assert.assertTrue( coordSys.isTime2D(coordSys.getAxis(AxisType.RunTime))); Assert.assertTrue( coordSys.isTime2D(coordSys.getTimeAxis())); } for (CoverageCoordAxis axis : cc.getCoordAxes()) { if (axis.getAxisType().isTime()) System.out.printf(" %12s %10s %5d %10s %s%n", axis.getName(), axis.getAxisType(), axis.getNcoords(), axis.getDependenceType(), axis.getSpacing()); } } } }
@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 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(); } }
CdmrFeatureProto.CoverageDataset.Builder encodeHeader(CoverageCollection gridDataset, String location) { CdmrFeatureProto.CoverageDataset.Builder builder = CdmrFeatureProto.CoverageDataset.newBuilder(); builder.setName(location); builder.setCoverageType(convertCoverageType(gridDataset.getCoverageType())); builder.setDateRange(encodeDateRange(gridDataset.getCalendarDateRange())); if (gridDataset.getLatlonBoundingBox() != null) builder.setLatlonRect(encodeRectangle(gridDataset.getLatlonBoundingBox())); if (gridDataset.getProjBoundingBox() != null) builder.setProjRect(encodeRectangle(gridDataset.getProjBoundingBox())); for (Attribute att : gridDataset.getGlobalAttributes()) builder.addAtts(NcStream.encodeAtt(att)); for (CoverageCoordSys gcs : gridDataset.getCoordSys()) builder.addCoordSys(encodeCoordSys(gcs)); for (CoverageTransform gct : gridDataset.getCoordTransforms()) builder.addCoordTransforms(encodeCoordTransform(gct)); for (CoverageCoordAxis axis : gridDataset.getCoordAxes()) builder.addCoordAxes(encodeCoordAxis(axis)); for (Coverage grid : gridDataset.getCoverages()) builder.addGrids(encodeGrid(grid)); return builder; }