// Creates the output product for the given request. private void createOutputProduct(ProgressMonitor pm) throws IOException, ProcessorException { // take only the first output product. There might be more but we will ignore // these in SMAC. ProductRef prod = getRequest().getOutputProductAt(0); checkParamNotNull(prod, "output product"); String productType = _inputProduct.getProductType() + "_SMAC"; String productName = getOutputProductNameSafe(); int sceneWidth = _inputProduct.getSceneRasterWidth(); int sceneHeight = _inputProduct.getSceneRasterHeight(); _outputProduct = new Product(productName, productType, sceneWidth, sceneHeight); ProductWriter writer = ProcessorUtils.createProductWriter(prod); _outputProduct.setProductWriter(writer); // loop over bands and create them // ------------------------------- if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.MERIS_NAME)) { addBandsToOutput("Atmosphere corrected MERIS band ", true); } else { addBandsToOutput("Atmosphere corrected band "); } ProductUtils.copyTiePointGrids(_inputProduct, _outputProduct); copyRequestMetaData(_outputProduct); copyFlagBands(_inputProduct, _outputProduct); // for MERIS FSG / FRG products copyBand( EnvisatConstants.MERIS_AMORGOS_L1B_CORR_LATITUDE_BAND_NAME, _inputProduct, _outputProduct); copyBand( EnvisatConstants.MERIS_AMORGOS_L1B_CORR_LONGITUDE_BAND_NAME, _inputProduct, _outputProduct); copyBand(EnvisatConstants.MERIS_AMORGOS_L1B_ALTIUDE_BAND_NAME, _inputProduct, _outputProduct); copyGeoCoding(_inputProduct, _outputProduct); // and initialize the disk represenation writer.writeProductNodes(_outputProduct, new File(prod.getFilePath())); copyBandData(getBandNamesToCopy(), _inputProduct, _outputProduct, pm); }
@Override public void initialize() throws OperatorException { if (computeErrorBands) { deactivateComputeTileMethod(); } if (endmemberFile != null) { loadEndmemberFile(); } if (sourceBandNames == null || sourceBandNames.length == 0) { Band[] bands = sourceProduct.getBands(); ArrayList<String> bandNameList = new ArrayList<String>(); for (Band band : bands) { if (band.getSpectralWavelength() > 0) { bandNameList.add(band.getName()); } } sourceBandNames = bandNameList.toArray(new String[bandNameList.size()]); } validateParameters(); sourceBands = new Band[sourceBandNames.length]; for (int i = 0; i < sourceBandNames.length; i++) { String sourceBandName = sourceBandNames[i]; Band sourceBand = sourceProduct.getBand(sourceBandName); if (sourceBand == null) { throw new OperatorException("Source band not found: " + sourceBandName); } if (sourceBand.getSpectralWavelength() <= 0) { throw new OperatorException("Source band without spectral wavelength: " + sourceBandName); } sourceBands[i] = sourceBand; } int numSourceBands = sourceBands.length; int numEndmembers = endmembers.length; if (numSourceBands < numEndmembers) { throw new OperatorException("Number of source bands must be >= number of endmembers."); } double[][] lsuMatrixElements = new double[numSourceBands][numEndmembers]; for (int j = 0; j < numEndmembers; j++) { Endmember endmember = endmembers[j]; double[] wavelengths = endmember.getWavelengths(); double[] radiations = endmember.getRadiations(); for (int i = 0; i < numSourceBands; i++) { Band sourceBand = sourceBands[i]; float wavelength = sourceBand.getSpectralWavelength(); float bandwidth = sourceBand.getSpectralBandwidth(); int k = findEndmemberSpectralIndex(wavelengths, wavelength, Math.max(bandwidth, minBandwidth)); if (k == -1) { throw new OperatorException( String.format( "Band %s: No matching endmember wavelength found (%f nm)", sourceBand.getName(), wavelength)); } lsuMatrixElements[i][j] = radiations[k]; } } if (UC_LSU.equals(unmixingModelName)) { spectralUnmixing = new UnconstrainedLSU(lsuMatrixElements); } else if (C_LSU.equals(unmixingModelName)) { spectralUnmixing = new ConstrainedLSU(lsuMatrixElements); } else if (FC_LSU.equals(unmixingModelName)) { spectralUnmixing = new FullyConstrainedLSU(lsuMatrixElements); } else if (unmixingModelName == null) { spectralUnmixing = new UnconstrainedLSU(lsuMatrixElements); } int width = sourceProduct.getSceneRasterWidth(); int height = sourceProduct.getSceneRasterHeight(); targetProduct = new Product(sourceProduct.getName() + "_unmixed", "SpectralUnmixing", width, height); abundanceBands = new Band[numEndmembers]; for (int i = 0; i < numEndmembers; i++) { abundanceBands[i] = targetProduct.addBand( endmembers[i].getName() + abundanceBandNameSuffix, ProductData.TYPE_FLOAT32); } if (computeErrorBands) { errorBands = new Band[numSourceBands]; for (int i = 0; i < errorBands.length; i++) { final String erroBandName = sourceBands[i].getName() + errorBandNameSuffix; errorBands[i] = targetProduct.addBand(erroBandName, ProductData.TYPE_FLOAT32); ProductUtils.copySpectralBandProperties(sourceBands[i], errorBands[i]); } summaryErrorBand = targetProduct.addBand("summary_error", ProductData.TYPE_FLOAT32); summaryErrorBand.setDescription("Root mean square error"); } ProductUtils.copyMetadata(sourceProduct, targetProduct); ProductUtils.copyTiePointGrids(sourceProduct, targetProduct); ProductUtils.copyGeoCoding(sourceProduct, targetProduct); }