2 min read
Using Satpy

This is a quick guide on using the satpy to zoom into a satellite image based on coordinates. I struggled to understand how to use this library in a recent machine learning project. Here is a guide for beginners to the topic like me.

Let’s assume that you want to find out how the weather in spain 🇪🇸 looks like.

You are in luck you have a recent satellite image on your computer.

you load it on your favorite image viewing software and you are met with figure 1.

::image{src=‘infrared.png’} Figure 1: Satellite Image. ::

Too far to distinguish whatever is happening in spain. I wanted to do this recently and found myself lost in a sea of documentation which explained more complex uses of the library than what I need. I just want to zoom in on one area!

Jump to full code to get a quick copy paste, free of charge.

Pieces of the puzzle

In the end we want to call the function resample which will give us a Scene object with the correct area. the resample function takes as argument an AreaDefinition.

Area Definition

The way to create an area definition is by using the create_area_def function, which takes in the following arguments:

  1. name: does not affect anything so we can go with 'spain'
  2. projection: this is important as it
  3. height: this is our desired output image size, we can go for 300
  4. width: this is our desired output image width, we can go for 300
  5. area_extent: here an array is expected.
  6. units

Full Code

import satpy

projection = ""
spain_coords = [50, 50, 50, 50]

spainAreaDefinition = create_area_def('spain',
                                      projection=projection,
                                      width=300,
                                      height=300,
                                      area_extent=spain_coords,
                                      units='degrees')

resampledScene = scene.resample(spainAreaDefinition)