MetPy Mondays #11 - Plotting GOES-16 Data with Widgets

Everyone has been really excited about exploring the incredibly high resolution GOES-16 imagery that is now available in an experimental capacity. We host some of this data on out THREDDS test server and it can be ingested with siphon and plotted in Python! In this week’s MetPy Monday we’ll go over how to use interactive widgets to select the region and channel to plot and produce images from the data.

In a past MetPy Monday we’ve used the notebook interactive widgets to create a simple calculator utility. Everything I’m doing is available in a notebook from our Unidata Python Workshop and can be downloaded here. There’s a lot going on here, but I want to focus on the interactivity this week.

To start out with, we need to import a slew of tools. We’re going to use datetime for generating datetime objects to request data and make nice timestamps, cartopy for mapping, the interactive widgets for UI, matplotlib for the image rendering, netCDF4 to read the data, and siphon to request data.

It’s nice to break the problem up into smaller chunks that become functions. Our first function takes the datetime object, channel, dataset index, and region. It then generates a request to the THREDDS data server and returns a dataset.

The next function is what we’ll actually call. It calls open_dataset to request the data, pulls out the important variables and does the map creation. Here you can see we use the projection variable from the satellite data to specify the globe that cartopy will use for its mapping. We also use that projection information to setup a Lambert Conformal projection. Finally, we get state boundaries much like we did in the mapping with cartopy tutorial.

Next, the function sets up a figure and axis object to plot on and removes any old images plotted there. It also adds the state boundaries and country borders to the map. We use matplotlib’s imshow function to plot the data and let cartopy take care of all the projection issues. We clip the map to the extents of the data by finding the maximum and minimum values of the x and y coordinates.

Finally, we dress up the plot a bit by adding annotations of the image time, channel number, and the notation that these data are still experimental. We use the string parse function (strptime) to create a datetime object from the dataset’s timestamp and then the string format function (strftime) to write it back out as a string in a more readable format. Matplotlib’s text function takes care of plotting the text, but we apply some path effects to outline the white text in black lettering, to help increase the readability on different backgrounds. Finally, we show the figure.

With all the heavy lifting done, all that’s left is creating the interactive parts of the notebook. First, we create a dictionary with the name of the channels on the satellite as the key and the channel number as the value.

We then populate a channel dropdown selector with that dictionary and create a region selector. The GOES satellite transmits images for full disk, CONUS, and two mesoscale regions at different time resolutions. With the widgets made, we just need to hook them up to the plotting function!

We get the current time, then wrap the plotGOES16channel function with interact, just like in the dew point example.

The output we get is a map with two drop down menus allowing us to select and view our data in real-time! With a relatively small amount of code, we were able to create a tool that could be used in the classroom or weather discussions. Try using widgets in your classroom and let us know what you’re doing with notebooks and Unidata technologies!


Post a Comment:
  • HTML Syntax: Allowed
Unidata Developer's Blog
A weblog about software development by Unidata developers*
Unidata Developer's Blog
A weblog about software development by Unidata developers*



News@Unidata blog

Take a poll!

What if we had an ongoing user poll in here?

Browse By Topic
Browse by Topic
« October 2017