GribCollectionImmutable.VariableIndex vindex = (GribCollectionImmutable.VariableIndex) coverage.getUserObject(); CoverageCoordSys orgCoordSys = coverage.getCoordSys(); ucar.nc2.util.Optional<CoverageCoordSys> opt = orgCoordSys.subset(params, false, true); if (!opt.isPresent()) throw new InvalidRangeException(opt.getErrorMessage()); CoverageCoordAxis runAxis = subsetCoordSys.getAxis(AxisType.RunTime); coordsSetAxes.addAll(axisAndDependents(runAxis, subsetCoordSys)); break; CoverageCoordAxis toAxis = subsetCoordSys.getAxis(AxisType.TimeOffset); if (toAxis != null) coordsSetAxes.addAll(axisAndDependents(toAxis, subsetCoordSys)); } else { CoverageCoordAxis toAxis = subsetCoordSys.getAxis(AxisType.Time); if (toAxis != null) coordsSetAxes.addAll(axisAndDependents(toAxis, subsetCoordSys)); CoverageCoordAxis1D vertAxis = (CoverageCoordAxis1D) subsetCoordSys.getZAxis(); coordsSetAxes.add(vertAxis); break; case timeIntv: case ens: CoverageCoordAxis axis = subsetCoordSys.getAxis(gribCoord.getType().axisType); coordsSetAxes.addAll(axisAndDependents(axis, subsetCoordSys)); break; geoArrayAxes.add(subsetCoordSys.getYAxis());
public CoverageAsPoint(CoverageCollection gcd, List<String> varNames, SubsetParams subset) throws IOException { this.gcd = gcd; this.subset = subset; latLonPoint = (LatLonPointImpl) subset.get(SubsetParams.latlonPoint); if (latLonPoint == null) throw new IllegalArgumentException("No latlon point"); varData = new ArrayList<>(varNames.size()); for (String varName : varNames) { Coverage cov = gcd.findCoverage(varName); // LOOK we should read all at once if possible if (cov != null) { varData.add(new VarData(cov)); if (dateUnit == null) { // assume all have the same time unit, just use the first one CoverageCoordSys csys = cov.getCoordSys(); CoverageCoordAxis timeAxis = csys.getTimeAxis(); this.dateUnit = timeAxis.getCalendarDateUnit(); } } } }
public Optional<CoverageCoordSys> subset(SubsetParams params, boolean makeCFcompliant, boolean finish) { Formatter errMessages = new Formatter(); List<CoverageCoordAxis> subsetAxes = new ArrayList<>(); for (CoverageCoordAxis axis : getAxes()) { if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.dependent) continue; if (axis.getAxisType().isHoriz()) continue; if (isTime2D(axis)) continue; for (CoverageCoordAxis dependent : getDependentAxes(subsetInd)) { Optional<CoverageCoordAxis> depo = dependent.subsetDependent(subsetInd); if (depo.isPresent()) subsetAxes.add(depo.get()); names.add(axis.getName()); CoverageCoordSys resultCoordSys = new CoverageCoordSys(null, names, this.getTransformNames(), this.getCoverageType()); MyCoordSysContainer fakeDataset = new MyCoordSysContainer(subsetAxes, getTransforms()); resultCoordSys.setDataset(fakeDataset); resultCoordSys.setHorizCoordSys(resultCoordSys.makeHorizCoordSys()); resultCoordSys.setIsConstantForecast(isConstantForecast.get()); if (finish) resultCoordSys.setImmutable();
public GeoReferencedArray(String coverageName, DataType dataType, Array data, CoverageCoordSys csSubset) { this.coverageName = coverageName; this.dataType = dataType; this.data = data; this.csSubset = csSubset; this.axes = csSubset.getAxes(); this.transforms = csSubset.getTransforms(); }
public HorizCoordSys makeHorizCoordSys() { CoverageCoordAxis xaxis = getAxis(AxisType.GeoX); CoverageCoordAxis yaxis = getAxis(AxisType.GeoY); CoverageCoordAxis lataxis = getAxis(AxisType.Lat); CoverageCoordAxis lonaxis = getAxis(AxisType.Lon); CoverageTransform hct = getHorizTransform(); return HorizCoordSys.factory((CoverageCoordAxis1D) xaxis, (CoverageCoordAxis1D) yaxis, lataxis, lonaxis, hct); }
@Test @Category(NeedsCdmUnitTest.class) public void testCrossLongitudeSeamGrib() throws Exception { String filename = TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_0p5deg_20100913_0000.grib2"; 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 = "VAR_2-0-0_L1"; Coverage coverage = gcs.findCoverageByAttribute(Grib.VARIABLE_ID_ATTNAME, gribId); // Land_cover_0__sea_1__land_surface Assert.assertNotNull(gribId, coverage); CoverageCoordSys cs = coverage.getCoordSys(); Assert.assertNotNull("coordSys", cs); System.out.printf(" org coverage shape=%s%n", Misc.showInts(cs.getShape())); HorizCoordSys hcs = cs.getHorizCoordSys(); Assert.assertNotNull("HorizCoordSys", hcs); Assert.assertEquals("rank", 3, cs.getShape().length); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 120.0); writeTestFile(gcs, coverage, bbox, new int[]{1, 21, 241}); } }
LatLonRect llbb = gds.getLatlonBoundingBox(); ProjectionRect projBB = gds.getProjBoundingBox(); ProjectionImpl proj = csys.getProjection(); ProjectionRect projBB2 = proj.latLonToProjBB(llbb); logger.info("ProjRect = {}", projBB); Optional<CoverageCoordSys> opt = csys.subset(subset); Assert.assertTrue(opt.isPresent()); Assert.assertEquals(csys.getXAxis().getNcoords(), csyss.getXAxis().getNcoords()); Assert.assertEquals(csys.getYAxis().getNcoords(), csyss.getYAxis().getNcoords());
Assert.assertNotNull(gcs); CoverageCoordAxis reftime = gcs.getAxis(AxisType.RunTime); Assert.assertNotNull(reftime); Assert.assertEquals(4, reftime.getNcoords()); assert cn.compareData("time", reftime.getCoordsAsArray(), Array.makeFromJavaArray(want), false); CoverageCoordAxis time = gcs.getTimeAxis(); Assert.assertNotNull(time); Assert.assertTrue(time instanceof TimeAxis2DFmrc);
assertNotNull("csys", csys); CoverageCoordAxis1D time = (CoverageCoordAxis1D) csys.getAxis(AxisType.Time); assertNotNull("time", time); Assert.assertEquals(1, time.getNcoords()); Assert.assertEquals(date, CalendarDate.parseISOformat(null, "2012-04-19T00:00:00Z")); CoverageCoordAxis1D vert = (CoverageCoordAxis1D) csys.getZAxis(); assertNotNull("vert", vert); Assert.assertEquals(1, vert.getNcoords());
Assert.assertNotNull(gcs); assert null == gcs.getZAxis(); CoverageCoordAxis time = gcs.getTimeAxis(); Assert.assertNotNull("time axis", time); double[] expect = new double[]{0., 6.0, 12.0, 18.0};
@Test public void testBestStride() throws IOException, InvalidRangeException { String endpoint = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; String covName = "Ozone_Mixing_Ratio_isobaric"; System.out.printf("Test Dataset %s%n", 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(); System.out.printf("csys shape = %s%n", Misc.showInts(csysShape)); SubsetParams params = new SubsetParams().setHorizStride(2); Optional<CoverageCoordSys> opt = csys.subset(params); if (!opt.isPresent()) { System.out.printf("err=%s%n", opt.getErrorMessage()); assert false; } CoverageCoordSys subsetCoordSys = opt.get(); int[] subsetShape = subsetCoordSys.getShape(); System.out.printf("csysSubset shape = %s%n", 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); } }
if (!gcs.isRegularSpatial()) throw new IllegalArgumentException("Must have 1D x and y axes for " + array.getCoverageName()); Projection proj = gcs.getProjection(); CoverageCoordAxis1D xaxis = (CoverageCoordAxis1D) gcs.getXAxis(); CoverageCoordAxis1D yaxis = (CoverageCoordAxis1D) gcs.getYAxis();
@Ignore("files not present") @Test public void testGridCoverageDatasetFmrc() throws IOException, InvalidRangeException { System.out.printf("%s%n", filename); try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.GRID.toString(), cc); System.out.printf(" %s type=%s%n", cc.getName(), cc.getCoverageType()); for (CoverageCoordSys coordSys : cc.getCoordSys()) { Assert.assertTrue( coordSys.isTime2D(coordSys.getAxis(AxisType.RunTime))); Assert.assertTrue( coordSys.isTime2D(coordSys.getTimeAxis())); } for (CoverageCoordAxis axis : cc.getCoordAxes()) { if (axis.getAxisType().isTime()) System.out.printf(" %12s %10s %5d %10s %s%n", axis.getName(), axis.getAxisType(), axis.getNcoords(), axis.getDependenceType(), axis.getSpacing()); } } } }
orgCoverages.add(orgGrid); CoverageCoordSys cs = orgGrid.getCoordSys(); orgCoordSys.put(cs.getName(), cs); for (String tname : cs.getTransformNames()) coordTransformSet.add(tname); Map<String, CoverageCoordSys> subsetCFCoordSys = new HashMap<>(); for (CoverageCoordSys orgCs : orgCoordSys.values()) { ucar.nc2.util.Optional<CoverageCoordSys> opt = orgCs.subset(params, true, false); // subsetCF make do some CF tweaks, not needed in regular subset if (!opt.isPresent()) return ucar.nc2.util.Optional.empty(opt.getErrorMessage()); subsetCFCoordSys.put(orgCs.getName(), subsetCoordSys); for (CoverageCoordAxis axis : subsetCoordSys.getAxes()) {
@Test public void testBestTimeCoordinates() throws IOException { String filename = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km.ncx4"; String gridName = "Pressure_surface"; try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); Assert.assertEquals(2, cc.getCoverageCollections().size()); CoverageCollection cd = cc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.GRID.toString(), cd); Coverage cov = cd.findCoverage(gridName); Assert.assertNotNull(gridName, cov); CoverageCoordSys csys = cov.getCoordSys(); Assert.assertNotNull("CoverageCoordSys", csys); CoverageCoordAxis time = csys.getAxis(AxisType.Time); Assert.assertNotNull(AxisType.Time.toString(), time); Assert.assertTrue(time.getClass().getName(), time instanceof CoverageCoordAxis1D); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, time.getSpacing()); Assert.assertEquals(CoverageCoordAxis.DependenceType.independent, time.getDependenceType()); Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), time.makeDate(0)); Assert2.assertNearlyEquals(6.0, time.getResolution()); Assert.assertEquals(false, csys.isTime2D(time)); CoverageCoordAxis runtime = csys.getAxis(AxisType.RunTime); Assert.assertNotNull(AxisType.RunTime.toString(), runtime); Assert.assertTrue(runtime.getClass().getName(), runtime instanceof CoverageCoordAxis1D); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, runtime.getSpacing()); Assert.assertEquals(CoverageCoordAxis.DependenceType.dependent, runtime.getDependenceType()); Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), runtime.makeDate(0)); } }
public GeoReferencedArray(String coverageName, DataType dataType, Array data, List<CoverageCoordAxis> axes, List<CoverageTransform> transforms, FeatureType type) { this.coverageName = coverageName; this.dataType = dataType; this.data = data; this.axes = axes; this.transforms = transforms; List<String> names = axes.stream().map(CoverageCoordAxis::getName).collect(Collectors.toList()); this.csSubset = new CoverageCoordSys(null, names, null, type); this.csSubset.setDataset(this); this.csSubset.setHorizCoordSys(this.csSubset.makeHorizCoordSys()); // check consistency Section cs = new Section(csSubset.getShape()); Section sdata = new Section(data.getShape()); assert cs.conformal(sdata); // reshape data if needed if (!cs.equalShape(sdata)) this.data = data.reshape(csSubset.getShape()); }
public boolean isRegularSpatial() { CoverageCoordAxis xaxis = getXAxis(); CoverageCoordAxis yaxis = getYAxis(); if (xaxis == null || !(xaxis instanceof CoverageCoordAxis1D) || !xaxis.isRegular()) return false; if (yaxis == null || !(yaxis instanceof CoverageCoordAxis1D) || !yaxis.isRegular()) return false; return true; }