/** * Returns a coordinate for the given two-dimensional grid coordinate axis. * This is (indirectly) a callback method for {@link #getAxes()}. */ @Override protected double coordinateForAxis(final Object axis, final int j, final int i) { return (axis instanceof CoordinateAxis2D) ? ((CoordinateAxis2D) axis).getCoordValue(j, i) : Double.NaN; } }
@Override protected Variable copy() { return new CoordinateAxis2D(this.ncd, this); }
/** * Only call if isInterval() * * @return bounds array pr null if not an interval */ public ArrayDouble.D3 getCoordBoundsArray() { if (coords == null) doRead(); return makeBoundsFromAux(); }
/** * @deprecated use getEdges() */ public ArrayDouble.D2 getXEdges() { ArrayDouble.D2 mids = getCoordValuesArray(); return makeEdges(mids); }
CoordinateAxis2D yAxis =(CoordinateAxis2D) coordSystem.getYHorizAxis(); int[] xShape = xAxis.getShape(); int[] yShape = yAxis.getShape(); LatLonPoint prev = fromProj.projToLatLon(xAxis.getCoordValue(0, 0), yAxis.getCoordValue(0, 0)); double x = xAxis.getCoordValue(i, 0); double y = yAxis.getCoordValue(i, 0); double x = xAxis.getCoordValue(xShape[0]-1, i); double y = yAxis.getCoordValue(xShape[0]-1, i); double x = xAxis.getCoordValue(i, xShape[1]-1); double y = yAxis.getCoordValue(i, xShape[1]-1); double x = xAxis.getCoordValue(0, i); double y = yAxis.getCoordValue(0, i);
public int findTimeIndexFromCalendarDate(int run_idx, CalendarDate want) throws IOException, InvalidRangeException { CoordinateAxisTimeHelper helper = getCoordinateAxisTimeHelper(); double wantOffset = helper.offsetFromRefDate(want); if (isInterval()) { ArrayDouble.D3 bounds = getCoordBoundsArray(); if (bounds == null) throw new IllegalStateException("getCoordBoundsArray returned null for coordinate "+getFullName()); ArrayDouble.D2 boundsForRun = (ArrayDouble.D2) bounds.slice(0,run_idx ); int idx = findSingleHit(boundsForRun, wantOffset); if (idx >= 0) return idx; if (idx == -1) return -1; // multiple hits = choose closest to the midpoint return findClosest(boundsForRun, wantOffset); } else { ArrayDouble.D2 values = getCoordValuesArray(); ArrayDouble.D1 valuesForRun = (ArrayDouble.D1) values.slice(0,run_idx ); for (int i=0; i<valuesForRun.getSize(); i++) { if (Misc.nearlyEquals(valuesForRun.get(i), wantOffset)) return i; } return -1; } }
/** * Get the coordinate values as a 1D double array, in canonical order. * * @return coordinate values * @throws UnsupportedOperationException if !isNumeric() */ public double[] getCoordValues() { if (coords == null) doRead(); if (!isNumeric()) throw new UnsupportedOperationException("CoordinateAxis2D.getCoordValues() on non-numeric"); return (double[]) coords.get1DJavaArray(double.class); }
private void doRead() { Array data; try { data = read(); // if (!hasCachedData()) setCachedData(data, false); //cache data for subsequent reading } catch (IOException ioe) { log.error("Error reading coordinate values " + ioe); throw new IllegalStateException(ioe); } if (data.getRank() != 2) throw new IllegalArgumentException("must be 2D"); if (debug) System.out.printf("Coordinate2D read%n"); coords = (ArrayDouble.D2) Array.factory(DataType.DOUBLE, data.getShape(), data.get1DJavaArray(DataType.DOUBLE)); if (this.axisType == AxisType.Lon) makeConnectedLon(coords); }
CoordinateAxisTimeHelper helper = tcoord2D.getCoordinateAxisTimeHelper(); if (timeCoord2DBoundsArray == null) timeCoord2DBoundsArray = tcoord2D.getCoordBoundsArray(); for (int t = 0; t < timeDim.getLength(); t++) { if (isTimeInterval) { dtCoords.set("timeDateIntv", timeBoundsDate); } else { double timeCoord = tcoord2D.getCoordValue(rtIndex, t); CalendarDate timeCoordDate = helper.makeCalendarDateFromOffset(timeCoord); dtCoords.setTime(timeCoordDate);
if (axis2.isInterval()) { ArrayDouble.D3 bounds = axis2.getCoordBoundsArray(); for (int i = 0; i < axis2.getShape(0); i++) for (int j = 0; j < axis2.getShape(1); j++) { double start = bounds.get(i, j, 0); double end = bounds.get(i, j, 1);
public ArrayDouble.D2 getMidpoints() { if (midpoint == null) doRead(); return midpoint; }
static void readAllRuntimes(Coverage cover, GridDatatype dt, CoordinateAxis1DTime runtimeAxis, CoordinateAxis1D ensAxis, CoordinateAxis1D vertAxis) { GridCoordSystem csys = dt.getCoordinateSystem(); CoordinateAxis1DTime timeAxis1D = csys.getTimeAxis1D(); CoordinateAxis timeAxis = csys.getTimeAxis(); CoordinateAxis2D timeAxis2D = (timeAxis instanceof CoordinateAxis2D) ? (CoordinateAxis2D) timeAxis : null; if (runtimeAxis == null) readAllTimes1D(cover, dt, null, -1, timeAxis1D, ensAxis, vertAxis); else if (timeAxis2D == null) { // 1D time or no time for (int i = 0; i < runtimeAxis.getSize(); i++) readAllTimes1D(cover, dt, runtimeAxis.getCalendarDate(i), i, timeAxis1D, ensAxis, vertAxis); } else { // 2D time TimeHelper helper = TimeHelper.factory(timeAxis.getUnitsString(), timeAxis.getAttributeContainer()); if (timeAxis2D.isInterval()) { ArrayDouble.D3 bounds = timeAxis2D.getCoordBoundsArray(); for (int i = 0; i < runtimeAxis.getSize(); i++) readAllTimes2D(cover, dt, runtimeAxis.getCalendarDate(i), i, helper, bounds.slice(0, i), ensAxis, vertAxis); } else { ArrayDouble.D2 coords = timeAxis2D.getCoordValuesArray(); for (int i = 0; i < runtimeAxis.getSize(); i++) readAllTimes2D(cover, dt, runtimeAxis.getCalendarDate(i), i, helper, coords.slice(0, i), ensAxis, vertAxis); } } }
public ArrayDouble.D2 getXEdges() { ArrayDouble.D2 mids = getCoordValuesArray(); return makeXEdges(mids); }
public ArrayDouble.D2 getYEdges() { ArrayDouble.D2 mids = getCoordValuesArray(); return makeYEdges(mids); }
public static void main(String[] args) { double connect = connectLon(-167.258, 156.55109); System.out.printf("%f%n", connect); connect = connectLon(connect, 47.010693); System.out.printf("%f%n", connect); }
private boolean detIsPositive(double x0, double y0, double x1, double y1, double x2, double y2) { double det = (x1*y2 - y1*x2 -x0*y2 + y0*x2 + x0*y1 - y0*x1); if (det == 0) log.warn("determinate = 0 on lat/lon=" + latCoord.getFullName() + ", " + latCoord.getFullName()); // LOOK needed? return det > 0; }
/** * @deprecated use getCoordValuesArray */ public ArrayDouble.D2 getMidpoints() { return getCoordValuesArray(); }
CoordinateAxis2D yAxis =(CoordinateAxis2D) coordSystem.getYHorizAxis(); int[] xShape = xAxis.getShape(); int[] yShape = yAxis.getShape(); LatLonPoint prev = fromProj.projToLatLon(xAxis.getCoordValue(0, 0), yAxis.getCoordValue(0, 0)); double x = xAxis.getCoordValue(i, 0); double y = yAxis.getCoordValue(i, 0); double x = xAxis.getCoordValue(xShape[0]-1, i); double y = yAxis.getCoordValue(xShape[0]-1, i); double x = xAxis.getCoordValue(i, xShape[1]-1); double y = yAxis.getCoordValue(i, xShape[1]-1); double x = xAxis.getCoordValue(0, i); double y = yAxis.getCoordValue(0, i);
/** * Get the coordinate values as a 1D double array, in canonical order. * * @return coordinate values * @throws UnsupportedOperationException if !isNumeric() */ public double[] getCoordValues() { if (coords == null) doRead(); if (!isNumeric()) throw new UnsupportedOperationException("CoordinateAxis2D.getCoordValues() on non-numeric"); return (double[]) coords.get1DJavaArray(DataType.DOUBLE); }