Set<String> ignored = NetCDFUtilities.getIgnoredDimensions(); for (CoordinateAxis axis : dataset.getCoordinateAxes()) { final int axisDimensions = axis.getDimensions().size(); if (axisDimensions > 0 && axisDimensions < 3) { String axisName = axis.getFullName(); if (axis.getAxisType() != null) { coordinates.put(axisName, CoordinateVariable.create(axis)); } else { axis.setAxisType(AxisType.GeoZ); coordinates.put(axisName, CoordinateVariable.create(axis)); LOGGER.fine( "Detected unparseable unit string in time axis: '" + axis.getUnitsString() + "'."); axis.setAxisType(AxisType.Time); coordinates.put(axisName, CoordinateVariable.create(axis)); } else if (!ignored.contains(axisName)) {
/** * Check whether the Y axis need to be flipped. Note that the method is synchronized since it * access the underlying Variable * * @param axis * @return * @throws IOException */ private synchronized boolean needFlipYAxis(CoordinateAxis axis) throws IOException { boolean flipYAxis = false; try { Array yAxisStart = axis.read(new Section().appendRange(2)); float y1 = yAxisStart.getFloat(0); float y2 = yAxisStart.getFloat(1); if (y2 > y1) { flipYAxis = true; } } catch (InvalidRangeException e) { throw new RuntimeException(e); } return flipYAxis; }
try { if (zAxis != null) { String axisName = zAxis.getFullName(); if (!NetCDFCRSUtilities.VERTICAL_AXIS_NAMES.contains(axisName)) { return null; String units = zAxis.getUnitsString(); AxisType axisType = zAxis.getAxisType(); || axisType == AxisType.RadialElevation) v_datumType = "geoidal"; else if (axisType == AxisType.Height) { if (!zAxis.getShortName().equalsIgnoreCase("height")) { v_datumType = "depth"; v_crsName = if (CF.POSITIVE_DOWN.equalsIgnoreCase(zAxis.getPositive())) { direction = OPPOSITES.get(axisType); csMap, getAxis( zAxis.getShortName(), getDirection(direction), units));
@Override public boolean canHandle(CoordinateAxis axis) { if (axis != null && "time".equalsIgnoreCase(axis.getShortName()) && CLIMATOLOGICAL_UNITS.equalsIgnoreCase(axis.getUnitsString())) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Climatological Time Handler Spi can handle the axis"); } return true; } return false; }
protected void init() { if (!coordinateAxis.isNumeric() || !(coordinateAxis instanceof CoordinateAxis1D) || (coordinateAxis.hasMissing() && !AxisType.Time.equals(coordinateAxis.getAxisType()))) { // Not sure time variable can have actual NoData values in the array. // Let's exclude it from GeneralHelper case. // We may revisit it if we find some data with FillValues in the array. axisHelper = new CoordinateAxisGeneralHelper(); } else { axisHelper = new CoordinateAxis1DNumericHelper(); } }
public static Class<?> suggestBinding(CoordinateAxis coordinateAxis) { Utilities.ensureNonNull("coordinateAxis", coordinateAxis); final AxisType axisType = coordinateAxis.getAxisType(); case Spectral: final DataType dataType = coordinateAxis.getDataType(); Attribute scaleFactor = coordinateAxis.findAttribute("scale_factor"); Attribute offsetFactor = coordinateAxis.findAttribute("offset"); if (scaleFactor != null || offsetFactor != null) { return Double.class; case RunTime: LOGGER.log(Level.FINE, "Date mapping for axis:" + coordinateAxis.toString()); return java.util.Date.class; default: LOGGER.log(Level.FINE, "Unable to find mapping for axis:" + coordinateAxis.toString()); return null;
varElem.setAttribute("name", var.getFullName()); List dims = var.getDimensions(); for (int i=0; i<dims.size(); i++) { Dimension dim = (Dimension) dims.get(i); DataType dt = var.getDataType(); varElem.setAttribute("type", dt.toString()); for (Attribute att : var.getAttributes()) { varElem.addContent(makeAttribute(att, "attribute")); if (var.isMetadata() || (showCoords && var.getRank() <= 1)) varElem.addContent( makeValues( var)); varElem.setAttribute(CDM.UNITS, var.getUnitsString()); if (var.getAxisType() != null) varElem.setAttribute("axisType", var.getAxisType().toString()); String positive = var.getPositive(); if (positive != null) varElem.setAttribute(CF.POSITIVE, positive); String boundaryRef = var.getBoundaryRef(); if (boundaryRef != null) varElem.setAttribute("boundaryRef", boundaryRef); List csys = var.getCoordinateSystems(); if (csys.size() > 0) {
private Element writeAxis2(CoordinateAxis axis, String name) { if (axis == null) return null; Element varElem = new Element(name); varElem.setAttribute("name", axis.getFullName()); varElem.setAttribute("shape", getShapeString(axis.getShape())); // axis.getDimensionsString()); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); // attributes for (Attribute att : axis.getAttributes()) varElem.addContent(ucar.nc2.ncml.NcMLWriter.writeAttribute(att, "attribute", null)); Element values = ucar.nc2.ncml.NcMLWriter.writeValues(axis, null, false); values.setAttribute("npts", Long.toString(axis.getSize())); varElem.addContent(values); return varElem; }
@Override public boolean isZPositive() { CoordinateAxis vertZaxis = getVerticalAxis(); if (vertZaxis == null) return false; if (vertZaxis.getPositive() != null) { return vertZaxis.getPositive().equalsIgnoreCase(ucar.nc2.constants.CF.POSITIVE_UP); } if (vertZaxis.getAxisType() == AxisType.Height) return true; if (vertZaxis.getAxisType() == AxisType.Pressure) return false; return true; // default }
if ((axis.getAxisType() == AxisType.Lat) || (axis.getAxisType() == AxisType.Lon)|| (axis.getAxisType() == AxisType.Time)) for (Dimension dim : axis.getDimensions()) dimSet.add(dim); if ((time != null) && (time.getRank() == 0)) { st.addJoin(new JoinArray(time, JoinArray.Type.scalar, 0)); st.time = time.getShortName(); if ((axis.getAxisType() == AxisType.Time) && axis.isCoordinateVariable()) { time = axis; break; Dimension obsDim = time.getDimension(0); TableConfig st = new TableConfig(Table.Type.Structure, obsDim.getShortName()); st.structureType = TableConfig.StructureType.PsuedoStructure;
try { if (timeAxis != null) { AxisType type = timeAxis.getAxisType(); String units = timeAxis.getUnitsString(); if (CF.POSITIVE_DOWN.equalsIgnoreCase(timeAxis.getPositive())) { direction = OPPOSITES.get(type); origin = unitsParts[1].trim(); } else { final Attribute attribute = timeAxis.findAttribute("time_origin"); if (attribute != null) { origin = attribute.getStringValue(); String axisName = timeAxis.getShortName();
static String[] getUnitDirection(CoordinateAxis axis) { AxisType type = axis.getAxisType(); String units = axis.getUnitsString(); if (CF.POSITIVE_DOWN.equalsIgnoreCase(axis.getPositive())) { direction = OPPOSITES.get(type);
if ((axis.getAxisType() == AxisType.Lat) || (axis.getAxisType() == AxisType.Lon)|| (axis.getAxisType() == AxisType.Time)) for (Dimension dim : axis.getDimensions()) dimSet.add(dim); if ((time != null) && (time.getRank() == 0)) { st.addJoin(new JoinArray(time, JoinArray.Type.scalar, 0)); st.time = time.getShortName(); if ((axis.getAxisType() == AxisType.Time) && axis.isIndependentCoordinate()) { time = axis; break; Dimension obsDim = time.getDimension(0); TableConfig st = new TableConfig(Table.Type.Structure, obsDim.getShortName()); st.structureType = TableConfig.StructureType.PsuedoStructure;
/** * @param binding * @param coordinateAxis */ public CoordinateVariable(Class<T> binding, CoordinateAxis coordinateAxis) { Utilities.ensureNonNull("coordinateAxis", coordinateAxis); Utilities.ensureNonNull("binding", binding); this.binding = binding; this.coordinateAxis = coordinateAxis; this.conversionFactor = 1d; AxisType axisType = coordinateAxis.getAxisType(); // Special management for projected coordinates with unit = km if ((axisType == AxisType.GeoX || axisType == AxisType.GeoY) && coordinateAxis.getUnitsString().equalsIgnoreCase("km")) { conversionFactor = KM_TO_M; convertAxis = true; } }
@Test @Category(NeedsCdmUnitTest.class) public void testRegular() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/nuwg/03061219_ruc.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getUnitsString().equals("hectopascals"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 7; assert zaxis2.getUnitsString().equals("hectopascals"); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 2 : data.getShape()[0]; assert data.getShape()[1] == 7 : data.getShape()[1]; assert data.getShape()[2] == 22 : data.getShape()[2]; assert data.getShape()[3] == 31 : data.getShape()[3]; // check axes for (CoordinateAxis axis : gcs_section.getCoordinateAxes()) { assert axis.getAxisType() != null; } } }
public int compare(CoordinateAxis c1, CoordinateAxis c2) { AxisType t1 = c1.getAxisType(); AxisType t2 = c2.getAxisType(); if ((t1 == null) && (t2 == null)) return c1.getShortName().compareTo(c2.getShortName()); if (t1 == null) return -1; if (t2 == null) return 1; return t1.axisOrder() - t2.axisOrder(); }
private boolean isSwath(java.util.List<CoordinateSystem> csysList) { CoordinateSystem use = null; for (CoordinateSystem csys : csysList) { if (use == null) use = csys; else if (csys.getCoordinateAxes().size() > use.getCoordinateAxes().size()) use = csys; } if (use == null) return false; CoordinateAxis lat = use.getLatAxis(); CoordinateAxis lon = use.getLonAxis(); CoordinateAxis time = use.getTaxis(); if ((lat == null) || (lat.getRank() != 2)) return false; if ((lon == null) || (lon.getRank() != 2)) return false; if ((time == null)) return false; // must have time - otherwise it can be a grid // lat/lon must have the same dimensions if (!lat.getDimension(0).equals(lon.getDimension(0))) return false; if (!lat.getDimension(1).equals(lon.getDimension(1))) return false; Set<Dimension> dims = new HashSet<Dimension>(10); for (Dimension d : lat.getDimensions()) dims.add(d); for (Dimension d : lon.getDimensions()) dims.add(d); // diff with grid - time dimension(s) are a subset of lat/lon dimensions for (Dimension d : time.getDimensions()) { if (!dims.contains(d)) return false; } return true; }
private String getTimeAttribute(CoordinateSystem cs) { CoordinateAxis timeAxis = cs.getTaxis(); String name = timeAxis != null ? timeAxis.getFullName() : NetCDFUtilities.TIME_DIM; DimensionMapper dimensionMapper = reader.georeferencing.getDimensionMapper(); String timeAttribute = dimensionMapper.getDimension(name.toUpperCase()); if (timeAttribute == null) { // Fallback on standard name timeAttribute = dimensionMapper.getDimension(NetCDFUtilities.TIME_DIM); } return timeAttribute; }
AxisType axisType = axis.getAxisType(); if (axisType != null) { if (axisType == AxisType.GeoX) xAxis = lesserRank(xAxis, axis); List<Dimension> dims = axis.getDimensions(); for (Dimension dim : dims) { if (!domain.contains(dim))
@Test @Category(NeedsCdmUnitTest.class) public void testWRF() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/wrf/wrfout_v2_Lambert.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getSize() == 27; VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; assert vt.getUnitString().equals("Pa"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 13 : data.getShape()[0]; assert data.getShape()[1] == 9 : data.getShape()[1]; assert data.getShape()[2] == 20 : data.getShape()[2]; assert data.getShape()[3] == 25 : data.getShape()[3]; GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 9 : zaxis2.getSize(); assert zaxis2.getUnitsString().equals(zaxis.getUnitsString()); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); VerticalTransform vt_section = gcs_section.getVerticalTransform(); assert vt_section != null; assert vt_section.getUnitString().equals(vt.getUnitString()); } }