/** Processes a request */ @Override public void process(ProgressMonitor pm) throws ProcessorException { pm.beginTask("Finalizing L3 Product...", 3); try { try { loadRequestParameter(); loadContext(); loadTemporalDatabase(); pm.worked(1); if (context.algorithmNeedsInterpretation()) { try { interpreteAlgorithm(SubProgressMonitor.create(pm, 1)); } finally { deleteFinalDatabase(); } } else { exportBinDatabase( temporalDB, createProjection(), outputProductRef, context.getBandDefinitions(), getMetadata(), SubProgressMonitor.create(pm, 1)); } } finally { deleteTemporalDatabase(); pm.worked(1); } } catch (IOException e) { throw new ProcessorException(e.getMessage(), e); } finally { pm.done(); } }
/** * Processes the request actually set. * * @param pm a monitor to inform the user about progress * @throws org.esa.beam.framework.processor.ProcessorException on any failure during processing */ @Override public void process(ProgressMonitor pm) throws ProcessorException { try { prepareProcessing(); pm.beginTask("Creating output product...", _inputBandList.size() + 1); try { createOutputProduct(SubProgressMonitor.create(pm, 1)); if (pm.isCanceled()) { setCurrentStatus(ProcessorConstants.STATUS_ABORTED); return; } // loop over all bands specified in request // ---------------------------------------- pm.setSubTaskName(SmacConstants.LOG_MSG_PROCESSING_CORRECTION); for (int i = 0; i < _inputBandList.size(); i++) { try { // here we use a try/catch for each band processed, so that the processor does not // completely quit // when something goes wrong while processing on of many bands // And we definitely decide which product type and dispacth appropriate. if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.MERIS_NAME)) { if (_useMerisADS) { processMerisBandWithADS(_inputBandList.get(i), SubProgressMonitor.create(pm, 1)); } else { processMerisBand(_inputBandList.get(i), SubProgressMonitor.create(pm, 1)); } } else if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.AATSR_NAME)) { processAatsrBand(_inputBandList.get(i), SubProgressMonitor.create(pm, 1)); } else { pm.worked(1); } if (pm.isCanceled()) { setCurrentStatus(ProcessorConstants.STATUS_ABORTED); return; } } catch (IOException e) { _logger.severe(ProcessorConstants.LOG_MSG_PROC_ERROR); _logger.severe(e.getMessage()); } } } finally { cleanUp(); pm.done(); } } catch (IOException e) { throw new ProcessorException("An I/O error occured:\n" + e.getMessage(), e); } _logger.info(ProcessorConstants.LOG_MSG_FINISHED_REQUEST); }
private BufferedImage createThumbNailImage(Dimension imgSize, ProgressMonitor pm) { Assert.notNull(pm, "pm"); String thumbNailBandName = getThumbnailBandName(); Band thumbNailBand = product.getBand(thumbNailBandName); Debug.trace( "ProductSubsetDialog: Reading thumbnail data for band '" + thumbNailBandName + "'..."); pm.beginTask("Creating thumbnail image", 5); BufferedImage image = null; try { MultiLevelSource multiLevelSource = BandImageMultiLevelSource.create(thumbNailBand, SubProgressMonitor.create(pm, 1)); final ImageLayer imageLayer = new ImageLayer(multiLevelSource); final int imageWidth = imgSize.width; final int imageHeight = imgSize.height; final int imageType = BufferedImage.TYPE_3BYTE_BGR; image = new BufferedImage(imageWidth, imageHeight, imageType); Viewport snapshotVp = new DefaultViewport(isModelYAxisDown(imageLayer)); final BufferedImageRendering imageRendering = new BufferedImageRendering(image, snapshotVp); final Graphics2D graphics = imageRendering.getGraphics(); graphics.setColor(getBackground()); graphics.fillRect(0, 0, imageWidth, imageHeight); snapshotVp.zoom(imageLayer.getModelBounds()); snapshotVp.moveViewDelta(snapshotVp.getViewBounds().x, snapshotVp.getViewBounds().y); imageLayer.render(imageRendering); pm.worked(4); } finally { pm.done(); } return image; }
private void readBandRasterDataSubSampling( Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, int destWidth, ProgressMonitor pm) throws IOException { final int sourceMinY = sourceOffsetY; final int sourceMaxY = sourceOffsetY + sourceHeight - 1; ProductData lineBuffer = ProductData.createInstance(destBuffer.getType(), sourceWidth); int destPos = 0; try { pm.beginTask("Reading sub sampled raster data...", 2 * (sourceMaxY - sourceMinY)); for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) { sourceBand.readRasterData( sourceOffsetX, sourceY, sourceWidth, 1, lineBuffer, SubProgressMonitor.create(pm, 1)); if (sourceStepX == 1) { copyData(lineBuffer, 0, destBuffer, destPos, destWidth); } else { copyLine(lineBuffer, 0, sourceWidth, sourceStepX, destBuffer, destPos); } pm.worked(1); destPos += destWidth; } } finally { pm.done(); } }
private void interpreteAlgorithm(ProgressMonitor pm) throws IOException, ProcessorException { pm.beginTask("Interpreting algorithm...", 2); try { createFinalDatabase(); processBinIterpretation(SubProgressMonitor.create(pm, 1)); exportBinDatabase( finalDB, createProjection(), outputProductRef, context.getBandDefinitions(), getMetadata(), SubProgressMonitor.create(pm, 1)); } finally { pm.done(); } }
/** * Exports the given bin database into the specified product. * * @param binDatabase the bin database to be exported * @param projection the projection, that should be used. * @param productRef the productRef, that describes the product to which to export to * @param bandDefinitions * @param metadata an array with the metadata. * @param pm a monitor to inform the user about progress * @throws IOException * @throws ProcessorException */ protected void exportBinDatabase( TemporalBinDatabase binDatabase, L3ProjectionRaster projection, ProductRef productRef, L3Context.BandDefinition[] bandDefinitions, MetadataElement[] metadata, ProgressMonitor pm) throws IOException, ProcessorException { ProductExporter exporter = new ProductExporter(binDatabase, getLogger()); final float stepsPerDegree; if (L3Constants.RESAMPLING_TYPE_VALUE_BINNING.equals(context.getResamplingType())) { final float kmPerDegree = BinDatabaseConstants.PI_EARTH_RADIUS / 180.f; final float gridCellSizeInKm = context.getGridCellSize(); stepsPerDegree = kmPerDegree / gridCellSizeInKm; } else { stepsPerDegree = context.getGridCellSize(); } exporter.setProjection(projection, stepsPerDegree); pm.beginTask("Exporting bin database...", tailorOutputProduct ? 2 : 1); boolean aborted; try { if (tailorOutputProduct) { exporter.estimateExportRegion(SubProgressMonitor.create(pm, 1)); } else { exporter.setExportRegion(context.getBorder()); } aborted = false; try { exporter.createOutputProduct(productRef, bandDefinitions, metadata); aborted = exporter.outputBinDatabase(context.getLocator(), SubProgressMonitor.create(pm, 1)); } catch (IOException e) { throw new ProcessorException("Couldn't export product: " + e.getMessage(), e); } finally { exporter.close(); } } finally { pm.done(); } if (aborted) { setCurrentState(L3Constants.STATUS_ABORTED); } }
@Override protected Product doInBackground(com.bc.ceres.core.ProgressMonitor pm) throws Exception { final TargetProductSelectorModel model = getTargetProductSelector().getModel(); pm.beginTask("Writing...", model.isOpenInAppSelected() ? 100 : 95); ProgressMonitorList.instance().add(pm); // NESTMOD saveTime = 0L; Product product = null; try { // free cache // NESTMOD JAI.getDefaultInstance().getTileCache().flush(); System.gc(); executeStartTime = Calendar.getInstance().getTime(); long t0 = System.currentTimeMillis(); Operator operator = null; if (targetProduct.getProductReader() instanceof OperatorProductReader) { final OperatorProductReader opReader = (OperatorProductReader) targetProduct.getProductReader(); if (opReader.getOperatorContext().getOperator() instanceof Output) { operator = opReader.getOperatorContext().getOperator(); } } if (operator == null) { WriteOp writeOp = new WriteOp(targetProduct, model.getProductFile(), model.getFormatName()); writeOp.setDeleteOutputOnFailure(true); writeOp.setWriteEntireTileRows(true); writeOp.setClearCacheAfterRowWrite(false); operator = writeOp; } final OperatorExecutor executor = OperatorExecutor.create(operator); executor.execute(SubProgressMonitor.create(pm, 95)); saveTime = System.currentTimeMillis() - t0; File targetFile = model.getProductFile(); if (model.isOpenInAppSelected() && targetFile.exists()) { product = ProductIO.readProduct(targetFile); if (product == null) { product = targetProduct; // todo - check - this cannot be ok!!! (nf) } pm.worked(5); } } finally { // free cache JAI.getDefaultInstance().getTileCache().flush(); System.gc(); pm.done(); ProgressMonitorList.instance().remove(pm); // NESTMOD if (product != targetProduct) { targetProduct.dispose(); } } return product; }
// Processes a single AATSR band. private void processAatsrBand(Band band, ProgressMonitor pm) throws IOException { // load appropriate Sensor coefficientFile and init algorithm // ---------------------------------------------------------- if (!loadBandCoefficients(band)) { _logger.severe( SmacConstants.LOG_MSG_COEFF_NOT_FOUND_1 + band.getName() + SmacConstants.LOG_MSG_COEFF_NOT_FOUND_2); setCurrentStatus(ProcessorConstants.STATUS_FAILED); return; } _logger.info( SmacConstants.LOG_MSG_GENERATING_PIXEL_1 + band.getName() + SmacConstants.LOG_MSG_GENERATING_PIXEL_2); // initialize vectors and other data // --------------------------------- int width = band.getSceneRasterWidth(); int height = band.getSceneRasterHeight(); Band outBand = _outputProduct.getBand(band.getName()); boolean isForwardBand = checkForAATSRForwardBand(band); float[] sza = new float[width]; float[] saa = new float[width]; float[] vza = new float[width]; float[] vaa = new float[width]; float[] taup550 = new float[width]; float[] uh2o = new float[width]; float[] uo3 = new float[width]; float[] press = new float[width]; boolean[] process = new boolean[width]; float[] toa = new float[width]; float[] toa_corr = new float[width]; TiePointGrid szaBand; TiePointGrid saaBand; TiePointGrid vzaBand; TiePointGrid vaaBand; Term bitMask; // set the tie point bands according to input band view // ---------------------------------------------------- if (isForwardBand) { szaBand = _szaFwdBand; saaBand = _saaFwdBand; vzaBand = _vzaFwdBand; vaaBand = _vaaFwdBand; bitMask = _bitMaskTermForward; } else { szaBand = _szaBand; saaBand = _saaBand; vzaBand = _vzaBand; vaaBand = _vaaBand; bitMask = _bitMaskTerm; } // initialize vectors // ------------------ for (int x = 0; x < width; x++) { taup550[x] = _tau_aero_550; uh2o[x] = _u_h2o; uo3[x] = _u_o3; press[x] = _surf_press; process[x] = true; } // progress init pm.beginTask( SmacConstants.LOG_MSG_GENERATING_PIXEL_1 + band.getName() + SmacConstants.LOG_MSG_GENERATING_PIXEL_2, height * 6); try { // loop over all scanlines for (int y = 0; y < band.getSceneRasterHeight(); y++) { // read scanline band.readPixels(0, y, width, 1, toa, SubProgressMonitor.create(pm, 1)); szaBand.readPixels(0, y, width, 1, sza, SubProgressMonitor.create(pm, 1)); saaBand.readPixels(0, y, width, 1, saa, SubProgressMonitor.create(pm, 1)); vzaBand.readPixels(0, y, width, 1, vza, SubProgressMonitor.create(pm, 1)); vaaBand.readPixels(0, y, width, 1, vaa, SubProgressMonitor.create(pm, 1)); // scale sun and view elevation to zenith angles sza = RsMathUtils.elevationToZenith(sza, sza); vza = RsMathUtils.elevationToZenith(vza, sza); // forEachPixel bitmask if (bitMask != null) { _inputProduct.readBitmask(0, y, width, 1, bitMask, process, ProgressMonitor.NULL); } // process scanline toa_corr = _algorithm.run( sza, saa, vza, vaa, taup550, uh2o, uo3, press, process, _invalidPixel, toa, toa_corr); // write scanline outBand.writePixels(0, y, width, 1, toa_corr, ProgressMonitor.NULL); // update progress pm.worked(1); if (pm.isCanceled()) { _logger.warning(ProcessorConstants.LOG_MSG_PROC_CANCELED); setCurrentStatus(ProcessorConstants.STATUS_ABORTED); return; } } } finally { pm.done(); } _logger.info(ProcessorConstants.LOG_MSG_PROC_SUCCESS); }
// Processes a single band MERIS data using the MERIS ADS. private void processMerisBandWithADS(Band band, ProgressMonitor pm) throws IOException { // load appropriate Sensor coefficientFile and init algorithm // ---------------------------------------------------------- if (!loadBandCoefficients(band)) { _logger.severe( SmacConstants.LOG_MSG_COEFF_NOT_FOUND_1 + band.getName() + SmacConstants.LOG_MSG_COEFF_NOT_FOUND_2); /*I18N*/ setCurrentStatus(ProcessorConstants.STATUS_FAILED); return; } _logger.info( SmacConstants.LOG_MSG_GENERATING_PIXEL_1 + band.getName() + SmacConstants.LOG_MSG_GENERATING_PIXEL_2); /*I18N*/ // initialize vectors and other data // --------------------------------- int width = band.getSceneRasterWidth(); int height = band.getSceneRasterHeight(); Band outBand = _outputProduct.getBand(convertMerisBandName(band)); float[] sza = new float[width]; float[] saa = new float[width]; float[] vza = new float[width]; float[] vaa = new float[width]; float[] taup550 = new float[width]; float[] uh2o = new float[width]; float[] uo3 = new float[width]; float[] press = new float[width]; float[] elev = new float[width]; boolean[] process = new boolean[width]; float[] toa = new float[width]; float[] toa_corr = new float[width]; // set up vector - this parameter is constant for the request for (int x = 0; x < width; x++) { taup550[x] = _tau_aero_550; process[x] = true; } // progress bar init // ----------------- pm.beginTask( SmacConstants.LOG_MSG_GENERATING_PIXEL_1 + band.getName() + SmacConstants.LOG_MSG_GENERATING_PIXEL_2, height * 10); try { // loop over all scanlines // ----------------------- for (int y = 0; y < height; y++) { // read scanline // ------------- band.readPixels(0, y, width, 1, toa, SubProgressMonitor.create(pm, 1)); _szaBand.readPixels(0, y, width, 1, sza, SubProgressMonitor.create(pm, 1)); _saaBand.readPixels(0, y, width, 1, saa, SubProgressMonitor.create(pm, 1)); _vzaBand.readPixels(0, y, width, 1, vza, SubProgressMonitor.create(pm, 1)); _vaaBand.readPixels(0, y, width, 1, vaa, SubProgressMonitor.create(pm, 1)); _wvBand.readPixels(0, y, width, 1, uh2o, SubProgressMonitor.create(pm, 1)); _o3Band.readPixels(0, y, width, 1, uo3, SubProgressMonitor.create(pm, 1)); _pressBand.readPixels(0, y, width, 1, press, SubProgressMonitor.create(pm, 1)); _elevBand.readPixels(0, y, width, 1, elev, SubProgressMonitor.create(pm, 1)); // scale radiance to reflectance // ------------------------------- toa = RsMathUtils.radianceToReflectance(toa, sza, band.getSolarFlux(), toa); // correct pressure due to elevation // --------------------------------- press = RsMathUtils.simpleBarometric(press, elev, press); // scale DU to cm * atm // ---------------------- uo3 = dobsonToCmAtm(uo3); // scale relative humidity to g/cm^2 // ----------------------------------- uh2o = relativeHumidityTogcm2(uh2o); // forEachPixel bitmask // ---------------- if (_bitMaskTerm != null) { _inputProduct.readBitmask(0, y, width, 1, _bitMaskTerm, process, ProgressMonitor.NULL); } // process scanline // ---------------- toa_corr = _algorithm.run( sza, saa, vza, vaa, taup550, uh2o, uo3, press, process, _invalidPixel, toa, toa_corr); // write scanline // -------------- outBand.writePixels(0, y, width, 1, toa_corr, ProgressMonitor.NULL); // update progressbar // ------------------ pm.worked(1); if (pm.isCanceled()) { _logger.warning(ProcessorConstants.LOG_MSG_PROC_CANCELED); setCurrentStatus(ProcessorConstants.STATUS_ABORTED); return; } } } finally { pm.done(); } _logger.info(ProcessorConstants.LOG_MSG_PROC_SUCCESS); }
// Processes a single spectralBand of MERIS data. private void processMerisBand(Band spectralBand, ProgressMonitor pm) throws IOException { // load appropriate Sensor coefficientFile and init algorithm // ---------------------------------------------------------- if (!loadBandCoefficients(spectralBand)) { _logger.severe( SmacConstants.LOG_MSG_COEFF_NOT_FOUND_1 + spectralBand.getName() + SmacConstants.LOG_MSG_COEFF_NOT_FOUND_2); setCurrentStatus(ProcessorConstants.STATUS_FAILED); return; } _logger.info( SmacConstants.LOG_MSG_GENERATING_PIXEL_1 + spectralBand.getName() + SmacConstants.LOG_MSG_GENERATING_PIXEL_2); /*I18N*/ // initialize vectors and other data int n; int width = spectralBand.getSceneRasterWidth(); int height = spectralBand.getSceneRasterHeight(); Band outBand = _outputProduct.getBand(convertMerisBandName(spectralBand)); float[] sza = new float[width]; float[] saa = new float[width]; float[] vza = new float[width]; float[] vaa = new float[width]; float[] taup550 = new float[width]; float[] uh2o = new float[width]; float[] uo3 = new float[width]; float[] press = new float[width]; boolean[] process = new boolean[width]; float[] toa = new float[width]; float[] toa_corr = new float[width]; for (n = 0; n < width; n++) { taup550[n] = _tau_aero_550; uh2o[n] = _u_h2o; uo3[n] = _u_o3; press[n] = _surf_press; process[n] = true; } // progress init pm.beginTask( SmacConstants.LOG_MSG_GENERATING_PIXEL_1 + spectralBand.getName() + SmacConstants.LOG_MSG_GENERATING_PIXEL_2, height * 6); try { // loop over all scanlines for (int y = 0; y < spectralBand.getSceneRasterHeight(); y++) { // read scanline spectralBand.readPixels(0, y, width, 1, toa, SubProgressMonitor.create(pm, 1)); _szaBand.readPixels(0, y, width, 1, sza, SubProgressMonitor.create(pm, 1)); _saaBand.readPixels(0, y, width, 1, saa, SubProgressMonitor.create(pm, 1)); _vzaBand.readPixels(0, y, width, 1, vza, SubProgressMonitor.create(pm, 1)); _vaaBand.readPixels(0, y, width, 1, vaa, SubProgressMonitor.create(pm, 1)); // scale radiances to reflectances toa = RsMathUtils.radianceToReflectance(toa, sza, spectralBand.getSolarFlux(), toa); // forEachPixel bitmask if (_bitMaskTerm != null) { _inputProduct.readBitmask(0, y, width, 1, _bitMaskTerm, process, ProgressMonitor.NULL); } // process scanline toa_corr = _algorithm.run( sza, saa, vza, vaa, taup550, uh2o, uo3, press, process, _invalidPixel, toa, toa_corr); // write scanline outBand.writePixels(0, y, width, 1, toa_corr, ProgressMonitor.NULL); // update progressbar pm.worked(1); if (pm.isCanceled()) { _logger.warning(ProcessorConstants.LOG_MSG_PROC_CANCELED); setCurrentStatus(ProcessorConstants.STATUS_ABORTED); return; } } } finally { pm.done(); } _logger.info(ProcessorConstants.LOG_MSG_PROC_SUCCESS); }