CdmrFeatureProto.CoordAxis.Builder encodeCoordAxis(CoverageCoordAxis axis) { CdmrFeatureProto.CoordAxis.Builder builder = CdmrFeatureProto.CoordAxis.newBuilder(); builder.setName(axis.getName()); builder.setDataType(NcStream.convertDataType(axis.getDataType())); builder.setAxisType(convertAxisType(axis.getAxisType())); builder.setNvalues(axis.getNcoords()); 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); for (Attribute att : axis.getAttributes()) builder.addAtts(NcStream.encodeAtt(att)); builder.setSpacing(convertSpacing(axis.getSpacing())); builder.setStartValue(axis.getStartValue()); builder.setEndValue(axis.getEndValue()); builder.setResolution(axis.getResolution()); if (!axis.isRegular() && axis.getNcoords() < MAX_INLINE_NVALUES) { double[] values = axis.getValues(); ByteBuffer bb = ByteBuffer.allocate(8 * values.length); DoubleBuffer db = bb.asDoubleBuffer();
private void writeCoordinateData(CoverageCollection subsetDataset, NetcdfFileWriter writer) throws IOException, InvalidRangeException { for (CoverageCoordAxis axis : subsetDataset.getCoordAxes()) { Variable v = writer.findVariable(axis.getName()); if (v != null) { if (show) System.out.printf("CFGridCoverageWriter2 write axis %s%n", v.getNameAndDimensions()); writer.write(v, axis.getCoordsAsArray()); } else { logger.error("CFGridCoverageWriter2 No variable for %s%n", axis.getName()); } if (axis.isInterval()) { Variable vb = writer.findVariable(axis.getName() + BOUNDS); writer.write(vb, axis.getCoordBoundsAsArray()); } } }
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); }
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 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 Element writeAxis(CoverageCoordAxis axis) throws IOException { Element varElem = new Element("axis"); varElem.setAttribute("name", axis.getName()); varElem.setAttribute("shape", Misc.showInts(axis.getShape())); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); if (axis.getDependsOn() != null && axis.getDependsOn().trim().length() > 0) varElem.setAttribute("dependsOn", axis.getDependsOn().trim()); for (Attribute att : axis.getAttributes()) { varElem.addContent(ncmlWriter.makeAttributeElement(att)); if (!axis.isRegular()) { Array array = axis.getCoordsAsArray(); boolean isRealType = (array.getDataType() == DataType.DOUBLE) || (array.getDataType() == DataType.FLOAT); IndexIterator iter = array.getIndexIterator(); values.setAttribute("spacing", axis.getSpacing().toString()); values.setAttribute("npts", Long.toString(axis.getNcoords())); values.setAttribute("start", Double.toString(axis.getStartValue())); values.setAttribute("end", Double.toString(axis.getEndValue())); if (axis.getResolution() != 0.0) values.setAttribute("resolution", Double.toString(axis.getResolution()));
@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()); } } } }
Assert.assertEquals(4, reftime.getNcoords()); double[] want = new double[]{0., 12., 24., 36.}; CompareNetcdf2 cn = new CompareNetcdf2(); assert cn.compareData("time", reftime.getCoordsAsArray(), Array.makeFromJavaArray(want), false); Assert.assertEquals(16, time.getNcoords());
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)); } }
@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)); } }
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 (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 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
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; ucar.nc2.util.Optional<CoverageCoordAxis> axiso = axis.subset(params); if (!axiso.isPresent()) errMessages.format("%s: %s;%n", axis.getName(), axiso.getErrorMessage()); else { Optional<CoverageCoordAxis> depo = dependent.subsetDependent(subsetInd); if (depo.isPresent()) subsetAxes.add(depo.get()); else errMessages.format("%s;%n", depo.getErrorMessage()); names.add(axis.getName());
@Override protected void setDataset(CoordSysContainer dataset) { if (shape != null) throw new RuntimeException("Cant change axis, once dataset is set"); shape = new int[2]; assert dependsOn.size() == 2; CoverageCoordAxis axis1 = dataset.findCoordAxis(dependsOn.get(0)); if (axis1 == null) throw new IllegalStateException("TimeAxis2DSwath cant find axis with name "+dependsOn.get(0)); CoverageCoordAxis axis2 = dataset.findCoordAxis(dependsOn.get(1)); if (axis2 == null) throw new IllegalStateException("TimeAxis2DSwath cant find axis with name "+dependsOn.get(1)); shape[0] = axis1.getNcoords(); shape[1] = axis2.getNcoords(); assert shape[0] * shape[1] == this.getNcoords(); }
CalendarDate runtime = null; for (CoverageCoordAxis axis : axes) { if (axis.getDependenceType() == CoverageCoordAxis.DependenceType.dependent) continue; CoverageCoordAxis1D axis1D = (CoverageCoordAxis1D) axis; int coordIdx = (axis.getDependenceType() == CoverageCoordAxis.DependenceType.scalar) ? 0 : odo[odoIndex]; if (axis.getAxisType() == AxisType.RunTime) { runtime = (CalendarDate) coord; result.setRunTime(runtime); } else if (axis.getAxisType() == AxisType.Time) { CoverageCoordAxis1D runtimeForBest = findDependent(axis, AxisType.RunTime); if (runtimeForBest != null) { else if (axis.getAxisType().isVert()) { if (coord instanceof Double) result.setVertCoord( (Double) coord); else if (axis.getAxisType() == AxisType.Ensemble) result.setEnsCoord((Double) coord); else if (!constantForecast && axis.getAxisType() == AxisType.TimeOffset) { if (coord instanceof Double) result.setTimeOffset( (Double) coord); double val = axis.isInterval() ? (axis1D.getCoordEdge1(coordIdx) + axis1D.getCoordEdge2(coordIdx)) / 2.0 : axis1D.getCoordMidpoint(coordIdx); assert runtime != null; result.set(SubsetParams.timeOffsetDate, axis.makeDateInTimeUnits(runtime, val)); // validation
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();
@Override public CoverageCoordAxis findCoordAxis(String want) { for (CoverageCoordAxis axis : axes) if (axis.getName().equals(want)) return axis; return null; } }
@Override protected void setDataset(CoordSysContainer dataset) { if (shape != null) throw new RuntimeException("Cant change axis once set"); shape = new int[2]; String runtimeName = dependsOn.get(0); CoverageCoordAxis runtime = dataset.findCoordAxis(runtimeName); if (runtime == null) throw new IllegalStateException("FmrcTimeAxis2D cant find runtime axis with name "+runtimeName); assert runtime instanceof CoverageCoordAxis1D; assert runtime.getAxisType() == AxisType.RunTime; runCoord = (CoverageCoordAxis1D) runtime; shape[0] = runtime.getNcoords(); shape[1] = ncoords / shape[0]; }
return readLatLonAxis2DCoordValues((LatLonAxis2D) coordAxis); java.util.Optional<Coordinate> opt = group.findCoordinate(coordAxis.getName()); if (!opt.isPresent()) throw new IllegalStateException(); Coordinate coord = opt.get(); List<TimeCoord.Tinv> intv = ((CoordinateTimeIntv) coord).getTimeIntervals(); double[] values; if (coordAxis.getSpacing() == CoverageCoordAxis.Spacing.discontiguousInterval) { values = new double[2 * intv.size()]; int count = 0;
List<CoverageCoordAxis> coordList = coord2axisMap.get(axis); if (coordList != null) { for (CoverageCoordAxis coord : coordList) names.add(new NameAndType(coord.getName(), coord.getAxisType()));