/** * Given a coordinate interval, find what grid element matches it. * @param target interval in this coordinate system * @param bounded if true, always return a valid index. otherwise can return < 0 or > n-1 * @return index of grid point containing it, or < 0 or > n-1 if outside grid area */ int findCoordElement(double[] target, boolean bounded) { switch (axis.getSpacing()) { case regularInterval: // can use midpoint return findCoordElementRegular((target[0]+target[1])/2, bounded); case contiguousInterval: // can use midpoint return findCoordElementContiguous((target[0]+target[1])/2, bounded); case discontiguousInterval: // cant use midpoint return findCoordElementDiscontiguousInterval(target, bounded); } throw new IllegalStateException("unknown spacing" + axis.getSpacing()); }
/** * Given a coordinate position, find what grid element contains it. * This means that * <pre> * edge[i] <= target < edge[i+1] (if values are ascending) * edge[i] > target >= edge[i+1] (if values are descending) * </pre> * * @param target position in this coordinate system * @param bounded if true, always return a valid index. otherwise can return < 0 or > n-1 * @return index of grid point containing it, or < 0 or > n-1 if outside grid area */ int findCoordElement(double target, boolean bounded) { switch (axis.getSpacing()) { case regularInterval: case regularPoint: return findCoordElementRegular(target, bounded); case irregularPoint: case contiguousInterval: return findCoordElementContiguous(target, bounded); case discontiguousInterval: return findCoordElementDiscontiguousInterval(target, bounded); } throw new IllegalStateException("unknown spacing" + axis.getSpacing()); }
@Override public String getSummary() { if (axisType != AxisType.RunTime) return super.getSummary(); if (ncoords < 7) { Formatter f = new Formatter(); for (int i = 0; i < ncoords; i++) { CalendarDate cd = makeDate(getCoordMidpoint(i)); if (i > 0) f.format(", "); f.format("%s", cd); } return f.toString(); } Formatter f = new Formatter(); CalendarDate start = makeDate(getStartValue()); f.format("start=%s", start); CalendarDate end = makeDate(getEndValue()); f.format(", end=%s", end); f.format(" (npts=%d spacing=%s)", getNcoords(), getSpacing()); return f.toString(); }
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; }
private Optional<CoverageCoordAxisBuilder> subsetValues(double minValue, double maxValue, int stride) { if (axis.getSpacing() == CoverageCoordAxis.Spacing.discontiguousInterval) return subsetValuesDiscontinuous(minValue, maxValue, stride); double lower = axis.isAscending() ? Math.min(minValue, maxValue) : Math.max(minValue, maxValue); double upper = axis.isAscending() ? Math.max(minValue, maxValue) : Math.min(minValue, maxValue); int minIndex = findCoordElement(lower, false); int maxIndex = findCoordElement(upper, false); if (minIndex >= axis.getNcoords()) return Optional.empty(String.format("no points in subset: lower %f > end %f", lower, axis.getEndValue())); if (maxIndex < 0) return Optional.empty(String.format("no points in subset: upper %f < start %f", upper, axis.getStartValue())); if (minIndex < 0) minIndex = 0; if (maxIndex >= axis.getNcoords()) maxIndex = axis.getNcoords() - 1; int count = maxIndex - minIndex + 1; if (count <= 0) throw new IllegalArgumentException("no points in subset"); try { return Optional.of(subsetByIndex(new Range(minIndex, maxIndex, stride))); } catch (InvalidRangeException e) { return Optional.empty(e.getMessage()); } }
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; }
double[] values = axis.getValues(); // will be null for regular double[] subsetValues = null; switch (axis.getSpacing()) { case regularInterval: case regularPoint:
@Test public void testScalarRuntimeCoordinate() throws IOException { String filename = TestDir.cdmUnitTestDir + "ncss/GFS/CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1.ncx4"; String gridName = "Pressure_surface"; try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) { Assert.assertNotNull(filename, cc); Assert.assertEquals(1, cc.getCoverageCollections().size()); CoverageCollection cd = cc.getCoverageCollections().get(0); Coverage cov = cd.findCoverage(gridName); Assert.assertNotNull(gridName, cov); CoverageCoordSys csys = cov.getCoordSys(); Assert.assertNotNull("CoverageCoordSys", csys); CoverageCoordAxis1D runtime = (CoverageCoordAxis1D) csys.getAxis(AxisType.RunTime); Assert.assertNotNull(AxisType.RunTime.toString(), runtime); Assert.assertTrue(runtime.getClass().getName(), runtime instanceof CoverageCoordAxis1D); Assert.assertEquals(CoverageCoordAxis.Spacing.regularPoint, runtime.getSpacing()); Assert.assertEquals(CoverageCoordAxis.DependenceType.scalar, runtime.getDependenceType()); CalendarDate startDate = runtime.makeDate(runtime.getCoordMidpoint(0)); Assert.assertEquals(CalendarDate.parseISOformat(null, "2012-02-27T00:00:00Z"), startDate); } }
builder.setDependsOn(timeAxisSubset.getName()); builder.spacing = timeAxisSubset.getSpacing(); builder.ncoords = timeAxisSubset.ncoords; builder.isSubset = true; switch (timeAxisSubset.getSpacing()) { case regularInterval: case regularPoint:
builder.setDependsOn(timeAxisSubset.getName()); builder.spacing = timeAxisSubset.getSpacing(); builder.ncoords = timeAxisSubset.ncoords; builder.isSubset = true; switch (timeAxisSubset.getSpacing()) { case regularInterval: case regularPoint:
Assert.assertNotNull(timeAxis); Assert.assertEquals(92, timeAxis.getNcoords()); Assert.assertEquals(CoverageCoordAxis.Spacing.discontiguousInterval, timeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, timeAxis.getStartValue()); Assert2.assertNearlyEquals(384.0, timeAxis.getEndValue());
Assert.assertNotNull(runtimeAxis); Assert.assertEquals(4, runtimeAxis.getNcoords()); Assert.assertEquals(CoverageCoordAxis.Spacing.regularPoint, runtimeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, runtimeAxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(6.0, runtimeAxis.getResolution());
Assert.assertNotNull(runtimeAxis); Assert.assertEquals(3, runtimeAxis.getNcoords()); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, runtimeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, runtimeAxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(6.0, runtimeAxis.getResolution());