public TestGribCoverageSubsetP(String endpoint, String covName, String rt_val, String time_val, Double time_offset, Double vert_level) { this.endpoint = endpoint; this.covName = covName; this.rt_val = (rt_val == null) ? null : CalendarDate.parseISOformat(null, rt_val); this.time_val = (time_val == null) ? null : CalendarDate.parseISOformat(null, time_val); this.time_offset = time_offset; this.vert_level = vert_level; }
public TestDtWithCoverageReadingSingleP(String endpoint, FeatureType type, String covName, String rt_val, Double ens_val, String time_val, Double vert_val, Integer time_idx) { this.endpoint = endpoint; this.type = type; this.covName = covName; this.gridName = (type == FeatureType.FMRC) ? "TwoD/"+ covName : "Best/"+covName; this.rt_val = rt_val == null ? null : CalendarDate.parseISOformat(null, rt_val); this.ens_val = ens_val; this.time_val = time_val == null ? null : CalendarDate.parseISOformat(null, time_val); this.vert_val = vert_val; this.time_idx = time_idx; }
public TestGridAsPointP(String ds, String varName, String query, Integer ntimes, Double dataVal, String date0) { this.ds = ds; this.varName = varName; this.query = query; this.ntimes = ntimes; this.dataVal = dataVal; this.date0 = CalendarDate.parseISOformat(null, date0); }
/** * Get CalendarDate from ISO date string * @param calendarName get Calendar from Calendar.get(calendarName). may be null * @param isoOrUdunits ISO or udunits date string * @return CalendarDate or null if not valid */ @Nullable public static CalendarDate parseUdunitsOrIso(String calendarName, String isoOrUdunits) { CalendarDate result; try { result = parseISOformat(calendarName, isoOrUdunits); } catch (Exception e) { try { result = parseUdunits(calendarName, isoOrUdunits); } catch (Exception e2) { return null; } } return result; }
public TestGridCoverageRemoteP(String endpoint, String covName, String rt_val, String time_val, Double time_offset, Double vert_level) { this.endpoint = ucar.nc2.ft.remote.CdmrFeatureDataset.SCHEME + TestOnLocalServer.withHttpPath(endpoint); this.covName = covName; this.rt_val = rt_val == null ? null : CalendarDate.parseISOformat(null, rt_val); this.time_val = time_val == null ? null : CalendarDate.parseISOformat(null, time_val); this.time_offset = time_offset; this.vert_level = vert_level; }
@Override CalendarDate extractRunDateWithError(MFile mfile) { CalendarDate result = super.extractRunDateWithError(mfile); // if there isn't a DateExtractor, see if a mapping exists between // filenames and runtimes as defied by the coordValue attribute // in explicitly defined file aggregations (i.e. not a directory scan) if (result == null) if (!this.filesRunDateMap.isEmpty()) { String dateString = filesRunDateMap.get(mfile.getPath()); result = CalendarDate.parseISOformat(null, dateString); } if (result == null) logger.error("Failed to find a run date associated with file {}", mfile.getPath()); return result; }
protected void setStartDate() { String datetime = ds.findAttValueIgnoreCase(null, "time_coverage_start", null); if (datetime != null) { startDate = CalendarDate.parseISOformat(null, datetime).toDate(); } else { startDate = calDateUnits.makeCalendarDate(time[0]).toDate(); } }
protected void setStartDate() { String datetime = ds.findAttValueIgnoreCase(null, "time_coverage_start", null); if (datetime != null) { startDate = CalendarDate.parseISOformat(null, datetime).toDate(); } else { startDate = calDateUnits.makeCalendarDate(time[0]).toDate(); } }
protected void setEndDate() { String datetime = ds.findAttValueIgnoreCase(null, "time_coverage_end", null); if (datetime != null) { endDate = CalendarDate.parseISOformat(null, datetime).toDate(); } else { endDate = calDateUnits.makeCalendarDate(time[time.length - 1]).toDate(); } }
protected void setEndDate() { String datetime = ds.findAttValueIgnoreCase(null, "time_coverage_end", null); if (datetime != null) { endDate = CalendarDate.parseISOformat(null, datetime).toDate(); } else { endDate = calDateUnits.makeCalendarDate(time[time.length - 1]).toDate(); } }
@Test public void checkModelVersionDate() { assertEquals(pds.calcTime(38), CalendarDate.parseISOformat("proleptic_gregorian", "2011-03-01T00:00:00")); }
@Test public void checkEndOfOverallIntervalDate() { assertEquals(pds.calcTime(45), CalendarDate.parseISOformat("proleptic_gregorian", "2010-12-29T06:00:00")); }
@Test public void testSizeEstimateTimeSubset() throws Exception { String fileIn = TestDir.cdmUnitTestDir + "ft/grid/cg/cg.ncml"; System.out.printf("Open %s%n", fileIn); try (ucar.nc2.dt.grid.GridDataset gds = GridDataset.open(fileIn)) { CalendarDateRange dateRange = CalendarDateRange.of(CalendarDate.parseISOformat(null, "2006-06-07T12:00:00Z"), CalendarDate.parseISOformat(null, "2006-06-07T13:00:00Z")); long totalSize = CFGridWriter2.makeSizeEstimate(gds, null, null, null, 1, null, null, 1, true); long subsetSize = CFGridWriter2.makeSizeEstimate(gds, null, null, null, 1, null, dateRange, 1, true); System.out.printf("total size = %d%n", totalSize); System.out.printf("subset size with date range = %d%n", subsetSize); assertTrue(subsetSize < totalSize); String varName = "CGusfc"; List<String> gridList = new ArrayList<>(); gridList.add(varName); totalSize = CFGridWriter2.makeSizeEstimate(gds, gridList, null, null, 1, null, null, 1, true); subsetSize = CFGridWriter2.makeSizeEstimate(gds, gridList, null, null, 1, null, dateRange, 1, true); System.out.printf("total size CGusfc only = %d%n", totalSize); System.out.printf("subset size CGusfc with date range = %d%n", subsetSize); assertTrue(subsetSize < totalSize); } }
@Test public void testSizeEstimateOnTP() throws Exception { String fileIn = TestDir.cdmUnitTestDir + "gribCollections/tp/GFSonedega.ncx4"; System.out.printf("Open %s%n", fileIn); try (GridDataset dataset = GridDataset.open(fileIn)) { List<String> gridList = new ArrayList<>(); gridList.add("Cloud_mixing_ratio_isobaric"); // static public long makeSizeEstimate(ucar.nc2.dt.GridDataset gds, List<String> gridList, // LatLonRect llbb, ProjectionRect projRect, int horizStride, Range zRange, // CalendarDateRange dateRange, int stride_time, boolean addLatLon) throws IOException, InvalidRangeException { CalendarDate date = CalendarDate.parseISOformat(null, "2015-03-26T06:00:00Z"); CalendarDateRange dateRange = CalendarDateRange.of( date, date); long totalSize = CFGridWriter2.makeSizeEstimate(dataset, gridList, null, null, 1, null, null, 1, true); long subsetSize = CFGridWriter2.makeSizeEstimate(dataset, gridList, null, null, 1, null, dateRange, 1, true); System.out.printf("total size Temp only = %d%n", totalSize); System.out.printf("subset size Temp only = %d%n", subsetSize); assertTrue(subsetSize == totalSize/2); } }
@Test public void checkNCSSDates() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/cdmUnitTest/ncss/climatology/PF5_SST_Climatology_Monthly_1985_2001.nc?var=sst&latitude=45&longitude=-20&temporal=all&accept=xml"); byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml); String results = new String(result, CDM.utf8Charset); if (show) System.out.printf("checkNCSSDates%n%s%n", results); Reader in = new StringReader( results ); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); XPathExpression<Element> xpath = XPathFactory.instance().compile("/stationFeatureCollection/stationFeature", Filters.element()); List<Element> dataTimeNodes = xpath.evaluate(doc); List<String> timePositionDateTime = new ArrayList<>(); for (Element e : dataTimeNodes) { CalendarDate cd = CalendarDate.parseISOformat(null, e.getAttributeValue("date")); System.out.printf(" extract date= %s%n", cd); timePositionDateTime.add(cd.toString());; } assertEquals(expectedDatesAsDateTime, timePositionDateTime); }
@Test public void checkWCSDates() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath("/wcs/cdmUnitTest/ncss/climatology/PF5_SST_Climatology_Monthly_1985_2001.nc?service=WCS&version=1.0.0&request=DescribeCoverage&coverage=sst"); byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml); Reader in = new StringReader( new String(result, CDM.utf8Charset)); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); Namespace wcs = Namespace.getNamespace("wcs", doc.getRootElement().getNamespaceURI()); Namespace gml = Namespace.getNamespace("gml", "http://www.opengis.net/gml"); XPathExpression<Element> xpath = XPathFactory.instance().compile("//wcs:temporalDomain/gml:timePosition", Filters.element(), null, wcs, gml); List<Element> timePositionNodes = xpath.evaluate(doc); List<String> timePositionDateTime = new ArrayList<>(); for (Element e : timePositionNodes) { System.out.printf("Date= %s%n", e.getText()); CalendarDate cd = CalendarDate.parseISOformat(null, e.getText()); timePositionDateTime.add(cd.toString()); } assertEquals(expectedDatesAsDateTime, timePositionDateTime); }
@Test // 1 runtime, 1 time (Time2DCoordSys case 1b) public void test1Runtime1TimeIntervalEdge() 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("test1Runtime1TimeInterval 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-01T00:00:00Z"); params.set(SubsetParams.runtime, runtime); CalendarDate time = CalendarDate.parseISOformat(null, "2015-03-06T19:30:00Z"); // (6,12), (12,18) params.set(SubsetParams.time, time); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); testGeoArray(geo, runtime, time, null); Array data = geo.getData(); Index ai = data.getIndex(); float testValue = data.getFloat(ai.set(0, 0, 3, 0)); Assert2.assertNearlyEquals(0.244f, testValue); } }
@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); } }