pytroll / satpy

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

Add an optional kwarg to CloudCompositor for RGBA output #2788

Closed yukaribbba closed 2 months ago

yukaribbba commented 2 months ago

Usually CloudCompositor produces an LA mode image. But sometimes you may want RGBA result. So this PR will add "mode" kwarg just like MaskingCompositor.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.94%. Comparing base (87d072d) to head (1c242a0). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2788 +/- ## ======================================= Coverage 95.94% 95.94% ======================================= Files 379 379 Lines 53693 53713 +20 ======================================= + Hits 51515 51535 +20 Misses 2178 2178 ``` | [Flag](https://app.codecov.io/gh/pytroll/satpy/pull/2788/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | Coverage Δ | | |---|---|---| | [behaviourtests](https://app.codecov.io/gh/pytroll/satpy/pull/2788/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `4.09% <4.76%> (+<0.01%)` | :arrow_up: | | [unittests](https://app.codecov.io/gh/pytroll/satpy/pull/2788/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `96.04% <100.00%> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 8785324481

Details


Totals Coverage Status
Change from base Build 8781051256: 0.0%
Covered Lines: 0
Relevant Lines: 0

💛 - Coveralls
djhoese commented 2 months ago

Could you explain more why/when this is needed? Normally writers or other compositors are supposed to handle these cases for you.

yukaribbba commented 2 months ago

My fault. Didn't realize that. Closing now

djhoese commented 2 months ago

If you have a use case where this isn't true let me know. There is very likely a case where things won't work, I just didn't know what that situation would be.

yukaribbba commented 2 months ago

Well some image viewing software can't display LA images correctly, such as Photo Viewer in Windows. That's why I start this. But your words remind me that I can build something with GenericCompositor like

    compositor: !!python/name:satpy.composites.GenericCompositor
    prerequisites:
      - name: C14
      - name: C14
      - compositor: !!python/name:satpy.composites.CloudCompositor
        prerequisites:
          - name: C14

But there are still some errors I'm trying to figure out.

yukaribbba commented 2 months ago

So GenericCompositor isn't helpful since CloudCompositor will add a "band" dimension which is not present in the first two. Therefore triggers the "incompatible areas". So I turn to MaskingCompositor and BackgroundCompositor.

  masking:
    compositor: !!python/name:satpy.composites.MaskingCompositor
    prerequisites:
      - name: C14
      - name: C14
    conditions:
      - method: less_equal
        value: 0
        transparency: 100
      - method: greater
        value: 0
        transparency: 100
      - method: isnan
        transparency: 100
    mode: RGBA
    standard_name: no_enhancement_spec

  ir_cloud_day_default_2000:
    compositor: !!python/name:satpy.composites.BackgroundCompositor
    prerequisites:
      - name: masking
      - compositor: !!python/name:satpy.composites.CloudCompositor
        prerequisites:
          - name: C14
    standard_name: ir_cloud_day_default

The logic is: lay a completely transparent RGBA image upon the LA image(day cloud) then you get the RGBA result because BackgroundCompositor will do that add_bands job. It's kinda magical but anyway I got what I want and no changes needed.

djhoese commented 2 months ago

Why is C14 being used here? Is the final result you want just a geotiff with the cloud compositor output as RGBA? And you need that so more image viewers will show the image correctly?

yukaribbba commented 2 months ago

Yes I want a geotiff in RGBA mode so that my image viewer can show it properly. C14 is used just for convenience since cloudcompositor will also use that band. Actually it can be any bands since all I need from that is just a transparent image . I'm not sure if other image viewers have such problems but in my Windows pc that is certain. Could just be a rare case, who knows...

djhoese commented 2 months ago

I think this is a good feature, but should maybe not be added to just the CloudCompositor. I wonder if there is a way to do this with enhancements. @pnuu @simonrp84 or @mraspaud any ideas how to take the output of a composite that is LA and produce an RGBA without modifying Satpy or trollimage?

pnuu commented 2 months ago

The first option that comes to mind is to create a composite that has C14 on all 3 channels and then use that with CloudCompositor.

yukaribbba commented 2 months ago

@pnuu Unfortunately CloudCompositor can only accept a single band otherwise it'll end it up like this:

<xarray.DataArray 'bands' (bands: 6)> Size: 24B
array(['R', 'G', 'B', 'R', 'G', 'B'], dtype='<U1')
Coordinates:
    crs      object 8B PROJCRS["unknown",BASEGEOGCRS["unknown",DATUM["Unknown...
  * bands    (bands) <U1 24B 'R' 'G' 'B' 'R' 'G' 'B'