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()); }
private void addGlobalAttributes(CoverageCollection gds, NetcdfFileWriter writer) { // global attributes for (Attribute att : gds.getGlobalAttributes()) { if (att.getShortName().equals(CDM.FILE_FORMAT)) continue; if (att.getShortName().equals(_Coordinate._CoordSysBuilder)) continue; writer.addGroupAttribute(null, att); } Attribute att = gds.findAttributeIgnoreCase(CDM.CONVENTIONS); if (att == null || !att.getStringValue().startsWith("CF-")) // preserve prev version of CF Convention if exists writer.addGroupAttribute(null, new Attribute(CDM.CONVENTIONS, "CF-1.0")); writer.addGroupAttribute(null, new Attribute("History", "Translated to CF-1.0 Conventions by Netcdf-Java CDM (CFGridCoverageWriter2)\n" + "Original Dataset = " + gds.getName() + "; Translation Date = " + CalendarDate.present())); LatLonRect llbb = gds.getLatlonBoundingBox(); if (llbb != null) { // this will replace any existing writer.addGroupAttribute(null, new Attribute(ACDD.LAT_MIN, llbb.getLatMin())); writer.addGroupAttribute(null, new Attribute(ACDD.LAT_MAX, llbb.getLatMax())); writer.addGroupAttribute(null, new Attribute(ACDD.LON_MIN, llbb.getLonMin())); writer.addGroupAttribute(null, new Attribute(ACDD.LON_MAX, llbb.getLonMax())); } }
CdmrFeatureProto.CoverageDataset.Builder encodeHeader(CoverageCollection gridDataset, String location) { CdmrFeatureProto.CoverageDataset.Builder builder = CdmrFeatureProto.CoverageDataset.newBuilder(); builder.setName(location); builder.setCoverageType(convertCoverageType(gridDataset.getCoverageType())); builder.setDateRange(encodeDateRange(gridDataset.getCalendarDateRange())); if (gridDataset.getLatlonBoundingBox() != null) builder.setLatlonRect(encodeRectangle(gridDataset.getLatlonBoundingBox())); if (gridDataset.getProjBoundingBox() != null) builder.setProjRect(encodeRectangle(gridDataset.getProjBoundingBox())); for (Attribute att : gridDataset.getGlobalAttributes()) builder.addAtts(NcStream.encodeAtt(att)); for (CoverageCoordSys gcs : gridDataset.getCoordSys()) builder.addCoordSys(encodeCoordSys(gcs)); for (CoverageTransform gct : gridDataset.getCoordTransforms()) builder.addCoordTransforms(encodeCoordTransform(gct)); for (CoverageCoordAxis axis : gridDataset.getCoordAxes()) builder.addCoordAxes(encodeCoordAxis(axis)); for (Coverage grid : gridDataset.getCoverages()) builder.addGrids(encodeGrid(grid)); return builder; }
LatLonRect llbb = gds.getLatlonBoundingBox(); ProjectionRect projBB = gds.getProjBoundingBox(); ProjectionImpl proj = csys.getProjection(); logger.info("ProjRect2 = {}", projBB2); SubsetParams subset = new SubsetParams().setLatLonBoundingBox(gds.getLatlonBoundingBox()); // should be the same! Optional<CoverageCoordSys> opt = csys.subset(subset); Assert.assertTrue(opt.isPresent());
LatLonRect llbb = gds.getLatlonBoundingBox(); ProjectionRect projBB = gds.getProjBoundingBox(); ProjectionImpl proj = csys.getProjection(); logger.info("ProjRect2 = {}", projBB2); SubsetParams subset = new SubsetParams().setLatLonBoundingBox(gds.getLatlonBoundingBox()); // should be the same! Optional<CoverageCoordSys> opt = csys.subset(subset); Assert.assertTrue(opt.isPresent());
LatLonRect llbb = gds.getLatlonBoundingBox(); Assert.assertNotNull("getLatlonBoundingBox", llbb); logger.debug("llbb={} ({})", llbb.toString2(), llbb); SubsetParams subset = new SubsetParams().setLatLonBoundingBox(gds.getLatlonBoundingBox()); // should be the same! Optional<CoverageCoordSys> opt = csys.subset(subset); Assert.assertTrue(opt.isPresent());
@Test @Category(NeedsExternalResource.class) public void testDodsSubset() throws Exception { String filename = "dods://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/CONUS_80km/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_surface"; 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.assertArrayEquals(new int[]{65, 361, 720}, cs.getShape()); LatLonRect llbb = gcs.getLatlonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); checkLatLonSubset(gcs, coverage, llbb_subset, new int[]{1, 35, 46}); } }
LatLonRect bb = gcd.getLatlonBoundingBox(); if (bb != null) rootElem.addContent(writeBoundingBox(bb));