Possible invalid memory manipulations in ApplyGammaNaughtRTC if the gamma area input has only band

Description

If we start from an S2 tile that fits entirely within an S1 image, the gamma area image will contain 2 bands. The second band indicates the presence of data (possible values: 1 = yes, 0 = no).

If there is no concatenation of area images, then the image is simply renamed and both bands are preserved.

However, if two S1 files are used, then concatenation occurs, and in the end, only one band remains. Additionally, the "no-data" metadata is lost.

A double issue arises afterward in SARGammaAreaToGammaNaughtRTCImageEstimation.

  • It systematically uses the pixel from band 2 to determine whether the area can be applied. But since there’s only one band, the pixel indicating applicability is more or less random.

  • Moreover, the result is written into 2 bands:

    • Band 1 = rectified gamma° image,
    • Band 2 = mask band = whether the gamma area was applied or not.

    And… as the output image is declared to contain only one band => data is lost.

Note: The schematic algorithm to process a pixel with ApplyRTC is:

If mask > epsilon // because comparing to 0 can be problematic
    If |area| > threshold
        out <- factor * sigma° / area
    Else
        out <- nodata
    EndIf
Else
    If option outputNoDataStatus is true # default is left to false in S1Tiling
        out <- nodata
    Else
        out <- sigma°
    EndIf
EndIf

Several options:

  1. Rework the Synthetize application to support multiple-bands — it’s explicitly written for single-band processing.

  2. Add a S1Tiling flow that extracts the mask bands into 2 files, concatenates them, and recombines them into the gamma area image in S2 geometry.

  3. Let it be, but ensure SARGammaAreaToGammaNaughtRTCImageEstimation recognizes the case of a single-band area image and uses no-data as a mask — we could have the case where the area is zero, while "there is some data".

  4. Or simply rework SARGammaAreaToGammaNaughtRTCImageEstimation. If the area is zero or nodata (with nodata = 0 by default), then suppose the mask is also zero.

The difference: we’ll always set nodata instead of the sigma° value — which is probably more relevant IMO.

The option that seems simplest is a mix between options 3. and 4. Hence the issue.

Additionally, I need to ensure the nodata metadata isn't lost by concatenation — even though luckily SARGammaAreaToGammaNaughtRTCImageEstimation assumes input nodata = 0 if not specified.

At the very least, we must not read from band 2 when there is only one band in the input.

One more question:

Should we produce a single-band output and rely on no-data if there’s no associated area info?

Or should we always output the second mask band if the information is available?