CoverageCoordAxisBuilder(CoverageCoordAxis from) { this.name = from.name; this.units = from.units; this.description = from.description; this.dataType = from.dataType; this.axisType = from.axisType; this.attributes = from.attributes; this.dependenceType = from.dependenceType; this.spacing = from.spacing; this.values = from.values; this.reader = from.reader; // used only if values == null this.dependsOn = from.dependsOn; this.startValue = from.startValue; this.endValue = from.endValue; this.resolution = from.resolution; this.ncoords = from.ncoords; this.isSubset = from.isSubset; this.timeHelper = from.timeHelper; if (from instanceof LatLonAxis2D) { LatLonAxis2D latlon = (LatLonAxis2D) from; this.shape = latlon.getShape(); this.userObject = latlon.getUserObject(); } }
@Override public Array getCoordBoundsAsArray() { // LOOK do we want to cache this ? return CoordinateAxis2D.makeEdges((ArrayDouble.D2) getCoordsAsArray()); // makeXEdges same as makeYEdges }
@Override public CoverageCoordAxis copy() { return new LatLonAxis2D(new CoverageCoordAxisBuilder(this)); }
public LatLonAxis2D subset(RangeIterator rangex, RangeIterator rangey) { CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(this); // subset the values double[] values = getValues(); int nx = rangex.length(); int ny = rangey.length(); double[] svalues = new double[nx * ny]; int count = 0; for (int y : rangey) for (int x : rangex) svalues[count++] = values[y * nx + x]; builder.values = svalues; builder.isSubset = true; builder.ncoords = nx * ny; builder.shape = new int[]{ny, nx}; return new LatLonAxis2D(builder); }
HorizCoordSys2D(LatLonAxis2D latCoord, LatLonAxis2D lonCoord) { super(null, null, latCoord, lonCoord, null); int[] shape = latCoord.getShape(); // y, x nrows = shape[0]; ncols = shape[1]; }
assert Arrays.equals(latAxis2D.getShape(), lonAxis2D.getShape()) : "2D lat/lon axes ought to have the same shape"; int[] midpointsShape = latAxis2D.getShape().clone(); // Clone because we will modify later. int strideX = calcStride(numXtotal, maxPointsInXEdge); ArrayDouble.D2 latEdges = (ArrayDouble.D2) latAxis2D.getCoordBoundsAsArray(); ArrayDouble.D2 lonEdges = (ArrayDouble.D2) lonAxis2D.getCoordBoundsAsArray();
} else { List<RangeIterator> ranges = opt.get(); lataxisSubset = latAxis2D.subset(ranges.get(1), ranges.get(0)); // x, y lonaxisSubset = lonAxis2D.subset(ranges.get(1), ranges.get(0)); lataxisSubset = latAxis2D.subset(new Range(0, ncols-1, horizStride), new Range(0, nrows-1, horizStride)); lonaxisSubset = lonAxis2D.subset(new Range(0, ncols-1, horizStride), new Range(0, nrows-1, horizStride)); } catch (InvalidRangeException e) { errMessages.format("%s;%n", e.getMessage()); if (lataxisSubset == null) lataxisSubset = (LatLonAxis2D) latAxis2D.copy(); if (lonaxisSubset == null) lonaxisSubset = (LatLonAxis2D) lonAxis2D.copy();
@Override public List<RangeIterator> getRanges() { return latAxis2D.getRanges(); // both are the same }
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=" + latAxis2D.getName() + ", " + lonAxis2D.getName()); // LOOK needed? return det > 0; }
@Override public Array getCoordsAsArray() { double[] values = getValues(); return Array.factory(DataType.DOUBLE, shape, values); }
Edges() { latEdge = (ArrayDouble.D2) latAxis2D.getCoordBoundsAsArray(); lonEdge = (ArrayDouble.D2) lonAxis2D.getCoordBoundsAsArray(); // assume missing values have been converted to NaNs latMinMax = MAMath.getMinMax(latEdge); lonMinMax = MAMath.getMinMax(lonEdge); // normalize to [minLon,minLon+360] int nlons = (int) lonEdge.getSize(); for (int i = 0; i < nlons; i++) { double nonVal = lonEdge.getDouble(i); lonEdge.setDouble(i, LatLonPointImpl.lonNormalFrom(nonVal, lonMinMax.min)); } if (debug) System.out.printf("Bounds (%d %d): lat= (%f,%f) lon = (%f,%f) %n", nrows, ncols, latMinMax.min, latMinMax.max, lonMinMax.min, lonMinMax.max); }
result.add(new LatLonAxis2D(builder)); remove.add(vindex);
double maxx = LatLonPointImpl.lonNormalFrom(urpt.getLongitude(), lonMinMax.min); int shape[] = lonAxis2D.getShape(); int ny = shape[0]; int nx = shape[1];
public double[] readLatLonAxis2DCoordValues(LatLonAxis2D coordAxis) throws IOException { GribCollectionImmutable.VariableIndex vindex = (GribCollectionImmutable.VariableIndex) coordAxis.getUserObject(); int[] shape = coordAxis.getShape(); List<RangeIterator> ranges = new ArrayList<>(); List<Integer> fullShape = new ArrayList<>(); for (Coordinate coord : vindex.getCoordinates()) { ranges.add(new Range(1)); fullShape.add(coord.getNCoords()); } ranges.add(new Range(shape[0])); fullShape.add(shape[0]); ranges.add(new Range(shape[1])); fullShape.add(shape[1]); SectionIterable siter = new SectionIterable(ranges, fullShape); GribDataReader dataReader = GribDataReader.factory(gribCollection, vindex); Array data; try { data = dataReader.readData(siter); // optimize pass in null ?? LOOK old way } catch (InvalidRangeException e) { throw new RuntimeException(e); } return (double[]) data.get1DJavaArray(DataType.DOUBLE); // LOOK lame conversion }
return new TimeAxis2DFmrcReg(builder); } else if (dependenceType == CoverageCoordAxis.DependenceType.twoD && (axisType == AxisType.Lat || axisType == AxisType.Lon)) { return new LatLonAxis2D(builder); } else if (axisType == AxisType.TimeOffset) { return new TimeOffsetAxis(builder);
for (int shape : latlon2D.getShape()) builder.addShape(shape);
@Override public Optional<CoordReturn> findXYindexFromCoord(double x, double y) { synchronized (this) { if (edges == null) edges = new Edges(); } CoordReturn result = new CoordReturn(); int[] index = new int[2]; boolean ok = edges.findCoordElement(y, x, index); if (!ok) return Optional.empty("not in grid2D"); result.x = index[1]; result.y = index[0]; result.xcoord = getLonAxis2D().getCoord(result.y, result.x); result.ycoord = getLatAxis2D().getCoord(result.y, result.x); return Optional.of(result); }
return ucar.nc2.util.Optional.of(new LatLonAxis2D(builder));