@Override public VariableSimpleIF getDataVariable(String shortName) { for (CoverageCollection cc : covCollections) { VariableSimpleIF result = cc.findCoverage(shortName); if (result != null) return result; } return null; }
public CoverageAsPoint(CoverageCollection gcd, List<String> varNames, SubsetParams subset) throws IOException { this.gcd = gcd; this.subset = subset; latLonPoint = (LatLonPointImpl) subset.get(SubsetParams.latlonPoint); if (latLonPoint == null) throw new IllegalArgumentException("No latlon point"); varData = new ArrayList<>(varNames.size()); for (String varName : varNames) { Coverage cov = gcd.findCoverage(varName); // LOOK we should read all at once if possible if (cov != null) { varData.add(new VarData(cov)); if (dateUnit == null) { // assume all have the same time unit, just use the first one CoverageCoordSys csys = cov.getCoordSys(); CoverageCoordAxis timeAxis = csys.getTimeAxis(); this.dateUnit = timeAxis.getCalendarDateUnit(); } } } }
private void writeCoverageData(CoverageCollection gdsOrg, SubsetParams subsetParams, CoverageCollection subsetDataset, NetcdfFileWriter writer) throws IOException, InvalidRangeException { for (Coverage coverage : subsetDataset.getCoverages()) { // we need to call readData on the original Coverage coverageOrg = gdsOrg.findCoverage(coverage.getName()); GeoReferencedArray array = coverageOrg.readData(subsetParams); // test conform to whatever axis.getCoordsAsArray() returns checkConformance(coverage, array, gdsOrg.getName()); Variable v = writer.findVariable(coverage.getName()); if (show) System.out.printf("CFGridCoverageWriter2 write coverage %s%n", v.getNameAndDimensions()); writer.write(v, array.getData()); } }
@Test public void testGridCoverageDatasetFmrc() throws IOException, InvalidRangeException { try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC); if (gcs == null) return; logger.debug("testGridCoverageDatasetFmrc {}", endpoint); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); readOne(cover, rt_val, time_val, time_offset, vert_level); } }
static int timeDataRead2(String remote, int stride) throws IOException, InvalidRangeException { logger.debug("--Coverage Read {} stride={} ", remote, stride); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(remote)) { CoverageCollection gcs = cc.getSingleCoverageCollection(); String gridName = "10_metre_V_wind_component_surface"; Coverage grid = gcs.findCoverage(gridName); Assert.assertNotNull(gridName, grid); SubsetParams params = new SubsetParams().setTimePresent().setHorizStride(stride); long start = System.currentTimeMillis(); GeoReferencedArray geo = grid.readData(params); long took = System.currentTimeMillis() - start; logger.debug("took={} size={}", took, geo.getData().getSize()); } return 1; } }
@Test public void testGridCoverageDatasetBest() throws IOException, InvalidRangeException { logger.debug("testGridCoverageDatasetBest {}", 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); // Cant subset on runtime for Best, so we set to null readOne(cover, null, time_val, time_offset, vert_level); } }
@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 testSrcNoParams() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1"; String covName = "Temperature_isobaric"; logger.debug("testSrcNoParams Dataset {} coverage {}", endpoint, covName); 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); SubsetParams params = new SubsetParams(); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); int[] resultShape = geo.getData().getShape(); int[] expectShape = new int[] {36, 29, 65, 93}; Assert.assertArrayEquals("shape", expectShape, resultShape); } }
@Test public void testReadGridCoverageSlice() throws IOException, InvalidRangeException { logger.debug("Test Dataset {} coverage {}", endpoint, covName); FeatureDatasetCoverage cc = null; try { Optional<FeatureDatasetCoverage> opt = CoverageDatasetFactory.openCoverageDataset(endpoint); Assert.assertTrue(opt.getErrorMessage(), opt.isPresent()); cc = opt.get(); Assert.assertNotNull(endpoint, cc); Assert.assertEquals(1, cc.getCoverageCollections().size()); CoverageCollection gcs = cc.getCoverageCollections().get(0); Assert.assertNotNull("gcs", gcs); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); readOne(cover, rt_val, time_val, time_offset, vert_level); } finally { if (cc != null) cc.close(); } }
@Test // there is no interval with offset value = 51 public void testNoIntervalFound() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Momentum_flux_u-component_surface_Mixed_intervals_Average"; logger.debug("test1Runtime1TimeOffset Dataset {} coverage {}", endpoint, covName); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC); Assert.assertNotNull("gcs", gcs); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); SubsetParams params = new SubsetParams(); CalendarDate runtime = CalendarDate.parseISOformat(null, "2015-03-01T12:00:00Z"); params.set(SubsetParams.runtime, runtime); double offsetVal = 51.0; // should fail params.set(SubsetParams.timeOffset, offsetVal); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); testGeoArray(geo, runtime, null, offsetVal); // should be empty, but instead its a bunch of NaNs assert Float.isNaN(geo.getData().getFloat(0)); } }
@Test // 1 runtime, 1 timeOffset (Time2DCoordSys case 1a) public void test1Runtime1TimeOffset() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Momentum_flux_u-component_surface_Mixed_intervals_Average"; logger.debug("test1Runtime1TimeOffset Dataset {} coverage {}", endpoint, covName); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(FeatureType.FMRC); Assert.assertNotNull("gcs", gcs); Coverage cover = gcs.findCoverage(covName); Assert.assertNotNull(covName, cover); SubsetParams params = new SubsetParams(); CalendarDate runtime = CalendarDate.parseISOformat(null, "2015-03-01T06:00:00Z"); params.set(SubsetParams.runtime, runtime); double offsetVal = 205.0; params.set(SubsetParams.timeOffset, offsetVal); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); testGeoArray(geo, runtime, null, offsetVal); // LOOK need to test data } }
@Test public void testScalarRuntimeCoordinate() throws IOException { String filename = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1.ncx4"; String gridName = "Pressure_surface"; try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); Assert.assertEquals(1, cc.getCoverageCollections().size()); CoverageCollection cd = cc.getCoverageCollections().get(0); Coverage cov = cd.findCoverage(gridName); Assert.assertNotNull(gridName, cov); CoverageCoordSys csys = cov.getCoordSys(); Assert.assertNotNull("CoverageCoordSys", csys); CoverageCoordAxis1D runtime = (CoverageCoordAxis1D) csys.getAxis(AxisType.RunTime); Assert.assertNotNull(AxisType.RunTime.toString(), runtime); Assert.assertTrue(runtime.getClass().getName(), runtime instanceof CoverageCoordAxis1D); Assert.assertEquals(CoverageCoordAxis.Spacing.regularPoint, runtime.getSpacing()); Assert.assertEquals(CoverageCoordAxis.DependenceType.scalar, runtime.getDependenceType()); CalendarDate startDate = runtime.makeDate(runtime.getCoordMidpoint(0)); Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), startDate); } }
@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 @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 public void testBadSize() throws IOException, InvalidRangeException { // Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/ds084.3/ds084.3.ncx4"; String covName = "Geopotential_height_isobaric"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.FMRC.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
public void testWrongRuntime() throws IOException, InvalidRangeException { Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/index/ds083.2_Grib2.ncx4"; String covName = "Soil_temperature_depth_below_surface_layer"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.GRID.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
@Test public void testNonOrthMRUTC() throws IOException, InvalidRangeException { Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/ds277.6/monthly/ds277.6.ncx4"; String ccName = "ds277.6#MRUTC-LatLon_418X360-4p83S-179p50W"; String covName = "Salinity_depth_below_sea_Average"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(ccName); Assert.assertNotNull(ccName, cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
@Test public void testNegDataSize() throws IOException, InvalidRangeException { Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/ds084.3/ds084.3.ncx4"; String covName = "v-component_of_wind_potential_vorticity_surface"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.FMRC.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
@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}); } }