resample the output of a composite

11 views
Skip to first unread message

Thanasis Karagiannidis

unread,
Oct 8, 2021, 10:53:57 AM10/8/21
to pyt...@googlegroups.com

Dear Pytroll community

 

I was wondering if it is possible to resample the output of a composite. For example, the output of the DayNightCompositor.

To demonstrate was I mean in my script I do the following:

compositor = DayNightCompositor("dnc", lim_low=65., lim_high=90., day_night="day_night")

global_scene = Scene(filenames = files, reader = 'seviri_l1b_hrit')

global_scene.load(['day_microphysics'])

global_scene.load(['night_microphysics'])

composite = compositor([global_scene['day_microphysics'],global_scene['night_microphysics']])

from satpy import writers

img = writers.to_image(composite)

img.save(filename="<mypath>/test_file.tif")

This works perfectly and saves the image. However the image is the full disk, upside-down etc.

I was wandering if it is possible to resample the composite using a predefined “area” (defined in my areas.yaml file) with the next line:

new_scene = global_scene.resample(area, resampler = nearest,  cache_dir=<mypath>).

If I use the line as is, only the first global_scene loaded is reasmpled (in my case global_scene.load(['day_microphysics'])).

 

Any help would be appreciated.

 

Best regards

 

Sakis

Raspaud Martin

unread,
Oct 11, 2021, 3:26:32 AM10/11/21
to pyt...@googlegroups.com
Dear Sakis,

Two possibilities that I can see:

First one, and recommanded one, is to define your composite in a
seviri.yaml file that you can have on you SATPY_CONFIG_DIR path, and
have something like:

```
full_day_microphysics:
compositor: !!python/name:satpy.composites.DayNightCompositor
standard_name: full_day_microphysics
prerequisites:
- day_microphysics
- night_microphysics
```

then you can just load that new composite instead, and resample and
save it.

The other solution is to just add the new composite to the
`global_scene`:
```
global_scene["full_day_microphysics"] = composite
```
etc.

Note that I didn't test the code bits I wrote here ;)

Best regards,
Martin

Panu Lahtinen

unread,
Oct 11, 2021, 3:34:02 AM10/11/21
to pyt...@googlegroups.com
On 11.10.2021 10.26, Raspaud Martin wrote:
> Dear Sakis,
>
> Two possibilities that I can see:
>
> First one, and recommanded one, is to define your composite in a
> seviri.yaml file that you can have on you SATPY_CONFIG_DIR path, and
> have something like:
>
> ```
> full_day_microphysics:
> compositor: !!python/name:satpy.composites.DayNightCompositor
> standard_name: full_day_microphysics
> prerequisites:
> - day_microphysics
> - night_microphysics
> ```

Note that in addition to the composite definition in
$SATPY_CONFIG_DIR/composites/seviri.yaml you'll also need the following
in $SATPY_CONFIG_DIR/enhancements/seviri.yaml:


```
full_day_microphysics:
standard_name: full_day_microphysics
operations:
- name: stretch
method: !!python/name:satpy.enhancements.stretch
kwargs:
stretch: crude
min_stretch: [0, 0, 0]
max_stretch: [1, 1, 1]
```

Without this, Satpy applies a dynamic stretch to the final composite and
will change the colors in unpredictable way.

See
https://satpy.readthedocs.io/en/stable/composites.html#creating-composite-configuration-files
for more explanation in adding your own composites to configuration files.


P

--
Finnish Meteorological Institute
Erik Palménin aukio 1, P.O.Box 503, FIN-00101 Helsinki, Finland
Room: 2B10a, Phone: +358 9 1929 3628, Fax: +358 9 1929 3146

David Hoese

unread,
Oct 11, 2021, 9:37:51 AM10/11/21
to pyt...@googlegroups.com
Hi Sakis,

I agree with Martin and Panu that this would probably be easiest if you
defined your own configuration directory with SATPY_CONFIG_PATH and put
some YAML files in there. That said, I don't see anything wrong with the
code you have. It does depend on where you put that resample call
though. My guess is that night_microphysics requires resampling before
it can be made, but if that were true then your `composite =
compositor(...)` line never should have worked. If you do the following
line right after your second `.load` call what do you get:

print(list(global_scene.keys()))

Also, because you are using the DayNightCompositor I think you might be
getting lucky with `to_image` as the data will already be scaled
properly for an image...I think. Note that even though you are saving to
`.tif` this will only be a regular TIFF image and not a geotiff which
usually would include geolocation information. If you were hoping for a
geotiff let me know and we can figure something out.

Dave

On 10/8/21 9:53 AM, Thanasis Karagiannidis wrote:
> Dear Pytroll community
>
> I was wondering if it is possible to resample the output of a composite.
> For example, the output of the DayNightCompositor.
>
> To demonstrate was I mean in my script I do the following:
>
> compositor = DayNightCompositor("dnc", lim_low=65., lim_high=90.,
> day_night="day_night")
>
> global_scene = Scene(filenames = files, reader = 'seviri_l1b_hrit')
>
> global_scene.load(['day_microphysics'])
>
> global_scene.load(['night_microphysics'])
>
> composite =
> compositor([global_scene['day_microphysics'],global_scene['night_microphysics']])
>
> from satpy import writers
>
> img = writers.to_image(composite)
>
> img.save(filename="<mypath>/test_file.tif")
>
> This works perfectly and saves the image. However the image is the full
> disk, upside-down etc.
>
> I was wandering if it is possible to resample the composite using a
> predefined “area” (defined in my areas.yaml file) with the next line:
>
> new_scene = global_scene.resample(area, resampler =
> nearest,cache_dir=<mypath>).
>
> If I use the line as is, only the first global_scene loaded is reasmpled
> (in my case global_scene.load(['day_microphysics'])).
>
> Any help would be appreciated.
>
> Best regards
>
> Sakis
>
> --
> 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/CAJ5NJ7x%2Bki1ZioJoQA2tmkVA0omOFBq8KQnMKc9FMBbLFVwZ6w%40mail.gmail.com
> <https://groups.google.com/d/msgid/pytroll/CAJ5NJ7x%2Bki1ZioJoQA2tmkVA0omOFBq8KQnMKc9FMBbLFVwZ6w%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Thanasis Karagiannidis

unread,
Oct 11, 2021, 11:25:07 AM10/11/21
to pyt...@googlegroups.com
Dear Raspaud, Panu and David

Thank you very much!

The solution global_scene[compositename]=composite worked just fine. Thank you. I think it is quite useful!

When I insert the line  print(list(global_scene.keys()))  I get: [DataID(name='DayNight_Microphysics', resolution=3000.403165817), DataID(name='day_microphysics', resolution=3000.403165817), DataID(name='night_microphysics', resolution=3000.403165817)]

As for the possibility to add the lines to to composites and enhancements yaml files, I will also test it. But in that case, how do I control the min/max sun angles? I refer to 65 and 90 of the line: compositor = DayNightCompositor("dnc", lim_low=65., lim_high=90., day_night="day_night").

Sakis


To unsubscribe from this group and stop receiving emails from it, send an email to pytroll+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pytroll/52c08580-1150-52e4-cdad-b770800343d9%40gmail.com.

David Hoese

unread,
Oct 11, 2021, 11:44:25 AM10/11/21
to pyt...@googlegroups.com
The keyword arguments to the compositor can be passed in the YAML like
the rest of the parameters. There is an example of this here (admittedly
in an odd place on that page):

https://satpy.readthedocs.io/en/stable/composites.html#using-other-composites

Dave
> <mailto:pytroll%2Bunsu...@googlegroups.com>
> > <mailto:pytroll+u...@googlegroups.com
> <mailto:pytroll%2Bunsu...@googlegroups.com>>.
> <https://groups.google.com/d/msgid/pytroll/CAJ5NJ7x%2Bki1ZioJoQA2tmkVA0omOFBq8KQnMKc9FMBbLFVwZ6w%40mail.gmail.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/pytroll/CAJ5NJ7x%2Bki1ZioJoQA2tmkVA0omOFBq8KQnMKc9FMBbLFVwZ6w%40mail.gmail.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%2Bunsu...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pytroll/52c08580-1150-52e4-cdad-b770800343d9%40gmail.com
> <https://groups.google.com/d/msgid/pytroll/52c08580-1150-52e4-cdad-b770800343d9%40gmail.com>.
>
> --
> 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/CAJ5NJ7x%2BoG6mvhjUSwFGxXcdnmWgQbd7EZ-A%3DFAKXs%3Dk3_CauA%40mail.gmail.com
> <https://groups.google.com/d/msgid/pytroll/CAJ5NJ7x%2BoG6mvhjUSwFGxXcdnmWgQbd7EZ-A%3DFAKXs%3Dk3_CauA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Thanasis Karagiannidis

unread,
Oct 11, 2021, 12:13:29 PM10/11/21
to pyt...@googlegroups.com
Like in the case of natural_with_night_fog!

Thank you very much!

Sakis

To unsubscribe from this group and stop receiving emails from it, send an email to pytroll+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pytroll/9fc32236-1f6d-d9f2-51c7-555ceb264fdf%40gmail.com.
Reply all
Reply to author
Forward
0 new messages