Last active
November 26, 2022 16:09
-
-
Save cmj/e2072d757729350b296a7c23411e8537 to your computer and use it in GitHub Desktop.
Convert HRRR smoke images to mp4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create animation from HRRR NW current smoke graphics. | |
# Considerably more accurate than with stitching forecasts. | |
# | |
# 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=NW | |
field=int | |
start=2022-09-12 # 2022-08-21 <- oldest available date as of 2022-09-11 | |
end=2022-09-12 # 2022-09-12 | |
#### | |
n=1 | |
dateutils.dseq $start $end -f '%Y%m%d' | while read date; do | |
for hour in {00..23}; do | |
# slurp and toss serving page to bypass apparent hotlinking countermeasures (?) | |
#curl -s -o /dev/null "https://rapidrefresh.noaa.gov/hrrr/HRRRsmoke/displayMapUpdated.cgi?keys=hrrr_ncep_jet:&runtime=${date}${hour}&plot_type=trc1_${domain}_${field}&fcst=000&time_inc=60&num_times=49&model=hrrr&ptitle=HRRR-Smoke%20Graphics&maxFcstLen=1&fcstStrLen=-1&domain=${domain}&adtfn=1" | |
wget -O "${date}${hour}-trc1_${domain}_${field}_f000.png" "https://rapidrefresh.noaa.gov/hrrr/HRRRsmoke/for_web/hrrr_ncep_jet/${date}${hour}/${domain}/trc1_${domain}_${field}_f000.png" | |
ln -sf ts-"${date}${hour}-trc1_${domain}_${field}_f000.png" $n.png | |
((n++)) | |
done | |
done | |
ls -1 20*trc1_${domain}_${field}_f000.png | while read d; do | |
stamp=$(date -d $(sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2}).*/\1-\2-\3T\4-00:00/' <<<$d) '+%b %d %H:00 %Z %Y') | |
convert -fill black -pointsize 20 -gravity NorthWest -draw "text 460,32 '$stamp'" $d ts-$d | |
done | |
# lazy helper for ffmpeg sequencing | |
#n=1; ls -1 ts-${date}${hour}-trc1_${domain}_${field}_f000.png | while read a; do ln -sf $a $n.png; ((n++)) done | |
anim=$(date '+%Y%m%d%H%M')-trc1_${domain}_${field}_f000.mp4 | |
ffmpeg -framerate 12 -i %d.png -c:v libx264 -r 30 $anim | |
# cleanup symlinks for future runs | |
find -maxdepth 1 -type l -delete | |
echo -e "\n\nFinished: mpv -loop $anim" | |
mpv -loop $anim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment