resizing image in satpy

10 views
Skip to first unread message

R Alb

unread,
Jan 30, 2023, 8:04:38 AM1/30/23
to pyt...@googlegroups.com
LS,
I have a problem with resizing an image in satpy.
Code as follows: (I hope this is enough)
>>>Code start
area = 'msg_ioc_3km'           #defined in areas.yaml, size=3712x3712

#resize to 1100x1100
from satpy.resample import get_area_def
sarea=get_area_def(area)
sarea.width=1100
sarea.height=1100
sarea.area_id='resized_1100'

global_scene = Scene(filenames = files, reader = reader)
resampler_kwargs = {'resampler': 'nearest', 'radius_of_influence': 20000, 'reduce_data': False}
new_scene = global_scene.resample(sarea, **resampler_kwargs)

#rest is to create the file:
save_objects = []
save_objects.append()
compute_writer_results(save_objects)
<<<Code end

Result is that the generated image has size 1100x1100, but the content is not resized. As a result about the upper-left part is shown in it's original size, so it looks like a cropped image.
If, instead, I define the size in areas.yaml (near 'shape:') to 1100x1100 then it works fine.
No caching used.
What's going wrong here?

Regards,
Rob.

Raspaud Martin

unread,
Jan 30, 2023, 8:48:53 AM1/30/23
to pyt...@googlegroups.com
Hi,

AreaDefinitions are not supposed to be modified I think, as they cache
a few things. So it's better to make a fresh one as you did, but here
is a way to do it programmatically:

sarea = get_area_def(area).copy(width=1100, height=1100)

Another shortcut that could be helpful if you want to divide the size
by an integer factor is:

sarea = get_area_def(area).aggregate(x=3, y=3)

(eg if you want something 3 times as small)

Hope this helps!

Best regards,
Martin

R Alb

unread,
Jan 30, 2023, 9:33:53 AM1/30/23
to pyt...@googlegroups.com
Martin,
Many thanks, that works.
Regards,
Rob.


Op ma 30 jan. 2023 om 14:48 schreef Raspaud Martin <martin....@smhi.se>:
--
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.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pytroll/bd07570e2c568f9decb9b1e3668eae75d75bce62.camel%40smhi.se.
Reply all
Reply to author
Forward
0 new messages