static boolean setFlagCodingsAndBitmaskDefs(final Product product) { final FlagCoding flagCoding = new FlagCoding("GLOBCOLOUR"); for (Flags flag : Flags.values()) { flagCoding.addFlag(flag.name(), flag.getMask(), flag.getDescription()); } boolean codingAdded = false; for (final String name : product.getBandNames()) { if (name.endsWith("flags")) { final Band band = product.getBand(name); if (band == null || band.isFloatingPointType() || band.getFlagCoding() != null) { continue; } if (!product.getFlagCodingGroup().contains(flagCoding.getName())) { product.getFlagCodingGroup().add(flagCoding); } band.setSampleCoding(flagCoding); addBitmaskDefinitions(product, name); codingAdded = true; } } return codingAdded; }
static boolean setQuicklookBandName(Product product) { if (product.getQuicklookBandName() == null) { for (String name : product.getBandNames()) { if (name.endsWith("mean") || name.endsWith("value")) { product.setQuicklookBandName(name); return true; } } } return false; }
@Override public void initialize() throws OperatorException { subsetReader = new ProductSubsetBuilder(); ProductSubsetDef subsetDef = new ProductSubsetDef(); if (tiePointGridNames != null) { subsetDef.addNodeNames(tiePointGridNames); } else { subsetDef.addNodeNames(sourceProduct.getTiePointGridNames()); } if (bandNames != null) { subsetDef.addNodeNames(bandNames); } else { subsetDef.addNodeNames(sourceProduct.getBandNames()); } String[] nodeNames = subsetDef.getNodeNames(); if (nodeNames != null) { final ArrayList<String> referencedNodeNames = new ArrayList<String>(); for (String nodeName : nodeNames) { collectReferencedRasters(nodeName, referencedNodeNames); } subsetDef.addNodeNames(referencedNodeNames.toArray(new String[referencedNodeNames.size()])); } if (geoRegion != null) { region = computePixelRegion(sourceProduct, geoRegion, 0); } if (fullSwath) { region = new Rectangle(0, region.y, sourceProduct.getSceneRasterWidth(), region.height); } if (region != null) { if (region.isEmpty()) { throw new OperatorException("No intersection with source product boundary."); } subsetDef.setRegion(region); } subsetDef.setSubSampling(subSamplingX, subSamplingY); if (copyMetadata) { subsetDef.setIgnoreMetadata(false); } try { targetProduct = subsetReader.readProductNodes(sourceProduct, subsetDef); } catch (Throwable t) { throw new OperatorException(t); } }
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++); } } }
private void metaMapPut( final String tag, final MetadataElement root, final Product product, final HashMap<Integer, CplxContainer> map) throws Exception { // pull out band names for this product final String[] bandNames = product.getBandNames(); final int numOfBands = bandNames.length; // map key: ORBIT NUMBER int mapKey = root.getAttributeInt(AbstractMetadata.ABS_ORBIT); // metadata: construct classes and define bands final String date = OperatorUtils.getAcquisitionDate(root); final SLCImage meta = new SLCImage(root); final Orbit orbit = new Orbit(root, orbitDegree); // TODO: mlook factores are hard-coded for now meta.setMlAz(1); meta.setMlRg(1); Band bandReal = null; Band bandImag = null; for (int i = 0; i < numOfBands; i++) { String bandName = bandNames[i]; if (bandName.contains(tag) && bandName.contains(date)) { final Band band = product.getBandAt(i); if (BandUtilsDoris.isBandReal(band)) { bandReal = band; } else if (product.getBandAt(i).getUnit().contains(Unit.ABS_PHASE)) { bandReal = band; } else if (BandUtilsDoris.isBandImag(band)) { bandImag = band; } } } try { map.put(mapKey, new CplxContainer(date, meta, orbit, bandReal, bandImag)); } catch (Exception e) { e.printStackTrace(); } }
public static void getSpectralBandList( Product inputProduct, String bandNamePrefix, String bandNameSuffix, int[] excludeBandIndices, ArrayList<Band> bandList) { final String[] bandNames = inputProduct.getBandNames(); Comparator<Band> byWavelength = new WavelengthComparator(); for (String name : bandNames) { if (name.startsWith(bandNamePrefix) && name.endsWith(bandNameSuffix)) { boolean exclude = false; if (excludeBandIndices != null) { for (int i : excludeBandIndices) { exclude = exclude || (i == inputProduct.getBand(name).getSpectralBandIndex() + 1); } } if (!exclude) { bandList.add(inputProduct.getBand(name)); } } } Collections.sort(bandList, byWavelength); }
// 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); } }