Examples of DateUnit


Examples of com.belladati.sdk.intervals.DateUnit

   */
  private static Interval<DateUnit> parseDateInterval(JsonNode node) {
    try {
      if (node.hasNonNull("dateInterval") && node.get("dateInterval").hasNonNull("aggregationType")) {
        JsonNode dateInterval = node.get("dateInterval");
        DateUnit unit = DateUnit.valueOf(dateInterval.get("aggregationType").asText().toUpperCase(Locale.ENGLISH));
        JsonNode interval = dateInterval.get("interval");
        String type = interval.get("type").asText().toLowerCase(Locale.ENGLISH);
        if ("relative".equals(type)) {
          // the server may send numbers inside strings
          // or numbers as decimals, e.g. 3.0
          // regardless, we treat them all as int
          String from = interval.get("from").asText();
          String to = interval.get("to").asText();
          return new RelativeInterval<DateUnit>(unit, (int) Float.parseFloat(from), (int) Float.parseFloat(to));
        } else if ("absolute".equals(type)) {
          // an absolute interval
          return new AbsoluteInterval<DateUnit>(unit, unit.parseAbsolute(interval.get("from")),
            unit.parseAbsolute(interval.get("to")));
        } else if ("custom".equals(type)) {
          // a custom interval
          return new CustomInterval<DateUnit>(unit, interval.get("from").asText(), interval.get("to").asText());
        }
      }
View Full Code Here

Examples of com.belladati.sdk.intervals.DateUnit

   */
  private static Interval<DateUnit> parseDateInterval(JsonNode node) {
    try {
      if (node.hasNonNull("dateInterval") && node.get("dateInterval").hasNonNull("aggregationType")) {
        JsonNode dateInterval = node.get("dateInterval");
        DateUnit unit = DateUnit.valueOf(dateInterval.get("aggregationType").asText().toUpperCase());
        JsonNode interval = dateInterval.get("interval");
        String type = interval.get("type").asText().toLowerCase();
        if ("relative".equals(type)) {
          // the server may send numbers inside strings
          // or numbers as decimals, e.g. 3.0
          // regardless, we treat them all as int
          String from = interval.get("from").asText();
          String to = interval.get("to").asText();
          return new RelativeInterval<DateUnit>(unit, (int) Float.parseFloat(from), (int) Float.parseFloat(to));
        } else if ("absolute".equals(type)) {
          // an absolute interval
          return new AbsoluteInterval<DateUnit>(unit, unit.parseAbsolute(interval.get("from")),
            unit.parseAbsolute(interval.get("to")));
        }
      }
    } catch (InvalidIntervalException e) {
      // ignore the interval
    } catch (NumberFormatException e) {
View Full Code Here

Examples of com.belladati.sdk.intervals.DateUnit

   */
  private static Interval<DateUnit> parseDateInterval(JsonNode node) {
    try {
      if (node.hasNonNull("dateInterval") && node.get("dateInterval").hasNonNull("aggregationType")) {
        JsonNode dateInterval = node.get("dateInterval");
        DateUnit unit = DateUnit.valueOf(dateInterval.get("aggregationType").asText().toUpperCase(Locale.ENGLISH));
        JsonNode interval = dateInterval.get("interval");
        String type = interval.get("type").asText().toLowerCase(Locale.ENGLISH);
        if ("relative".equals(type)) {
          // the server may send numbers inside strings
          // or numbers as decimals, e.g. 3.0
          // regardless, we treat them all as int
          String from = interval.get("from").asText();
          String to = interval.get("to").asText();
          return new RelativeInterval<DateUnit>(unit, (int) Float.parseFloat(from), (int) Float.parseFloat(to));
        } else if ("absolute".equals(type)) {
          // an absolute interval
          return new AbsoluteInterval<DateUnit>(unit, unit.parseAbsolute(interval.get("from")),
            unit.parseAbsolute(interval.get("to")));
        }
      }
    } catch (InvalidIntervalException e) {
      // ignore the interval
    } catch (NumberFormatException e) {
View Full Code Here

Examples of com.belladati.sdk.intervals.DateUnit

   */
  private static Interval<DateUnit> parseDateInterval(JsonNode node) {
    try {
      if (node.hasNonNull("dateInterval") && node.get("dateInterval").hasNonNull("aggregationType")) {
        JsonNode dateInterval = node.get("dateInterval");
        DateUnit unit = DateUnit.valueOf(dateInterval.get("aggregationType").asText().toUpperCase(Locale.ENGLISH));
        JsonNode interval = dateInterval.get("interval");
        String type = interval.get("type").asText().toLowerCase(Locale.ENGLISH);
        if ("relative".equals(type)) {
          // the server may send numbers inside strings
          // or numbers as decimals, e.g. 3.0
          // regardless, we treat them all as int
          String from = interval.get("from").asText();
          String to = interval.get("to").asText();
          return new RelativeInterval<DateUnit>(unit, (int) Float.parseFloat(from), (int) Float.parseFloat(to));
        } else if ("absolute".equals(type)) {
          // an absolute interval
          return new AbsoluteInterval<DateUnit>(unit, unit.parseAbsolute(interval.get("from")),
            unit.parseAbsolute(interval.get("to")));
        }
      }
    } catch (InvalidIntervalException e) {
      // ignore the interval
    } catch (NumberFormatException e) {
View Full Code Here

Examples of ucar.nc2.units.DateUnit

      Variable time = ds.findVariable("time_offset");
      if (time != null) {
        Variable base = ds.findVariable("base_time");
        int base_time = base.readScalarInt();
        try {
          DateUnit dunit = new DateUnit("seconds since 1970-01-01 00:00");
          String time_units = "seconds since " + dunit.makeStandardDateString(base_time);
          time.addAttribute(new Attribute("units", time_units));
          time.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.name()));
        } catch (Exception e) {
          e.printStackTrace();
        }
View Full Code Here

Examples of ucar.nc2.units.DateUnit

    return " ";
  }

private String isUdunits(String unit) {
    try {
      new DateUnit(unit);
      return "date";
    } catch (Exception e) {
      // ok
    }
View Full Code Here

Examples of ucar.nc2.units.DateUnit

    // String timeUnit = lookup.getTimeRangeUnitName(this.timeUnit);

    DateFormatter formatter = new DateFormatter();
    String refDate = formatter.toDateTimeStringISO(baseDate);
    String udunit = timeUdunit + " since " + refDate;
    DateUnit dateUnit = null;
    try {
      dateUnit = new DateUnit(udunit);
    } catch (Exception e) {
      log.error("TimeCoord not added, cant make DateUnit from String '" + udunit + "'", e);
      return;
    }

    // create the data
    Array coordArray = null;
    Array boundsArray = null;
    int ntimes = getNTimes();
    coordData = new int[ntimes];
    if (!isInterval()) {
      for (int i = 0; i < times.size(); i++)
        coordData[i] = (int) dateUnit.makeValue(times.get(i)); // LOOK why int ?
      coordArray = Array.factory(DataType.INT, new int[]{ntimes}, coordData);

    } else {
      int[] boundsData = new int[ntimes * 2];
      for (int i = 0; i < timeIntvs.size(); i++) {
View Full Code Here

Examples of ucar.nc2.units.DateUnit

    assert time.getDataType() == DataType.DOUBLE;

    assert time.getDimension(0) == ncfile.findDimension("time");

    String units = time.getUnitsString();
    DateUnit du = new DateUnit(units);
    DateFormatter df = new DateFormatter();

    String[] result = new String[] {"2006-06-07T12:00:00Z",   "2006-06-07T13:00:00Z",   "2006-06-07T14:00:00Z"};
    try {
      Array data = time.read();
      assert data.getRank() == 1;
      assert data.getSize() == 3;
      assert data.getShape()[0] == 3;
      assert data.getElementType() == double.class;

      NCdump.printArray(data, "time coord", System.out, null);

      int count = 0;
      IndexIterator dataI = data.getIndexIterator();
      while (dataI.hasNext()) {
        double val = dataI.getDoubleNext();
        Date dateVal = du.makeDate(val);
        String dateS = df.toDateTimeStringISO(dateVal);
        assert dateS.equals( result[count]) : dateS+" != "+ result[count];
        count++;
      }
View Full Code Here

Examples of ucar.nc2.units.DateUnit

    int ncoords = (int) org.getSize();
    timeDates = new Date[ncoords];

    // see if it has a valid udunits unit
    DateUnit dateUnit = null;
    String units = org.getUnitsString();
    if (units != null) {
      try {
         dateUnit = new DateUnit(units);
       } catch (Exception e) {
        // not a date unit - ok to fall through
      }
    }

    // has a valid date unit - read data
    if (dateUnit != null) {
      Array data = org.read();

      int count = 0;
      IndexIterator ii = data.getIndexIterator();
      for (int i = 0; i < ncoords; i++) {
        double val = ii.getDoubleNext();
        if (Double.isNaN(val)) continue;
        Date d = dateUnit.makeDate(val);
        timeDates[count++] = d;
      }

      // if we encountered NaNs, shorten it up
      if (count != ncoords) {
        Dimension localDim = new Dimension(getShortName(), count, false);
        setDimension(0, localDim);

        // set the shortened values
        Array shortData = Array.factory(data.getElementType(), new int[]{count});
        Index ima = shortData.getIndex();
        int count2 = 0;
        ii = data.getIndexIterator();
        for (int i = 0; i < ncoords; i++) {
          double val = ii.getDoubleNext();
          if (Double.isNaN(val)) continue;
          shortData.setDouble(ima.set0(count2), val);
          count2++;
        }
        // here we have to decouple from the original variable
        cache = new Cache();
        setCachedData(shortData, true);

        // shorten up the timeDate array
        Date[] keep = timeDates;
        timeDates = new Date[count];
        System.arraycopy(keep, 0, timeDates, 0, timeDates.length);
      }

      return;
    } // has valid date unit

    //  see if its a String, and if we can parse the values as an ISO date
    if (org.getDataType() == DataType.STRING) {
      ArrayObject data = (ArrayObject) org.read();
      IndexIterator ii = data.getIndexIterator();
      for (int i = 0; i < ncoords; i++) {
        String coordValue = (String) ii.getObjectNext();
        Date d = DateUnit.getStandardOrISO(coordValue);
        if (d == null) {
          if (errMessages != null)
            errMessages.format("DateUnit cannot parse String= %s\n", coordValue);
          else
            System.out.println("DateUnit cannot parse String= " + coordValue + "\n");

          throw new IllegalArgumentException();
        } else {
          timeDates[i] = d;
        }
      }
      return;
    }

    // hack something in here so it doesnt fail
    if (units != null) {
      try {
        // if in time unit, use CF convention "since 1-1-1 0:0:0"
        dateUnit = new DateUnit(units+" since 0001-01-01 00:00:00");
      } catch (Exception e) {
        try {
          if (errMessages != null)
            errMessages.format("Time Coordinate must be udunits or ISO String: hack since 0001-01-01 00:00:00\n");
          else
            System.out.println("Time Coordinate must be udunits or ISO String: hack since 0001-01-01 00:00:00\n");
          dateUnit = new DateUnit("secs since 0001-01-01 00:00:00");
        } catch (Exception e1) {
          // cant happpen
        }
      }
    }

    Array data = org.read();
    IndexIterator ii = data.getIndexIterator();
    for (int i = 0; i < ncoords; i++) {
      double val = ii.getDoubleNext();
      Date d = dateUnit.makeDate(val);
      timeDates[i] = d;
    }
  }
View Full Code Here

Examples of ucar.nc2.units.DateUnit

     * @throws Exception _more_
     */
    protected void setTimeUnits() throws Exception {
        Variable t  = ds.findVariable("time");
        String   ut = t.getUnitsString();
        dateUnits = new DateUnit(ut);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.