public int[] getShape() { if (getDependenceType() == CoverageCoordAxis.DependenceType.scalar) return new int[0]; return new int[]{ncoords}; }
private List<CoverageCoordAxis> axisAndDependents(CoverageCoordAxis axis, CoverageCoordSys csys) { List<CoverageCoordAxis> result = new ArrayList<>(); if (axis.getDependenceType() != CoverageCoordAxis.DependenceType.dependent) result.add(axis); for (CoverageCoordAxis dependent : csys.getDependentAxes(axis)) result.add(dependent); return result; } }
public boolean isTime2D( CoverageCoordAxis axis) { if (time2DCoordSys == null) return false; if (axis instanceof TimeOffsetAxis) return true; if (axis instanceof TimeAxis2DFmrc) return true; return (axis.getAxisType() == AxisType.RunTime) && (axis.getDependenceType() != CoverageCoordAxis.DependenceType.dependent); }
public String getIndependentAxisNamesOrdered() { StringBuilder sb = new StringBuilder(); for (CoverageCoordAxis axis : coordSys.getAxes()) { if (!(axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent)) continue; sb.append(axis.getName()); sb.append(" "); } return sb.toString(); }
private CoordsSet(boolean constantForecast, List<CoverageCoordAxis> axes) { this.constantForecast = constantForecast; List<CoverageCoordAxis1D> indAxes = new ArrayList<>(); int rank = 0; for (CoverageCoordAxis axis : axes) { if (axis.getDependenceType() != CoverageCoordAxis.DependenceType.dependent) // independent or scalar indAxes.add( (CoverageCoordAxis1D) axis); if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) rank++; } this.axes = axes; this.shape = new int[rank]; int count = 0; for (CoverageCoordAxis1D axis : indAxes) { if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) shape[count++] = axis.getNcoords(); } }
public RangeIterator getRangeIterator() { if (getDependenceType() == CoverageCoordAxis.DependenceType.scalar) return Range.EMPTY; try { return new Range(axisType.toString(), 0, ncoords - 1); } catch (InvalidRangeException e) { throw new RuntimeException(e); } }
public Range getRange() { if (getDependenceType() == CoverageCoordAxis.DependenceType.scalar) return Range.EMPTY; try { return new Range(axisType.toString(), 0, ncoords - 1); } catch (InvalidRangeException e) { throw new RuntimeException(e); } }
private CoverageCoordAxis1D findDependent( CoverageCoordAxis independentAxis, AxisType axisType) { for (CoverageCoordAxis axis : axes) { if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.dependent) { for (String axisName : axis.dependsOn) { if (axisName.equalsIgnoreCase(independentAxis.getName()) && axis.getAxisType() == axisType) return (CoverageCoordAxis1D) axis; } } } return null; } }
public List<RangeIterator> getRanges() { List<RangeIterator> result = new ArrayList<>(); for (CoverageCoordAxis axis : getAxes()) { if (axis.getAxisType().isHoriz()) continue; if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) result.add(axis.getRangeIterator()); } result.addAll(horizCoordSys.getRanges()); // may be 2D return result; }
indent.incr(); f.format("%s", getDependenceType()); if (dependsOn.size() > 0) { f.format(" :");
private void addDimensions(CoverageCollection subsetDataset, NetcdfFileWriter writer) { // each independent coordinate is a dimension Map<String, Dimension> dimHash = new HashMap<>(); for (CoverageCoordAxis axis : subsetDataset.getCoordAxes()) { if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) { Dimension d = writer.addDimension(null, axis.getName(), axis.getNcoords()); dimHash.put(axis.getName(), d); } if (axis.isInterval()) { if (null == dimHash.get(BOUNDS_DIM)) { Dimension d = writer.addDimension(null, BOUNDS_DIM, 2); dimHash.put(BOUNDS_DIM, d); } } } }
if (axis.getAxisType().isHoriz()) continue; if (isTime2D(axis)) continue; if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) rank++; if (axis.getAxisType().isHoriz()) continue; if (isTime2D(axis)) continue; if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) result[count++] = axis.getNcoords();
@Test public void testGridCoverageDatasetRdavm() throws IOException, InvalidRangeException { if (showDetails) System.out.printf("%s%n", filename); try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, fdc); for (CoverageCollection cc : fdc.getCoverageCollections()) { 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())); //} if (showDetails) 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()); } } } }
private void addCoordinateAxes(CoverageCollection subsetDataset, NetcdfFileWriter writer) { for (CoverageCoordAxis axis : subsetDataset.getCoordAxes()) { String dims; if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.independent) { dims = axis.getName(); } else if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.scalar) { dims = ""; } else { dims = axis.getDependsOn(); } boolean hasBounds = false; if (axis.isInterval()) { Variable vb = writer.addVariable(null, axis.getName()+BOUNDS, axis.getDataType(), dims+" "+BOUNDS_DIM); vb.addAttribute(new Attribute(CDM.UNITS, axis.getUnits())); hasBounds = true; } Variable v = writer.addVariable(null, axis.getName(), axis.getDataType(), dims); addVariableAttributes(v, axis.getAttributes()); v.addAttribute(new Attribute(CDM.UNITS, axis.getUnits())); // override what was in att list if (hasBounds) v.addAttribute(new Attribute(CF.BOUNDS, axis.getName()+BOUNDS)); if (axis.getAxisType() == AxisType.TimeOffset) v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_OFFSET)); } }
if (axis.getUnits() != null) builder.setUnits(axis.getUnits()); if (axis.getDescription() != null) builder.setDescription(axis.getDescription()); builder.setDepend(convertDependenceType(axis.getDependenceType())); for (String s : axis.getDependsOnList()) builder.addDependsOn(s);
@Test public void testGaussianLats() throws IOException { String filename = TestDir.cdmUnitTestDir + "formats/grib1/cfs.wmo"; try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); String gridName = "Albedo_surface_Average"; 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); CoverageCoordAxis latAxis = csys.getAxis(AxisType.Lat); Assert.assertNotNull(AxisType.RunTime.toString(), latAxis); Assert.assertTrue(latAxis.getClass().getName(), latAxis instanceof CoverageCoordAxis1D); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, latAxis.getSpacing()); Assert.assertEquals(CoverageCoordAxis.DependenceType.independent, latAxis.getDependenceType()); Attribute att = latAxis.findAttribute(CDM.GAUSSIAN); Assert.assertNotNull(att); Assert.assertEquals("true", att.getStringValue()); } }
@Test public void testTimeOffsetSubsetWhenTimePresent() throws IOException { String filename = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1"; String gridName = "Temperature_isobaric"; logger.debug("file {} coverage {}", filename, gridName); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); 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()); CoverageCoordAxis runtime = 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()); Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), runtime.makeDate(0)); } }
@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)); } }
@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()); } } } }
@Test public void test2DTimeCoordinates() 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.FMRC); Assert.assertNotNull(FeatureType.FMRC.toString(), cd); Coverage cov = cd.findCoverage(gridName); Assert.assertNotNull(gridName, cov); CoverageCoordSys csys = cov.getCoordSys(); Assert.assertNotNull("CoverageCoordSys", csys); 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.independent, runtime.getDependenceType()); Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), runtime.makeDate(0)); Assert2.assertNearlyEquals(6.0, runtime.getResolution()); CoverageCoordAxis time = csys.getAxis(AxisType.TimeOffset); Assert.assertNotNull(AxisType.TimeOffset.toString(), time); Assert.assertTrue(time.getClass().getName(), time instanceof TimeOffsetAxis); 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(true, csys.isTime2D(time)); } }