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;
  }
  /**
   * Processes all source products and writes the output file. The target product represents the
   * written output file
   *
   * @throws org.esa.snap.framework.gpf.OperatorException If a processing error occurs.
   */
  @Override
  public void initialize() throws OperatorException {
    formatterConfig = new FormatterConfig();
    formatterConfig.setBandConfigurations(bandConfigurations);
    formatterConfig.setOutputFile(outputFile);
    formatterConfig.setOutputFormat(outputFormat);
    formatterConfig.setOutputType(outputType);
    formatterConfig.setProductCustomizerConfig(productCustomizerConfig);

    validateInput();

    ProductData.UTC startDateUtc = null;
    ProductData.UTC endDateUtc = null;
    if (startDateTime != null) {
      startDateUtc = parseStartDateUtc(startDateTime);
      double startMJD = startDateUtc.getMJD();
      double endMJD = startMJD + periodDuration;
      endDateUtc = new ProductData.UTC(endMJD);
    }

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    if (region == null) {
      // TODO use JTS directly (nf 2013-11-06)
      regionArea = new Area();
    }

    final BinningConfig binningConfig = createConfig();

    binningContext = binningConfig.createBinningContext(region, startDateUtc, periodDuration);

    BinningProductFilter productFilter =
        createSourceProductFilter(binningContext.getDataPeriod(), startDateUtc, endDateUtc, region);

    metadataAggregator = MetadataAggregatorFactory.create(metadataAggregatorName);
    numProductsAggregated = 0;

    try {
      // Step 1: Spatial binning - creates time-series of spatial bins for each bin ID ordered by
      // ID. The tree map structure is <ID, time-series>
      SpatialBinCollection spatialBinMap = doSpatialBinning(productFilter);
      if (!spatialBinMap.isEmpty()) {
        // update region
        if (region == null && regionArea != null) {
          region = JTS.shapeToGeometry(regionArea, new GeometryFactory());
        }
        // Step 2: Temporal binning - creates a list of temporal bins, sorted by bin ID
        TemporalBinList temporalBins = doTemporalBinning(spatialBinMap);
        // Step 3: Formatting
        try {
          if (startDateTime != null) {
            writeOutput(temporalBins, startDateUtc, endDateUtc);
          } else {
            writeOutput(temporalBins, minDateUtc, maxDateUtc);
          }
        } finally {
          temporalBins.close();
        }
      } else {
        getLogger().warning("No bins have been generated, no output has been written");
      }
    } catch (OperatorException e) {
      throw e;
    } catch (Exception e) {
      throw new OperatorException(e);
    } finally {
      cleanSourceProducts();
    }

    stopWatch.stopAndTrace(
        String.format("Total time for binning %d product(s)", numProductsAggregated));

    globalMetadata.processMetadataTemplates(metadataTemplateDir, this, targetProduct, getLogger());
  }