Skip to content

Instantly share code, notes, and snippets.

@cmj
Last active October 16, 2022 16:53
Show Gist options
  • Save cmj/8a1de34f5622b40cedd24a1872be1aec to your computer and use it in GitHub Desktop.
Save cmj/8a1de34f5622b40cedd24a1872be1aec to your computer and use it in GitHub Desktop.
HRRR smoke animation forecast
#!/bin/bash
# Create animation from HRRR smoke FORECAST from runs at 12z. Overlay local TZ timestamp.
# Domains available: full,NW,NC,NE,SW,SC,SE,GreatLakes,EastCO,SEA-POR,CentralCA,CHI-DET,NYC-BOS,DCArea,SouthFL,ATL,SouthCA,VortexSE
# Fields: int,sfc,1000ft,6000ft
domain=SEA-POR
field=int
today=$(date '+%Y%m%d')
####
n=1
# slurp and toss serving page to bypass apparent hotlinking countermeasures (?)
curl -s -o /dev/null "https://rapidrefresh.noaa.gov/hrrr/HRRRsmoke/jsloopUpdated.cgi?dsKeys=hrrr_ncep_jet:&runTime=${today}12&plotName=trc1_SEA-POR_int&fcstInc=60&numFcsts=49&model=hrrr&ptitle=null&maxFcstLen=48&fcstStrLen=-1&domain=SEA-POR"
for hour in {00..48}; do
sfile="${today}12-trc1_${domain}_${field}_f0${hour}.png"
if [[ ! -s $sfile ]]; then
curl -o $sfile -f "https://rapidrefresh.noaa.gov/hrrr/HRRRsmoke/for_web/hrrr_ncep_jet/${today}12/${domain}/trc1_${domain}_${field}_f0${hour}.png"
fi
# simplify for ffmpeg sequencing
ln -sf ts-$sfile $n.png
((n++))
done
ls -1 20*trc1_${domain}_${field}_f0*.png | while read d; do
stime=$(sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2}).*f0([0-9]{2}).*/\1-\2-\3T12:00Z \4h/' <<<$d)
stamp=$(date -d $(dateutils.dadd ${stime})Z '+%b %d %H:00 %Z %Y')
convert -fill black -pointsize 20 -gravity NorthWest -draw "text 460,32 '$stamp'" $d ts-$d
done
anim=$(date '+%Y%m%d%H%M')-trc1_${domain}_${field}.mp4
# 12 25
ffmpeg -framerate 6 -i %d.png -c:v libx264 -r 12 $anim
# cleanup symlinks for future runs
find -maxdepth 1 -type l -delete
echo -e "\n\nFinished: mpv -loop $anim"
mpv -loop $anim
@cmj
Copy link
Author

cmj commented Oct 16, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment