private boolean isSampleInvalid(Band firstNdviBand, Band secondNdviBand, int x, int y) {
   return !firstNdviBand.isPixelValid(x, y) && !secondNdviBand.isPixelValid(x, y);
 }
  @Override
  public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm)
      throws OperatorException {

    final Rectangle targetRectangle = targetTile.getRectangle();

    final String name = targetBand.getName();
    final String currentMonth = name.substring(TARGET_BAND_PREFIX.length(), name.length());

    final List<Product> currentMonthDataProducts = halfmonthlyDataProductsMap.get(currentMonth);
    List<Product> currentMonthFlagProducts;

    if (currentMonthDataProducts.size() != 2) {
      return;
    }

    final Band firstNdviBand = currentMonthDataProducts.get(0).getBand("band_1");
    final Tile firstNdviTile = getSourceTile(firstNdviBand, targetRectangle);
    final Band secondNdviBand = currentMonthDataProducts.get(1).getBand("band_1");
    final Tile secondNdviTile = getSourceTile(secondNdviBand, targetRectangle);

    Band firstNdviFlagBand;
    Tile firstNdviFlagTile = null;
    Band secondNdviFlagBand;
    Tile secondNdviFlagTile = null;
    if (writeFlags) {
      currentMonthFlagProducts = halfmonthlyFlagProductsMap.get(currentMonth);
      if (currentMonthFlagProducts.size() != 2) {
        return;
      }
      firstNdviFlagBand = currentMonthFlagProducts.get(0).getBand("band_1");
      firstNdviFlagTile = getSourceTile(firstNdviFlagBand, targetRectangle);
      secondNdviFlagBand = currentMonthFlagProducts.get(1).getBand("band_1");
      secondNdviFlagTile = getSourceTile(secondNdviFlagBand, targetRectangle);
    }

    for (int y = targetRectangle.y; y < targetRectangle.y + targetRectangle.height; y++) {
      checkForCancellation();
      for (int x = targetRectangle.x; x < targetRectangle.x + targetRectangle.width; x++) {
        final boolean isSampleInvalid = isSampleInvalid(firstNdviBand, secondNdviBand, x, y);
        final boolean isSampleMissing = isSampleMissing(firstNdviTile, secondNdviTile, x, y);

        if (!isSampleInvalid && !isSampleMissing) {
          final int firstNdvi = firstNdviTile.getSampleInt(x, y);
          final int secondNdvi = secondNdviTile.getSampleInt(x, y);
          if (firstNdviBand.isPixelValid(x, y) && secondNdviBand.isPixelValid(x, y)) {
            final int maxNdvi = Math.max(firstNdvi, secondNdvi);
            if (writeFlags) {
              if (firstNdvi >= secondNdvi) {
                final int firstNdviFlag = firstNdviFlagTile.getSampleInt(x, y);
                targetTile.setSample(x, y, firstNdviFlag);
              } else {
                final int secondNdviFlag = secondNdviFlagTile.getSampleInt(x, y);
                targetTile.setSample(x, y, secondNdviFlag);
              }
            } else {
              targetTile.setSample(x, y, maxNdvi);
            }
          } else if (!firstNdviBand.isPixelValid(x, y)) {
            if (writeFlags) {
              final int firstNdviFlag = firstNdviFlagTile.getSampleInt(x, y);
              targetTile.setSample(x, y, firstNdviFlag);
            } else {
              targetTile.setSample(x, y, firstNdvi);
            }
          } else if (!secondNdviBand.isPixelValid(x, y)) {
            if (writeFlags) {
              final int secondNdviFlag = secondNdviFlagTile.getSampleInt(x, y);
              targetTile.setSample(x, y, secondNdviFlag);
            } else {
              targetTile.setSample(x, y, secondNdvi);
            }
          }
        } else {
          targetTile.setSample(x, y, Constants.NDVI_INVALID_VALUE);
        }
      }
    }
  }