コード例 #1
0
ファイル: SeadasFileReader.java プロジェクト: bcdev/seadas
 private MetadataElement getMetadataElementSave(Product product, String name) {
   final MetadataElement metadataElement = product.getMetadataRoot().getElement(name);
   final MetadataElement namedElem;
   if (metadataElement == null) {
     namedElem = new MetadataElement(name);
     product.getMetadataRoot().addElement(namedElem);
   } else {
     namedElem = metadataElement;
   }
   return namedElem;
 }
コード例 #2
0
ファイル: ProductUtilities.java プロジェクト: bcdev/glob-box
  /**
   * Returns the UTC for a global time attribute.
   *
   * @param product the product.
   * @param timeAttrName the name of the time attribute.
   * @return the attribute value as UTC or {@code null} if the attribute vallue cannot be parsed.
   * @see MetadataAttribute
   * @see ProductData.UTC
   */
  public static ProductData.UTC getTimeAttrValue(final Product product, final String timeAttrName) {
    final MetadataElement pa = product.getMetadataRoot().getElement(GLOBAL_ATTRIBUTES);
    if (pa == null) {
      return null;
    }
    final MetadataAttribute timeAttr = pa.getAttribute(timeAttrName);
    if (timeAttr == null) {
      return null;
    }
    final ProductData timeAttrData = timeAttr.getData();
    if (timeAttrData == null) {
      return null;
    }

    final String timeString = timeAttrData.getElemString();
    if ("".equals(timeString.trim())) {
      return null;
    }

    ProductData.UTC utc = null;
    for (final String pattern : DATE_TIME_PATTERNS) {
      try {
        utc = ProductData.UTC.parse(timeString, pattern);
        break; // utc is never null here
      } catch (ParseException ignored) {
        // ignore
      } catch (IllegalArgumentException ignored) {
        // ignore
      }
    }

    return utc;
  }
コード例 #3
0
ファイル: SeadasFileReader.java プロジェクト: bcdev/seadas
  public void addBandMetadata(Product product) throws ProductIOException {
    Group group = ncFile.findGroup("Geophysical_Data");
    if (productReader.getProductType() == SeadasProductReader.ProductType.Level2_Aquarius) {
      group = ncFile.findGroup("Aquarius_Data");
    }
    if (productReader.getProductType() == SeadasProductReader.ProductType.Level1B_HICO) {
      group = ncFile.findGroup("products");
    }
    if (group != null) {
      final MetadataElement bandAttributes = new MetadataElement("Band_Attributes");
      List<Variable> variables = group.getVariables();
      for (Variable variable : variables) {
        final String name = variable.getShortName();
        final MetadataElement sdsElement = new MetadataElement(name + ".attributes");
        final int dataType = getProductDataType(variable);
        final MetadataAttribute prodtypeattr = new MetadataAttribute("data_type", dataType);

        sdsElement.addAttribute(prodtypeattr);
        bandAttributes.addElement(sdsElement);

        final List<Attribute> list = variable.getAttributes();
        for (Attribute varAttribute : list) {
          addAttributeToElement(sdsElement, varAttribute);
        }
      }
      final MetadataElement metadataRoot = product.getMetadataRoot();
      metadataRoot.addElement(bandAttributes);
    }
  }
コード例 #4
0
ファイル: SeadasFileReader.java プロジェクト: bcdev/seadas
  public void addInputParamMetadata(Product product) throws ProductIOException {

    Variable inputParams = ncFile.findVariable("Input_Parameters");
    if (inputParams != null) {
      final MetadataElement inputParamsMeta = new MetadataElement("Input_Parameters");
      Array array;
      try {
        array = inputParams.read();
      } catch (IOException e) {
        throw new ProductIOException(e.getMessage());
      }

      String[] lines = array.toString().split("\n");
      for (String line : lines) {
        String[] parts = line.split("=");
        if (parts.length == 2) {
          final String name = parts[0].trim();
          final String value = parts[1].trim();
          final ProductData data = ProductData.createInstance(ProductData.TYPE_ASCII, value);
          final MetadataAttribute attribute = new MetadataAttribute(name, data, true);
          inputParamsMeta.addAttribute(attribute);
        }
      }

      final MetadataElement metadataRoot = product.getMetadataRoot();
      metadataRoot.addElement(inputParamsMeta);
    }
  }
コード例 #5
0
ファイル: SeadasFileReader.java プロジェクト: bcdev/seadas
  public void addGlobalMetadata(Product product) {
    final MetadataElement globalElement = new MetadataElement("Global_Attributes");
    addAttributesToElement(globalAttributes, globalElement);

    final MetadataElement metadataRoot = product.getMetadataRoot();
    metadataRoot.addElement(globalElement);
  }
コード例 #6
0
ファイル: ProductUtilities.java プロジェクト: bcdev/glob-box
  static boolean isDiagnosticDataSet(final Product product) {
    final MetadataElement pa = product.getMetadataRoot().getElement(GLOBAL_ATTRIBUTES);

    if (pa == null) {
      return false;
    }

    final MetadataAttribute siteId = pa.getAttribute(ProductAttributes.SITE_ID);
    final MetadataAttribute siteLat = pa.getAttribute(ProductAttributes.SITE_LAT);
    final MetadataAttribute siteLon = pa.getAttribute(ProductAttributes.SITE_LON);

    return siteId != null && siteLat != null && siteLon != null;
  }
コード例 #7
0
  protected Product createProduct(
      GCTileFile refGcFile, String prodName, String prodType, int width, int height)
      throws IOException {
    final Product product = new Product(prodName, prodType, width, height);
    product.setFileLocation(new File(refGcFile.getFilePath()));
    product.setStartTime(refGcFile.getStartDate());
    product.setEndTime(refGcFile.getEndDate());

    addGeoCoding(product);
    addBands(product, refGcFile);
    addIndexCodingAndBitmasks(product.getBand("SM"));
    refGcFile.readMetadata(product.getMetadataRoot());
    return product;
  }
コード例 #8
0
ファイル: Slant2HeightOp.java プロジェクト: ppolabs/jlinda
  private void constructSourceMetadata() throws Exception {

    // define sourceMaster/sourceSlave name tags
    final String masterTag = "ifg";
    final String slaveTag = "dummy";
    final MetadataElement masterMeta = AbstractMetadata.getAbstractedMetadata(sourceProduct);
    final String slaveMetadataRoot = AbstractMetadata.SLAVE_METADATA_ROOT;
    MetadataElement[] slaveRoot;

    /* organize metadata */
    // put sourceMaster metadata into the masterMap
    metaMapPut(masterTag, masterMeta, sourceProduct, masterMap);

    // pug sourceSlave metadata into slaveDefoMap
    slaveRoot = sourceProduct.getMetadataRoot().getElement(slaveMetadataRoot).getElements();
    for (MetadataElement meta : slaveRoot) {
      metaMapPut(slaveTag, meta, sourceProduct, slaveMap);
    }
  }
コード例 #9
0
  public void addSmiMetadata(final Product product) {
    //        Variable l3mvar = ncFile.findVariable("l3m_data");
    final MetadataElement bandAttributes = new MetadataElement("Band_Attributes");
    List<Variable> variables = ncFile.getVariables();
    for (Variable variable : variables) {
      final String name = variable.getShortName();
      final MetadataElement sdsElement = new MetadataElement(name);
      final int dataType = getProductDataType(variable);
      final MetadataAttribute prodtypeattr = new MetadataAttribute("data_type", dataType);

      sdsElement.addAttribute(prodtypeattr);
      bandAttributes.addElement(sdsElement);

      final List<Attribute> list = variable.getAttributes();
      for (Attribute varAttribute : list) {
        addAttributeToElement(sdsElement, varAttribute);
      }
    }
    final MetadataElement metadataRoot = product.getMetadataRoot();
    metadataRoot.addElement(bandAttributes);
  }
コード例 #10
0
 private ProductNodeSubsetPane createAnnotationSubsetPane() {
   final MetadataElement metadataRoot = product.getMetadataRoot();
   final MetadataElement[] metadataElements = metadataRoot.getElements();
   final String[] metaNodes;
   if (metadataElements.length == 0) {
     return null;
   }
   // metadata elements must be added to includeAlways list
   // to ensure that they are selected if isIgnoreMetada is set to false
   if (givenProductSubsetDef != null && !givenProductSubsetDef.isIgnoreMetadata()) {
     metaNodes = new String[metadataElements.length];
     for (int i = 0; i < metadataElements.length; i++) {
       final MetadataElement metadataElement = metadataElements[i];
       metaNodes[i] = metadataElement.getName();
     }
   } else {
     metaNodes = new String[0];
   }
   final String[] includeNodes = StringUtils.addToArray(metaNodes, Product.HISTORY_ROOT_NAME);
   return new ProductNodeSubsetPane(metadataElements, includeNodes, true);
 }
コード例 #11
0
ファイル: ProductUtilities.java プロジェクト: bcdev/glob-box
  static boolean addDiagnosticSitePin(Product product) {
    final MetadataElement pa = product.getMetadataRoot().getElement(GLOBAL_ATTRIBUTES);
    if (pa == null || product.getGeoCoding() == null) {
      return false;
    }

    final MetadataAttribute siteIdAttr = pa.getAttribute(ProductAttributes.SITE_ID);
    final MetadataAttribute siteLonAttr = pa.getAttribute(ProductAttributes.SITE_LON);
    final MetadataAttribute siteLatAttr = pa.getAttribute(ProductAttributes.SITE_LAT);
    if (siteIdAttr == null || siteLonAttr == null || siteLatAttr == null) {
      return false;
    }

    final String siteId = siteIdAttr.getData().getElemString();
    final float siteLon = siteLonAttr.getData().getElemFloat();
    final float siteLat = siteLatAttr.getData().getElemFloat();

    final String pinName = new StringBuilder("SITE").append("_").append(siteId).toString();
    if (product.getPinGroup().contains(pinName)) {
      return false;
    }

    final String pinLabel = pa.getAttributeString(ProductAttributes.SITE_NAME, pinName);

    final Placemark pointPlacemark =
        Placemark.createPointPlacemark(
            PinDescriptor.getInstance(),
            pinName,
            pinLabel,
            "GlobColour diagnostic site",
            null,
            new GeoPos(siteLat, siteLon),
            product.getGeoCoding());
    product.getPinGroup().add(pointPlacemark);

    return true;
  }
コード例 #12
0
  public void addGeocoding(Product product) throws IOException {

    double pixelX = 0.5;
    double pixelY = 0.5;
    double easting;
    double northing;
    double pixelSizeX;
    double pixelSizeY;
    boolean pixelRegistered = true;
    if (productReader.getProductType() == SeadasProductReader.ProductType.ANCNRT) {
      pixelRegistered = false;
    }
    if (productReader.getProductType() == SeadasProductReader.ProductType.OISST) {

      Variable lon = ncFile.findVariable("lon");
      Variable lat = ncFile.findVariable("lat");
      Array lonData = lon.read();
      // TODO: handle the 180 degree shift with the NOAA products - need to modify
      // SeaDasFileReader:readBandData
      // Below is a snippet from elsewhere in BEAM that deals with this issue...
      // SPECIAL CASE: check if we have a global geographic lat/lon with lon from 0..360 instead of
      // -180..180
      //            if (isShifted180(lonData)) {
      //                // if this is true, subtract 180 from all longitudes and
      //                // add a global attribute which will be analyzed when setting up the
      // image(s)
      //                final List<Variable> variables = ncFile.getVariables();
      //                for (Variable next : variables) {
      //                    next.getAttributes().add(new Attribute("LONGITUDE_SHIFTED_180", 1));
      //                }
      //                for (int i = 0; i < lonData.getSize(); i++) {
      //                    final Index ii = lonData.getIndex().set(i);
      //                    final double theLon = lonData.getDouble(ii) - 180.0;
      //                    lonData.setDouble(ii, theLon);
      //                }
      //            }
      final Array latData = lat.read();

      final int lonSize = lon.getShape(0);
      final Index i0 = lonData.getIndex().set(0);
      final Index i1 = lonData.getIndex().set(lonSize - 1);

      pixelSizeX =
          (lonData.getDouble(i1) - lonData.getDouble(i0)) / (product.getSceneRasterWidth() - 1);
      easting = lonData.getDouble(i0);

      final int latSize = lat.getShape(0);
      final Index j0 = latData.getIndex().set(0);
      final Index j1 = latData.getIndex().set(latSize - 1);
      pixelSizeY =
          (latData.getDouble(j1) - latData.getDouble(j0)) / (product.getSceneRasterHeight() - 1);

      // this should be the 'normal' case
      if (pixelSizeY < 0) {
        pixelSizeY = -pixelSizeY;
        northing = latData.getDouble(latData.getIndex().set(0));
      } else {
        northing = latData.getDouble(latData.getIndex().set(latSize - 1));
      }
      northing -= pixelSizeX / 2.0;
      easting += pixelSizeY / 2.0;

      try {
        product.setGeoCoding(
            new CrsGeoCoding(
                DefaultGeographicCRS.WGS84,
                product.getSceneRasterWidth(),
                product.getSceneRasterHeight(),
                easting,
                northing,
                pixelSizeX,
                pixelSizeY,
                pixelX,
                pixelY));
      } catch (FactoryException e) {
        throw new IllegalStateException(e);
      } catch (TransformException e) {
        throw new IllegalStateException(e);
      }

    } else {

      String east = "Easternmost_Longitude";
      String west = "Westernmost_Longitude";
      String north = "Northernmost_Latitude";
      String south = "Southernmost_Latitude";
      Attribute latmax = ncFile.findGlobalAttributeIgnoreCase("geospatial_lat_max");
      if (latmax != null) {
        east = "geospatial_lon_max";
        west = "geospatial_lon_min";
        north = "geospatial_lat_max";
        south = "geospatial_lat_min";
      } else {
        latmax = ncFile.findGlobalAttributeIgnoreCase("upper_lat");
        if (latmax != null) {
          east = "right_lon";
          west = "left_lon";
          north = "upper_lat";
          south = "lower_lat";
        }
      }

      final MetadataElement globalAttributes =
          product.getMetadataRoot().getElement("Global_Attributes");
      easting = (float) globalAttributes.getAttribute(east).getData().getElemDouble();
      float westing = (float) globalAttributes.getAttribute(west).getData().getElemDouble();
      pixelSizeX = Math.abs(easting - westing) / product.getSceneRasterWidth();
      northing = (float) globalAttributes.getAttribute(north).getData().getElemDouble();
      float southing = (float) globalAttributes.getAttribute(south).getData().getElemDouble();
      if (northing < southing) {
        mustFlipY = true;
        northing = (float) globalAttributes.getAttribute(south).getData().getElemDouble();
        southing = (float) globalAttributes.getAttribute(north).getData().getElemDouble();
      }
      pixelSizeY = Math.abs(northing - southing) / product.getSceneRasterHeight();
      if (pixelRegistered) {
        northing -= pixelSizeY / 2.0;
        westing += pixelSizeX / 2.0;
      } else {
        pixelX = 0.0;
        pixelY = 0.0;
      }
      try {
        product.setGeoCoding(
            new CrsGeoCoding(
                DefaultGeographicCRS.WGS84,
                product.getSceneRasterWidth(),
                product.getSceneRasterHeight(),
                westing,
                northing,
                pixelSizeX,
                pixelSizeY,
                pixelX,
                pixelY));
      } catch (FactoryException e) {
        throw new IllegalStateException(e);
      } catch (TransformException e) {
        throw new IllegalStateException(e);
      }
    }
  }
コード例 #13
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);
    }
  }