pytroll / satpy

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

How to use compositors,enhancements and modify Functions? #1875

Open haiyangdaozhang opened 2 years ago

haiyangdaozhang commented 2 years ago

Dear :

I am interested in compositors and enhancements. I checked their yaml files, but I don't know how to set them.

  1. For example, I want to set one-half of the A channel as the R band, one-half of the B channel as the G band, and the C channel as the B band. How can I set it in the yaml file?

  2. When I create a compositor, there will be Nan data in a channel at a certain position. It will cause the position of the 3 channel synthesized picture to become transparent. How can I modify it to make nan equal to another value, so that it will not appear transparent in RGB products.

  3. In the enhancement yaml files, I want to set the percentage of a channel to set the enhancement range instead of a specific value. How to configure the enhanced files?

  4. In addition, if I want to modify a channel in the code, how should I achieve it?

How can I get more detailed docments to introduce these usages?

Thank you!

Haidao

djhoese commented 2 years ago
  1. To make an RGB image from other datasets, try using the GenericCompositor. You can see an example here:

    https://github.com/pytroll/satpy/blob/8e2beeb943d2162005e1782d7b9f74380abf86fc/satpy/etc/composites/visir.yaml#L129-L135

    For the "half" part you'll either need to configure an enhancement to do the math for you or you'd have to code your own compositor in python. I'm not sure we have anything that let's you easily multiple by a factor.

  2. There are a couple existing compositor classes that try to deal with fill values in different ways, but none of them look like what you want:

    https://github.com/pytroll/satpy/blob/8e2beeb943d2162005e1782d7b9f74380abf86fc/satpy/composites/__init__.py#L396-L431

    One "simple" way of doing this would be to pass fill_value=0 to the Scene.save_datasets method. For image writers like the "geotiff" writer this will make all NaNs equal to the fill value you specify (0 for black). Otherwise, as with question 1, you'd have to code your own compositor or enhancement to do that for you.

  3. You could use the "linear" stretch which calls this method in trollimage:

    https://github.com/pytroll/trollimage/blob/5aeef5a2534442434cb00b0a9e091bf72a222130/trollimage/xrimage.py#L1169-L1174

    Theoretically if you set the cut-offs to 0.25 and 0.25, you would be left with the 50% in the middle of the image. Note that this enhancement method will perform slower than other stretch methods like "crude" as it needs to look at the entire image to come up with min/max values.

  4. "modify a channel in the code", what do you mean by that?

haiyangdaozhang commented 2 years ago

Hello David:

Thank you for your response! I study your satpy lesson on the Youtube. I think it's very useful !

For Question 2 : I saw some FillingCompositor in yaml files. Channel 2 has some Nan data. It causes the postion of RGB products to become Nan. Can I change yaml files to set its fill_value = 100 or other values?

yaml file: overview: compositor: !!python/name:satpy.composites.GenericCompositor prerequisites:

Question 4 means that I can use yaml files to create compositor with modifiers. But if I don't use these yaml files, how can I use modifiers to calibrate a channel in the python codes?

yaml file: true_color_crefl: compositor: !!python/name:satpy.composites.GenericCompositor prerequisites:

Thank you!

Haidao

djhoese commented 2 years ago

For question 2, no I don't think so. Those compositors are really only meant for filling data from one dataset with the data from another.

For question 4, you mean you want to load (in python) a band with these modifiers applied? You should be able to do scn.load(['1'], modifiers=('sunz_corrected', 'rayleigh_corrected_crefl')). You can also use DataQuery objects to have even more control over what you're requesting:

from satpy import DataQuery

dq1 = DataQuery(name="1", modifiers=("sunz_corrected", "rayleigh_corrected_crefl"))
dq4 = DataQuery(name="4", modifiers=("sunz_corrected",))

scn.load([dq1, dq4])
haiyangdaozhang commented 2 years ago

Thank you!

I see this: https://satpy.readthedocs.io/en/latest/api/satpy.composites.html?highlight=Filler#satpy.composites.Filler

Bases: satpy.composites.GenericCompositor

Fix holes in projectable 1 with data from projectable 2.

Collect custom configuration values.

Parameters
common_channel_mask (bool) – If True, mask all the channels with a mask that combines all the invalid areas of the given data

May I set common_channel_mask been False in yaml files?

haiyangdaozhang commented 2 years ago

I tried this:

scn1.load(["1", "2"], modifiers=('sunz_corrected',))
scn1.keys()

It shows:

[DataID(name='1', wavelength=WavelengthRange(min=0.62, central=0.645, max=0.67, unit='µm'), resolution=250, calibration=<calibration.reflectance>, modifiers=()),
 DataID(name='2', wavelength=WavelengthRange(min=0.841, central=0.8585, max=0.876, unit='µm'), resolution=250, calibration=<calibration.reflectance>, modifiers=())]

It seems that modifiers not works. Maybe I should create sunz_corrected ?