private TemporalBinList doTemporalBinning(SpatialBinCollection spatialBinMap) throws IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); long numberOfBins = spatialBinMap.size(); final TemporalBinner temporalBinner = new TemporalBinner(binningContext); final CellProcessorChain cellChain = new CellProcessorChain(binningContext); final TemporalBinList temporalBins = new TemporalBinList((int) numberOfBins); Iterable<List<SpatialBin>> spatialBinListCollection = spatialBinMap.getBinCollection(); int binCounter = 0; int percentCounter = 0; long hundredthOfNumBins = numberOfBins / 100; for (List<SpatialBin> spatialBinList : spatialBinListCollection) { binCounter += spatialBinList.size(); SpatialBin spatialBin = spatialBinList.get(0); long spatialBinIndex = spatialBin.getIndex(); TemporalBin temporalBin = temporalBinner.processSpatialBins(spatialBinIndex, spatialBinList); temporalBin = temporalBinner.computeOutput(spatialBinIndex, temporalBin); temporalBin = cellChain.process(temporalBin); temporalBins.add(temporalBin); if (binCounter >= hundredthOfNumBins) { binCounter = 0; getLogger().info(String.format("Finished %d%% of temporal bins", ++percentCounter)); } } stopWatch.stop(); getLogger() .info(String.format("Temporal binning of %d bins done, took %s", numberOfBins, stopWatch)); return temporalBins; }
private void processSource(Product sourceProduct, SpatialBinner spatialBinner) throws IOException { final StopWatch stopWatch = new StopWatch(); stopWatch.start(); updateDateRangeUtc(sourceProduct); metadataAggregator.aggregateMetadata(sourceProduct); final String productName = sourceProduct.getName(); getLogger().info(String.format("Spatial binning of product '%s'...", productName)); getLogger().fine(String.format("Product start time: '%s'", sourceProduct.getStartTime())); getLogger().fine(String.format("Product end time: '%s'", sourceProduct.getEndTime())); if (region != null) { SubsetOp subsetOp = new SubsetOp(); subsetOp.setSourceProduct(sourceProduct); subsetOp.setGeoRegion(region); sourceProduct = subsetOp.getTargetProduct(); // TODO mz/nf/mp 2013-11-06: avoid creation of subset products // - replace subset with rectangle as parameter to SpatialProductBinner // - grow rectangle by binSize in pixel units (see lc-tools of LC-CCI project) } final long numObs = SpatialProductBinner.processProduct( sourceProduct, spatialBinner, addedVariableBands, ProgressMonitor.NULL); stopWatch.stop(); getLogger() .info( String.format( "Spatial binning of product '%s' done, %d observations seen, took %s", productName, numObs, stopWatch)); if (region == null && regionArea != null) { for (GeneralPath generalPath : ProductUtils.createGeoBoundaryPaths(sourceProduct)) { try { Area area = new Area(generalPath); regionArea.add(area); } catch (Throwable e) { getLogger() .log( Level.SEVERE, String.format("Failed to handle product boundary: %s", e.getMessage()), e); // sometimes the Area constructor throw an "java.lang.InternalError: Odd number of new // curves!" // then just ignore this geometry } } } ++numProductsAggregated; }
private void writeOutput( List<TemporalBin> temporalBins, ProductData.UTC startTime, ProductData.UTC stopTime) throws Exception { StopWatch stopWatch = new StopWatch(); stopWatch.start(); initMetadataProperties(); if (outputBinnedData) { try { writeNetCDFBinFile(temporalBins, startTime, stopTime); } catch (Exception e) { getLogger() .log(Level.SEVERE, String.format("Failed to write binned data: %s", e.getMessage()), e); } } if (outputTargetProduct) { getLogger() .info(String.format("Writing mapped product '%s'...", formatterConfig.getOutputFile())); final MetadataElement processingGraphMetadata = getProcessingGraphMetadata(); Formatter.format( binningContext.getPlanetaryGrid(), getTemporalBinSource(temporalBins), binningContext.getBinManager().getResultFeatureNames(), formatterConfig, region, startTime, stopTime, processingGraphMetadata); stopWatch.stop(); String msgPattern = "Writing mapped product '%s' done, took %s"; getLogger().info(String.format(msgPattern, formatterConfig.getOutputFile(), stopWatch)); if (outputType.equalsIgnoreCase("Product")) { final File writtenProductFile = new File(outputFile); String format = Formatter.getOutputFormat(formatterConfig, writtenProductFile); writtenProduct = ProductIO.readProduct(writtenProductFile, format); this.targetProduct = copyProduct(writtenProduct); } else { this.targetProduct = new Product("Dummy", "t", 10, 10); } } else { this.targetProduct = new Product("Dummy", "t", 10, 10); } }