OpticalCalibration generates wrong image from in-memory connection (Python API)
Description
The OpticalCalibration
application generates a wrong output image when the input comes from in-memory connection from the ExtractROI
application, which is a common use-case.
Tested with a Spot-6 MS product from Airbus DS.
Steps to reproduce
OK: ExtractROI -> file -> OpticalCalibration -> file
graph LR;
'DIM_SPOT7_MS_..._1.XML'-->ExtractROI-->'roi.tif'
'roi.tif'-->OpticalCalibration-->'roi_cal.tif';
import otbApplication
dimap = "/data/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/DIM_SPOT6_MS_201503261014386_ORT_SPOT6_20170524_1422391k0ha487979cy_1.XML"
roi2 = otbApplication.Registry.CreateApplication("ExtractROI")
roi2.SetParameterString("in", dimap)
roi2.SetParameterString("out", "/data/roi.tif")
roi2.ExecuteAndWriteOutput()
app2 = otbApplication.Registry.CreateApplication("OpticalCalibration")
app2.SetParameterString("in", "/data/roi.tif")
app2.SetParameterString("level","toa")
app2.SetParameterString("out", "/data/roi_cal.tif")
app2.ExecuteAndWriteOutput()
2022-10-12 20:15:56 (INFO) OpticalCalibration:
File: /data/roi.tif
Sensor detected: SPOT 6
Parameters extract from input image:
Acquisition Day: 26
Acquisition Month: 3
Acquisition Year: 2015
Acquisition Sun Elevation Angle: 42.7316
Acquisition Sun Azimuth Angle: 146.957
Acquisition Viewing Elevation Angle: 81.9074
Acquisition Viewing Azimuth Angle: 199.101
Solar Irradiance (per band): 1540.49 1826.09 1982.67 1094.75
2022-10-12 20:15:56 (INFO) OpticalCalibration: Default RAM limit for OTB is 256 MB
2022-10-12 20:15:56 (INFO) OpticalCalibration: GDAL maximum cache size is 1599 MB
2022-10-12 20:15:56 (INFO) OpticalCalibration: OTB will use at most 8 threads
2022-10-12 20:15:56 (INFO) OpticalCalibration: Using Acquisition gain from image metadata (per band): [10.34, 9.35, 8.01, 13.88]
2022-10-12 20:15:56 (INFO) OpticalCalibration: Using Acquisition bias from image metadata (per band): [0, 0, 0, 0]
2022-10-12 20:15:56 (INFO) OpticalCalibration: Compute Top of Atmosphere reflectance
2022-10-12 20:15:56 (INFO) OpticalCalibration: Clamp values between [0, 100]
NOK: In-memory ExtractROI -> OpticalCalibration
graph LR;
'DIM_SPOT7_MS_..._1.XML'-->ExtractROI-->OpticalCalibration-->'roi_cal.tif';
roi = otbApplication.Registry.CreateApplication("ExtractROI")
roi.SetParameterString("in", dimap)
roi.Execute()
app = otbApplication.Registry.CreateApplication("OpticalCalibration")
app.SetParameterInputImage("in", roi.GetParameterOutputImage("out"))
app.SetParameterString("level","toa")
app.SetParameterString("out", "/data/roi_cal.tif")
app.ExecuteAndWriteOutput()
The generated image in the second case is not calibrated correctly. No error message, but the logs don't show all the expected parameters:
2022-10-12 20:15:54 (INFO) OpticalCalibration: Default RAM limit for OTB is 256 MB
2022-10-12 20:15:54 (INFO) OpticalCalibration: GDAL maximum cache size is 1599 MB
2022-10-12 20:15:54 (INFO) OpticalCalibration: OTB will use at most 8 threads
2022-10-12 20:15:54 (INFO) OpticalCalibration: Using Acquisition gain from image metadata (per band): [10.34, 9.35, 8.01, 13.88]
2022-10-12 20:15:54 (INFO) OpticalCalibration: Using Acquisition bias from image metadata (per band): [0, 0, 0, 0]
2022-10-12 20:15:54 (INFO) OpticalCalibration: Compute Top of Atmosphere reflectance
2022-10-12 20:15:54 (INFO) OpticalCalibration: Clamp values between [0, 100]
It's like some of the acquisition parameters are not here.
I have tried to dig the problem but I still fail to understand the metadata related classes of OTB. Also I am not able to retrieve them, in python or C++. I am under the impression that the metadata is not correctly passed between the apps. Maybe related to #2313 (closed) , not sure.
Configuration information
OTB 8.1.0 Ubuntu 20.04