public double getCoordEdgeFirst() { return getCoordEdge1(0); }
private boolean contains(double target, int coordIdx) { double midVal1 = axis.getCoordEdge1(coordIdx); double midVal2 = axis.getCoordEdge2(coordIdx); if (midVal1 < midVal2) return (midVal1 <= target && target <= midVal2); else return (midVal1 >= target && target >= midVal2); }
private boolean contains(double target, int coordIdx, boolean ascending) { double midVal1 = axis.getCoordEdge1(coordIdx); double midVal2 = axis.getCoordEdge2(coordIdx); if (ascending) return (midVal1 <= target && target <= midVal2); else return (midVal1 >= target && target >= midVal2); }
private int findCoordElementRegular(double coordValue, boolean bounded) { int n = axis.getNcoords(); if (n == 1 && bounded) return 0; double distance = coordValue - axis.getCoordEdge1(0); double exactNumSteps = distance / axis.getResolution(); //int index = (int) Math.round(exactNumSteps); // ties round to +Inf int index = (int) exactNumSteps; // truncate down if (bounded && index < 0) return 0; if (bounded && index >= n) return n - 1; // check that found point is within interval if (index >= 0 && index < n) { double lower = axis.getCoordEdge1(index); double upper = axis.getCoordEdge2(index); if (axis.isAscending()) { assert lower <= coordValue : lower + " should be le " + coordValue; assert upper >= coordValue : upper + " should be ge " + coordValue; } else { assert lower >= coordValue : lower + " should be ge " + coordValue; assert upper <= coordValue : upper + " should be le " + coordValue; } } return index; }
private double[] makeValues(int index) { double[] subsetValues = null; // null for regular switch (axis.getSpacing()) { case irregularPoint: subsetValues = new double[1]; subsetValues[0] = axis.getCoordMidpoint(index); break; case discontiguousInterval: case contiguousInterval: subsetValues = new double[2]; subsetValues[0] = axis.getCoordEdge1(index); subsetValues[1] = axis.getCoordEdge2(index); break; } return subsetValues; }
public double getCoordMidpoint(int index) { if (index < 0 || index >= getNcoords()) throw new IllegalArgumentException("Index out of range=" + index); loadValuesIfNeeded(); switch (spacing) { case regularPoint: return startValue + index * getResolution(); case irregularPoint: return values[index]; case regularInterval: return startValue + (index + .5) * getResolution(); case contiguousInterval: case discontiguousInterval: return (getCoordEdge1(index) + getCoordEdge2(index)) / 2; } throw new IllegalStateException("Unknown spacing=" + spacing); }
private int findCoordElementDiscontiguousInterval(double[] target, boolean bounded) { for (int i = 0; i < axis.getNcoords(); i++) { double edge1 = axis.getCoordEdge1(i); double edge2 = axis.getCoordEdge2(i); if (Misc.nearlyEquals(edge1, target[0]) && Misc.nearlyEquals(edge2, target[1])) return i; } return -1; }
@Override public Array getCoordBoundsAsArray() { Array result = Array.factory(getDataType(), new int[]{ncoords, 2}); int count = 0; for (int i = 0; i < ncoords; i++) { result.setDouble(count++, getCoordEdge1(i)); result.setDouble(count++, getCoordEdge2(i)); } return result; }
public Object getCoordObject(int index) { if (axisType == AxisType.RunTime) return makeDate(getCoordMidpoint(index)); if (isInterval()) return new double[]{getCoordEdge1(index), getCoordEdge2(index)}; return getCoordMidpoint(index); }
private List<LatLonPoint> calcLatLon1DBoundaryPoints(int maxPointsInYEdge, int maxPointsInXEdge) { if (!isLatLon1D) { throw new UnsupportedOperationException("Coordinate system is not 1D latitude/longitude."); } checkMaxPointsInEdges(maxPointsInYEdge, maxPointsInXEdge); int numYtotal = latAxis.getNcoords(); int numXtotal = lonAxis.getNcoords(); int strideY = calcStride(numYtotal, maxPointsInYEdge); int strideX = calcStride(numXtotal, maxPointsInXEdge); List<LatLonPoint> points = new LinkedList<>(); // Bottom boundary points for (int i = 0; i < numXtotal; i += strideX) { points.add(new LatLonPointImpl(latAxis.getCoordEdgeFirst(), lonAxis.getCoordEdge1(i))); } // Right boundary points for (int j = 0; j < numYtotal; j += strideY) { points.add(new LatLonPointImpl(latAxis.getCoordEdge1(j), lonAxis.getCoordEdgeLast())); } // Top boundary points for (int i = numXtotal - 1; i >= 0; i -= strideX) { points.add(new LatLonPointImpl(latAxis.getCoordEdgeLast(), lonAxis.getCoordEdge2(i))); } // Left boundary points for (int j = numYtotal - 1; j >= 0; j -= strideY) { points.add(new LatLonPointImpl(latAxis.getCoordEdge2(j), lonAxis.getCoordEdgeFirst())); } assertNotExceedingMaxBoundaryPoints(points.size(), maxPointsInYEdge, maxPointsInXEdge); return points; }
public List<NamedObject> getCoordValueNames() { loadValuesIfNeeded(); if (timeHelper != null) return timeHelper.getCoordValueNames(this); List<NamedObject> result = new ArrayList<>(); for (int i = 0; i < ncoords; i++) { Object value = null; switch (spacing) { case regularPoint: case irregularPoint: value = Format.d(getCoordMidpoint(i), 3); break; case regularInterval: case contiguousInterval: case discontiguousInterval: value = new CoordInterval(getCoordEdge1(i), getCoordEdge2(i), 3); break; } result.add(new NamedAnything(value, value + " " + getUnits())); } return result; }
points.add(new ProjectionPointImpl(xAxis.getCoordEdge1(i), yAxis.getCoordEdgeFirst())); points.add(new ProjectionPointImpl(xAxis.getCoordEdgeLast(), yAxis.getCoordEdge1(j)));
@Nonnull private CoverageCoordAxisBuilder subsetValuesClosest(double[] want) { int closest_index = findCoordElement(want, true); // bounded, always valid index if (closest_index < 0) findCoordElement(want, true); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(axis); if (axis.spacing == CoverageCoordAxis.Spacing.regularInterval) { double val1 = axis.getCoordEdge1(closest_index); double val2 = axis.getCoordEdge2(closest_index); builder.subset(1, val1, val2, val2-val1, null); } else { builder.subset(1, 0, 0, 0.0, makeValues(closest_index)); } try { builder.setRange(new Range(closest_index, closest_index)); } catch (InvalidRangeException e) { throw new RuntimeException(e); // cant happen } return builder; }
public List<NamedObject> getCoordValueNames(CoverageCoordAxis1D axis) { axis.loadValuesIfNeeded(); List<NamedObject> result = new ArrayList<>(); for (int i = 0; i < axis.getNcoords(); i++) { double value; switch (axis.getSpacing()) { case regularPoint: case irregularPoint: value = axis.getCoordMidpoint(i); result.add(new NamedAnything(makeDate(value), axis.getAxisType().toString())); break; case regularInterval: case contiguousInterval: case discontiguousInterval: CoordInterval coord = new CoordInterval(axis.getCoordEdge1(i), axis.getCoordEdge2(i), 3); result.add(new NamedAnything(coord, coord + " " + axis.getUnits())); break; } } return result; }
@Nonnull private CoverageCoordAxisBuilder subsetValuesClosest(double want) { int closest_index = findCoordElement(want, true); // bounded, always valid index CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(axis); if (axis.spacing == CoverageCoordAxis.Spacing.regularPoint) { double val = axis.getCoordMidpoint(closest_index); builder.subset(1, val, val, 0.0, null); } else if (axis.spacing == CoverageCoordAxis.Spacing.regularInterval) { double val1 = axis.getCoordEdge1(closest_index); double val2 = axis.getCoordEdge2(closest_index); builder.subset(1, val1, val2, val2-val1, null); } else { builder.subset(1, 0, 0, 0.0, makeValues(closest_index)); } try { builder.setRange(new Range(closest_index, closest_index)); } catch (InvalidRangeException e) { throw new RuntimeException(e); // cant happen } return builder; }
if (axis.isAscending()) { if (target < axis.getCoordEdge1(0)) return bounded ? 0 : -1; else if (target > axis.getCoordEdgeLast()) if (target > axis.getCoordEdge1(0)) return bounded ? 0 : -1; else if (target < axis.getCoordEdgeLast())
private void addAdjustedTimeCoords(SubsetParams result, CoverageCoordAxis1D axis, int coordIdx, CalendarDate runtime) { // this must be adjusted to be offset from the runtime. // adjust = end - start // axisCoordOffset + axis.reftime = offset + runtime // offset = axisCoordOffset + axis.reftime - runtime // offset = axisCoordOffset + adjust // offset = axisCoordOffset + end - start = axisCoordOffset + axis.reftime - runtime // therefore: end = reftime, start = runtime double adjust = axis.getOffsetInTimeUnits(runtime, axis.getRefDate()); if (axis.isInterval()) { double[] adjustVal = new double[] {axis.getCoordEdge1(coordIdx)+adjust, axis.getCoordEdge2(coordIdx)+adjust}; result.setTimeOffsetIntv(adjustVal); double mid = (adjustVal[0]+adjustVal[1]) / 2.0; result.set(SubsetParams.timeOffsetUnit, axis.makeDateInTimeUnits(runtime, mid)); // validation result.set(SubsetParams.timeOffsetUnit, axis.getCalendarDateUnit()); // validation } else { double adjustVal = axis.getCoordMidpoint(coordIdx) + adjust; result.setTimeOffset(adjustVal); result.set(SubsetParams.timeOffsetDate, axis.makeDateInTimeUnits(runtime, adjustVal)); // validation result.set(SubsetParams.timeOffsetUnit, axis.getCalendarDateUnit()); // validation } }
CoverageCoordAxis1D timeAxis1D = (CoverageCoordAxis1D) timeAxis; if (timeAxis.isInterval()) { Assert.assertTrue("time coord lower", timeAxis1D.getCoordEdge1(0) <= offsetVal); // lower <= time Assert.assertTrue("time coord lower", timeAxis1D.getCoordEdge2(0) >= offsetVal); // upper >= time
CoverageCoordAxis1D timeAxis1D = (CoverageCoordAxis1D) timeAxis; if (timeAxis.isInterval()) { CalendarDate lower = timeAxis1D.makeDate(timeAxis1D.getCoordEdge1(0)); Assert.assertTrue("time coord lower", !lower.isAfter(time)); // lower <= time CalendarDate upper = timeAxis1D.makeDate(timeAxis1D.getCoordEdge2(0));
CalendarDate lower = timeAxis1D.makeDate(timeAxis1D.getCoordEdge1(0)); Assert.assertTrue("time coord lower", !lower.isAfter(time)); // lower <= time CalendarDate upper = timeAxis1D.makeDate(timeAxis1D.getCoordEdge2(0));