Invertion of channel

72 views
Skip to first unread message

b. schitter

unread,
Mar 31, 2020, 3:18:59 PM3/31/20
to pytroll
Hi Dave,

can I invert the output of a single channel (i.e. IR_108 or WV_062) during processing?

Best regards,
Bernhard

David Hoese

unread,
Mar 31, 2020, 4:01:08 PM3/31/20
to pyt...@googlegroups.com
Hi Bernhard,

This is described in the documentation in this section:
https://satpy.readthedocs.io/en/latest/composites.html#enhancing-the-images

The bottom of that section describes customizing a YAML file to store
the configuration to use it in the future. If you swap out a few of the
parameters you can make it work for one specific channel:

enhancements:
ir108_invert:
name: IR_108
operations:
- name: inverse
method: !!python/name:satpy.enhancements.invert
args: [True]
- name: stretch
method: !!python/name:satpy.enhancements.stretch
kwargs:
stretch: linear

I think this should work. Note also that we've considered inverting IR
channels the default, but haven't gotten around to changing it.

Dave
> --
> You received this message because you are subscribed to the Google
> Groups "pytroll" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pytroll/1ad09a64-3e7a-4c8c-81b3-367999a7de78%40googlegroups.com
> <https://groups.google.com/d/msgid/pytroll/1ad09a64-3e7a-4c8c-81b3-367999a7de78%40googlegroups.com?utm_medium=email&utm_source=footer>.

b. schitter

unread,
Dec 2, 2020, 5:26:14 AM12/2/20
to pytroll
Hi Dave,

thank you very much - the invertion works.

Now I have another question. Is it possible to define for the inverted product its own colormap (i.e. red: 0-100, green: 0-100, blue: -60-30) in the yaml file?

David Hoese

unread,
Dec 2, 2020, 6:42:12 AM12/2/20
to pyt...@googlegroups.com
Hi Bernard,

Here is an example from the Satpy builtin configs which joins two
colormaps together:

https://github.com/pytroll/satpy/blob/a18b6e2fae74a71beea01a26a3a0ffcaabd91016/satpy/etc/enhancements/generic.yaml#L756-L764

This uses builtin colormaps from the "trollimage" package, but you can
see the other options for how the colormaps can be defined here:

https://github.com/pytroll/satpy/blob/master/satpy/enhancements/__init__.py#L165-L196

Dave

On 12/2/20 4:26 AM, b. schitter wrote:
> Hi Dave,
>
> <https://groups.google.com/d/msgid/pytroll/1ad09a64-3e7a-4c8c-81b3-367999a7de78%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/pytroll/1ad09a64-3e7a-4c8c-81b3-367999a7de78%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "pytroll" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pytroll/3121c018-086e-4f0a-81c8-e8347c9e870fn%40googlegroups.com
> <https://groups.google.com/d/msgid/pytroll/3121c018-086e-4f0a-81c8-e8347c9e870fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

b. schitter

unread,
Dec 2, 2020, 7:57:13 AM12/2/20
to pytroll
Hi Dave,

I tried it out, but it didn't work as expected. Here a short except of my configs:

In the seviri.yaml I created a product:

  ZZ9_TEST:
    compositor: !!python/name:satpy.composites.GenericCompositor
    standard_name: ZZ9_TEST
    prerequisites:
      - name: HRV
        modifiers: [sunz_corrected]
      - name: HRV
        modifiers: [sunz_corrected]
      - IR_108

In generic.yaml I inserted the following:

  ZZ9_TEST:
    standard_name: ZZ9_TEST

    operations:
    - name: inverse
      method: !!python/name:satpy.enhancements.invert
      args:
      - [false, false, true]

    - name: stretch
      method: !!python/name:satpy.enhancements.stretch
      kwargs: {stretch: linear}
    - name: colorize
      method: !!python/name:satpy.enhancements.colorize ''
      kwargs:
        palettes:
          - {colors: reds, min_value: 0, max_value: 100}
          - {colors: greens, min_value: 0, max_value: 100}
          - {colors: blues, min_value: -60, max_value: 30}

When I try to use this in this way, I get the error "Image should be greyscale to colorize"

Can you tell me what I made wrong?

Best regards

David Hoese

unread,
Dec 2, 2020, 8:04:15 AM12/2/20
to pyt...@googlegroups.com
Bernard,

Your composite is an RGB which means it is already "in color". It
doesn't really work to colorize (add a colormap to) an image that is
already in color. Adding a colormap is usually only used when converting
a single channel (L = Luminance) to RGB.

If you could describe what you're hoping to get out of this maybe I can
help further, but in general the issue is trying to apply colors to an
image that is already in color.

Dave
> --
> You received this message because you are subscribed to the Google
> Groups "pytroll" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pytroll/6299adca-7e55-4d48-a46a-f21b276b5375n%40googlegroups.com
> <https://groups.google.com/d/msgid/pytroll/6299adca-7e55-4d48-a46a-f21b276b5375n%40googlegroups.com?utm_medium=email&utm_source=footer>.

b. schitter

unread,
Dec 2, 2020, 8:22:02 AM12/2/20
to pytroll
Hi Dave,

I attached 2 images. One image created with satpy and another with an other software we use in our office.

As you can see, the images are a little bit different (colorization). I thought, that the RGB-Values are the reason for this, because in the other software the RGB channels are defined with the given min-max values).

Best regards,
Bernhard


ZZ9_SATPY_202012021230.jpeg
ZZ9_ONL_202012021230.png

David Hoese

unread,
Dec 2, 2020, 8:30:09 AM12/2/20
to pyt...@googlegroups.com
Ah ok. These are likely the limits of each individual band in the
"stretch" portion of your enhancement. You can see this kind of
configuration here:

https://github.com/pytroll/satpy/blob/a18b6e2fae74a71beea01a26a3a0ffcaabd91016/satpy/etc/enhancements/generic.yaml#L83-L95

There are other examples in Satpy too if you search around that file.
This enhancement stretches each channel to a min and max value
(linearly) and then applies a gamma correction. In this case the gamma
correction is odd since it doesn't do anything (gamma of 1 has no effect).

Hopefully this can clear a few things up. Otherwise let me know.

Dave
> --
> You received this message because you are subscribed to the Google
> Groups "pytroll" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pytroll/7e56caaf-67a4-4a1c-9511-616b89273d87n%40googlegroups.com
> <https://groups.google.com/d/msgid/pytroll/7e56caaf-67a4-4a1c-9511-616b89273d87n%40googlegroups.com?utm_medium=email&utm_source=footer>.

b. schitter

unread,
Dec 2, 2020, 8:40:51 AM12/2/20
to pytroll
This I read already and tried out.

When I define the gereric.yaml in this way I get the error, that linear doesn't support min_stretch.

ZZ9_TEST:
    standard_name: ZZ9_TEST

    operations:
    - name: inverse
      method: !!python/name:satpy.enhancements.invert
      args:
      - [false, false, true]

    - name: stretch
      method: !!python/name:satpy.enhancements.stretch
      kwargs: {stretch: linear}
    - name:  stretch
     method: !!python/name:satpy.enhancements.stretch

     kwargs:

     stretch: linear

     min_stretch: [0, 0, -60]

     max_stretch: [100, 100, 30]


When I define the gereric.yaml in this way nearly the whole image is yellow.

ZZ9_TEST:
    standard_name: ZZ9_TEST

    operations:
    - name: inverse
      method: !!python/name:satpy.enhancements.invert
      args:
      - [false, false, true]

    - name: stretch
      method: !!python/name:satpy.enhancements.stretch
      kwargs: {stretch: linear}
    - name:  stretch
     method: !!python/name:satpy.enhancements.stretch

     kwargs:

     stretch: crude

     min_stretch: [0, 0, -60]

     max_stretch: [100, 100, 30]

Best regards,
Bernhard

David Hoese

unread,
Dec 2, 2020, 11:16:33 AM12/2/20
to pyt...@googlegroups.com
Double check your indentation/spacing. At least with the way you've
pasted it here it doesn't look like stretch/min_stretch/max_stretch are
all "under" the "kwargs:" item, which they must be.

Additionally, you shouldn't need *both* of those stretch operations.
Make sure to remove the first one where you have "stretch: linear".
Otherwise, please provide the full traceback for the error message you
are seeing.

Dave
> --
> You received this message because you are subscribed to the Google
> Groups "pytroll" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pytroll/28aa1354-0f7a-4267-9ad3-72c3fb9a9b2cn%40googlegroups.com
> <https://groups.google.com/d/msgid/pytroll/28aa1354-0f7a-4267-9ad3-72c3fb9a9b2cn%40googlegroups.com?utm_medium=email&utm_source=footer>.

b. schitter

unread,
Dec 2, 2020, 3:53:41 PM12/2/20
to pytroll
Hi Dave,

I think, the intention is correct. I attached the generic.yaml, with the definition at the beginning of the file.

With stretch: linear (as defined in the generic.yaml) and min_stratch and max_stretch I get the described error (see attached traceback.txt).

Best regards,
Bernhard



generic.yaml
traceback.txt
Reply all
Reply to author
Forward
0 new messages