Files
resolved/scripts/fetch-clouds.sh
T
2026-10-18 12:59:52 -04:00

53 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# Downloads NASA's Blue Marble cloud map and resizes it for the renderer.
#
# scripts/fetch-clouds.sh
#
# Source: the cloud layer of NASA's Blue Marble (2002), from
# https://science.nasa.gov/earth/earth-observatory/the-blue-marble-true-color-global-imagery-at-1km-resolution/:
# Terra MODIS clouds of 2001 July 29 (day 210), with thermal infrared over the poles,
# as two 21600 x 21600 PNGs, the western and eastern hemispheres (1 km per pixel).
# Produced by Reto Stöckli, NASA Goddard Space Flight Center; NASA asks that users
# credit "NASA Goddard Space Flight Center".
#
# The two halves are joined and resized to 16384 x 8192 (2.45 km per pixel, the size
# of the Earth maps), one gray channel, into data/clouds/blue-marble.png. The
# renderer reads a pixel's value as the cloud's reflectance there (docs/optics.md,
# "Clouds"); resizing averages those values as they are. Uses ImageMagick (`magick`).
#
# The originals go to data/clouds/source/ and are checked by sha256. Both
# directories are gitignored.
set -eu
base='https://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57747'
root="$(cd "$(dirname "$0")/.." && pwd)/data/clouds"
mkdir -p "$root/source"
# file name, sha256
sums=$(cat <<'EOF'
cloud.W.2001210.21600x21600.png d7a6b03bb54b8ba56f72af6d1d49f191a25c12e911c43739c900e893d10eb814
cloud.E.2001210.21600x21600.png 11eb1aaf8e6056b9aebc0de4894dc5ad8a21cbe8738c6ddc92e88701eb7e1b99
EOF
)
echo "$sums" | while read -r name sum; do
original="$root/source/$name"
if [ ! -f "$original" ]; then
echo "fetching $name"
curl -fsSL "$base/$name" -o "$original.part"
mv "$original.part" "$original"
fi
echo "$sum $original" | sha256sum -c --quiet -
done
map="$root/blue-marble.png"
if [ ! -f "$map" ]; then
echo "resizing"
magick "$root/source/cloud.W.2001210.21600x21600.png" \
"$root/source/cloud.E.2001210.21600x21600.png" +append \
-colorspace Gray -filter Lanczos -resize 16384x8192! \
+repage -depth 8 "$map.part.png"
mv "$map.part.png" "$map"
fi