Make the MO global analysis videoΒΆ

To make the video you need to run the plot script thousands of times, making an image file for each point in time, and then to merge the thousands of resulting images into a single video.

To make a smooth video we generate one frame each 30 minutes - the temperatures and winds are available on the hour and the precipitation on the half hours, so making frames at 15 and 45 minutes past the hour makes each frame the same (as opposed to having some original data frames and some interpolated data frames).

This script makes a list of commands to plot a frame each 30 minutes over a year:

#!/usr/bin/env python

# Make all the individual frames for a movie

import os
import subprocess
import datetime

# Where to put the output files
opdir="%s/slurm_output" % os.getenv('SCRATCH')
if not os.path.isdir(opdir):
    os.makedirs(opdir)

# Function to check if the job is already done for this timepoint
def is_done(year,month,day,hour):
    op_file_name=("%s/images/opfc_global_3var_meanp/" +
                  "%04d%02d%02d%02d%02d.png") % (
                            os.getenv('SCRATCH'),
                            year,month,day,int(hour),
                                        int(hour%1*60))
    if os.path.isfile(op_file_name):
        return True
    return False

f=open("run.txt","w+")

start_day=datetime.datetime(2018,   9, 26,  0, 15)
end_day  =datetime.datetime(2019,   9, 18, 23, 45)

current_day=start_day
while current_day<=end_day:
    if is_done(current_day.year,current_day.month,
                   current_day.day,current_day.hour+current_day.minute/60):
        current_day=current_day+datetime.timedelta(minutes=30)
        continue
    cmd=("./global_3var.py --year=%d --month=%d " +
         "--day=%d --hour=%f "+
         "--pole_latitude=90 --pole_longitude=180 "+
         "--npg_longitude=0 "+
         "--zoom=1 "+
         "\n") % (
           current_day.year,current_day.month,
             current_day.day,current_day.hour+current_day.minute/60)
    f.write(cmd)
    current_day=current_day+datetime.timedelta(minutes=30)
f.close()

You will want to run those jobs in parallel, either with GNU parallel or by submitting them to a batch system (I used the MO SPICE cluster).

When all the frame images are rendered make a video using ffmpeg. Because of all the detail in the wind and precipitation fields, this video requires a lot of bandwidth, so render it at 20Mbps bandwidth (this is also why the frames are 3840X2160 in size - this produces a 4k video.

ffmpeg -r 48 -pattern_type glob -i opfc_global_3var_meanp/\*.png \
       -c:v libx264 -threads 16 -preset veryslow -tune film \
       -profile:v high -level 4.2 -pix_fmt yuv420p -b:v 19M \
       -maxrate 19M -bufsize 20M -c:a copy opfc_global_3var_meanp.mp4