public double getIncrement() { if (!(coordinateAxis instanceof CoordinateAxis1D)) { return Double.NaN; } return convertAxis ? ((CoordinateAxis1D) coordinateAxis).getIncrement() * conversionFactor : ((CoordinateAxis1D) coordinateAxis).getIncrement(); }
VertCoord(CoordinateAxis1D axis) { this.axis = axis; this.name = axis.getFullName(); this.units = axis.getUnitsString(); int n = (int) axis.getSize(); if (axis.isInterval()) { values1 = axis.getBound1(); values2 = axis.getBound2(); } else { values1 = new double[n]; for (int i = 0; i < axis.getSize(); i++) values1[i] = axis.getCoordValue(i); } }
/** * true if increasing z coordinate values means "up" in altitude */ @Override public boolean isZPositive() { 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; return vertZaxis.getAxisType() != AxisType.Pressure; }
@Override public CoordinateAxis copyNoCache() { CoordinateAxis1D axis = new CoordinateAxis1D(ncd, getParentGroup(), getShortName(), getDataType(), getDimensionsString(), getUnitsString(), getDescription()); // other state axis.axisType = this.axisType; axis.boundaryRef = this.boundaryRef; axis.isContiguous = this.isContiguous; axis.positive = this.positive; axis.cache = new Variable.Cache(); // decouple cache return axis; }
/** * Copy constructor * @param ncd ok to reparent * @param org copy from here */ CoordinateAxis1D(NetcdfDataset ncd, CoordinateAxis1D org) { super(ncd, org); this.orgName = org.orgName; this.cache = new Variable.Cache(); // decouple cache org.setCaching(true); // copy rest of state this.increment = org.getIncrement(); this.isAscending = org.isAscending; this.isInterval = org.isInterval(); this.isRegular = org.isRegular(); this.coords = org.getCoordValues(); this.edge = org.getCoordEdges(); this.names = org.names; if (isInterval) { this.bound1 = org.getBound1(); this.bound2 = org.getBound2(); } this.wasBoundsDone = org.wasBoundsDone; this.wasCalcRegular = org.wasCalcRegular; this.wasRead = org.wasRead; }
/** * Sets the scale and offset coefficients in the given "grid to CRS" transform if possible. * This method is invoked only for variables that represent a coordinate system axis. */ @Override protected boolean trySetTransform(final Matrix gridToCRS, final int srcDim, final int tgtDim, final Vector values) throws IOException, DataStoreException { if (variable instanceof CoordinateAxis1D) { final CoordinateAxis1D axis = (CoordinateAxis1D) variable; if (axis.isRegular()) { gridToCRS.setElement(tgtDim, srcDim, axis.getIncrement()); gridToCRS.setElement(tgtDim, gridToCRS.getNumCol() - 1, axis.getStart()); return true; } } return super.trySetTransform(gridToCRS, srcDim, tgtDim, values); }
public void setVertical(CoordinateAxis1D vaxis) { int n = (int) vaxis.getSize(); double size = vaxis.getCoordValue(n - 1) - vaxis.getCoordValue(0); double resolution = vaxis.getIncrement(); String units = vaxis.getUnitsString(); this.updown = new Range(vaxis.getCoordValue(0), size, resolution, units); if (units != null) { setZPositiveUp(SimpleUnit.isCompatible("m", units)); } }
double scaler = (xaxis.getUnitsString().equalsIgnoreCase("km")) ? 1000.0 : 1.0; double xStart = xaxis.getCoordEdge(0) * scaler; double yStart = yaxis.getCoordEdge(0) * scaler; double xInc = xaxis.getIncrement() * scaler; double yInc = Math.abs(yaxis.getIncrement()) * scaler; if (yaxis.getCoordValue(0) < yaxis.getCoordValue(1)) { data = data.flip(0); yStart = yaxis.getCoordEdge((int) yaxis.getSize()) * scaler; if (!xaxis.isRegular() || !yaxis.isRegular()) { throw new IllegalArgumentException("Must be evenly spaced grid = " + grid.getFullName());
int[] maxValues = new int[ndim]; maxValues[0] = (int) ( xaxis.getSize() - 1 ); maxValues[1] = (int) ( yaxis.getSize() - 1 ); if ( zaxis != null ) maxValues[2] = (int) ( zaxis.getSize() - 1 ); origin[0] = xaxis.getStart(); origin[1] = yaxis.getStart(); if ( zaxis != null ) origin[2] = zaxis.getStart(); xoffset[0] = xaxis.getIncrement(); rectifiedGridElem.addContent( new Element( "offsetVector", gmlNS) yoffset[1] = yaxis.getIncrement(); rectifiedGridElem.addContent( new Element( "offsetVector", gmlNS ) zoffset[2] = zaxis.getIncrement(); rectifiedGridElem.addContent( new Element( "offsetVector", gmlNS )
/** * Given a coordinate position, find what grid element contains it, or is closest to it. * * @param coordVal position in this coordinate system * @return index of grid point containing it, or best estimate of closest grid interval. */ public int findCoordElementBounded(double coordVal) { if (!isNumeric()) throw new UnsupportedOperationException("CoordinateAxis.findCoordElementBounded() on non-numeric"); if (isRegular()) return findCoordElementRegular(coordVal, true); if (isContiguous()) return findCoordElementIrregular(coordVal, true); else return findCoordElementNonContiguous(coordVal, true); }
public Axis( CoordinateAxis1D coordAxis) { this.coordAxis = coordAxis; this.name = this.coordAxis.getFullName(); this.label = this.coordAxis.getFullName(); this.description = this.coordAxis.getDescription(); this.isNumeric = this.coordAxis.isNumeric(); this.values = new ArrayList<String>(); for ( int i = 0; i < this.coordAxis.getSize(); i++ ) this.values.add( this.coordAxis.getCoordName( i ).trim() ); }
public boolean isRegular() { return coordinateAxis instanceof CoordinateAxis1D && ((CoordinateAxis1D) coordinateAxis).isRegular(); }
TimeCoord(Date runDate, CoordinateAxis1D axis) { this.axis = axis; DateUnit unit = null; try { unit = new DateUnit(axis.getUnitsString()); } catch (Exception e) { throw new IllegalArgumentException("Not a unit of time "+axis.getUnitsString()); } int n = (int) axis.getSize(); offset = new double[n]; for (int i = 0; i < axis.getSize(); i++) { Date d = unit.makeDate(axis.getCoordValue(i)); offset[i] = getOffsetInHours(runDate, d); } }
double[] xCoords = xAxis.getCoordValues(); double[] yCoords = yAxis.getCoordValues(); double maxY = upperRigth.getY(); int minY_idx = yAxis.findCoordElement(minY); int maxY_idx = yAxis.findCoordElement(maxY); int minX_idx = xAxis.findCoordElement(minX); int maxX_idx = xAxis.findCoordElement(maxX); Range xRange = new Range(Math.min(minX_idx, maxX_idx), Math.max(minX_idx, maxX_idx), horizStride);
/** * Get the list of names, to be used for user selection. * The ith one refers to the ith coordinate. * * @return List of ucar.nc2.util.NamedObject, or empty list. */ public List<NamedObject> getNames() { int n = getDimension(0).getLength(); List<NamedObject> names = new ArrayList<>(n); for (int i = 0; i < n; i++) names.add(new ucar.nc2.util.NamedAnything(getCoordName(i), getShortName() + " " + getUnitsString())); return names; }
double[] bounds1 = getBound1(); double[] bounds2 = getBound2(); int n = bounds1.length; return bounded ? n - 1 : -1; int[] idx = findSingleHit(bounds1, bounds2, target); if (idx[0] == 0 && !bounded) return -1; // no hits if (idx[0] == 1) return idx[1]; // one hit return findClosest(coords, target); return bounded ? n - 1 : -1; int[] idx = findSingleHit(bounds2, bounds1, target); if (idx[0] == 0 && !bounded) return -1; // no hits if (idx[0] == 1) return idx[1]; return findClosest(getCoordValues(), target);
return axis1D.getCoordValues(); return axis1D.getCoordEdges(); double[] bounds1 = axis1D.getBound1(); double[] bounds2 = axis1D.getBound2(); int count = 0; for (int i = 0; i < n; i++) {
/** * The "name" of the ith coordinate. If nominal, this is all there is to a coordinate. * If numeric, this will return a String representation of the coordinate. * * @param index which one ? * @return the ith coordinate value as a String */ public String getCoordName(int index) { if (!wasRead) doRead(); if (isNumeric()) return Format.d(getCoordValue(index), 5, 8); else return names[index]; }