Declarative Plotting with Satellite Data

Unidata Python Workshop


Overview:

  • Teaching: 20 minutes
  • Exercises: 15 minutes

Questions

  1. How can satellite data be accessed with siphon?
  2. How can maps of satellite data be made using the declarative plotting interface?

Table of Contents

  1. Accessing data with Siphon
  2. Plotting the data

Accessing data with Siphon

As we saw with the PlottingSatelliteData notebook, GOES 16/17 data is available via the Unidata THREDDS server and can be accessed with siphon. We make use of fstrings in order to provide date, region, and channel variables to the URL string.


In [ ]:
from siphon.catalog import TDSCatalog
from datetime import datetime

In [ ]:
# Create variables for URL generation
image_date = datetime.utcnow().date()
region = 'Mesoscale-1'
channel = 8

# Create the URL to provide to siphon
data_url =  ('https://thredds.ucar.edu/thredds/catalog/satellite/goes/east/products/'
            f'CloudAndMoistureImagery/{region}/Channel{channel:02d}/'
            f'{image_date:%Y%m%d}/catalog.xml')

In [ ]:
cat = TDSCatalog(data_url)

In [ ]:
dataset = cat.datasets[1]
print(dataset)

In [ ]:
ds = dataset.remote_access(use_xarray=True)
print(ds)

Plotting the Data

To plot our data we'll be using MetPy's new declarative plotting functionality. You can write lots of matplotlib based code, but this interface greatly reduces the number of lines you need to write to get a great starting plot and then lets you customize it. The declarative plotting interface consists of three fundamental objects/concepts:

  • Plot - This is the actual representation of the data and can be ImagePlot, ContourPlot, or Plot2D.
  • Panel - This is a single panel (i.e. coordinate system). Panels contain plots. Currently the MapPanel is the only panel type available.
  • Panel Container - The container can hold multiple panels to make a multi-pane figure. Panel Containers can be thought of as the whole figure object in matplotlib.

So containers have panels which have plots. It takes a second to get that straight in your mind, but it makes setting up complex figures very simple.

For this plot we need a single panel and we want to plot the satellite image, so we'll use the ImagePlot.


In [ ]:
from metpy.plots import ImagePlot, MapPanel, PanelContainer
%matplotlib inline

Let's start out with the smallest element, the plot, and build up to the largest, the panel container.

First, we'll make the ImagePlot:


In [ ]:
img = ImagePlot()
img.data = ds
img.field = 'Sectorized_CMI'

Next, we'll make the panel that our image will go into, the MapPanel object and add the image to the plots on the panel.


In [ ]:
panel = MapPanel()
panel.plots = [img]

Finally, we make the PanelContainer and add the panel to its container. Remember that since we can have multiple plots on a panel and multiple panels on a plot, we use lists. In this case is just happens to be a list of length 1.


In [ ]:
pc = PanelContainer()
pc.panels = [panel]

Unlike working with matplotlib directly in the notebooks, this figure hasn't actually been rendered yet. Calling the show method of the panel container builds up everything, renders, and shows it to us.


In [ ]:
pc.show()

Exercise

  • Look at the documentation for the ImagePlot here and figure out how to set the colormap of the image. For this image, let's go with the WVCIMSS_r colormap as this is a mid-level water vapor image. Set the range for the colormap to 195-265 K.
  • BONUS: Use the MetPy add_timestamp method from metpy.plots to add a timestamp to the plot. You can get the axes object to plot on from the ImagePlot. The call will look something like img.ax. This needs to happen after the panels have been added to the PanelContainer.
  • DAILY DOUBLE: Using the start_date_time attribute on the dataset ds, change the call to add_timestamp to use that date and time and the pretext to say GOES 16 Channel X.

In [ ]:
# Import for the bonus exercise
from metpy.plots import add_timestamp

# Make the image plot
# YOUR CODE GOES HERE

# Make the map panel and add the image to it
# YOUR CODE GOES HERE

# Make the panel container and add the panel to it
# YOUR CODE GOES HERE

# Show the plot
# YOUR CODE GOES HERE

Solution


In [ ]:
# %load solutions/sat_map.py