Standard name and calibration are wrong when applying the nir_reflectance modifier
Describe the bug
Standard name and calibration are wrong when applying the nir_reflectance modifier.
To Reproduce
from satpy import Scene, DataQuery
from glob import glob
seviri_files = glob("/media/nas/x21308/scratch/SEVIRI/202103300900/H-000*")
sc = Scene(filenames={"seviri_l1b_hrit": seviri_files})
sc.load([DataQuery(name="IR_039", modifiers=("nir_reflectance",))])
print(sc["IR_039"].attrs["standard_name"])
print(sc["IR_039"].attrs["calibration"])
Expected behaviour
toa_bidirectional_reflectance
reflectance
Actual results
toa_brightness_temperature
brightness_temperature
Environment Info:
- OS: Suse
- Satpy Version: main
Additional context
This is the only modifier (I think) that changes the quantity and thus the calibration. Therefore, standard name and calibration need to be changed when the modifier is applied.
The calibration is what is loaded from the files (given implicitely in the .load() call), so I think that's fine. The standard name might need updating. Though I'm not sure it is exactly toa_bidirectional_reflectance, but that can be debated, as usual 😅
Calibration is not loaded from the files. The files contain bytes, usually encoding counts, those counts are converted to some calibrated quantity, usually based on data within the files, sometimes with external coefficients. A calibration is just a modifier built into the reader. I could apply my own calibration by loading counts and defining a modifier to change those counts into something else, and then I would want to update the calibration as well.
Typically the calibration is loaded from the files as per-channel calibration coefficient attributes. With modifier you can't use the calibration coefficients stored within the files, as those are accessible only at the file handler level, thus the calibration level is given at call to .load(). Some data are stored pre-calibrated, so then there might not be calibration coefficients present.
In many/most cases, we load from the file calibration coefficients and counts, not calibrated data. When I wrote "Calibration is not loaded from the file", I meant that a quantity with the calibration level "brightness temperature" is not (usually) loaded from the file. The data returned by the filehandler is a modification of the data stored in the file, but this modification is currently not stated in the modifiers key in the DataID.
The modification of the calibration in the modifier (or in a composite) is risky and may need my PR #3018. It is similar to a composite that updates the resolution of a dataset. Because resolution is used in the DataID we need to take care to reflect those changes from the compositor/modifier in the dictionaries in the Scene and dependency tree.
Standard name being updated is no problem.