HorizCoordSys horizCoordSys = subsetDataset.getHorizCoordSys(); if (horizCoordSys.isLatLon2D()) { // We already have 2D lat/lon vars. return false;
private void addLatLon2D(CoverageCollection subsetDataset, NetcdfFileWriter writer) { HorizCoordSys horizCoordSys = subsetDataset.getHorizCoordSys(); CoverageCoordAxis1D xAxis = horizCoordSys.getXAxis(); CoverageCoordAxis1D yAxis = horizCoordSys.getYAxis(); Dimension xDim = writer.findDimension(xAxis.getName()); Dimension yDim = writer.findDimension(yAxis.getName()); assert xDim != null : "We should've added X dimension in addDimensions()."; assert yDim != null : "We should've added Y dimension in addDimensions()."; List<Dimension> dims = Arrays.asList(yDim, xDim); Variable latVar = writer.addVariable("lat", DataType.DOUBLE, dims); latVar.addAttribute(new Attribute(CDM.UNITS, CDM.LAT_UNITS)); latVar.addAttribute(new Attribute(CF.STANDARD_NAME, CF.LATITUDE)); latVar.addAttribute(new Attribute(CDM.LONG_NAME, "latitude coordinate")); latVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString())); Variable lonVar = writer.addVariable("lon", DataType.DOUBLE, dims); lonVar.addAttribute(new Attribute(CDM.UNITS, CDM.LON_UNITS)); lonVar.addAttribute(new Attribute(CF.STANDARD_NAME, CF.LONGITUDE)); lonVar.addAttribute(new Attribute(CDM.LONG_NAME, "longitude coordinate")); lonVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString())); }
@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); } }
Assert.assertEquals(FeatureType.CURVILINEAR, gds.getCoverageType()); HorizCoordSys hcs = gds.getHorizCoordSys(); Assert.assertNotNull(endpoint, hcs); Assert.assertTrue(endpoint, !hcs.isProjection());
private void writeLatLon2D(CoverageCollection subsetDataset, NetcdfFileWriter writer) throws IOException, InvalidRangeException { HorizCoordSys horizCoordSys = subsetDataset.getHorizCoordSys(); CoverageCoordAxis1D xAxis = horizCoordSys.getXAxis(); CoverageCoordAxis1D yAxis = horizCoordSys.getYAxis();
@Test public void TestGribCurvilinearSubset() 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 coverage = gds.findCoverage(covName); Assert.assertNotNull(covName, coverage); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(64.0, -61.), new LatLonPointImpl(59.0, -52.)); SubsetParams params = new SubsetParams().set(SubsetParams.timePresent, true).set(SubsetParams.latlonBB, bbox); GeoReferencedArray geo = coverage.readData(params); logger.debug("csys shape={}", Misc.showInts(geo.getCoordSysForData().getShape())); Array data = geo.getData(); logger.debug("data shape={}", Misc.showInts(data.getShape())); Assert.assertArrayEquals(geo.getCoordSysForData().getShape(), data.getShape()); int[] expectedShape = new int[] {1, 165, 161}; Assert.assertArrayEquals(expectedShape, data.getShape()); } }