예제 #1
1
  public Map<Band, Variable> addBands(
      Product product, Variable idxVariable, List<Variable> l3ProdVars) {

    final Structure binListStruc = (Structure) idxVariable;

    final Map<Band, Variable> bandToVariableMap = new HashMap<Band, Variable>();

    //        bandToVariableMap.put(addBand(product, "bin_num", ProductData.TYPE_UINT32),
    // binListStruc.select("bin_num").findVariable("bin_num"));
    bandToVariableMap.put(
        addBand(product, "weights", ProductData.TYPE_FLOAT32),
        binListStruc.select("weights").findVariable("weights"));
    bandToVariableMap.put(
        addBand(product, "nobs", ProductData.TYPE_UINT16),
        binListStruc.select("nobs").findVariable("nobs"));
    bandToVariableMap.put(
        addBand(product, "nscenes", ProductData.TYPE_UINT16),
        binListStruc.select("nscenes").findVariable("nscenes"));
    //        ncFile.getRootGroup().findGroup("Level-3 Binned Data").findVariable("BinList");
    if (ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("qual_l3") != null) {
      bandToVariableMap.put(
          addBand(product, "qual_l3", ProductData.TYPE_UINT8),
          ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("qual_l3"));
    }
    String groupnames = "";
    for (Variable l3Var : l3ProdVars) {
      String varName = l3Var.getShortName();
      final int dataType = ProductData.TYPE_FLOAT32;

      if (!varName.contains("Bin")
          && (!varName.startsWith("qual"))
          && (!varName.equalsIgnoreCase("SEAGrid"))
          && (!varName.equalsIgnoreCase("Input_Files"))) {
        final Structure binStruc = (Structure) l3Var;
        if (groupnames.length() == 0) {
          groupnames = varName;
        } else {
          groupnames = groupnames + ":" + varName;
        }

        List<String> vnames = binStruc.getVariableNames();
        for (String bandvar : vnames) {
          bandToVariableMap.put(
              addBand(product, bandvar, dataType), binStruc.select(bandvar).findVariable(bandvar));
        }
        // Add virtual band for product mean
        StringBuilder prodname = new StringBuilder(varName);
        prodname.append("_mean");

        String calcmean = ComputeBinMeans(varName);
        Band varmean =
            new VirtualBand(
                prodname.toString(),
                ProductData.TYPE_FLOAT32,
                product.getSceneRasterWidth(),
                product.getSceneRasterHeight(),
                calcmean);
        varmean.setNoDataValue(Double.NaN);
        varmean.setNoDataValueUsed(true);
        product.addBand(varmean);

        // Add virtual band for product stdev
        int underscore = prodname.indexOf("_mean");
        prodname.delete(underscore, underscore + 5);
        prodname.append("_stdev");

        String calcstdev = ComputeBinVariances(varName);

        Band varstdev =
            new VirtualBand(
                prodname.toString(),
                ProductData.TYPE_FLOAT32,
                product.getSceneRasterWidth(),
                product.getSceneRasterHeight(),
                calcstdev);
        varstdev.setNoDataValue(Double.NaN);
        varstdev.setNoDataValueUsed(true);

        product.addBand(varstdev);
      }
    }
    product.setAutoGrouping(groupnames);
    return bandToVariableMap;
  }
예제 #2
0
 private ProductNodeSubsetPane createBandSubsetPane() {
   Band[] bands = product.getBands();
   if (bands.length == 0) {
     return null;
   }
   return new ProductNodeSubsetPane(product.getBands(), true);
 }
예제 #3
0
  /**
   * Provides an implementation of the <code>readProductNodes</code> interface method. Clients
   * implementing this method can be sure that the input object and eventually the subset
   * information has already been set.
   *
   * <p>
   *
   * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code>
   * method.
   *
   * @throws java.io.IOException if an I/O error occurs
   */
  @Override
  protected Product readProductNodesImpl() throws IOException {

    Product product;
    try {
      final File fileFromInput = ReaderUtils.getFileFromInput(getInput());
      dataDir = createDirectory(fileFromInput);
      dataDir.readProductDirectory();
      product = dataDir.createProduct();
      addCalibrationLUT(product, fileFromInput.getParentFile());
      product.getGcpGroup();
      product.setFileLocation(fileFromInput);
      product.setProductReader(this);
      product.setModified(false);

      final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
      isAscending = absRoot.getAttributeString(AbstractMetadata.PASS).equals("ASCENDING");
      isAntennaPointingRight =
          absRoot.getAttributeString(AbstractMetadata.antenna_pointing).equals("right");
    } catch (Exception e) {
      Debug.trace(e.toString());
      final IOException ioException = new IOException(e.getMessage());
      ioException.initCause(e);
      throw ioException;
    }

    return product;
  }
예제 #4
0
 private void addSubsetInfoMetadata(Product product) {
   if (getSubsetDef() != null) {
     ProductSubsetDef subsetDef = getSubsetDef();
     Product sourceProduct = getSourceProduct();
     String nameSubsetinfo = "SubsetInfo";
     MetadataElement subsetElem = new MetadataElement(nameSubsetinfo);
     addAttribString("SourceProduct.name", sourceProduct.getName(), subsetElem);
     subsetElem.setAttributeInt("SubSampling.x", subsetDef.getSubSamplingX());
     subsetElem.setAttributeInt("SubSampling.y", subsetDef.getSubSamplingY());
     if (subsetDef.getRegion() != null) {
       Rectangle region = subsetDef.getRegion();
       subsetElem.setAttributeInt("SubRegion.x", region.x);
       subsetElem.setAttributeInt("SubRegion.y", region.y);
       subsetElem.setAttributeInt("SubRegion.width", region.width);
       subsetElem.setAttributeInt("SubRegion.height", region.height);
     }
     String[] nodeNames = subsetDef.getNodeNames();
     if (nodeNames != null) {
       for (int i = 0; i < nodeNames.length; i++) {
         addAttribString("ProductNodeName." + (i + 1), nodeNames[i], subsetElem);
       }
     }
     ProductUtils.addElementToHistory(product, subsetElem);
   }
 }
예제 #5
0
  @Override
  public Product createProduct() throws IOException {

    sceneHeight =
        ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("BinIndex").getShape(0);
    sceneWidth = sceneHeight * 2;

    grid = new ISINGrid(sceneHeight);

    String productName = getStringAttribute("Product_Name");

    Product product =
        new Product(productName, "NASA-OBPG-L3", sceneWidth, sceneHeight, productReader);
    product.setFileLocation(productReader.getInputFile());
    product.setProductReader(productReader);

    addGlobalMetadata(product);

    final Variable idxVariable =
        ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("BinList");
    List<Variable> l3ProdVars = ncFile.getVariables();
    variableMap = addBands(product, idxVariable, l3ProdVars);
    //        try {
    //            addBandsBinMap(product);
    //        } catch (InvalidRangeException e) {
    //            e.printStackTrace();
    //        }
    if (product.getNumBands() == 0) {
      throw new ProductIOException("No bands found.");
    }

    initGeoCoding(product);

    return product;
  }
예제 #6
0
  private static void setSubsetSRGRCoefficients(
      final Product sourceProduct,
      final Product targetProduct,
      final ProductSubsetDef subsetDef,
      final MetadataElement absRoot,
      final boolean nearRangeOnLeft) {

    final MetadataElement SRGRCoefficientsElem = absRoot.getElement("SRGR_Coefficients");
    if (SRGRCoefficientsElem != null) {
      final double rangeSpacing = absRoot.getAttributeDouble("RANGE_SPACING", 0);
      final double colIndex = subsetDef.getRegion() == null ? 0 : subsetDef.getRegion().getX();

      for (MetadataElement srgrList : SRGRCoefficientsElem.getElements()) {
        final double grO = srgrList.getAttributeDouble("ground_range_origin", 0);
        double ground_range_origin_subset;
        if (nearRangeOnLeft) {
          ground_range_origin_subset = grO + colIndex * rangeSpacing;
        } else {
          final double colIndexFromRight =
              sourceProduct.getSceneRasterWidth() - colIndex - targetProduct.getSceneRasterWidth();
          ground_range_origin_subset = grO + colIndexFromRight * rangeSpacing;
        }
        srgrList.setAttributeDouble("ground_range_origin", ground_range_origin_subset);
      }
    }
  }
예제 #7
0
 private ProductNodeSubsetPane createTiePointGridSubsetPane() {
   TiePointGrid[] tiePointGrids = product.getTiePointGrids();
   if (tiePointGrids.length == 0) {
     return null;
   }
   return new ProductNodeSubsetPane(
       product.getTiePointGrids(),
       new String[] {BeamConstants.LAT_DS_NAME, BeamConstants.LON_DS_NAME},
       true);
 }
예제 #8
0
 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;
 }
예제 #9
0
 private static boolean isNearRangeOnLeft(final Product product) {
   final TiePointGrid incidenceAngle = product.getTiePointGrid("incident_angle");
   if (incidenceAngle != null) {
     final double incidenceAngleToFirstPixel = incidenceAngle.getPixelDouble(0, 0);
     final double incidenceAngleToLastPixel =
         incidenceAngle.getPixelDouble(product.getSceneRasterWidth() - 1, 0);
     return (incidenceAngleToFirstPixel < incidenceAngleToLastPixel);
   } else {
     return true;
   }
 }
예제 #10
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);
   }
 }
예제 #11
0
  private static RasterDataNode[] getReferencedNodes(final RasterDataNode node) {
    final Product product = node.getProduct();
    if (product != null) {
      final List<String> expressions = new ArrayList<String>(10);
      if (node.getValidPixelExpression() != null) {
        expressions.add(node.getValidPixelExpression());
      }
      final ProductNodeGroup<Mask> overlayMaskGroup = node.getOverlayMaskGroup();
      if (overlayMaskGroup.getNodeCount() > 0) {
        final Mask[] overlayMasks =
            overlayMaskGroup.toArray(new Mask[overlayMaskGroup.getNodeCount()]);
        for (final Mask overlayMask : overlayMasks) {
          final String expression;
          if (overlayMask.getImageType() == Mask.BandMathsType.INSTANCE) {
            expression = Mask.BandMathsType.getExpression(overlayMask);
          } else if (overlayMask.getImageType() == Mask.RangeType.INSTANCE) {
            expression = Mask.RangeType.getExpression(overlayMask);
          } else {
            expression = null;
          }
          if (expression != null) {
            expressions.add(expression);
          }
        }
      }
      if (node instanceof VirtualBand) {
        final VirtualBand virtualBand = (VirtualBand) node;
        expressions.add(virtualBand.getExpression());
      }

      final ArrayList<Term> termList = new ArrayList<Term>(10);
      for (final String expression : expressions) {
        try {
          final Term term = product.parseExpression(expression);
          if (term != null) {
            termList.add(term);
          }
        } catch (ParseException e) {
          // @todo se handle parse exception
          Debug.trace(e);
        }
      }

      final Term[] terms = termList.toArray(new Term[termList.size()]);
      final RasterDataSymbol[] refRasterDataSymbols = BandArithmetic.getRefRasterDataSymbols(terms);
      return BandArithmetic.getRefRasters(refRasterDataSymbols);
    }
    return new RasterDataNode[0];
  }
예제 #12
0
  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);
    }
  }
예제 #13
0
  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);
    }
  }
예제 #14
0
  public void addGlobalMetadata(Product product) {
    final MetadataElement globalElement = new MetadataElement("Global_Attributes");
    addAttributesToElement(globalAttributes, globalElement);

    final MetadataElement metadataRoot = product.getMetadataRoot();
    metadataRoot.addElement(globalElement);
  }
예제 #15
0
  protected void addTiePointGridsToProduct(final Product product) {
    final GeoCoding geoCoding = getSourceProduct().getGeoCoding();
    final String latGridName;
    final String lonGridName;
    if (geoCoding instanceof TiePointGeoCoding) {
      final TiePointGeoCoding tiePointGeoCoding = (TiePointGeoCoding) geoCoding;
      final TiePointGrid latGrid = tiePointGeoCoding.getLatGrid();
      final TiePointGrid lonGrid = tiePointGeoCoding.getLonGrid();
      latGridName = latGrid.getName();
      lonGridName = lonGrid.getName();
    } else {
      latGridName = null;
      lonGridName = null;
    }

    for (int i = 0; i < getSourceProduct().getNumTiePointGrids(); i++) {
      final TiePointGrid sourceTiePointGrid = getSourceProduct().getTiePointGridAt(i);
      final String gridName = sourceTiePointGrid.getName();

      if (isNodeAccepted(gridName)
          || (gridName.equals(latGridName) || gridName.equals(lonGridName))) {
        final TiePointGrid tiePointGrid =
            TiePointGrid.createSubset(sourceTiePointGrid, getSubsetDef());
        if (isFullScene(getSubsetDef()) && sourceTiePointGrid.isStxSet()) {
          copyStx(sourceTiePointGrid, tiePointGrid);
        }
        product.addTiePointGrid(tiePointGrid);
        copyImageInfo(sourceTiePointGrid, tiePointGrid);
      }
    }
  }
예제 #16
0
 private Band addBand(Product product, String varName, int productType) {
   Band band =
       new Band(
           varName, productType, product.getSceneRasterWidth(), product.getSceneRasterHeight());
   band.setScalingOffset(0.0);
   band.setScalingFactor(1.0);
   band.setLog10Scaled(false);
   if (productType == ProductData.TYPE_FLOAT32) {
     band.setNoDataValue(Double.NaN);
   } else {
     band.setNoDataValue(-999);
   }
   band.setNoDataValueUsed(true);
   product.addBand(band);
   return band;
 }
예제 #17
0
 private void initGeoCoding(Product product) throws IOException {
   float pixelX = 0.0f;
   float pixelY = 0.0f;
   float easting = -180f;
   float northing = +90f;
   float pixelSizeX = 360.0f / sceneWidth;
   float pixelSizeY = 180.0f / sceneHeight;
   try {
     product.setGeoCoding(
         new CrsGeoCoding(
             DefaultGeographicCRS.WGS84,
             sceneWidth,
             sceneHeight,
             easting,
             northing,
             pixelSizeX,
             pixelSizeY,
             pixelX,
             pixelY));
   } catch (FactoryException e) {
     throw new IOException(e);
   } catch (TransformException e) {
     throw new IOException(e);
   }
 }
예제 #18
0
  private static void setLatLongMetadata(
      final Product product,
      final MetadataElement absRoot,
      final String tagLat,
      final String tagLon,
      final float x,
      final float y) {
    final PixelPos pixelPos = new PixelPos(x, y);
    final GeoPos geoPos = new GeoPos();
    if (product.getGeoCoding() == null) return;
    product.getGeoCoding().getGeoPos(pixelPos, geoPos);

    final MetadataAttribute lat = absRoot.getAttribute(tagLat);
    if (lat != null) lat.getData().setElemDouble(geoPos.getLat());
    final MetadataAttribute lon = absRoot.getAttribute(tagLon);
    if (lon != null) lon.getData().setElemDouble(geoPos.getLon());
  }
예제 #19
0
 protected void setSpectralBand(Product product) {
   int spectralBandIndex = 0;
   for (String name : product.getBandNames()) {
     Band band = product.getBandAt(product.getBandIndex(name));
     if (name.matches("\\w+_\\d{3,}")) {
       String[] parts = name.split("_");
       String wvlstr = parts[parts.length - 1].trim();
       // Some bands have the wvl portion in the middle...
       if (!wvlstr.matches("^\\d{3,}")) {
         wvlstr = parts[parts.length - 2].trim();
       }
       final float wavelength = Float.parseFloat(wvlstr);
       band.setSpectralWavelength(wavelength);
       band.setSpectralBandIndex(spectralBandIndex++);
     }
   }
 }
예제 #20
0
  protected Band addNewBand(Product product, Variable variable) {
    final int sceneRasterWidth = product.getSceneRasterWidth();
    final int sceneRasterHeight = product.getSceneRasterHeight();
    Band band = null;

    int variableRank = variable.getRank();
    if (variableRank == 2) {
      final int[] dimensions = variable.getShape();
      final int height = dimensions[0] - leadLineSkip - tailLineSkip;
      final int width = dimensions[1];
      if (height == sceneRasterHeight && width == sceneRasterWidth) {
        final String name = variable.getShortName();
        final int dataType = getProductDataType(variable);
        band = new Band(name, dataType, width, height);
        final String validExpression = bandInfoMap.get(name);
        if (validExpression != null && !validExpression.equals("")) {
          band.setValidPixelExpression(validExpression);
        }
        product.addBand(band);

        try {
          band.setNoDataValue(
              (double) variable.findAttribute("bad_value_scaled").getNumericValue().floatValue());
          band.setNoDataValueUsed(true);
        } catch (Exception ignored) {
        }

        final List<Attribute> list = variable.getAttributes();
        for (Attribute hdfAttribute : list) {
          final String attribName = hdfAttribute.getShortName();
          if ("units".equals(attribName)) {
            band.setUnit(hdfAttribute.getStringValue());
          } else if ("long_name".equals(attribName)) {
            band.setDescription(hdfAttribute.getStringValue());
          } else if ("slope".equals(attribName)) {
            band.setScalingFactor(hdfAttribute.getNumericValue(0).doubleValue());
          } else if ("intercept".equals(attribName)) {
            band.setScalingOffset(hdfAttribute.getNumericValue(0).doubleValue());
          }
        }
      }
    }
    return band;
  }
예제 #21
0
  private boolean checkFlagDatasetIncluded() {
    final String[] nodeNames = productSubsetDef.getNodeNames();
    final List<String> flagDsNameList = new ArrayList<String>(10);
    boolean flagDsInSubset = false;
    for (int i = 0; i < product.getNumBands(); i++) {
      Band band = product.getBandAt(i);
      if (band.getFlagCoding() != null) {
        flagDsNameList.add(band.getName());
        if (StringUtils.contains(nodeNames, band.getName())) {
          flagDsInSubset = true;
        }
        break;
      }
    }

    final int numFlagDs = flagDsNameList.size();
    boolean ok = true;
    if (numFlagDs > 0 && !flagDsInSubset) {
      int status =
          JOptionPane.showConfirmDialog(
              getJDialog(),
              "No flag dataset selected.\n\n"
                  + "If you do not include a flag dataset in the subset,\n"
                  + "you will not be able to create bitmask overlays.\n\n"
                  + "Do you wish to include the available flag dataset(s)\n"
                  + "in the current subset?\n",
              "No Flag Dataset Selected",
              JOptionPane.YES_NO_CANCEL_OPTION);
      if (status == JOptionPane.YES_OPTION) {
        productSubsetDef.addNodeNames(flagDsNameList.toArray(new String[numFlagDs]));
        ok = true;
      } else if (status == JOptionPane.NO_OPTION) {
        /* OK, no flag datasets wanted */
        ok = true;
      } else if (status == JOptionPane.CANCEL_OPTION) {
        ok = false;
      }
    }

    return ok;
  }
예제 #22
0
  private Product createProduct() {
    Product sourceProduct = getSourceProduct();
    Debug.assertNotNull(sourceProduct);
    Debug.assertTrue(getSceneRasterWidth() > 0);
    Debug.assertTrue(getSceneRasterHeight() > 0);
    final String newProductName;
    if (this.newProductName == null || this.newProductName.length() == 0) {
      newProductName = sourceProduct.getName();
    } else {
      newProductName = this.newProductName;
    }
    final Product product =
        new Product(
            newProductName,
            sourceProduct.getProductType(),
            getSceneRasterWidth(),
            getSceneRasterHeight(),
            this);
    product.setPointingFactory(sourceProduct.getPointingFactory());
    if (newProductDesc == null || newProductDesc.length() == 0) {
      product.setDescription(sourceProduct.getDescription());
    } else {
      product.setDescription(newProductDesc);
    }
    if (!isMetadataIgnored()) {
      ProductUtils.copyMetadata(sourceProduct, product);
      addTiePointGridsToProduct(product);
      addFlagCodingsToProduct(product);
      addIndexCodingsToProduct(product);
    }
    addBandsToProduct(product);
    if (!isMetadataIgnored()) {
      addGeoCodingToProduct(product);
    }
    ProductUtils.copyVectorData(sourceProduct, product);
    ProductUtils.copyMasks(sourceProduct, product);
    ProductUtils.copyOverlayMasks(sourceProduct, product);
    ProductUtils.copyPreferredTileSize(sourceProduct, product);
    setSceneRasterStartAndStopTime(product);
    addSubsetInfoMetadata(product);

    return product;
  }
예제 #23
0
 private void updateMemDisplay() {
   if (product != null) {
     long storageMem = product.getRawStorageSize(productSubsetDef);
     double factor = 1.0 / (1024 * 1024);
     double megas = MathUtils.round(factor * storageMem, 10);
     if (megas > memWarnLimit) {
       memLabel.setForeground(MEM_LABEL_WARN_COLOR);
     } else {
       memLabel.setForeground(MEM_LABEL_NORM_COLOR);
     }
     memLabel.setText(MEM_LABEL_TEXT + megas + "M");
   } else {
     memLabel.setText(" ");
   }
 }
예제 #24
0
  private boolean checkReferencedRastersIncluded() {
    final Set<String> notIncludedNames = new TreeSet<String>();
    final List<String> includedNodeNames = Arrays.asList(productSubsetDef.getNodeNames());
    for (final String nodeName : includedNodeNames) {
      final RasterDataNode rasterDataNode = product.getRasterDataNode(nodeName);
      if (rasterDataNode != null) {
        collectNotIncludedReferences(rasterDataNode, notIncludedNames);
      }
    }

    boolean ok = true;
    if (!notIncludedNames.isEmpty()) {
      StringBuilder nameListText = new StringBuilder();
      for (String notIncludedName : notIncludedNames) {
        nameListText.append("  '").append(notIncludedName).append("'\n");
      }

      final String pattern =
          "The following dataset(s) are referenced but not included\n"
              + "in your current subset definition:\n"
              + "{0}\n"
              + "If you do not include these dataset(s) into your selection,\n"
              + "you might get unexpected results while working with the\n"
              + "resulting product.\n\n"
              + "Do you wish to include the referenced dataset(s) into your\n"
              + "subset definition?\n"; /*I18N*/
      final MessageFormat format = new MessageFormat(pattern);
      int status =
          JOptionPane.showConfirmDialog(
              getJDialog(),
              format.format(new Object[] {nameListText.toString()}),
              "Incomplete Subset Definition", /*I18N*/
              JOptionPane.YES_NO_CANCEL_OPTION);
      if (status == JOptionPane.YES_OPTION) {
        final String[] nodenames = notIncludedNames.toArray(new String[notIncludedNames.size()]);
        productSubsetDef.addNodeNames(nodenames);
        ok = true;
      } else if (status == JOptionPane.NO_OPTION) {
        ok = true;
      } else if (status == JOptionPane.CANCEL_OPTION) {
        ok = false;
      }
    }
    return ok;
  }
예제 #25
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);
  }
예제 #26
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);
 }
예제 #27
0
  // Don't do this...it hurts.  Too much of a memory hog...
  private void addBandsBinMap(Product product) throws IOException, InvalidRangeException {
    String[] bandList = product.getBandNames();
    if (rowInfo == null) {
      rowInfo = createRowInfos();
    }

    final int height = sceneHeight;
    final int width = sceneWidth;
    final ISINGrid grid = this.grid;

    // loop over lines
    try {
      int[] lineOffsets = new int[1];
      int[] lineLengths = new int[1];
      int[] stride = new int[1];
      stride[0] = 1;

      //            for (int y = sourceOffsetY; y < sourceOffsetY + sourceHeight; y++) {
      for (String name : bandList) {
        if (name.endsWith("mean") || name.endsWith("stdev")) continue;
        Band band = product.getBand(name);
        ProductData buffer;
        final Variable variable = variableMap.get(band);
        DataType prodtype = variable.getDataType();
        float[] fbuffer = new float[width * height];
        short[] sbuffer = new short[width * height];
        int[] ibuffer = new int[width * height];
        byte[] bbuffer = new byte[width * height];

        if (prodtype == DataType.FLOAT) {
          Arrays.fill(fbuffer, Float.NaN);
          buffer = ProductData.createInstance(fbuffer);
        } else if (prodtype == DataType.SHORT) {
          Arrays.fill(sbuffer, (short) -999);
          buffer = ProductData.createInstance(sbuffer);
        } else if (prodtype == DataType.BYTE) {
          Arrays.fill(bbuffer, (byte) 255);
          buffer = ProductData.createInstance(bbuffer);
        } else {
          Arrays.fill(ibuffer, -999);
          buffer = ProductData.createInstance(ibuffer);
        }

        for (int y = 0; y < height; y++) {

          final int rowIndex = (height - 1) - y;
          final RowInfo rowInfo = this.rowInfo[rowIndex];
          if (rowInfo != null) {
            final Array bindata;

            final int lineOffset = rowInfo.offset;
            final int lineLength = rowInfo.length;

            lineOffsets[0] = lineOffset;
            lineLengths[0] = lineLength;

            synchronized (ncFile) {
              bindata =
                  variable
                      .read()
                      .section(lineOffsets, lineLengths, stride); // .copyTo1DJavaArray();
            }
            int lineIndex0 = 0;
            for (int x = 0; x < width; x++) {
              final double lon = x * 360.0 / width;
              final int binIndex = grid.getBinIndex(rowIndex, lon);
              int lineIndex = -1;
              for (int i = lineIndex0; i < lineLength; i++) {
                int binidx = bins[lineOffset + i];
                if (binidx >= binIndex) {
                  if (binidx == binIndex) {
                    lineIndex = i;
                  }
                  lineIndex0 = i;
                  break;
                }
              }

              if (lineIndex >= 0) {
                final int rasterIndex = width * y + x;
                final Array elem;
                elem = Array.factory(bindata.copyTo1DJavaArray());
                for (int i = 0; i < elem.getSize(); i++) {
                  if (prodtype == DataType.FLOAT) {

                    buffer.setElemFloatAt(rasterIndex, elem.getFloat(i));
                  } else {
                    buffer.setElemIntAt(rasterIndex, elem.getInt(i));
                  }
                  //                                System.arraycopy(bindata, lineIndex, buffer,
                  // rasterIndex, 1);
                }
              }
            }
          }
        }
        band.setDataElems(buffer);
      }
    } catch (IOException e) {
      throw new IOException("Could not map product " + product.getName(), e);
    }
  }
예제 #28
0
  @Override
  protected void addFlagsAndMasks(Product product) {
    Band QFBand = product.getBand("l3m_qual");
    if (QFBand != null) {
      FlagCoding flagCoding = new FlagCoding("SST_Quality");
      flagCoding.addFlag("Best", 0x00, "Highest quality retrieval");
      flagCoding.addFlag("Good", 0x01, "Good quality retrieval");
      flagCoding.addFlag("Questionable", 0x02, "Questionable quality retrieval");
      flagCoding.addFlag("Bad", 0x03, "Bad quality retrieval");
      product.getFlagCodingGroup().add(flagCoding);
      QFBand.setSampleCoding(flagCoding);

      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Best",
                  "Highest quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "l3m_qual == 0",
                  SeadasFileReader.Cornflower,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Good",
                  "Good quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "l3m_qual == 1",
                  SeadasFileReader.LightPurple,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Questionable",
                  "Questionable quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "l3m_qual == 2",
                  SeadasFileReader.BurntUmber,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Bad",
                  "Bad quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "l3m_qual == 3",
                  SeadasFileReader.FailRed,
                  0.6));
    }
    QFBand = product.getBand("qual_sst");
    if (QFBand != null) {
      FlagCoding flagCoding = new FlagCoding("SST_Quality");
      flagCoding.addFlag("Best", 0x00, "Highest quality retrieval");
      flagCoding.addFlag("Good", 0x01, "Good quality retrieval");
      flagCoding.addFlag("Questionable", 0x02, "Questionable quality retrieval");
      flagCoding.addFlag("Bad", 0x03, "Bad quality retrieval");
      product.getFlagCodingGroup().add(flagCoding);
      QFBand.setSampleCoding(flagCoding);

      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Best",
                  "Highest quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst == 0",
                  SeadasFileReader.Cornflower,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Good",
                  "Good quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst == 1",
                  SeadasFileReader.LightPurple,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Questionable",
                  "Questionable quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst == 2",
                  SeadasFileReader.BurntUmber,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Bad",
                  "Bad quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst == 3",
                  SeadasFileReader.FailRed,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "No Data",
                  "No data retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst == -1",
                  SeadasFileReader.MediumGray,
                  0.6));
    }
    QFBand = product.getBand("qual_sst4");
    if (QFBand != null) {
      FlagCoding flagCoding = new FlagCoding("SST_Quality");
      flagCoding.addFlag("Best", 0x00, "Highest quality retrieval");
      flagCoding.addFlag("Good", 0x01, "Good quality retrieval");
      flagCoding.addFlag("Questionable", 0x02, "Questionable quality retrieval");
      flagCoding.addFlag("Bad", 0x03, "Bad quality retrieval");
      product.getFlagCodingGroup().add(flagCoding);
      QFBand.setSampleCoding(flagCoding);

      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Best",
                  "Highest quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst4 == 0",
                  SeadasFileReader.Cornflower,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Good",
                  "Good quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst4 == 1",
                  SeadasFileReader.LightPurple,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Questionable",
                  "Questionable quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst4 == 2",
                  SeadasFileReader.BurntUmber,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "Bad",
                  "Bad quality retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst4 == 3",
                  SeadasFileReader.FailRed,
                  0.6));
      product
          .getMaskGroup()
          .add(
              Mask.BandMathsType.create(
                  "No Data",
                  "No data retrieval",
                  product.getSceneRasterWidth(),
                  product.getSceneRasterHeight(),
                  "qual_sst4 == -1",
                  SeadasFileReader.MediumGray,
                  0.6));
    }
  }
예제 #29
0
  @Override
  public Product createProduct() throws ProductIOException {

    int[] dims;
    int sceneHeight = 0;
    int sceneWidth = 0;
    Group geodata = ncFile.findGroup("geophysical_data");
    if (productReader.getProductType() == SeadasProductReader.ProductType.OISST) {
      dims = ncFile.getVariables().get(4).getShape();
      sceneHeight = dims[2];
      sceneWidth = dims[3];
      mustFlipY = true;
    } else if (productReader.getProductType() == SeadasProductReader.ProductType.ANCCLIM) {
      List<Variable> vars = ncFile.getVariables();
      for (Variable v : vars) {
        if (v.getRank() == 2) {
          dims = v.getShape();
          sceneHeight = dims[0];
          sceneWidth = dims[1];
        }
      }
    } else {
      if (geodata != null) {
        dims = geodata.getVariables().get(0).getShape();
        sceneHeight = dims[0];
        sceneWidth = dims[1];
      } else {
        ucar.nc2.Dimension latdim = ncFile.findDimension("lat");
        ucar.nc2.Dimension londim = ncFile.findDimension("lon");
        if (latdim != null) {
          sceneHeight = latdim.getLength();
          sceneWidth = londim.getLength();
        } else {
          dims = ncFile.getVariables().get(0).getShape();
          sceneHeight = dims[0];
          sceneWidth = dims[1];
        }
      }
    }

    String productName = productReader.getInputFile().getName();
    try {
      productName = getStringAttribute("Product_Name");
    } catch (Exception ignored) {

    }

    SeadasProductReader.ProductType productType = productReader.getProductType();

    Product product = new Product(productName, productType.toString(), sceneWidth, sceneHeight);
    product.setDescription(productName);

    product.setFileLocation(productReader.getInputFile());
    product.setProductReader(productReader);

    addGlobalMetadata(product);
    addSmiMetadata(product);
    //        variableMap = addBands(product, ncFile.getVariables());
    variableMap = addSmiBands(product, ncFile.getVariables());
    try {
      addGeocoding(product);
    } catch (Exception ignored) {
    }
    addFlagsAndMasks(product);
    if (productReader.getProductType() == SeadasProductReader.ProductType.Bathy) {
      mustFlipY = true;
      Dimension tileSize = new Dimension(640, 320);
      product.setPreferredTileSize(tileSize);
    }
    return product;
  }
예제 #30
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);
      }
    }
  }