pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.07k stars 297 forks source link

scene.save_datasets() outputs different values for AHI_HSD reader with calibration="brightness_temperature" #2710

Closed jayepraveen999 closed 10 months ago

jayepraveen999 commented 10 months ago

Describe the bug

I want to save the raw infrared bands from AHI sensor to .tif files with brightness_temperature as calibration. However, scene.load(filenames, reader="ahi_hsd", calibration="brightness_temperature") works as expected but when I try to save it using scene.save_datasets(), the values are within the range of [0-1] which doesn't make any sense for brightnesss_temperature product. To Reproduce

# Your code here
scene = satpy.Scene(reader='ahi_hsd', filenames=filenames)

scene.load(['B07', 'B11', 'B12', 'B13', 'B14', 'B15'],calibration='brightness_temperature')
print(np.unique(scene["B07"].values)) # to check if the calibration is applied and how the values look like

# save datasets as geotiffs   
scene.save_datasets(writer='geotiff', dtype= np.float32, enchance= False, base_dir="reprocess_data/input_data/himawari8")

Expected behavior When I read any of the saved .tif files from above, I expect they would have values of brightness_temperature which I printed after loading.

output of the print statement in the above code:
array([176.01837, 176.40892, 176.7933 , ..., 330.69333, 330.8056 ,
             nan], dtype=float32)

Actual results

import rasterio

data = rasterio.open("../reprocess_data/input_data/himawari8/B07_20200108_042000.tif")
np.unique(data.read(1))

output:
array([-0.34350264, -0.27109495, -0.22607319, ...,  1.6576164 ,
        1.6579522 ,         nan], dtype=float32)

Environment Info:

djhoese commented 10 months ago

You have a typo:

enchance= False

should be:

enhance=False

djhoese commented 10 months ago

Also note that the brightness temperature calibration is the default in Satpy for those types of bands so no need to specify it in the .load call.

jayepraveen999 commented 10 months ago

oops. Thank you!!

I am thinking if I should submit PR to raise Value Error if valid arguments are not passed for save_datasets() method. Your thoughts @djhoese ?

djhoese commented 10 months ago

That is not actually possible due to the way many of Satpy's Scene's methods use **kwargs. For writers it is even more difficult as a single set of kwargs is passed, split by a special classmethod on the Writer object, then some kwargs are sent to Writer.__init__ and the rest to Writer.save_datasets.

It is one of those: if we did it over again we'd probably be smarter about it, but it is the way it is. If you'd like to still look at it and see if it can be done then be my guest it would be great to do those types of checks. I'm just not very optimistic about how cleanly it can be implemented.

jayepraveen999 commented 10 months ago

Agreed. Then I will push this further in my list :) Closing the issue for now.