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)); } } }
private CoordinateAxis1DTime makeTimeAxisForRun(int run_index) { VariableDS section; try { section = (VariableDS) tAxis.slice(0, run_index); return CoordinateAxis1DTime.factory(ds, section, null); } catch (InvalidRangeException | IOException e) { e.printStackTrace(); } return null; }
private Range makeTimeRange(CalendarDateRange dateRange, CoordinateAxis1DTime timeAxis, int stride_time) throws InvalidRangeException { Range timeRange = null; if ((dateRange != null) && (timeAxis != null)) { int startIndex = timeAxis.findTimeIndexFromCalendarDate(dateRange.getStart()); int endIndex = timeAxis.findTimeIndexFromCalendarDate(dateRange.getEnd()); if (startIndex < 0) throw new InvalidRangeException("start time=" + dateRange.getStart() + " must be >= " + timeAxis.getCalendarDate(0)); if (endIndex < 0) throw new InvalidRangeException("end time=" + dateRange.getEnd() + " must be >= " + timeAxis.getCalendarDate(0)); if (stride_time <= 1) stride_time = 1; timeRange = new Range(startIndex, endIndex, stride_time); } return timeRange; }
/** * only if isRegular() LOOK REDO * * @return time unit * @throws Exception on bad unit string */ public TimeUnit getTimeResolution() throws Exception { String tUnits = getUnitsString(); StringTokenizer stoker = new StringTokenizer(tUnits); double tResolution = getIncrement(); return new TimeUnit(tResolution, stoker.nextToken()); }
@Override public List<NamedObject> getNames() { List<CalendarDate> cdates = getCalendarDates(); List<NamedObject> names = new ArrayList<>(cdates.size()); for (CalendarDate cd : cdates) names.add(new NamedAnything(CalendarDateFormatter.toDateTimeStringISO(cd), getShortName())); // "calendar date")); return names; }
this.helper= new CoordinateAxisTimeHelper(getCalendarFromAttribute(), getUnitsString()); Dimension localDim = new Dimension(getShortName(), count, false); setDimension(0, localDim); setCachedData(shortData, true);
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); } } }
/** * Get the the ith CalendarDate. * @param idx index * @return the ith CalendarDate */ public CalendarDate getCalendarDate (int idx) { List<CalendarDate> cdates = getCalendarDates(); // in case we want to lazily evaluate return cdates.get(idx); }
CoordinateAxis1DTime timeCoordVar = CoordinateAxis1DTime.factory(ncDataset, vds, null); dateList.addAll(timeCoordVar.getCalendarDates());
@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); } } } }
/** * Does not handle non-standard Calendars * @deprecated use getCalendarDateRange() */ public DateRange getDateRange() { CalendarDateRange cdr = getCalendarDateRange(); return cdr.toDateRange(); }
int startIndex = timeAxis.findTimeIndexFromCalendarDate( timeRange.getStart() ); int endIndex = timeAxis.findTimeIndexFromCalendarDate( timeRange.getEnd() ); if ( startIndex < 0 || startIndex > timeAxis.getSize() -1 || endIndex < 0 || endIndex > timeAxis.getSize() - 1 ) CalendarDateRange cdr = timeAxis.getCalendarDateRange(); String availStart = cdr.getStart().toString(); String availEnd = cdr.getEnd().toString();
/** * 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]; }
@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]; }
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); } } }
/** * Does not handle non-standard Calendars * @deprecated use findTimeIndexFromCalendarDate */ public int findTimeIndexFromDate(java.util.Date d) { return findTimeIndexFromCalendarDate( CalendarDate.of(d)); }
Date[] runDates = runtimeCoord.getTimeDates(); baseDate = runDates[0]; runtimes = Arrays.asList(runDates); runtimeDimName = runtimeCoord.getDimension(0).getShortName(); coordSet.add(runtimeCoord.getFullName()); Date[] forecastDates = timeCoordRun.getTimeDates();
assert !runAxis.isScalar(); Assert.assertEquals(10, runAxis.getSize()); Assert.assertNotNull(gridName, cov); CoverageCoordAxis ccaRuntime = cd.findCoordAxis(runAxis.getFullName()); Assert.assertNotNull(runAxis.getFullName(), ccaRuntime); Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, ccaRuntime.getSpacing());
/** * Does not handle non-standard Calendars * @deprecated use getCalendarDate() */ public java.util.Date getTimeDate (int idx) { return getCalendarDate(idx).toDate(); }
@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]; }