Created
September 28, 2018 09:24
-
-
Save philronan/2669be118ed9a04d0c6f1bbaffdf0b93 to your computer and use it in GitHub Desktop.
Grab images of Earth from the Himawari-8 satellite
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 | |
# Fetch full-resolution Earth images from the Himawari-8 satellite | |
# Requires ImageMagick, curl, Perl | |
# The URL structure of the image server is liable to change, but currently looks like this: | |
# Typical url = https://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/YYYY/MM/DD/hhmm00_XX_YY.png | |
# YYYY/MM/DD = date | |
# hhmm = UTC time (rounded to 10 minutes) | |
# XX, YY = X and Y coordinates of tile (0 <= XX, YY <= 19) | |
# Images updated every 10 minutes, but take about 20 minutes to go online | |
# Generate timestamp data for the URL and output filename | |
t=`date -u -v-22M "+%Y/%m/%d/%H%M" | head -c 14`"000" | |
t0=`echo $t | sed s/[^0-9]/-/g` | |
baseurl="https://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/$t"_ | |
# Create a random prefix for temp file names | |
rr=`cat /dev/urandom | xxd -p | head -c32` | |
# Progress bar width | |
pw=60 | |
# Images are served as a 20x20 mosaic of 550x550 pixel PNG images | |
for i in {0..19} ; do | |
for j in {0..19} ; do | |
curl -s "$baseurl$i"_"$j.png" > /tmp/$rr-$i-$j.png | |
perl -e '$w='"$pw"'; $p='"$[i * 20 + j]"'; $x=int($p*$w/400+.5); $y=$w-$x; print "\rDownloading [\33[32m", "#" x $x, "-" x $y, "\33[0m]";' | |
done | |
done | |
echo " Done" | |
# Assemble each column | |
for i in {0..19} ; do | |
convert -append `ls /tmp/$rr-$i-* | sort -t- -k3 -n` /tmp/slice-$rr-$i.png | |
perl -e '$w='"$pw"'; $p='"$i"'; $x=int($p*$w/25+.5); $y=$w-$x; print "\rStitching [\33[32m", "#" x $x, "-" x $y, "\33[0m]";' | |
done | |
# And now stitch the columns together | |
convert +append `ls /tmp/slice-$rr-* | sort -t- -k3 -n` "earth-$t0.png" | |
perl -e '$w='"$pw"'; print "\rStitching [\33[32m", "#" x $w, "\33[0m]";' | |
# Remove the temporary files | |
rm /tmp/$rr-* | |
rm /tmp/slice-$rr-* | |
echo " Done" | |
echo -e "\x1B[32mCreated file earth-$t0.png\x1B[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment