public TestCoverageFileWriterP(String endpoint, FeatureType type, List<String> covList, SubsetParams params, NetcdfFileWriter.Version version) { this.endpoint = endpoint; this.type = type; this.covList = covList; this.version = version; this.params = (params != null) ? params : new SubsetParams(); }
public SubsetParams setTime(CalendarDate date) { set(time, date); return this; } public CalendarDate getTime() { return (CalendarDate) get(time);}
case Pressure: case Height: Double dval = params.getVertCoord(); if (dval != null) return Optional.of(helper.subsetClosest(dval)); double[] intv = params.getVertCoordIntv(); if (intv != null) return Optional.of(helper.subsetClosest((intv[0]+intv[1])/2)); double[] vertRange = params.getVertRange(); // used by WCS if (vertRange != null) return helper.subset(vertRange[0], vertRange[1], 1); Double eval = params.getDouble(SubsetParams.ensCoord); if (eval != null) { return Optional.of(helper.subsetClosest(eval)); if (params.isTrue(SubsetParams.timePresent)) return Optional.of(helper.subsetLatest()); CalendarDate date = (CalendarDate) params.get(SubsetParams.time); if (date != null) return Optional.of(helper.subsetClosest(date)); Integer stride = (Integer) params.get(SubsetParams.timeStride); if (stride == null || stride < 0) stride = 1; CalendarDateRange dateRange = (CalendarDateRange) params.get(SubsetParams.timeRange);
switch (coord.getType()) { case runtime: CalendarDate runtimeCooord = coords.getRunTime(); idx = coord.getIndex(runtimeCooord); runIdx = idx; double[] timeIntv = coords.getTimeOffsetIntv(); idx = coord.getIndex(new TimeCoord.Tinv((int) timeIntv[0], (int) timeIntv[1])); break; Double timeOffset = coords.getTimeOffset(); // Double int coordInt = timeOffset.intValue(); idx = coord.getIndex(coordInt); timeIntv = coords.getTimeOffsetIntv(); if (timeIntv != null) { TimeCoord.Tinv coordTinv = new TimeCoord.Tinv((int) timeIntv[0], (int) timeIntv[1]); Double timeCoord = coords.getTimeOffset(); if (timeCoord != null) { coordInt = timeCoord.intValue(); double[] vertIntv = coords.getVertCoordIntv(); if (vertIntv != null) { VertCoord.Level coordVert = new VertCoord.Level(vertIntv[0], vertIntv[1]); Double vertCoord = coords.getVertCoord(); if (vertCoord != null) { VertCoord.Level coordVert = new VertCoord.Level(vertCoord);
@Parameterized.Parameters(name = "{0}") public static List<Object[]> getTestParameters() { List<Object[]> result = new ArrayList<>(); // SRC result.add(new Object[]{TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1", FeatureType.GRID, Lists.newArrayList("Temperature_isobaric"), new SubsetParams().set(SubsetParams.timePresent, true), NetcdfFileWriter.Version.netcdf3}); result.add(new Object[]{TestDir.cdmUnitTestDir + "ft/coverage/03061219_ruc.nc", FeatureType.GRID, Lists.newArrayList("P_sfc", "P_trop"), null, NetcdfFileWriter.Version.netcdf3}); result.add(new Object[]{TestDir.cdmUnitTestDir + "ft/coverage/03061219_ruc.nc", FeatureType.GRID, Lists.newArrayList("P_sfc", "P_trop"), null, NetcdfFileWriter.Version.netcdf4}); result.add(new Object[]{TestDir.cdmUnitTestDir + "ft/coverage/03061219_ruc.nc", FeatureType.GRID, Lists.newArrayList("P_sfc", "P_trop", "T"), null, NetcdfFileWriter.Version.netcdf3}); result.add(new Object[]{TestDir.cdmUnitTestDir + "ft/coverage/ECME_RIZ_201201101200_00600_GB", FeatureType.GRID, Lists.newArrayList("Surface_pressure_surface"), null, NetcdfFileWriter.Version.netcdf3}); // scalar runtime, ens coord result.add(new Object[]{TestDir.cdmUnitTestDir + "ft/coverage/testCFwriter.nc", FeatureType.GRID, Lists.newArrayList("PS", "Temperature"), null, NetcdfFileWriter.Version.netcdf3}); // both x,y and lat,lon result.add(new Object[]{TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4", FeatureType.GRID, Lists.newArrayList("Soil_temperature_depth_below_surface_layer"), null, NetcdfFileWriter.Version.netcdf4}); // TwoD Best // */ return result; }
CalendarDate wantRuntime = coords.getRunTime(); CalendarDate refdate = gr.getReferenceDate(); Assert.assertEquals("runtime", wantRuntime, refdate); CalendarDate wantTimeOffset = (CalendarDate) coords.get(SubsetParams.timeOffsetDate); if (gr.getPDS().isTimeInterval()) { TimeCoord.TinvDate tinv = cust.getForecastTimeInterval(gr); double[] wantTimeOffsetIntv = coords.getTimeOffsetIntv(); if (wantTimeOffset != null) { Assert.assertTrue("time coord lower", !tinv.getStart().isAfter(wantTimeOffset)); // lower <= time Double vertCoord = coords.getVertCoord(); double[] vertCoordIntv = coords.getVertCoordIntv(); double level1val = pds.getLevelValue1(); Double wantEns = coords.getEnsCoord(); if (wantEns != null) { Grib2Pds.PdsEnsemble pdse = (Grib2Pds.PdsEnsemble) pds;
CalendarDate rt_val = coords.getRunTime(); boolean runtimeOk = true; if (rt_val != null) { CalendarDate time_val = coords.getTime(); if (time_val == null) { time_val = (CalendarDate) coords.get(SubsetParams.timeOffsetDate); if (bean.isTimeInterval()) { TimeCoord.TinvDate dateFromGribRecord = bean.getTimeIntervalDates(); CalendarDate[] date_bounds = (CalendarDate[]) coords.get("timeDateIntv"); if (date_bounds == null) { date_bounds = makeDateBounds(coords, rt_val); Double vert_val = coords.getVertCoord(); double[] edge = coords.getVertCoordIntv(); boolean vertOk = true; if (edge != null) {
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 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 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 testBestPresent() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Temperature_altitude_above_msl"; logger.debug("testBestPresent 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(); params.set(SubsetParams.timePresent, true); params.setVertCoord(3658.0); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); // should not be missing ! assert !Float.isNaN(geo.getData().getFloat(0)); Array data = geo.getData(); Index ai = data.getIndex(); float testValue = data.getFloat(ai.set(0, 0, 3, 0)); Assert2.assertNearlyEquals(244.8f, testValue); } }
@Test public void testBestTimeCoord() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Temperature_altitude_above_msl"; logger.debug("testBestPresent 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(); params.setTime(CalendarDate.parseISOformat(null, "2015-03-03T00:00:00Z")); params.setVertCoord(3658.0); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); // should not be missing ! assert !Float.isNaN(geo.getData().getFloat(0)); Array data = geo.getData(); Index ai = data.getIndex(); float testValue = data.getFloat(ai.set(0, 0, 0, 0)); Assert2.assertNearlyEquals(244.3f, testValue); } }
Assert.assertEquals(6*35*9*65*93*4, size); SubsetParams subset = new SubsetParams().setRunTime(CalendarDate.parseISOformat(null,"2014-10-24T12:00:00Z")) .setTimeOffset(42).setVertCoord(500); GeoReferencedArray geo = cover.readData(subset); Array data = geo.getData();
private void addAdjustedTimeCoords(SubsetParams result, CoverageCoordAxis1D axis, int coordIdx, CalendarDate runtime) { // this must be adjusted to be offset from the runtime. // adjust = end - start // axisCoordOffset + axis.reftime = offset + runtime // offset = axisCoordOffset + axis.reftime - runtime // offset = axisCoordOffset + adjust // offset = axisCoordOffset + end - start = axisCoordOffset + axis.reftime - runtime // therefore: end = reftime, start = runtime double adjust = axis.getOffsetInTimeUnits(runtime, axis.getRefDate()); if (axis.isInterval()) { double[] adjustVal = new double[] {axis.getCoordEdge1(coordIdx)+adjust, axis.getCoordEdge2(coordIdx)+adjust}; result.setTimeOffsetIntv(adjustVal); double mid = (adjustVal[0]+adjustVal[1]) / 2.0; result.set(SubsetParams.timeOffsetUnit, axis.makeDateInTimeUnits(runtime, mid)); // validation result.set(SubsetParams.timeOffsetUnit, axis.getCalendarDateUnit()); // validation } else { double adjustVal = axis.getCoordMidpoint(coordIdx) + adjust; result.setTimeOffset(adjustVal); result.set(SubsetParams.timeOffsetDate, axis.makeDateInTimeUnits(runtime, adjustVal)); // validation result.set(SubsetParams.timeOffsetUnit, axis.getCalendarDateUnit()); // validation } }
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; } }
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()); }
SubsetParams params = new SubsetParams().set(SubsetParams.timePresent, true).setLatLonBoundingBox(bbox); GeoReferencedArray geo = coverage.readData(params); logger.debug("geoCs shape={}", Misc.showInts(geo.getCoordSysForData().getShape()));
@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); } }
dtCoords.set("timeDateIntv", tcoord1D.getCoordBoundsDate(t)); dtCoords.setTimeOffsetIntv(tcoord1D.getCoordBounds(t)); } else { dtCoords.setTime(tcoord1D.getCalendarDate(t)); timeBoundsDate[0] = helper.makeCalendarDateFromOffset(timeBounds[0]); timeBoundsDate[1] = helper.makeCalendarDateFromOffset(timeBounds[1]); dtCoords.setTimeOffsetIntv(timeBounds); dtCoords.set("timeDateIntv", timeBoundsDate); } else { double timeCoord = tcoord2D.getCoordValue(rtIndex, t); CalendarDate timeCoordDate = helper.makeCalendarDateFromOffset(timeCoord); dtCoords.setTime(timeCoordDate);