@Override public CoordinateAxis1DTime getTimeAxisForRun(int run_index) { if (!hasTimeAxis() || hasTimeAxis1D() || runTimeAxis == null) return null; int nruns = (int) runTimeAxis.getSize(); if ((run_index < 0) || (run_index >= nruns)) throw new IllegalArgumentException("getTimeAxisForRun index out of bounds= " + run_index); if (timeAxisForRun == null) timeAxisForRun = new CoordinateAxis1DTime[nruns]; if (timeAxisForRun[run_index] == null) timeAxisForRun[run_index] = makeTimeAxisForRun(run_index); return timeAxisForRun[run_index]; }
@Override public CoordinateAxis1DTime getTimeAxisForRun(int run_index) { if (!hasTimeAxis() || hasTimeAxis1D() || runTimeAxis == null) return null; int nruns = (int) runTimeAxis.getSize(); if ((run_index < 0) || (run_index >= nruns)) throw new IllegalArgumentException("getTimeAxisForRun index out of bounds= " + run_index); if (timeAxisForRun == null) timeAxisForRun = new CoordinateAxis1DTime[nruns]; if (timeAxisForRun[run_index] == null) timeAxisForRun[run_index] = makeTimeAxisForRun(run_index); return timeAxisForRun[run_index]; }
@Override public CoordinateAxis1DTime getTimeAxisForRun(CalendarDate runTime) { CoordinateAxis1DTime runTimeAxis = getRunTimeAxis(); int runIndex = runTimeAxis.findTimeIndexFromCalendarDate(runTime); int nruns = (int) runTimeAxis.getSize(); if ((runIndex < 0) || (runIndex >= nruns)) throw new IllegalArgumentException("getTimeAxisForRun index out of bounds= " + runIndex); if (timeAxisForRun == null) timeAxisForRun = new CoordinateAxis1DTime[nruns]; if (timeAxisForRun[runIndex] == null) timeAxisForRun[runIndex] = makeTimeAxisForRun(runIndex); return timeAxisForRun[runIndex]; }
@Override public CoordinateAxis1DTime getTimeAxisForRun(CalendarDate runTime) { CoordinateAxis1DTime runTimeAxis = getRunTimeAxis(); if (runTimeAxis == null) return null; int runIndex = runTimeAxis.findTimeIndexFromCalendarDate(runTime); int nruns = (int) runTimeAxis.getSize(); if ((runIndex < 0) || (runIndex >= nruns)) throw new IllegalArgumentException("getTimeAxisForRun index out of bounds= " + runIndex); if (timeAxisForRun == null) timeAxisForRun = new CoordinateAxis1DTime[nruns]; if (timeAxisForRun[runIndex] == null) timeAxisForRun[runIndex] = makeTimeAxisForRun(runIndex); return timeAxisForRun[runIndex]; }
/** * @deprecated doesnt work correctly for intervals */ @Override public CoordinateAxis1DTime getTimeAxisForRun(int run_index) { if (!hasTimeAxis() || hasTimeAxis1D() || runTimeAxis == null) return null; int nruns = (int) runTimeAxis.getSize(); if ((run_index < 0) || (run_index >= nruns)) throw new IllegalArgumentException("getTimeAxisForRun index out of bounds= " + run_index); if (timeAxisForRun == null) timeAxisForRun = new CoordinateAxis1DTime[nruns]; if (timeAxisForRun[run_index] == null) timeAxisForRun[run_index] = makeTimeAxisForRun(run_index); return timeAxisForRun[run_index]; }
/** * Get the list of times as Dates. * If 2D, return list of unique dates. * * @return array of java.util.Date, or Date[0]. * @deprecated use getCalendarDates */ public java.util.Date[] getTimeDates() { if ((timeTaxis != null) && (timeTaxis.getSize() > 0)) { return timeTaxis.getTimeDates(); } else if ((tAxis != null) && (tAxis.getSize() > 0)) { return makeTimes2D(); } return new Date[0]; }
/** * Get the list of times as Dates. * If 2D, return list of unique dates. * * @return array of java.util.Date, or Date[0]. * @deprecated use getCalendarDates */ public java.util.Date[] getTimeDates() { if ((timeTaxis != null) && (timeTaxis.getSize() > 0)) { return timeTaxis.getTimeDates(); } else if ((tAxis != null) && (tAxis.getSize() > 0)) { return makeTimes2D(); } return new Date[0]; }
/** * Get the list of times as Dates. * If 2D, return list of unique dates. * * @return array of java.util.Date, or Date[0]. * @deprecated use getCalendarDates */ public java.util.Date[] getTimeDates() { if ((timeTaxis != null) && (timeTaxis.getSize() > 0)) { return timeTaxis.getTimeDates(); } else if ((tAxis != null) && (tAxis.getSize() > 0)) { return makeTimes2D(); } return new Date[0]; }
TimeCoord(CalendarDate runDate, CoordinateAxis1DTime axis) { this.runDate = runDate; this.axisName = axis.getFullName(); 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(); if (axis.isInterval()) { this.isInterval = true; this.bound1 = new double[n]; this.bound2 = new double[n]; double[] orgBound1 = axis.getBound1(); double[] orgBound2 = axis.getBound2(); this.bound2 = new double[n]; for (int i = 0; i < axis.getSize(); i++) { this.bound1[i] = getValueInHours(unit, orgBound1[i]); this.bound2[i] = getValueInHours(unit, orgBound2[i]); } } else { offset = new double[n]; for (int i = 0; i < axis.getSize(); i++) { offset[i] = getValueInHours(unit, axis.getCoordValue(i)); } } }
int n = (int) axis.getSize(); if (axis.isInterval()) { this.isInterval = true; double[] orgBound2 = axis.getBound2(); this.bound2 = new double[n]; for (int i = 0; i < axis.getSize(); i++) { this.bound1[i] = getValueInHours(unit, orgBound1[i]); this.bound2[i] = getValueInHours(unit, orgBound2[i]); for (int i = 0; i < axis.getSize(); i++) { offset[i] = getValueInHours(cal, unit, axis.getCoordValue(i));
int n = (int) axis.getSize(); if (axis.isInterval()) { this.isInterval = true; double[] orgBound2 = axis.getBound2(); this.bound2 = new double[n]; for (int i = 0; i < axis.getSize(); i++) { this.bound1[i] = getValueInHours(unit, orgBound1[i]); this.bound2[i] = getValueInHours(unit, orgBound2[i]); for (int i = 0; i < axis.getSize(); i++) { offset[i] = getValueInHours(cal, unit, axis.getCoordValue(i));
static void readAllTimes1D(Coverage cover, GridDatatype dt, CalendarDate rt_val, int rt_idx, CoordinateAxis1DTime timeAxis, CoordinateAxis1D ensAxis, CoordinateAxis1D vertAxis) { if (timeAxis == null) readAllEnsembles(cover, dt, rt_val, rt_idx, null, -1, ensAxis, vertAxis); else { for (int i = 0; i < timeAxis.getSize(); i++) { CalendarDate timeDate = timeAxis.isInterval() ? timeAxis.getCoordBoundsMidpointDate(i) : timeAxis.getCalendarDate(i); readAllEnsembles(cover, dt, rt_val, rt_idx, timeDate, i, ensAxis, vertAxis); } } }
@Test public void testFloatingPointCompare() throws Exception { String spec = TestDir.cdmUnitTestDir+"ft/fmrc/fp_precision/sediment_thickness_#yyMMddHHmm#.*\\.nc$"; System.out.printf("%n====================FMRC dataset %s%n", spec); Formatter errlog = new Formatter(); Fmrc fmrc = Fmrc.open(spec, errlog); assert (fmrc != null) : errlog; try (ucar.nc2.dt.GridDataset gridDs = fmrc.getDatasetBest()) { GridDatatype v = gridDs.findGridByShortName("thickness_of_sediment"); assert v != null; GridCoordSystem gcs = v.getCoordinateSystem(); CoordinateAxis1DTime time = gcs.getTimeAxis1D(); Assert.assertEquals("hours since 2015-03-08 12:51:00.000 UTC", time.getUnitsString()); Assert.assertEquals(74, time.getSize()); Array data = time.read(); logger.debug("{}", NCdumpW.toString(data)); for (CalendarDate cd : time.getCalendarDates()) { assert cd.getFieldValue(CalendarPeriod.Field.Minute) == 0 : System.out.printf("%s%n", cd); } } } }
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 void testOceanSigma() throws java.io.IOException, InvalidRangeException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open( TestDir.cdmUnitTestDir + "conventions/cf/gomoos_cf.nc"); GridDatatype grid = gds.findGridDatatype("temp"); assert grid != null; GridCoordSystem gcs = grid.getCoordinateSystem(); assert gcs != null; VerticalCT vct = gcs.getVerticalCT(); assert vct != null; assert vct.getVerticalTransformType() == VerticalCT.Type.OceanSigma; VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; CoordinateAxis1DTime taxis = gcs.getTimeAxis1D(); for (int t=0; t<taxis.getSize(); t++) { System.out.printf("vert coord for time = %s%n", taxis.getTimeDate(t)); ArrayDouble.D3 ca = vt.getCoordinateArray(t); assert ca != null; assert ca.getRank() == 3 : ca.getRank(); int[] shape = ca.getShape(); for (int i = 0; i < 3; i++) System.out.println(" shape " + i + " = " + shape[i]); } gds.close(); }
@Test public void testCOARDSdefaultCalendar() throws IOException { try (GridDataset ds = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/coards/olr.day.mean.nc")) { GeoGrid grid = ds.findGridByName("olr"); assert grid != null; GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime time = gcs.getTimeAxis1D(); assert time != null; CalendarDate first = time.getCalendarDate(0); CalendarDate cd = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, "2002-01-01T00:00:00Z"); assert first.equals(cd) : first + " != " + cd; CalendarDate last = time.getCalendarDate((int) time.getSize() - 1); CalendarDate cd2 = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, "2012-12-02T00:00:00Z"); assert last.equals(cd2) : last + " != " + cd2; } }
Assert.assertNotNull("runtime axis", runAxis); assert !runAxis.isScalar(); Assert.assertEquals(10, runAxis.getSize());
Assert.assertEquals(4, reftime.getSize()); double[] want = new double[]{0., 12., 24., 36.}; CompareNetcdf2 cn = new CompareNetcdf2();
Assert.assertNotNull("runtime axis", runAxis); assert !runAxis.isScalar(); Assert.assertEquals(10, runAxis.getSize()); double[] runValuesDt = runAxis.getCoordValues(); Assert.assertNotNull("time axis", timeAxis); assert !timeAxis.isScalar(); Assert.assertEquals(10, timeAxis.getSize()); double[] timeValuesDt = timeAxis.getCoordValues();
Assert.assertEquals(1, reftime.getSize()); double[] runtimeValues = new double[]{0.}; CompareNetcdf2 cn = new CompareNetcdf2();