Exemplo n.º 1
0
  public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
    for (Variable v : ds.getVariables()) checkIfAxis(v);

    int year = ds.readAttributeInteger(null, "YEAR", -1);
    int doy = ds.readAttributeInteger(null, "DAY", -1);
    double time = ds.readAttributeDouble(null, "TIME", Double.NaN);

    if ((year > 0) && (doy > 0) && !Double.isNaN(time)) {
      Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
      cal.clear();
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.DAY_OF_YEAR, doy);

      int hour = (int) time;
      cal.set(Calendar.HOUR_OF_DAY, hour);

      time -= hour;
      time *= 60;
      int minute = (int) time;
      cal.set(Calendar.MINUTE, minute);

      time -= minute;
      time *= 60;
      cal.set(Calendar.SECOND, (int) time);

      VariableDS var =
          new VariableDS(
              ds,
              null,
              null,
              "timeFromAtts",
              DataType.LONG,
              "",
              "seconds since 1970-01-01 00:00",
              "time generated from global attributes");
      // LOOK : cant handle scalar coordinates yet
      // var.addAttribute( new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
      ds.addVariable(null, var);
      ArrayLong.D0 data = new ArrayLong.D0();
      data.set(cal.getTime().getTime() / 1000);
      var.setCachedData(data, true);
    }

    ds.finish();
  }
Exemplo n.º 2
0
 private static Array getNcScalar(Number inNum, IObservationGroup.DataType dataType) {
   Array ret = null;
   switch (dataType) {
     case INT:
       ret = new ArrayInt.D0();
       ((ArrayInt.D0) ret).set(inNum.intValue());
       break;
     case LONG:
       ret = new ArrayLong.D0();
       ((ArrayLong.D0) ret).set(inNum.longValue());
       break;
     case FLOAT:
       ret = new ArrayFloat.D0();
       ((ArrayFloat.D0) ret).set(inNum.floatValue());
       break;
     case DOUBLE:
       ret = new ArrayDouble.D0();
       ((ArrayDouble.D0) ret).set(inNum.doubleValue());
       break;
   }
   return ret;
 }
Exemplo n.º 3
0
  public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
    ds.addAttribute(null, new Attribute("FeatureType", FeatureType.IMAGE.toString())); // LOOK

    Group vhrr = ds.findGroup("VHRR");
    Group loc = vhrr.findGroup("Geo-Location");
    Variable lat = loc.findVariable("Latitude");
    lat.addAttribute(new Attribute(CDM.UNITS, "degrees_north"));
    lat.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
    Variable lon = loc.findVariable("Longitude");
    lon.addAttribute(new Attribute(CDM.UNITS, "degrees_east"));
    lon.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));

    int[] shape = lat.getShape();
    assert shape.length == 2;
    Dimension scan = new Dimension("scan", shape[0]);
    Dimension xscan = new Dimension("xscan", shape[1]);
    vhrr.addDimension(scan);
    vhrr.addDimension(xscan);

    lat.setDimensions("scan xscan");
    lon.setDimensions("scan xscan");

    Group data = vhrr.findGroup("Image Data");
    for (Variable v : data.getVariables()) {
      int[] vs = v.getShape();
      if ((vs.length == 2) && (vs[0] == shape[0]) && (vs[1] == shape[1])) {
        v.setDimensions("scan xscan");
        v.addAttribute(new Attribute(_Coordinate.Axes, "lat lon time"));
      }
    }

    /* Group PRODUCT_METADATA {

    Group PRODUCT_DETAILS {
      PRODUCT_DETAILS:UNIQUE_ID = "3AVHR_22NOV2007_0902";
      PRODUCT_DETAILS:PRODUCT_TYPE = "STANDARD(FULL DISK) ";
      PRODUCT_DETAILS:PROCESSING_SOFTWARE = "InPGS_XXXXXXXXXXXXXX";
      PRODUCT_DETAILS:SPACECRAFT_ID = "INSAT-3A  ";
      PRODUCT_DETAILS:SENSOR_ID = "VHR";
      PRODUCT_DETAILS:ACQUISITION_TYPE = "FULL FRAME     ";
      PRODUCT_DETAILS:ACQUISITION_DATE = "22NOV2007";
      PRODUCT_DETAILS:ACQUISITION_TIME_IN_GMT = "0902";
      PRODUCT_DETAILS:PRODUCT_NAME = "      FULL DISK";
      PRODUCT_DETAILS:PROCESSING_LEVEL = "L1B";
      PRODUCT_DETAILS:BAND_COMBINATION = "Visible(VIS),Thermal Infrared(TIR),Water Vapour(WV)";
      PRODUCT_DETAILS:PRODUCT_CODE = "ST00001HD";
    } */

    Group info = ds.findGroup("PRODUCT_METADATA/PRODUCT_DETAILS");
    String dateS = info.findAttribute("ACQUISITION_DATE").getStringValue();
    String timeS = info.findAttribute("ACQUISITION_TIME_IN_GMT").getStringValue();

    SimpleDateFormat format = new SimpleDateFormat("ddMMMyyyyHHmm");
    format.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
    try {
      Date d = format.parse(dateS + timeS);
      VariableDS time =
          new VariableDS(
              ds,
              vhrr,
              null,
              "time",
              DataType.LONG,
              "",
              "seconds since 1970-01-01 00:00",
              "time generated from PRODUCT_METADATA/PRODUCT_DETAILS");

      time.addAttribute(
          new Attribute(
              _Coordinate.AxisType,
              AxisType.Time.toString())); // // LOOK : cant handle scalar coordinates yet ??
      time.addAttribute(new Attribute("IsoDate", new DateFormatter().toDateTimeStringISO(d)));
      CoordinateAxis1D timeAxis = new CoordinateAxis1D(ds, time);
      ds.addVariable(vhrr, timeAxis);
      ArrayLong.D0 timeData = new ArrayLong.D0();
      timeData.set(d.getTime() / 1000);
      time.setCachedData(timeData, true);

    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e.getMessage());
    }

    ds.finish();
  }