Automating SUVI YouTube
Table of Contents
Intro
The Sun is changing all the time. In order to identify interesting new events to study, a solar physicist must monitor data streams observing the Sun on a regular basis. I thought it might be neat to make a tool that would automatically download extreme ultraviolet images of the Sun from the GOES-R SUVI instrument and then upload them as a movie to YouTube for easy monitoring. My goal was to use Prefect to run the entire process on a schedule. However, it appears YouTube has special restrictions on who can upload using scripts. For now, I can have the video creation automated but have to manually upload the video each day.
Core Code
Below is the core of the code that makes this happen.
""" Downloads SUVI data as specified to a temporary directory and returns that directory path"""
=
=
=
=
return
""" Renders a movie for one SUVI channel where each frame gets the specified duration.
Since the SUVI images have a high dynamic range, we raise the brightneses to the `channel_power`
and scale the output plot between `channel_min` and `channel_max`.
"""
=
,
= .
= .
return
=
return
=
=
=
=
=
= -
Walkthrough
It's easiest to read this code from bottom to top. You'll see that the script when executed starts by calling make_suvi_channel_movie
.
This Prefect flow handles the main logic. (If you've never used Prefect I'd recommend checking out their docs. I find them quite helpful.])
First, we use a Python package I made a while back called goes-solar-retriever
to download the SUVI images for a given day. We download them all to one temporary directory. We'll open them one-by-one in the
render_suvi_channel_movie
function to avoid overloading our memory with too many images. We can make one frame at a time.
(You may still have trouble with this approach if you tried a long period of data because of how I used ImageClip
from MoviePy
.
I'm not sure how much memory each clip consumes. Another approach is to write a .png
file for each frame and then use a tool like ffmpeg
to generate a movie.)
In the internal make_frame
function, we do some fancy scaling of the images so that they look better. We also set each frame to show for
0.25 seconds. With 360 images per day from SUVI's Level 2 products, we can make a 1.5 minute video. YouTube converts any videos shorter than
a minute to the shorts format. That would be undesirable for us because it means you cannot scrobble through the video; you're stuck watching it from
beginning to end.
Automating the YouTube upload
As I mentioned in the intro, due to restrictions from YouTube you cannot upload from a script and make the video public automatically it seems. Everytime I tried my video got locked for review. I believe they're worried that spammers/scammers could upload many videos using scripts. It seems there is a way around this, but it takes a special review that I didn't apply for.
However, if you had permissions to upload public videos there is a nice Python package called simple-youtube-api
that simplifies interfacing with YouTube.
If you read its GitHub or just Googling around you can find instructions on setting up the needed credentials.
# log in into the channel
=
# setting up the video that is going to be uploaded
=
# setting snippet
# setting status
# uploading video and printing the results
=
# liking video
By injecting that task at the end of your flow, you could upload the videos automatically.
Extending with thematic maps
We can extend the code above to generate thematic map movies from SUVI as well. The thematic map product identifies what different phenomena are present on the Sun, e.g. bright regions, coronal holes, filaments. You can read more about my thematic map work in this press release or in this paper. The image below shows a three-color composite of SUVI images on the left and a thematic map on the right. Yellow, for example, are bright regions while green are coronal holes.
The code gets a bit more complicated because the thematic maps neede to be rendered with a specific color table.
I added a utility build_thmap_cmap
to help with this process.
Code for thematic maps
=
=
=
return
=
,
=
= .
= .
= .
= .
# plot thmap
=
# plot channel image
return
=
return
=
=
=
=
=
=
Results and future improvements
You can see the first such movie I created at this YouTube video. The colormap could be changed to match the standard SUVI colormaps. It also doesn't have high enough contrast in my opinion. But it's a first step.
I would like to continue this line of automated visualization and include other detection algorithms. For example, it would be cool to be able to identify all the bright points on the Sun over the course of a day, analyze their properties, and output a result chart.