示例#1
0
 private void setSceneRasterStartAndStopTime(Product product) {
   final Product sourceProduct = getSourceProduct();
   final ProductData.UTC startTime = sourceProduct.getStartTime();
   final ProductData.UTC stopTime = sourceProduct.getEndTime();
   final ProductSubsetDef subsetDef = getSubsetDef();
   if (startTime != null
       && stopTime != null
       && subsetDef != null
       && subsetDef.getRegion() != null) {
     final double height = sourceProduct.getSceneRasterHeight();
     final Rectangle region = subsetDef.getRegion();
     final double regionY = region.getY();
     final double regionHeight = region.getHeight();
     final double dStart = startTime.getMJD();
     final double dStop = stopTime.getMJD();
     final double vPerLine = (dStop - dStart) / (height - 1);
     final double newStart = vPerLine * regionY + dStart;
     final double newStop = vPerLine * (regionHeight - 1) + newStart;
     product.setStartTime(new ProductData.UTC(newStart));
     product.setEndTime(new ProductData.UTC(newStop));
   } else {
     product.setStartTime(startTime);
     product.setEndTime(stopTime);
   }
 }
示例#2
0
  private ProductData.UTC getUTCAttribute(String key, List<Attribute> globalAttributes) {
    Attribute attribute = findAttribute(key, globalAttributes);
    Boolean isModis = false;
    try {
      isModis = findAttribute("MODIS_Resolution", globalAttributes).isString();
    } catch (Exception ignored) {
    }

    if (attribute != null) {
      String timeString = attribute.getStringValue().trim();
      final DateFormat dateFormat = ProductData.UTC.createDateFormat("yyyyDDDHHmmssSSS");
      final DateFormat dateFormatModis =
          ProductData.UTC.createDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
      final DateFormat dateFormatOcts =
          ProductData.UTC.createDateFormat("yyyyMMdd HH:mm:ss.SSSSSS");
      try {
        if (isModis) {
          final Date date = dateFormatModis.parse(timeString);
          String milliSeconds = timeString.substring(timeString.length() - 3);
          return ProductData.UTC.create(date, Long.parseLong(milliSeconds) * 1000);
        } else if (productReader.getProductType() == SeadasProductReader.ProductType.Level1A_OCTS) {
          final Date date = dateFormatOcts.parse(timeString);
          String milliSeconds = timeString.substring(timeString.length() - 3);
          return ProductData.UTC.create(date, Long.parseLong(milliSeconds) * 1000);
        } else {
          final Date date = dateFormat.parse(timeString);
          String milliSeconds = timeString.substring(timeString.length() - 3);
          return ProductData.UTC.create(date, Long.parseLong(milliSeconds) * 1000);
        }
      } catch (ParseException ignored) {
      }
    }
    return null;
  }
示例#3
0
  private static void updateMetadata(
      final Product sourceProduct, final Product targetProduct, ProductSubsetDef subsetDef)
      throws IOException {

    try {
      final MetadataElement root = targetProduct.getMetadataRoot();
      if (root == null) return;

      final MetadataElement absRoot = root.getElement("Abstracted_Metadata");
      if (absRoot == null) return;

      boolean nearRangeOnLeft = isNearRangeOnLeft(targetProduct);

      final MetadataAttribute firstLineTime = absRoot.getAttribute("first_line_time");
      if (firstLineTime != null) {
        final ProductData.UTC startTime = targetProduct.getStartTime();
        if (startTime != null) firstLineTime.getData().setElems(startTime.getArray());
      }
      final MetadataAttribute lastLineTime = absRoot.getAttribute("last_line_time");
      if (lastLineTime != null) {
        final ProductData.UTC endTime = targetProduct.getEndTime();
        if (endTime != null) lastLineTime.getData().setElems(endTime.getArray());
      }
      final MetadataAttribute totalSize = absRoot.getAttribute("total_size");
      if (totalSize != null) totalSize.getData().setElemUInt(targetProduct.getRawStorageSize());

      if (nearRangeOnLeft) {
        setLatLongMetadata(targetProduct, absRoot, "first_near_lat", "first_near_long", 0.5f, 0.5f);
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "first_far_lat",
            "first_far_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            0.5f);

        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_near_lat",
            "last_near_long",
            0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_far_lat",
            "last_far_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
      } else {
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "first_near_lat",
            "first_near_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            0.5f);
        setLatLongMetadata(targetProduct, absRoot, "first_far_lat", "first_far_long", 0.5f, 0.5f);

        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_near_lat",
            "last_near_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_far_lat",
            "last_far_long",
            0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
      }

      final MetadataAttribute height = absRoot.getAttribute("num_output_lines");
      if (height != null) height.getData().setElemUInt(targetProduct.getSceneRasterHeight());

      final MetadataAttribute width = absRoot.getAttribute("num_samples_per_line");
      if (width != null) width.getData().setElemUInt(targetProduct.getSceneRasterWidth());

      final MetadataAttribute offsetX = absRoot.getAttribute("subset_offset_x");
      if (offsetX != null && subsetDef.getRegion() != null)
        offsetX.getData().setElemUInt(subsetDef.getRegion().x);

      final MetadataAttribute offsetY = absRoot.getAttribute("subset_offset_y");
      if (offsetY != null && subsetDef.getRegion() != null)
        offsetY.getData().setElemUInt(subsetDef.getRegion().y);

      final MetadataAttribute slantRange = absRoot.getAttribute("slant_range_to_first_pixel");
      if (slantRange != null) {
        final TiePointGrid srTPG = targetProduct.getTiePointGrid("slant_range_time");
        if (srTPG != null) {
          final double slantRangeTime;
          if (nearRangeOnLeft) {
            slantRangeTime = srTPG.getPixelDouble(0, 0) / 1000000000.0; // ns to s
          } else {
            slantRangeTime =
                srTPG.getPixelDouble(targetProduct.getSceneRasterWidth() - 1, 0)
                    / 1000000000.0; // ns to s
          }
          final double halfLightSpeed = 299792458.0 / 2.0;
          final double slantRangeDist = slantRangeTime * halfLightSpeed;
          slantRange.getData().setElemDouble(slantRangeDist);
        }
      }

      setSubsetSRGRCoefficients(sourceProduct, targetProduct, subsetDef, absRoot, nearRangeOnLeft);
    } catch (Exception e) {
      throw new IOException(e);
    }
  }