-
-
Save adriel/223f3597ce2a5d2d4f851b9ade0ea4ab to your computer and use it in GitHub Desktop.
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
.DS_Store |
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
Example: https://denpa.moe/~syrup/himawari8.png |
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
#!/usr/bin/env bash | |
## This script downloads an image of earth from Japan's Himawari8 satellite. | |
## It is configurable for 1,100^2, 2,200^2, or 8,800^2 pixel outputs. | |
## It requires; | |
## aria2c(1) from https://aria2.github.io/ | |
## montage(1) from imagemagick (http://www.imagemagick.org/) | |
## date(1) from either BSD or GNU utils | |
## curl(1) from http://curl.haxx.se/ | |
## jq(1) from https://stedolan.github.io/jq/ | |
## Configuration | |
OUTPUT_DIR='/Users/adriel/Downloads' | |
TMP_DIR="$TMPDIR" | |
URL_BASE='https://himawari8-dl.nict.go.jp/himawari8/img/D531106'; | |
## The amount of tiles on one side | |
## This value should be either 1, 2, 4, 16 or 20 | |
## Each tile is 550px x 550px, so 4 (default) will produce an image 2,200px x 2,200px | |
TILE_COUNT='20'; | |
## Check requirements | |
## TODO Add check for gdate (GNU date (for Mac)) | |
if ! aria2c --version >/dev/null 2>&1; then | |
echo "aria2c(1) is not installed, but is required by this script."; | |
echo "Please see installation instructions at https://aria2.github.io/"; | |
exit 1; | |
fi; | |
if ! jq --version >/dev/null 2>&1; then | |
echo "jq(1) is not installed, but is required by this script."; | |
echo "Please see installation instructions at https://stedolan.github.io/jq/"; | |
exit 1; | |
fi; | |
if ! curl --version >/dev/null 2>&1; then | |
echo "curl(1) is not installed, but is required by this script."; | |
echo "Please see installation instructions at http://curl.haxx.se/"; | |
exit 1; | |
fi; | |
if ! montage --version >/dev/null 2>&1; then | |
echo "montage(1) from ImageMagick is not installed, but is required by this script."; | |
echo "Please see installation instructions at http://www.imagemagick.org/"; | |
exit 1; | |
fi; | |
if ! date >/dev/null 2>&1; then | |
echo "date(1) is not installed, but is required by this script."; | |
echo "Please get a copy for your OS from either GNU or BSD utils."; | |
exit 1; | |
fi; | |
## Get the latest picture | |
LATEST_FILE="$(curl -s "${URL_BASE}/latest.json" | jq -r -e .date)"; | |
if [ "$?" -ne 0 ]; then | |
echo "Unable to get latest picture date"; | |
exit 1; | |
fi; | |
## Parse the date into the filename | |
DATE_FORMAT='+%Y/%m/%d/%H%M%S'; | |
IMAGE_URL="$(gdate -d "${LATEST_FILE}" "${DATE_FORMAT}")"; | |
IMAGE_CAP_DATE="$(gdate -d "${LATEST_FILE}" "+%F %T")"; | |
sec=$(TZ="UTC" gdate +'%s' -d "$IMAGE_CAP_DATE"); | |
NZ_DATE=$(TZ="Pacific/Auckland" gdate -d "@$sec" "+%Y-%m-%d %I.%M%p %Z"); | |
OUTPUT_FILENAME="${NZ_DATE}_himawari8.png"; | |
echo -e "GMT: $IMAGE_URL \nNZT: $NZ_DATE"; | |
## Make the directory for the images | |
TMP_IMAGE_DIR="$(mktemp -d "${TMP_DIR}/himawari8.XXXXXXXX")"; | |
## Download each of the files | |
echo "Downloading tiles..."; | |
> "${TMP_IMAGE_DIR}/dl_list.txt"; | |
X=0; | |
while [ "${X}" -lt "${TILE_COUNT}" ]; do | |
Y=0; | |
while [ "${Y}" -lt "${TILE_COUNT}" ]; do | |
## Add leading 0's to X & Y to keep images in A-Z order | |
PADDED_X=$(printf "%02d\n" $X); | |
PADDED_Y=$(printf "%02d\n" $Y); | |
# https://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/2019/08/20/084000_0_7.png | |
echo -e "${URL_BASE}/${TILE_COUNT}d/550/${IMAGE_URL}_${X}_${Y}.png \n out=sat_${PADDED_Y}_${PADDED_X}.png" >> "${TMP_IMAGE_DIR}/dl_list.txt" | |
printf "\rDownloaded ${X}, ${Y} ($((X * TILE_COUNT + Y + 1)) / $((TILE_COUNT * TILE_COUNT)))"; | |
printf ' %0.s' {0..9}; | |
Y="$((Y+1))"; | |
done; | |
X="$((X+1))"; | |
done; | |
## Concurrent download images | |
aria2c --max-concurrent-downloads=50 -i "${TMP_IMAGE_DIR}/dl_list.txt" -d "$TMP_IMAGE_DIR" -q; | |
## Beautiful code | |
printf "\rTile links generated."; printf ' %0.s' {0..9}; printf '\n\n'; | |
## Create the image | |
echo "Creating image..."; | |
montage "${TMP_IMAGE_DIR}/"*.png -geometry 550x550 "${OUTPUT_DIR}/${OUTPUT_FILENAME}" >/dev/null 2>&1; | |
# gm montage "${TMP_IMAGE_DIR}/"*.png -geometry 550x550 "${OUTPUT_DIR}/${OUTPUT_FILENAME}"; | |
echo "Image created: ${OUTPUT_DIR}/${OUTPUT_FILENAME}"; | |
open "${OUTPUT_DIR}/${OUTPUT_FILENAME}" | |
## Remove the temporary directory | |
if [ -n "${TMP_IMAGE_DIR}" ]; then | |
rm "${TMP_IMAGE_DIR}/"*.png; | |
rm "${TMP_IMAGE_DIR}/dl_list.txt"; | |
rmdir "${TMP_IMAGE_DIR}"; | |
fi; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment