/** 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(); } }
@Override protected void readBandRasterDataImpl( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { pm.beginTask("Reading band data...", 3); NITFReaderWrapper reader = readerMap.get(destBand); try { reader.readBandData( sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, sourceStepX, sourceStepY, destBuffer, pm); } finally { pm.done(); } }
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 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; }
/** * The template method which is called by the {@link * org.esa.snap.framework.dataio.AbstractProductReader#readBandRasterDataImpl(int, int, int, int, * int, int, org.esa.snap.framework.datamodel.Band, int, int, int, int, * org.esa.snap.framework.datamodel.ProductData, com.bc.ceres.core.ProgressMonitor)} } method * after an optional spatial subset has been applied to the input parameters. * * <p>The destination band, buffer and region parameters are exactly the ones passed to the * original {@link org.esa.snap.framework.dataio.AbstractProductReader#readBandRasterDataImpl} * call. Since the <code>destOffsetX</code> and <code>destOffsetY</code> parameters are already * taken into acount in the <code>sourceOffsetX</code> and <code>sourceOffsetY</code> parameters, * an implementor of this method is free to ignore them. * * @param sourceOffsetX the absolute X-offset in source raster co-ordinates * @param sourceOffsetY the absolute Y-offset in source raster co-ordinates * @param sourceWidth the width of region providing samples to be read given in source raster * co-ordinates * @param sourceHeight the height of region providing samples to be read given in source raster * co-ordinates * @param sourceStepX the sub-sampling in X direction within the region providing samples to be * read * @param sourceStepY the sub-sampling in Y direction within the region providing samples to be * read * @param destBand the destination band which identifies the data source from which to read the * sample values * @param destBuffer the destination buffer which receives the sample values to be read * @param destOffsetX the X-offset in the band's raster co-ordinates * @param destOffsetY the Y-offset in the band's raster co-ordinates * @param destWidth the width of region to be read given in the band's raster co-ordinates * @param destHeight the height of region to be read given in the band's raster co-ordinates * @param pm a monitor to inform the user about progress * @throws java.io.IOException if an I/O error occurs * @see #getSubsetDef */ @Override protected void readBandRasterDataImpl( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { final int sourceMinX = sourceOffsetX; final int sourceMinY = sourceOffsetY; final int sourceMaxX = sourceOffsetX + sourceWidth - 1; final int sourceMaxY = sourceOffsetY + sourceHeight - 1; final File dataFile = bandDataFiles.get(destBand); final ImageInputStream inputStream = getOrCreateImageInputStream(destBand, dataFile); if (inputStream == null) { return; } int destPos = 0; pm.beginTask("Reading band '" + destBand.getName() + "'...", sourceMaxY - sourceMinY); // For each scan in the data source try { synchronized (inputStream) { for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) { if (pm.isCanceled()) { break; } final long sourcePosY = (long) sourceY * destBand.getRasterWidth(); if (sourceStepX == 1) { long inputPos = sourcePosY + sourceMinX; destBuffer.readFrom(destPos, destWidth, inputStream, inputPos); destPos += destWidth; } else { for (int sourceX = sourceMinX; sourceX <= sourceMaxX; sourceX += sourceStepX) { long inputPos = sourcePosY + sourceX; destBuffer.readFrom(destPos, 1, inputStream, inputPos); destPos++; } } } pm.worked(1); } } finally { pm.done(); } }
public synchronized void readBandData( Band destBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException, InvalidRangeException { if (mustFlipY) { sourceOffsetY = destBand.getSceneRasterHeight() - (sourceOffsetY + sourceHeight); } if (mustFlipX) { sourceOffsetX = destBand.getSceneRasterWidth() - (sourceOffsetX + sourceWidth); } sourceOffsetY += leadLineSkip; start[0] = sourceOffsetY; start[1] = sourceOffsetX; stride[0] = sourceStepY; stride[1] = sourceStepX; count[0] = sourceHeight; count[1] = sourceWidth; Object buffer = destBuffer.getElems(); Variable variable = variableMap.get(destBand); pm.beginTask("Reading band '" + variable.getShortName() + "'...", sourceHeight); try { Section section = new Section(start, count, stride); Array array; int[] newshape = {sourceHeight, sourceWidth}; array = variable.read(section); if (array.getRank() == 3) { array = array.reshapeNoCopy(newshape); } Object storage; if (mustFlipX && !mustFlipY) { storage = array.flip(1).copyTo1DJavaArray(); } else if (!mustFlipX && mustFlipY) { storage = array.flip(0).copyTo1DJavaArray(); } else if (mustFlipX && mustFlipY) { storage = array.flip(0).flip(1).copyTo1DJavaArray(); } else { storage = array.copyTo1DJavaArray(); } arraycopy(storage, 0, buffer, 0, destBuffer.getNumElems()); } finally { pm.done(); } }
@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; }
@Override public synchronized void readBandRasterData( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException { AvhrrFile.RawCoordinates rawCoord = noaaFile.getRawCoordinates(sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight); final float[] targetData = (float[]) destBuffer.getElems(); int targetIdx = rawCoord.targetStart; pm.beginTask("Reading AVHRR band '" + getBandName() + "'...", rawCoord.maxY - rawCoord.minY); try { for (int rawY = rawCoord.minY; rawY <= rawCoord.maxY; rawY += sourceStepY) { if (pm.isCanceled()) { break; } boolean validData = hasData(rawY); if (validData) { if (calibrator.requiresCalibrationData()) { readCalibrationCoefficients(rawY, calibrationData); validData = calibrator.processCalibrationData(calibrationData); } if (validData) { readData(rawY); validData = containsValidCounts(); if (validData) { for (int sourceX = rawCoord.minX; sourceX <= rawCoord.maxX; sourceX += sourceStepX) { targetData[targetIdx] = calibrator.calibrate(lineOfCounts[sourceX]); targetIdx += rawCoord.targetIncrement; } } } } if (!validData) { for (int sourceX = rawCoord.minX; sourceX <= rawCoord.maxX; sourceX += sourceStepX) { targetData[targetIdx] = AvhrrConstants.NO_DATA_VALUE; targetIdx += rawCoord.targetIncrement; } } pm.worked(1); } } 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); }
@Override public void readBandRasterData( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, final ProductData destBuffer, final ProgressMonitor pm) throws IOException { AvhrrFile.RawCoordinates rawCoord = metopFile.getRawCoordinates(sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight); final float[] targetData = (float[]) destBuffer.getElems(); final float scalingFactor = (float) super.getScalingFactor(); pm.beginTask( MessageFormat.format("Reading AVHRR band ''{0}''...", getBandName()), rawCoord.maxY - rawCoord.minY); int targetIdx = rawCoord.targetStart; for (int sourceY = rawCoord.minY; sourceY <= rawCoord.maxY; sourceY += sourceStepY) { if (pm.isCanceled()) { break; } if (hasData(sourceY)) { final int dataOffset = getDataOffset(sourceOffsetX, sourceY); synchronized (inputStream) { final short[] radianceScanLine = new short[metopFile.getProductWidth()]; inputStream.seek(dataOffset); inputStream.readFully(radianceScanLine, 0, sourceWidth); for (int sourceX = 0; sourceX <= sourceWidth - 1; sourceX++) { targetData[targetIdx] = calibrator.calibrate(radianceScanLine[sourceX] * scalingFactor); targetIdx += rawCoord.targetIncrement; } } } else { for (int sourceX = rawCoord.minX; sourceX <= rawCoord.maxX; sourceX += sourceStepX) { targetData[targetIdx] = AvhrrConstants.NO_DATA_VALUE; targetIdx += rawCoord.targetIncrement; } } pm.worked(1); } 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(); } }
/** Interpretes the bins of the temporal database if algorithm needs this to be done. */ protected void processBinIterpretation(ProgressMonitor pm) throws IOException { getLogger().info(L3Constants.LOG_MSG_INTERPRETE_BIN_CONTENT); final int rowOffset = temporalDB.getRowOffset(); final int colOffset = temporalDB.getColOffset(); final int width = temporalDB.getWidth(); final int height = temporalDB.getHeight(); Point rowcol = new Point(); Bin tempBin = temporalDB.createBin(); Bin finalBin = finalDB.createBin(); pm.beginTask(L3Constants.LOG_MSG_INTERPRETE_BIN_CONTENT, height - rowOffset); try { for (int row = rowOffset; row < rowOffset + height; row++) { rowcol.y = row; for (int col = colOffset; col < colOffset + width; col++) { rowcol.x = col; temporalDB.read(rowcol, tempBin); final L3Context.BandDefinition[] bandDefinitions = context.getBandDefinitions(); for (int bandIndex = 0; bandIndex < bandDefinitions.length; bandIndex++) { final L3Context.BandDefinition bandDef = bandDefinitions[bandIndex]; final Algorithm algo = bandDef.getAlgorithm(); tempBin.setBandIndex(bandIndex); finalBin.setBandIndex(bandIndex); algo.interprete(tempBin, finalBin); } finalDB.write(rowcol, finalBin); } // update progressbar pm.worked(1); if (pm.isCanceled()) { getLogger().warning(L3Constants.LOG_MSG_PROC_CANCELED); setCurrentState(L3Constants.STATUS_ABORTED); break; } } } finally { pm.done(); finalDB.flush(); } getLogger().info(ProcessorConstants.LOG_MSG_SUCCESS); }
/** * 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); } }
/** * Overridden to call the {@link #computeSample(int, int, Sample[], WritableSample) computeSample} * method for every pixel in the given tile's rectangle. * * @param targetBand The target band. * @param targetTile The current tile associated with the target band to be computed. * @param pm A progress monitor which should be used to determine computation cancelation * requests. * @throws OperatorException */ @Override public final void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException { final Rectangle targetRectangle = targetTile.getRectangle(); final Point location = new Point(); final Sample[] sourceSamples = createSourceSamples(targetRectangle, location); final Sample sourceMaskSamples = createSourceMaskSamples(targetRectangle, location); final WritableSample targetSample = createTargetSample(targetTile, location); final int x1 = targetTile.getMinX(); final int y1 = targetTile.getMinY(); final int x2 = targetTile.getMaxX(); final int y2 = targetTile.getMaxY(); try { pm.beginTask(getId(), targetTile.getHeight()); if (sourceMaskSamples != null) { for (location.y = y1; location.y <= y2; location.y++) { for (location.x = x1; location.x <= x2; location.x++) { if (sourceMaskSamples.getBoolean()) { computeSample(location.x, location.y, sourceSamples, targetSample); } else { setInvalid(targetSample); } } pm.worked(1); } } else { for (location.y = y1; location.y <= y2; location.y++) { for (location.x = x1; location.x <= x2; location.x++) { computeSample(location.x, location.y, sourceSamples, targetSample); } pm.worked(1); } } } finally { pm.done(); } }
// 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); }
/** {@inheritDoc} */ public void writeBandRasterData( Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, ProductData sourceBuffer, ProgressMonitor pm) throws IOException { checkBufferSize(sourceWidth, sourceHeight, sourceBuffer); final int sourceBandWidth = sourceBand.getSceneRasterWidth(); final int sourceBandHeight = sourceBand.getSceneRasterHeight(); checkSourceRegionInsideBandRegion( sourceWidth, sourceBandWidth, sourceHeight, sourceBandHeight, sourceOffsetX, sourceOffsetY); int memTypeID = -1; int memSpaceID = -1; pm.beginTask("Writing band '" + sourceBand.getName() + "'...", 1); try { final int datasetID = getOrCreateBandH5D(sourceBand); final int fileSpaceID = H5.H5Dget_space(datasetID); final long[] memDims = new long[] {sourceHeight, sourceWidth}; final long[] memStart = new long[2]; final long[] memCount = new long[2]; final long[] fileStart = new long[2]; final long[] fileCount = new long[2]; memTypeID = createH5TypeID(sourceBuffer.getType()); memSpaceID = H5.H5Screate_simple(2, memDims, null); memStart[0] = 0; memStart[1] = 0; memCount[0] = sourceHeight; memCount[1] = sourceWidth; H5.H5Sselect_hyperslab( memSpaceID, HDF5Constants.H5S_SELECT_SET, memStart, null, memCount, null); fileStart[0] = sourceOffsetY; fileStart[1] = sourceOffsetX; fileCount[0] = sourceHeight; fileCount[1] = sourceWidth; H5.H5Sselect_hyperslab( fileSpaceID, HDF5Constants.H5S_SELECT_SET, fileStart, null, fileCount, null); H5.H5Dwrite( datasetID, memTypeID, memSpaceID, fileSpaceID, HDF5Constants.H5P_DEFAULT, sourceBuffer.getElems()); pm.worked(1); } catch (IOException e) { throw e; } catch (HDF5Exception e) { throw new ProductIOException(createErrorMessage(e)); } finally { closeH5S(memSpaceID); closeH5T(memTypeID); pm.done(); } }
private static Band[] createXYDisplacementBands(final Product product, ProgressMonitor pm) { final int width = product.getSceneRasterWidth(); final int height = product.getSceneRasterHeight(); ImageInfo blueToRedGrad = new ImageInfo( new ColorPaletteDef( new ColorPaletteDef.Point[] { new ColorPaletteDef.Point(-1.0, Color.BLUE), new ColorPaletteDef.Point(0.0, Color.WHITE), new ColorPaletteDef.Point(1.0, Color.RED), })); ImageInfo amplGrad = new ImageInfo( new ColorPaletteDef( new ColorPaletteDef.Point[] { new ColorPaletteDef.Point(0.0, Color.WHITE), new ColorPaletteDef.Point(1.0, Color.RED), })); ImageInfo phaseGrad = new ImageInfo( new ColorPaletteDef( new ColorPaletteDef.Point[] { new ColorPaletteDef.Point(-Math.PI, Color.WHITE), new ColorPaletteDef.Point(0.0, Color.BLUE), new ColorPaletteDef.Point(+Math.PI, Color.WHITE), })); final Band bandX = new Band("gc_displ_x", ProductData.TYPE_FLOAT64, width, height); configureBand(bandX, blueToRedGrad.clone(), "pixels", "Geo-coding X-displacement"); final Band bandY = new Band("gc_displ_y", ProductData.TYPE_FLOAT64, width, height); configureBand(bandY, blueToRedGrad.clone(), "pixels", "Geo-coding Y-displacement"); final Band bandAmpl = new VirtualBand( "gc_displ_ampl", ProductData.TYPE_FLOAT64, width, height, "ampl(gc_displ_x, gc_displ_y)"); configureBand(bandAmpl, amplGrad.clone(), "pixels", "Geo-coding displacement amplitude"); final Band bandPhase = new VirtualBand( "gc_displ_phase", ProductData.TYPE_FLOAT64, width, height, "phase(gc_displ_x, gc_displ_y)"); configureBand(bandPhase, phaseGrad.clone(), "radians", "Geo-coding displacement phase"); final double[] dataX = new double[width * height]; final double[] dataY = new double[width * height]; bandX.setRasterData(ProductData.createInstance(dataX)); bandY.setRasterData(ProductData.createInstance(dataY)); pm.beginTask( "Computing geo-coding displacements for product '" + product.getName() + "'...", height); try { final GeoPos geoPos = new GeoPos(); final PixelPos pixelPos1 = new PixelPos(); final PixelPos pixelPos2 = new PixelPos(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double maxX = 0; double maxY = 0; double valueX = 0; double valueY = 0; for (float[] offset : OFFSETS) { pixelPos1.setLocation(x + offset[0], y + offset[1]); product.getGeoCoding().getGeoPos(pixelPos1, geoPos); product.getGeoCoding().getPixelPos(geoPos, pixelPos2); double dx = pixelPos2.x - pixelPos1.x; double dy = pixelPos2.y - pixelPos1.y; if (Math.abs(dx) > maxX) { maxX = Math.abs(dx); valueX = dx; } if (Math.abs(dy) > maxY) { maxY = Math.abs(dy); valueY = dy; } } dataX[y * width + x] = valueX; dataY[y * width + x] = valueY; } if (pm.isCanceled()) { return null; } pm.worked(1); } } finally { pm.done(); } return new Band[] {bandX, bandY, bandAmpl, bandPhase}; }
/** * Writes raster data from the given in-memory source buffer into the data sink specified by the * given source band and region. * * <p> * * <h3>Source band</h3> * * The source band is used to identify the data sink in which this method transfers the sample * values given in the source buffer. The method does not modify the pixel data of the given * source band at all. * * <p> * * <h3>Source buffer</h3> * * The first element of the source buffer corresponds to the given <code>sourceOffsetX</code> and * <code>sourceOffsetY</code> of the source region. These parameters are an offset within the * band's raster data and <b>not</b> an offset within the source buffer.<br> * The number of elements in the buffer must be exactly be <code>sourceWidth * sourceHeight</code> * . The pixel values to be writte are considered to be stored in line-by-line order, so the * raster X co-ordinate varies faster than the Y. * * <p> * * <h3>Source region</h3> * * The given destination region specified by the <code>sourceOffsetX</code>, <code>sourceOffsetY * </code>, <code>sourceWidth</code> and <code>sourceHeight</code> parameters is given in the * source band's raster co-ordinates. These co-ordinates are identical with the destination raster * co-ordinates since product writers do not support spectral or spatial subsets. * * @param sourceBand the source band which identifies the data sink to which to write the sample * values * @param regionData the data buffer which provides the sample values to be written * @param regionX the X-offset in the band's raster co-ordinates * @param regionY the Y-offset in the band's raster co-ordinates * @param regionWidth the width of region to be written given in the band's raster co-ordinates * @param regionHeight the height of region to be written given in the band's raster co-ordinates * @throws java.io.IOException if an I/O error occurs * @throws IllegalArgumentException if the number of elements source buffer not equals <code> * sourceWidth * * sourceHeight</code> or the source region is out of the band's * raster * @see Band#getRasterWidth() * @see Band#getRasterHeight() */ public void writeBandRasterData( final Band sourceBand, final int regionX, final int regionY, final int regionWidth, final int regionHeight, final ProductData regionData, ProgressMonitor pm) throws IOException { if (!tempProduct.containsBand(sourceBand.getName())) { throw new IllegalArgumentException( "'" + sourceBand.getName() + "' is not a band of the product"); } final int bandDataType = ifd.getBandDataType(); final int stripIndex = getStripIndex(sourceBand); final TiffValue[] offsetValues = ifd.getEntry(TiffTag.STRIP_OFFSETS).getValues(); final long stripOffset = ((TiffLong) offsetValues[stripIndex]).getValue(); final TiffValue[] bitsPerSampleValues = ifd.getEntry(TiffTag.BITS_PER_SAMPLE).getValues(); final long elemSize = ((TiffShort) bitsPerSampleValues[stripIndex]).getValue() / 8; final long sourceWidthBytes = sourceBand.getSceneRasterWidth() * elemSize; final long regionOffsetXInBytes = regionX * elemSize; final long pixelOffset = sourceWidthBytes * regionY + regionOffsetXInBytes; final long startOffset = stripOffset + pixelOffset; pm.beginTask("Writing band '" + sourceBand.getName() + "'...", regionHeight); try { for (int y = 0; y < regionHeight; y++) { ios.seek(startOffset + y * sourceWidthBytes); final int stride = y * regionWidth; if (bandDataType == ProductData.TYPE_UINT8) { final byte[] data = new byte[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = (byte) regionData.getElemUIntAt(stride + x); } ios.write(data); } else if (bandDataType == ProductData.TYPE_INT8) { final byte[] data = new byte[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = (byte) regionData.getElemIntAt(stride + x); } ios.write(data); } else if (bandDataType == ProductData.TYPE_UINT16) { final short[] data = new short[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = (short) regionData.getElemUIntAt(stride + x); } ios.writeShorts(data, 0, regionWidth); } else if (bandDataType == ProductData.TYPE_INT16) { final short[] data = new short[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = (short) regionData.getElemIntAt(stride + x); } ios.writeShorts(data, 0, regionWidth); } else if (bandDataType == ProductData.TYPE_UINT32) { final int[] data = new int[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = (int) regionData.getElemUIntAt(stride + x); } ios.writeInts(data, 0, regionWidth); } else if (bandDataType == ProductData.TYPE_INT32) { final int[] data = new int[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = regionData.getElemIntAt(stride + x); } ios.writeInts(data, 0, regionWidth); } else if (bandDataType == ProductData.TYPE_FLOAT32) { final float[] data = new float[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = regionData.getElemFloatAt(stride + x); } ios.writeFloats(data, 0, regionWidth); } else if (bandDataType == ProductData.TYPE_FLOAT64) { final double[] data = new double[regionWidth]; for (int x = 0; x < regionWidth; x++) { data[x] = regionData.getElemDoubleAt(stride + x); } ios.writeDoubles(data, 0, regionWidth); } pm.worked(1); } } finally { pm.done(); } }
@Override public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException { if (targetBand.isFlagBand()) { // no computations return; } final Rectangle rectangle = targetTile.getRectangle(); final int bigWidth = (int) (scalingFactor * rectangle.getWidth()); final int bigHeight = (int) (scalingFactor * rectangle.getHeight()); final int bigX = (int) (scalingFactor * rectangle.getX()); final int bigY = (int) (scalingFactor * rectangle.getY()); final Rectangle big = new Rectangle(bigX, bigY, bigWidth, bigHeight); pm.beginTask("Processing frame...", rectangle.height); try { // todo: clean up the tiles which are not finally needed (depends on how many channels are // used) final Tile szMerisTile = getSourceTile(synergyProduct.getTiePointGrid("sun_zenith"), big); final Tile vzMerisTile = getSourceTile(synergyProduct.getTiePointGrid("view_zenith"), big); final Tile saMerisTile = getSourceTile(synergyProduct.getTiePointGrid("sun_azimuth"), big); final Tile pressureTile = getSourceTile(synergyProduct.getTiePointGrid("atm_press"), big); final Tile seAatsrNadirTile = getSourceTile( synergyProduct.getBand( "sun_elev_nadir" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile veAatsrNadirTile = getSourceTile( synergyProduct.getBand( "view_elev_nadir" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile saAatsrNadirTile = getSourceTile( synergyProduct.getBand( "sun_azimuth_nadir" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile seAatsrFwardTile = getSourceTile( synergyProduct.getBand( "sun_elev_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile veAatsrFwardTile = getSourceTile( synergyProduct.getBand( "view_elev_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile saAatsrFwardTile = getSourceTile( synergyProduct.getBand( "sun_azimuth_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile vaAatsrFwardTile = getSourceTile( synergyProduct.getBand( "view_azimuth_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""), big); final Tile merisRad13Tile = getSourceTile( synergyProduct.getBand( "radiance_13" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_MERIS + ""), big); final Tile merisRad14Tile = getSourceTile( synergyProduct.getBand( "radiance_14" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_MERIS + ""), big); final Band reflecNadir16Band = synergyProduct.getBand( "reflec_nadir_1600" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""); final Tile aatsrReflNadir1600Tile = getSourceTile(reflecNadir16Band, big); final Band reflecNadir87Band = synergyProduct.getBand( "reflec_nadir_0870" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""); final Tile aatsrReflNadir0870Tile = getSourceTile(reflecNadir87Band, big); final Band reflecFward16Band = synergyProduct.getBand( "reflec_fward_1600" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""); final Tile aatsrReflFward1600Tile = getSourceTile(reflecFward16Band, big); final Band reflecFward87Band = synergyProduct.getBand( "reflec_fward_0870" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""); final Tile aatsrReflFward0870Tile = getSourceTile(reflecFward87Band, big); final Tile wsTile = getSourceTile(glintProduct.getBand(GlintAveOp.RESULT_WINDSPEED_NAME), rectangle); // Flags tiles final Tile isInvalid = getSourceTile(invalidBand, rectangle); for (int iY = rectangle.y; iY < rectangle.y + rectangle.height; iY++) { for (int iX = rectangle.x; iX < rectangle.x + rectangle.width; iX++) { final int iTarX = (int) (scalingFactor * iX + aveBlock); final int iTarY = (int) (scalingFactor * iY + aveBlock); checkForCancellation(); final float aatsrViewElevationNadir = getAvePixel(veAatsrNadirTile, iTarX, iTarY); final float aatsrSunElevationNadir = getAvePixel(seAatsrNadirTile, iTarX, iTarY); final float aatsrViewElevationFward = getAvePixel(veAatsrFwardTile, iTarX, iTarY); final float aatsrSunElevationFward = getAvePixel(seAatsrFwardTile, iTarX, iTarY); // just use one windspeed (the 'closer to ECMWF' one from Glint retrieval) final float ws = wsTile.getSampleFloat(iX, iY); if (isInvalid.getSampleBoolean(iX, iY) || ws == SynergyConstants.OUTPUT_WS_BAND_NODATAVALUE) { targetTile.setSample(iX, iY, noDataVal); } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOT_BAND_NAME) && (aot550Result[iX][iY] > 0.0 || aot550Result[iX][iY] == SynergyConstants.OUTPUT_AOT_BAND_NODATAVALUE)) { targetTile.setSample(iX, iY, aot550Result[iX][iY]); } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANG_BAND_NAME) && (angResult[iX][iY] > 0.0 || angResult[iX][iY] == SynergyConstants.OUTPUT_ANG_BAND_NODATAVALUE)) { targetTile.setSample(iX, iY, angResult[iX][iY]); } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOTERR_BAND_NAME) && (aot550ErrorResult[iX][iY] > 0.0 || aot550ErrorResult[iX][iY] == SynergyConstants.OUTPUT_AOTERR_BAND_NODATAVALUE)) { targetTile.setSample(iX, iY, aot550ErrorResult[iX][iY]); } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANGERR_BAND_NAME) && (angErrorResult[iX][iY] > 0.0 || angErrorResult[iX][iY] == SynergyConstants.OUTPUT_ANGERR_BAND_NODATAVALUE)) { targetTile.setSample(iX, iY, aot550ErrorResult[iX][iY]); } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_GLINT_BAND_NAME) && (glintResult[iX][iY] > 0.0 || glintResult[iX][iY] == SynergyConstants.OUTPUT_GLINT_BAND_NODATAVALUE)) { targetTile.setSample(iX, iY, glintResult[iX][iY]); } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_WS_BAND_NAME) && (wsResult[iX][iY] > 0.0 || wsResult[iX][iY] == SynergyConstants.OUTPUT_WS_BAND_NODATAVALUE)) { targetTile.setSample(iX, iY, wsResult[iX][iY]); } else { final float merisViewAzimuth = getAvePixel(vaMerisTileComplete, iTarX, iTarY); final float merisSunAzimuth = getAvePixel(saMerisTile, iTarX, iTarY); final float merisAzimuthDifference = GlintPreparation.removeAzimuthDifferenceAmbiguity( merisViewAzimuth, merisSunAzimuth); final float merisViewZenith = getAvePixel(vzMerisTile, iTarX, iTarY); final float merisSunZenith = getAvePixel(szMerisTile, iTarX, iTarY); final float merisRad13 = getAvePixel(merisRad13Tile, iTarX, iTarY) / SynergyConstants.MERIS_13_SOLAR_FLUX; final float merisRad14 = getAvePixel(merisRad14Tile, iTarX, iTarY) / SynergyConstants.MERIS_14_SOLAR_FLUX; final double aatsrSeNadir = getAvePixel(seAatsrNadirTile, iTarX, iTarY); final double aatsrSeFward = getAvePixel(seAatsrFwardTile, iTarX, iTarY); // for RP test data (unit '%'), we need to divide AATSR reflectances by 100. // however, the correct AATSR units should be 'dl', as for the Synergy products created // in the Synergy module float aatsrUnitCorrFactor = 1.0f; if (reflecNadir87Band.getUnit().equals("%")) { // check for one band should be enough aatsrUnitCorrFactor = 100.0f; } final float aatsrReflNadir87 = (float) (getAvePixel(aatsrReflNadir0870Tile, iTarX, iTarY) / (Math.PI * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeNadir)) * aatsrUnitCorrFactor)); final float aatsrReflNadir16 = (float) (getAvePixel(aatsrReflNadir1600Tile, iTarX, iTarY) / (Math.PI * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeNadir)) * aatsrUnitCorrFactor)); final float aatsrReflFward87 = (float) (getAvePixel(aatsrReflFward0870Tile, iTarX, iTarY) / (Math.PI * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeFward)) * aatsrUnitCorrFactor)); final float aatsrReflFward16 = (float) (getAvePixel(aatsrReflFward1600Tile, iTarX, iTarY) / (Math.PI * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeFward)) * aatsrUnitCorrFactor)); final float aatsrViewAzimuthNadir = getAvePixel(vaAatsrNadirTileComplete, iTarX, iTarY); final float aatsrSunAzimuthNadir = getAvePixel(saAatsrNadirTile, iTarX, iTarY); final float aatsrViewAzimuthFward = vaAatsrFwardTile.getSampleFloat(iTarX, iTarY); final float aatsrSunAzimuthFward = saAatsrFwardTile.getSampleFloat(iTarX, iTarY); final float aatsrAzimuthDifferenceNadir = GlintPreparation.removeAzimuthDifferenceAmbiguity( aatsrViewAzimuthNadir, aatsrSunAzimuthNadir); final float aatsrAzimuthDifferenceFward = aatsrViewAzimuthFward - aatsrSunAzimuthFward; // negative pressures were stored in LUT to ensure ascending sequence final float surfacePressure = -1.0f * getAvePixel(pressureTile, iTarX, iTarY); // breadboard begin STEP 1 final float[] glintArray = doSynAOStep1( aatsrViewElevationNadir, aatsrViewElevationFward, aatsrSunElevationNadir, aatsrSunElevationFward, aatsrAzimuthDifferenceNadir, aatsrAzimuthDifferenceFward, merisViewZenith, merisSunZenith, merisAzimuthDifference, surfacePressure, ws); glintResult[iX][iY] = glintArray[0]; wsResult[iX][iY] = ws; // breadboard end STEP 1 // breadboard begin STEP 2 doSynAOStep2(); // breadboard end STEP 2 // breadboard begin STEP 3 doSynAOStep3( iY, iX, merisRad13, merisRad14, aatsrReflNadir16, aatsrReflNadir87, aatsrReflFward16, aatsrReflFward87); // breadboard end STEP 3 if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOT_BAND_NAME)) { targetTile.setSample(iX, iY, aot550Result[iX][iY]); } if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANG_BAND_NAME)) { targetTile.setSample(iX, iY, angResult[iX][iY]); } if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOTERR_BAND_NAME)) { targetTile.setSample(iX, iY, aot550ErrorResult[iX][iY]); } if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANGERR_BAND_NAME)) { targetTile.setSample(iX, iY, angErrorResult[iX][iY]); } if (targetBand.getName().equals(SynergyConstants.OUTPUT_GLINT_BAND_NAME)) { targetTile.setSample(iX, iY, glintResult[iX][iY]); } if (targetBand.getName().equals(SynergyConstants.OUTPUT_WS_BAND_NAME)) { targetTile.setSample(iX, iY, wsResult[iX][iY]); } } pm.worked(1); } } } catch (Exception e) { throw new OperatorException( "Failed to process ocean aerosol algorithm:\n" + e.getMessage(), e); } finally { pm.done(); } }
// 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); }
@Override protected void readBandRasterDataImpl( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { if (isGlobalShifted180) { // SPECIAL CASE of a global geographic lat/lon with lon from 0..360 instead of -180..180 readBandRasterDataImplGlobalShifted180( sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, sourceStepX, sourceStepY, destBand, destOffsetX, destOffsetY, destWidth, destHeight, destBuffer, pm); } else { // the normal case!! final int destSize = destWidth * destHeight; pm.beginTask("Reading data...", 3); try { final Raster data = readRect( sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, destOffsetX, destOffsetY, destWidth, destHeight); pm.worked(1); Integer bandIdx = bandMap.get(destBand); if (bandIdx == null) { bandIdx = 0; } final DataBuffer dataBuffer = data.getDataBuffer(); final SampleModel sampleModel = data.getSampleModel(); final int dataBufferType = dataBuffer.getDataType(); boolean isInteger = dataBufferType == DataBuffer.TYPE_SHORT || dataBufferType == DataBuffer.TYPE_USHORT || dataBufferType == DataBuffer.TYPE_INT; boolean isIntegerTarget = destBuffer.getElems() instanceof int[]; if (isInteger && isIntegerTarget) { sampleModel.getSamples( 0, 0, data.getWidth(), data.getHeight(), bandIdx, (int[]) destBuffer.getElems(), dataBuffer); } else if (dataBufferType == DataBuffer.TYPE_FLOAT && destBuffer.getElems() instanceof float[]) { sampleModel.getSamples( 0, 0, data.getWidth(), data.getHeight(), bandIdx, (float[]) destBuffer.getElems(), dataBuffer); } else { final double[] dArray = new double[destSize]; sampleModel.getSamples( 0, 0, data.getWidth(), data.getHeight(), bandIdx, dArray, dataBuffer); if (destBuffer.getElems() instanceof double[]) { //noinspection SuspiciousSystemArraycopy System.arraycopy(dArray, 0, destBuffer.getElems(), 0, dArray.length); } else { int i = 0; for (double value : dArray) { destBuffer.setElemDoubleAt(i++, value); } } } pm.worked(1); } finally { pm.done(); } } }
private void readBandRasterDataImplGlobalShifted180( int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { final int destSize = destWidth * destHeight; pm.beginTask("Reading data...", 3); try { final Raster dataLeft = readRect( sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, destOffsetX, destOffsetY, destWidth / 2, destHeight); final Raster dataRight = readRect( sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, destOffsetX + destWidth / 2, destOffsetY, destWidth / 2, destHeight); pm.worked(1); double[] dArrayLeft = new double[destSize / 2]; double[] dArrayRight = new double[destSize / 2]; Integer bandIdx = bandMap.get(destBand); if (bandIdx == null) { bandIdx = 0; } final DataBuffer dataBufferLeft = dataLeft.getDataBuffer(); final DataBuffer dataBufferRight = dataRight.getDataBuffer(); final SampleModel sampleModelLeft = dataLeft.getSampleModel(); final SampleModel sampleModelRight = dataRight.getSampleModel(); sampleModelLeft.getSamples( 0, 0, dataLeft.getWidth(), dataLeft.getHeight(), bandIdx, dArrayLeft, dataBufferLeft); sampleModelRight.getSamples( 0, 0, dataRight.getWidth(), dataRight.getHeight(), bandIdx, dArrayRight, dataBufferRight); pm.worked(1); int dArrayIndex = 0; for (int y = 0; y < destHeight; y++) { for (int x = 0; x < destWidth / 2; x++) { destBuffer.setElemDoubleAt(dArrayIndex++, dArrayRight[y * destWidth / 2 + x]); } for (int x = 0; x < destWidth / 2; x++) { destBuffer.setElemDoubleAt(dArrayIndex++, dArrayLeft[y * destWidth / 2 + x]); } } pm.worked(1); } finally { pm.done(); } }
@Override public synchronized void readBandData( Band destBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException, InvalidRangeException { final Variable variable = variableMap.get(destBand); DataType prodtype = variable.getDataType(); float[] fbuffer; short[] sbuffer; int[] ibuffer; byte[] bbuffer; Object buffer; if (prodtype == DataType.FLOAT) { fbuffer = (float[]) destBuffer.getElems(); Arrays.fill(fbuffer, Float.NaN); buffer = fbuffer; } else if (prodtype == DataType.SHORT) { sbuffer = (short[]) destBuffer.getElems(); Arrays.fill(sbuffer, (short) -999); buffer = sbuffer; } else if (prodtype == DataType.BYTE) { bbuffer = (byte[]) destBuffer.getElems(); Arrays.fill(bbuffer, (byte) 255); buffer = bbuffer; } else { ibuffer = (int[]) destBuffer.getElems(); Arrays.fill(ibuffer, -999); buffer = ibuffer; } 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 (int y = sourceOffsetY; y < sourceOffsetY + sourceHeight; y += sourceStepY) { if (pm.isCanceled()) { break; } final int rowIndex = (height - 1) - y; final RowInfo rowInfo = this.rowInfo[rowIndex]; if (rowInfo != null) { final int lineOffset = rowInfo.offset; final int lineLength = rowInfo.length; lineOffsets[0] = lineOffset; lineLengths[0] = lineLength; final Object bindata; synchronized (ncFile) { bindata = variable.read().section(lineOffsets, lineLengths, stride).copyTo1DJavaArray(); } int lineIndex0 = 0; for (int x = sourceOffsetX; x < sourceOffsetX + sourceWidth; 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 = sourceWidth * (y - sourceOffsetY) + (x - sourceOffsetX); System.arraycopy(bindata, lineIndex, buffer, rasterIndex, 1); } } pm.worked(1); } } } finally { pm.done(); } }
// 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); }