/** Creates Metadata nodes for all the necessary information. */ protected MetadataElement[] getMetadata() { MetadataElement[] metadata = new MetadataElement[2]; MetadataElement fileList = new MetadataElement("Input_Products"); final String[] productList = context.getProcessedProducts(); String keyString; for (int n = 0; n < productList.length; n++) { keyString = "Product." + n; fileList.addAttribute( new MetadataAttribute(keyString, ProductData.createInstance(productList[n]), true)); } metadata[0] = fileList; MetadataElement binParams = new MetadataElement("Binning_Parameter"); binParams.addAttribute( new MetadataAttribute( "Resampling_Type", ProductData.createInstance(context.getResamplingType()), true)); final String cellSizeName; if (L3Constants.RESAMPLING_TYPE_VALUE_BINNING.equals(context.getResamplingType())) { cellSizeName = "Bin_Size_In_Km"; } else { cellSizeName = "Bins_Per_Degree"; } binParams.addAttribute( new MetadataAttribute( cellSizeName, ProductData.createInstance(new float[] {context.getGridCellSize()}), true)); final L3Context.BandDefinition[] bandDefs = context.getBandDefinitions(); for (int bandIndex = 0; bandIndex < bandDefs.length; bandIndex++) { final L3Context.BandDefinition bandDef = bandDefs[bandIndex]; binParams.addAttribute( new MetadataAttribute( "Geophysical_Parameter_" + bandIndex, ProductData.createInstance(bandDef.getBandName()), true)); binParams.addAttribute( new MetadataAttribute( "Bitmask_" + bandIndex, ProductData.createInstance(bandDef.getBitmaskExp()), true)); binParams.addAttribute( new MetadataAttribute( "Algorithm_" + bandIndex, ProductData.createInstance(bandDef.getAlgorithm().getTypeString()), true)); } metadata[1] = binParams; return metadata; }
/** * 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); } }