Java Code Examples for ucar.nc2.time.CalendarDate#parseISOformat()
The following examples show how to use
ucar.nc2.time.CalendarDate#parseISOformat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsistentDatesTest.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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, StandardCharsets.UTF_8)); 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); }
Example 2
Source File: MFileCollectionManager.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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; }
Example 3
Source File: TestCoverageSubsetTime.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test // 1 runtime, all times (Time2DCoordSys case 1c) public void testConstantRuntime() 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("testConstantRuntime 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); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); CoverageCoordSys geoCs = geo.getCoordSysForData(); CoverageCoordAxis runtimeAxis = geoCs.getAxis(AxisType.RunTime); Assert.assertNotNull(runtimeAxis); Assert.assertTrue(runtimeAxis instanceof CoverageCoordAxis1D); Assert.assertEquals(1, runtimeAxis.getNcoords()); CoverageCoordAxis1D runtimeAxis1D = (CoverageCoordAxis1D) runtimeAxis; Assert.assertEquals("runtime coord", runtime, runtimeAxis.makeDate(runtimeAxis1D.getCoordMidpoint(0))); CoverageCoordAxis1D timeAxis = (CoverageCoordAxis1D) geoCs.getAxis(AxisType.TimeOffset); Assert.assertNotNull(timeAxis); Assert.assertEquals(92, timeAxis.getNcoords()); Assert.assertEquals(CoverageCoordAxis.Spacing.discontiguousInterval, timeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, timeAxis.getStartValue()); Assert2.assertNearlyEquals(384.0, timeAxis.getEndValue()); // LOOK need to test data } }
Example 4
Source File: TestCoverageSubsetTime.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDiscontiguousIntervalSubsetTimeRange() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/GFS_Global_2p5deg_20150301_0000.grib2.ncx4"; String covName = "Total_precipitation_surface_Mixed_intervals_Accumulation"; logger.debug("testDiscontiguousIntervalTime Dataset {} coverage {}", endpoint, covName); try (FeatureDatasetCoverage featureDatasetCoverage = CoverageDatasetFactory.open(endpoint)) { assertThat(featureDatasetCoverage).isNotNull(); CoverageCollection coverageCollection = featureDatasetCoverage.findCoverageDataset(FeatureType.GRID); assertThat(coverageCollection).isNotNull(); Coverage coverage = coverageCollection.findCoverage(covName); assertThat(coverage).isNotNull(); SubsetParams params = new SubsetParams(); CalendarDate runTime = CalendarDate.parseISOformat(null, "2015-03-01T00:00:00Z"); params.setRunTime(runTime); CalendarDate subsetTimeStart = CalendarDate.parseISOformat(null, "2015-03-02T06:00:00Z"); CalendarDate subsetTimeEnd = CalendarDate.parseISOformat(null, "2015-03-02T12:00:00Z"); // expect: any interval containing or ending on the start or end times // idx keep interval // 08 N (24.000000, 27.000000) == (2015-03-02T00:00:00Z, 2015-03-02T03:00:00Z) // 09 Y (24.000000, 30.000000) == (2015-03-02T00:00:00Z, 2015-03-02T06:00:00Z) // 10 Y (30.000000, 33.000000) == (2015-03-02T06:00:00Z, 2015-03-02T09:00:00Z) // 11 Y (30.000000, 36.000000) == (2015-03-02T06:00:00Z, 2015-03-02T12:00:00Z) // 12 N (36.000000, 39.000000) == (2015-03-02T12:00:00Z, 2015-03-02T15:00:00Z) int expectedStartIndex = 9; int expectedEndIndex = 11; params.setTimeRange(CalendarDateRange.of(subsetTimeStart, subsetTimeEnd)); logger.debug(" subset {}", params); GeoReferencedArray geo = coverage.readData(params); assertThat(geo).isNotNull(); CoverageCoordAxis timeAxis = geo.findCoordAxis("time"); assertThat(timeAxis).isNotNull(); assertThat(timeAxis.getSpacing()).isEqualTo(Spacing.discontiguousInterval); assertThat(timeAxis.getRange()).isEqualTo(new Range(expectedStartIndex, expectedEndIndex)); } }
Example 5
Source File: TestGridCoverageRemoteP.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 6
Source File: TestAggExisting.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void testStartAndEnd(Variable timeVar, String start, String end) throws IOException { Array vals = timeVar.read(); int[] shape = vals.getShape(); // check start date of aggregation CalendarDateUnit calendarDateUnit = getCalendarDateUnit(timeVar); CalendarDate calendarDate = calendarDateUnit.makeCalendarDate(vals.getInt(0)); CalendarDate expected = CalendarDate.parseISOformat(calendarDateUnit.getCalendar().name(), start); assertThat(calendarDate).isEqualTo(expected); // check end date of aggregation calendarDate = calendarDateUnit.makeCalendarDate(vals.getInt(shape[0] - 1)); expected = CalendarDate.parseISOformat(calendarDateUnit.getCalendar().name(), end); assertThat(calendarDate).isEqualTo(expected); }
Example 7
Source File: RadarServerController.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
CalendarDate parseTime(String timeString) { if (timeString == null) return null; if (timeString.equalsIgnoreCase("present")) { return CalendarDate.present(); } else { return CalendarDate.parseISOformat(null, timeString); } }
Example 8
Source File: DsgSubsetWriterTest.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void setupClass() throws URISyntaxException { // The WaterML marshaller usually initializes wml2:generationDate and om:resultTime to "now". This is a problem, // because those values will always differ from the fixed values we have in our expectedResultResource files. // So, to facilitate testing, we're going to fix the values that the marshaller emits. MarshallingUtil.fixedGenerationDate = CalendarDate.of(Calendar.gregorian, 1970, 1, 1, 0, 0, 0); MarshallingUtil.fixedResultTime = CalendarDate.of(Calendar.gregorian, 1970, 1, 1, 0, 0, 0); ncssDiskCache = new NcssDiskCache(DiskCache2.getDefault().getRootDirectory()); subsetParamsAll = new SubsetParams(); subsetParamsAll.setVariables(Arrays.asList("pr", "tas")); subsetParamsPoint = new SubsetParams(); subsetParamsPoint.setVariables(Arrays.asList("pr")); subsetParamsPoint.setTime(CalendarDate.parseISOformat(null, "1970-01-01 02:00:00Z")); // Full extension is (40.0, -100.0) to (68.0, -58.0). LatLonRect bbox = new LatLonRect(LatLonPoint.create(40.0, -100.0), LatLonPoint.create(53.0, -58.0)); subsetParamsPoint.setLatLonBoundingBox(bbox); subsetParamsStation1 = new SubsetParams(); subsetParamsStation1.setVariables(Arrays.asList("tas")); CalendarDate start = CalendarDate.parseISOformat(null, "1970-01-05T00:00:00Z"); CalendarDate end = CalendarDate.parseISOformat(null, "1970-02-05T00:00:00Z"); subsetParamsStation1.setTimeRange(CalendarDateRange.of(start, end)); subsetParamsStation1.setStations(Arrays.asList("AAA", "CCC")); subsetParamsStation2 = new SubsetParams(); subsetParamsStation2.setVariables(Arrays.asList("pr", "tas")); // The nearest will be "1970-01-21 00:00:00Z" subsetParamsStation2.setTime(CalendarDate.parseISOformat(null, "1970-01-21 01:00:00Z")); }
Example 9
Source File: TestRadarUF.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void checkMetadata() throws IOException { String fileIn = TestDir.cdmUnitTestDir + "formats/uf/" + fname; try (ucar.nc2.NetcdfFile ncf = ucar.nc2.NetcdfFiles.open(fileIn)) { Attribute att = ncf.findGlobalAttribute("StationLongitude"); Assert.assertEquals(lon, att.getNumericValue().doubleValue(), 0.001); att = ncf.findGlobalAttribute("StationLatitude"); Assert.assertEquals(lat, att.getNumericValue().doubleValue(), 0.001); att = ncf.findGlobalAttribute("StationElevationInMeters"); Assert.assertEquals(height, att.getNumericValue().doubleValue(), 0.1); att = ncf.findGlobalAttribute("instrument_name"); Assert.assertEquals(radarName, att.getStringValue()); att = ncf.findGlobalAttribute("site_name"); Assert.assertEquals(siteName, att.getStringValue()); att = ncf.findGlobalAttribute("time_coverage_start"); CalendarDate date = CalendarDate.parseISOformat(null, att.getStringValue()); Assert.assertEquals(start, date); att = ncf.findGlobalAttribute("time_coverage_end"); date = CalendarDate.parseISOformat(null, att.getStringValue()); Assert.assertEquals(end, date); } }
Example 10
Source File: TestAggExistingNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void testStartAndEnd(Variable timeVar, String start, String end) throws IOException { Array vals = timeVar.read(); int[] shape = vals.getShape(); // check start date of aggregation CalendarDateUnit calendarDateUnit = getCalendarDateUnit(timeVar); CalendarDate calendarDate = calendarDateUnit.makeCalendarDate(vals.getInt(0)); CalendarDate expected = CalendarDate.parseISOformat(calendarDateUnit.getCalendar().name(), start); assertThat(calendarDate).isEqualTo(expected); // check end date of aggregation calendarDate = calendarDateUnit.makeCalendarDate(vals.getInt(shape[0] - 1)); expected = CalendarDate.parseISOformat(calendarDateUnit.getCalendar().name(), end); assertThat(calendarDate).isEqualTo(expected); }
Example 11
Source File: TestGrib2Records.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TestGrib2Records(String ds, int gdsTemplate, int param, long datalen, String refdateIso) { this.filename = "../grib/src/test/data/" + ds; this.gdsTemplate = gdsTemplate; this.pdsTemplate = param; this.datalen = datalen; this.refdate = CalendarDate.parseISOformat("ISO8601", refdateIso); this.check = gdsTemplate >= 0; }
Example 12
Source File: TestGribCoverageSubsetP.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 13
Source File: TestGridAsPointP.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
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); }
Example 14
Source File: TestCoverageSubsetTime.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test // all runtimes, 1 time (Time2DCoordSys case 2a) not time interval public void testConstantForecast() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Pressure_convective_cloud_bottom"; logger.debug("testConstantForecast 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 time = CalendarDate.parseISOformat(null, "2015-03-01T15:00:00Z"); params.set(SubsetParams.time, time); params.set(SubsetParams.runtimeAll, true); logger.debug(" subset {}", params); GeoReferencedArray geo = cover.readData(params); CoverageCoordSys geoCs = geo.getCoordSysForData(); CoverageCoordAxis1D runtimeAxis = (CoverageCoordAxis1D) geoCs.getAxis(AxisType.RunTime); Assert.assertNotNull(runtimeAxis); Assert.assertEquals(3, runtimeAxis.getNcoords()); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, runtimeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, runtimeAxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(6.0, runtimeAxis.getResolution()); CoverageCoordAxis timeAxis = geoCs.getAxis(AxisType.Time); if (timeAxis != null) { Assert.assertTrue(timeAxis instanceof CoverageCoordAxis1D); Assert.assertEquals(1, timeAxis.getNcoords()); CoverageCoordAxis1D timeAxis1D = (CoverageCoordAxis1D) timeAxis; if (timeAxis.isInterval()) { CalendarDate lower = timeAxis1D.makeDate(timeAxis1D.getCoordEdge1(0)); Assert.assertTrue("time coord lower", !lower.isAfter(time)); // lower <= time CalendarDate upper = timeAxis1D.makeDate(timeAxis1D.getCoordEdge2(0)); Assert.assertTrue("time coord lower", !upper.isBefore(time)); // upper >= time } else { Assert.assertEquals("time coord", time, timeAxis1D.makeDate(timeAxis1D.getCoordMidpoint(0))); } } CoverageCoordAxis timeOffsetAxis = geoCs.getAxis(AxisType.TimeOffset); if (timeOffsetAxis != null) { Assert.assertTrue(timeOffsetAxis instanceof TimeOffsetAxis); Assert.assertEquals(3, timeOffsetAxis.getNcoords()); Assert.assertEquals(CoverageCoordAxis.DependenceType.dependent, timeOffsetAxis.getDependenceType()); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, timeOffsetAxis.getSpacing()); // LOOK wrong } } }
Example 15
Source File: TestCoverageSubsetTime.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testDiscontiguousIntervalSubsetSpecificOffsets() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/GFS_Global_2p5deg_20150301_0000.grib2.ncx4"; String covName = "Total_precipitation_surface_Mixed_intervals_Accumulation"; logger.debug("testDiscontiguousIntervalSubsetSpecificOffsets Dataset {} coverage {}", endpoint, covName); try (FeatureDatasetCoverage featureDatasetCoverage = CoverageDatasetFactory.open(endpoint)) { assertThat(featureDatasetCoverage).isNotNull(); CoverageCollection coverageCollection = featureDatasetCoverage.findCoverageDataset(FeatureType.GRID); assertThat(coverageCollection).isNotNull(); Coverage coverage = coverageCollection.findCoverage(covName); assertThat(coverage).isNotNull(); SubsetParams params = new SubsetParams(); CalendarDate runTime = CalendarDate.parseISOformat(null, "2015-03-01T00:00:00Z"); params.setRunTime(runTime); double intervalStart = 30; double intervalStop = 33; params.setTimeOffsetIntv(new double[] {intervalStart, intervalStop}); logger.debug(" subset {}", params); // expect: any interval [(]start, stop] containing the requested time // idx interval // 08 (24.000000, 27.000000) == (2015-03-02T00:00:00Z, 2015-03-02T03:00:00Z) // 09 (24.000000, 30.000000) == (2015-03-02T00:00:00Z, 2015-03-02T06:00:00Z) // 10 (30.000000, 33.000000) == (2015-03-02T06:00:00Z, 2015-03-02T09:00:00Z) // 11 (30.000000, 36.000000) == (2015-03-02T06:00:00Z, 2015-03-02T12:00:00Z) // 12 (36.000000, 39.000000) == (2015-03-02T12:00:00Z, 2015-03-02T15:00:00Z) int expectedStartIndex = 10; // only one match :-) int expectedEndIndex = expectedStartIndex; GeoReferencedArray geo = coverage.readData(params); assertThat(geo).isNotNull(); CoverageCoordAxis timeAxis = geo.findCoordAxis("time"); assertThat(timeAxis).isNotNull(); assertThat(timeAxis.getSpacing()).isEqualTo(Spacing.discontiguousInterval); assertThat(timeAxis.getRange()).isEqualTo(new Range(expectedStartIndex, expectedEndIndex)); params = new SubsetParams(); params.setRunTime(runTime); intervalStart = 30; intervalStop = 36; params.setTimeOffsetIntv(new double[] {intervalStart, intervalStop}); logger.debug(" subset {}", params); // expect: any interval [(]start, stop] containing the requested time // idx interval // 08 (24.000000, 27.000000) == (2015-03-02T00:00:00Z, 2015-03-02T03:00:00Z) // 09 (24.000000, 30.000000) == (2015-03-02T00:00:00Z, 2015-03-02T06:00:00Z) // 10 (30.000000, 33.000000) == (2015-03-02T06:00:00Z, 2015-03-02T09:00:00Z) // 11 (30.000000, 36.000000) == (2015-03-02T06:00:00Z, 2015-03-02T12:00:00Z) // 12 (36.000000, 39.000000) == (2015-03-02T12:00:00Z, 2015-03-02T15:00:00Z) expectedStartIndex = 11; // only one match :-) expectedEndIndex = expectedStartIndex; geo = coverage.readData(params); assertThat(geo).isNotNull(); timeAxis = geo.findCoordAxis("time"); assertThat(timeAxis).isNotNull(); assertThat(timeAxis.getSpacing()).isEqualTo(Spacing.discontiguousInterval); assertThat(timeAxis.getRange()).isEqualTo(new Range(expectedStartIndex, expectedEndIndex)); } }
Example 16
Source File: TestCoverageSubsetTime.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testDiscontiguousIntervalSubsetSpecificOffsetsNoExactMatch() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/GFS_Global_2p5deg_20150301_0000.grib2.ncx4"; String covName = "Total_precipitation_surface_Mixed_intervals_Accumulation"; logger.debug("testDiscontiguousIntervalSubsetSpecificOffsetsNoExactMatch Dataset {} coverage {}", endpoint, covName); try (FeatureDatasetCoverage featureDatasetCoverage = CoverageDatasetFactory.open(endpoint)) { assertThat(featureDatasetCoverage).isNotNull(); CoverageCollection coverageCollection = featureDatasetCoverage.findCoverageDataset(FeatureType.GRID); assertThat(coverageCollection).isNotNull(); Coverage coverage = coverageCollection.findCoverage(covName); assertThat(coverage).isNotNull(); SubsetParams params = new SubsetParams(); CalendarDate runTime = CalendarDate.parseISOformat(null, "2015-03-01T00:00:00Z"); params.setRunTime(runTime); double intervalStart = 30; double intervalStop = 39; params.setTimeOffsetIntv(new double[] {intervalStart, intervalStop}); logger.debug(" subset {}", params); // expect: any interval [(]start, stop] containing the requested time // idx interval // 08 (24.000000, 27.000000) == (2015-03-02T00:00:00Z, 2015-03-02T03:00:00Z) // 09 (24.000000, 30.000000) == (2015-03-02T00:00:00Z, 2015-03-02T06:00:00Z) // 10 (30.000000, 33.000000) == (2015-03-02T06:00:00Z, 2015-03-02T09:00:00Z) // 11 (30.000000, 36.000000) == (2015-03-02T06:00:00Z, 2015-03-02T12:00:00Z) // 12 (36.000000, 39.000000) == (2015-03-02T12:00:00Z, 2015-03-02T15:00:00Z) // no exact match on interval, so for now match closest midpoint with smallest width // midpoint is 34.9 // 10 has midpoint of 31.5 // 11 has midpoint of 33 // 12 has midpoint of 37.5 // so index 11 is closest int expectedStartIndex = 11; int expectedEndIndex = expectedStartIndex; GeoReferencedArray geo = coverage.readData(params); assertThat(geo).isNotNull(); CoverageCoordAxis timeAxis = geo.findCoordAxis("time"); assertThat(timeAxis).isNotNull(); assertThat(timeAxis.getSpacing()).isEqualTo(Spacing.discontiguousInterval); assertThat(timeAxis.getRange()).isEqualTo(new Range(expectedStartIndex, expectedEndIndex)); } }
Example 17
Source File: TestCoverageHorizSubset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test @Category(NeedsCdmUnitTest.class) public void testLongitudeSubsetWithHorizontalStride() throws IOException, InvalidRangeException { String filename = TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_onedeg_20100913_0000.grib2"; String gribId = "VAR_0-3-0_L1"; try (FeatureDatasetCoverage featureDatasetCoverage = CoverageDatasetFactory.open(filename)) { CoverageCollection coverageCollection = featureDatasetCoverage.findCoverageDataset(FeatureType.GRID); Coverage coverage = coverageCollection.findCoverageByAttribute(Grib.VARIABLE_ID_ATTNAME, gribId); final CalendarDate validTime = CalendarDate.parseISOformat(null, "2010-09-21T00:00:00Z"); HorizCoordSys origHcs = coverage.getCoordSys().getHorizCoordSys(); // Next, create the subset param and make the request SubsetParams params = new SubsetParams(); // subset Time axis params.setTime(validTime); // subset across the seam final LatLonRect subsetLatLonRequest = new LatLonRect(LatLonPoint.create(-15, -10), 30, 20); params.setLatLonBoundingBox(subsetLatLonRequest); // set a horizontal stride final int stride = 2; params.setHorizStride(stride); // make subset GeoReferencedArray geo = coverage.readData(params); // Check that TimeAxis is 1D, has one coordinate, and it's equal to the time we requested CoverageCoordAxis timeAxis = geo.getCoordSysForData().getTimeAxis(); assertThat(timeAxis).isInstanceOf(CoverageCoordAxis1D.class); CoverageCoordAxis1D timeAxis1d = (CoverageCoordAxis1D) timeAxis; assertThat(timeAxis1d.getNcoords()).isEqualTo(1); assertThat(timeAxis1d.makeDate((double) timeAxis1d.getCoordObject(0))).isEqualTo(validTime); // make sure the bounding box requested by subset is contained within the // horizontal coordinate system of the GeoReferencedArray produced by the // subset HorizCoordSys subsetHcs = geo.getCoordSysForData().getHorizCoordSys(); assertThat(subsetLatLonRequest.containedIn(subsetHcs.calcLatLonBoundingBox())).isTrue(); // make sure resolution of the lat and lon grids of the subset take into account the stride // by comparing the resolution CoverageCoordAxis1D origLonAxis = origHcs.getXAxis(); CoverageCoordAxis1D origLatAxis = origHcs.getYAxis(); CoverageCoordAxis1D subsetLonAxis = subsetHcs.getXAxis(); CoverageCoordAxis1D subsetLatAxis = subsetHcs.getYAxis(); final double tol = 0.001; assertThat(origLonAxis.getResolution()).isNotWithin(tol).of(subsetLonAxis.getResolution()); assertThat(origLonAxis.getResolution()).isWithin(tol).of(subsetLonAxis.getResolution() / stride); assertThat(origLatAxis.getResolution()).isNotWithin(tol).of(subsetLatAxis.getResolution()); assertThat(origLatAxis.getResolution()).isWithin(tol).of(subsetLatAxis.getResolution() / stride); // check to make sure we get data from both sides of the seam by testing that // half of the array isn't empty. // slice along longitude in the middle of the array. Array geoData = geo.getData(); int middle = geoData.getShape()[1] / 2; Array data = geo.getData().slice(2, middle).reduce(); // flip the array int numValsToSum = 3; Array dataFlip = data.flip(0); Section sec = Section.builder().appendRange(0, numValsToSum).build(); IndexIterator dii = data.getIndexIterator(); IndexIterator diiFlip = dataFlip.getIndexIterator(); final double initialSumVal = 0; double sumData = initialSumVal; double sumDataFlip = initialSumVal; for (int i = 0; i < numValsToSum - 1; i++) { double val = dii.getDoubleNext(); double valFlip = diiFlip.getDoubleNext(); // only sum if not missing if (!geo.isMissing(val)) sumData += val; if (!geo.isMissing(valFlip)) sumDataFlip += valFlip; } assertThat(sumData).isNotEqualTo(initialSumVal); assertThat(sumDataFlip).isNotEqualTo(initialSumVal); } }
Example 18
Source File: WcsRequestParser.java From tds with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static CalendarDateRange parseTime(String time) throws thredds.server.wcs.v1_0_0_1.WcsException { if (time == null || time.equals("")) return null; CalendarDateRange dateRange; // try { if (time.contains(",")) { log.debug("parseTime(): Unsupported time parameter (list) [" + time + "]."); throw new thredds.server.wcs.v1_0_0_1.WcsException( thredds.server.wcs.v1_0_0_1.WcsException.Code.InvalidParameterValue, "TIME", "Not currently supporting time list."); // String[] timeList = time.split( "," ); // dateRange = new DateRange( date, date, null, null ); } else if (time.contains("/")) { String[] timeRange = time.split("/"); if (timeRange.length != 2) { log.debug("parseTime(): Unsupported time parameter (time range with resolution) [" + time + "]."); throw new thredds.server.wcs.v1_0_0_1.WcsException( thredds.server.wcs.v1_0_0_1.WcsException.Code.InvalidParameterValue, "TIME", "Not currently supporting time range with resolution."); } dateRange = CalendarDateRange.of(CalendarDate.parseISOformat(null, timeRange[0]), CalendarDate.parseISOformat(null, timeRange[1])); } else { CalendarDate date = CalendarDate.parseISOformat(null, time); dateRange = CalendarDateRange.of(date, date); } } /* * catch ( ParseException e ) * { * log.debug( "parseTime(): Failed to parse time parameter [" + time + "]: " + e.getMessage() ); * throw new WcsException( WcsException.Code.InvalidParameterValue, "TIME", * "Invalid time format [" + time + "]." ); * } */ return dateRange; }
Example 19
Source File: DefaultConventions.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override @Nullable protected AxisType getAxisType(VariableDS.Builder vb) { AxisType result = getAxisTypeCoards(vb); if (result != null) { return result; } String vname = vb.shortName; if (vname == null) { return null; } String unit = vb.getUnits(); if (unit == null) { unit = ""; } String desc = vb.getDescription(); if (desc == null) { desc = ""; } if (vname.equalsIgnoreCase("x") || findAlias(vb).equalsIgnoreCase("x")) { return AxisType.GeoX; } if (vname.equalsIgnoreCase("lon") || vname.equalsIgnoreCase("longitude") || findAlias(vb).equalsIgnoreCase("lon")) { return AxisType.Lon; } if (vname.equalsIgnoreCase("y") || findAlias(vb).equalsIgnoreCase("y")) { return AxisType.GeoY; } if (vname.equalsIgnoreCase("lat") || vname.equalsIgnoreCase("latitude") || findAlias(vb).equalsIgnoreCase("lat")) { return AxisType.Lat; } if (vname.equalsIgnoreCase("lev") || findAlias(vb).equalsIgnoreCase("lev") || (vname.equalsIgnoreCase("level") || findAlias(vb).equalsIgnoreCase("level"))) { return AxisType.GeoZ; } if (vname.equalsIgnoreCase("z") || findAlias(vb).equalsIgnoreCase("z") || vname.equalsIgnoreCase("altitude") || desc.contains("altitude") || vname.equalsIgnoreCase("depth") || vname.equalsIgnoreCase("elev") || vname.equalsIgnoreCase("elevation")) { if (SimpleUnit.isCompatible("m", unit)) // units of meters { return AxisType.Height; } } if (vname.equalsIgnoreCase("time") || findAlias(vb).equalsIgnoreCase("time")) { if (SimpleUnit.isDateUnit(unit)) { return AxisType.Time; } } if (vname.equalsIgnoreCase("time") && vb.dataType == DataType.STRING) { if (vb.orgVar != null) { try { Array firstValue = vb.orgVar.read("0"); if (firstValue instanceof ArrayObject.D1) { ArrayObject.D1 sarry = (ArrayObject.D1) firstValue; String firstStringValue = (String) sarry.get(0); if (CalendarDate.parseISOformat(null, firstStringValue) != null) { // valid iso date string LOOK return AxisType.Time; } } } catch (IOException | InvalidRangeException e) { logger.warn("time string error", e); } } } return null; }
Example 20
Source File: DefaultConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected AxisType getAxisType(NetcdfDataset ds, VariableEnhanced ve) { AxisType result = getAxisTypeCoards(ds, ve); if (result != null) return result; Variable v = (Variable) ve; String vname = v.getShortName(); if (vname == null) return null; String unit = v.getUnitsString(); if (unit == null) unit = ""; String desc = v.getDescription(); if (desc == null) desc = ""; if (vname.equalsIgnoreCase("x") || findAlias(ds, v).equalsIgnoreCase("x")) return AxisType.GeoX; if (vname.equalsIgnoreCase("lon") || vname.equalsIgnoreCase("longitude") || findAlias(ds, v).equalsIgnoreCase("lon")) return AxisType.Lon; if (vname.equalsIgnoreCase("y") || findAlias(ds, v).equalsIgnoreCase("y")) return AxisType.GeoY; if (vname.equalsIgnoreCase("lat") || vname.equalsIgnoreCase("latitude") || findAlias(ds, v).equalsIgnoreCase("lat")) return AxisType.Lat; if (vname.equalsIgnoreCase("lev") || findAlias(ds, v).equalsIgnoreCase("lev") || (vname.equalsIgnoreCase("level") || findAlias(ds, v).equalsIgnoreCase("level"))) return AxisType.GeoZ; if (vname.equalsIgnoreCase("z") || findAlias(ds, v).equalsIgnoreCase("z") || vname.equalsIgnoreCase("altitude") || desc.contains("altitude") || vname.equalsIgnoreCase("depth") || vname.equalsIgnoreCase("elev") || vname.equalsIgnoreCase("elevation")) { if (SimpleUnit.isCompatible("m", unit)) // units of meters return AxisType.Height; } if (vname.equalsIgnoreCase("time") || findAlias(ds, v).equalsIgnoreCase("time")) { if (SimpleUnit.isDateUnit(unit)) return AxisType.Time; } if (vname.equalsIgnoreCase("time") && v.getDataType() == DataType.STRING) { try { Array firstValue = v.read("0"); if (firstValue instanceof ArrayObject.D1) { ArrayObject.D1 sarry = (ArrayObject.D1) firstValue; String firstStringValue = (String) sarry.get(0); if (CalendarDate.parseISOformat(null, firstStringValue) != null) // valid iso date string return AxisType.Time; } } catch (IOException | InvalidRangeException e) { logger.warn("time string error", e); } } return null; }