Files
resolved/scripts/fetch-earth.sh
T
2026-10-18 00:05:42 -04:00

203 lines
13 KiB
Bash
Executable File

#!/bin/sh
# Downloads NASA's Blue Marble Next Generation monthly Earth images and resizes
# them for the renderer.
#
# scripts/fetch-earth.sh [--sharp MM ...]
#
# Source: Blue Marble: Next Generation (2004), base map without topography or
# bathymetry, one image per month, from
# https://science.nasa.gov/earth/earth-observatory/blue-marble-next-generation/.
# Produced by Reto Stöckli, NASA Earth Observatory; NASA asks that users credit
# "NASA Earth Observatory".
#
# The global maps: NASA's 21600 x 10800 images (1 arcminute, 1.85 km per pixel at
# the equator), resized to 16384 x 8192 (2.45 km), the largest texture lavapipe
# takes, into data/earth/bmng-2004-MM.jpg. Resizing uses ImageMagick (`magick`).
#
# With --sharp and month numbers (01 to 12), also the sharp maps for those months:
# NASA's 86400 x 43200 images (15 arcseconds, 460 m), published as eight JPEG tiles
# of 21600 x 21600 (about 330 MB a month), made into data/earth/sharp-2004-MM.tiles
# by `resolved earth-tiles` (about 3 minutes and 4.9 GB a month; it builds the CLI
# first).
#
# The originals go to data/earth/source/ and are checked by sha256. Both
# directories are gitignored.
set -eu
sharp=""
if [ "${1:-}" = "--sharp" ]; then
shift
sharp="$*"
fi
base='https://assets.science.nasa.gov/content/dam/science/esd/eo/images/bmng/bmng-base'
root="$(cd "$(dirname "$0")/.." && pwd)/data/earth"
mkdir -p "$root/source"
# month number, folder name, sha256 of the original
months=$(cat <<'EOF'
01 january c2f2c80a352518cfea23d462dad6f6e778375ddd74bbec5786bcfc85cc49c61d
02 february 8800081f38b53bfa1e3f0c2fa17be694b7646942fe5add009ea0dcd64c03e70b
03 march af37f61a9715c59dc86763df19f588a20c9d92b3d0a8034a0b00acd6b97ccb7d
04 april 3bd13f173555eb24451c45d3a83ca177baca02e9a8bdd9fa3e4989f7b496ce6b
05 may 0de40c868680ab9e86fef42406d76386b243b32444ff50edfd406b296638c206
06 june 282608580a290723655bfbe917e69ea2f93f4da068dfa96ff4a152b1c6ec36be
07 july dea8b4dc8a4f93f5f8bce0c8c85a508a178e7901e9ed8e6bf86e6ce7ef6d61e2
08 august 926be7253be90a1fd57071a33afbfe7a712a2dfe0d5b5b4602bc5dfbcfdc2c89
09 september 7cf788e13a3a7b4a926b524f8f71d635c56a18c48ba0bfe35695b05a305db3f3
10 october bf568ceca2ad55e9c8dd7bcedfd0e419201d03bb560206a7bfa2cc57c1e04c64
11 november 1959bbe72897d3e9526c440dae3ec04cfdbdc4080c8ff0b14632925ae31167b1
12 december b0ffc9d12205689aeaec66116bbae2c4c263fcd98a0cbadba8d5488567b53278
EOF
)
# The sharp maps' tiles: file name, sha256.
sharp_sums=$(cat <<'EOF'
world.200401.3x21600x21600.A1.jpg 8953cad5e491003b5d82fb230c9338bb88bf02af91a24c1fa80ab72fd0bb55ff
world.200401.3x21600x21600.A2.jpg 8c81cc3f212c7edfd3592d4395394fec48dd65ebffb32f1f5de73c0417b87c58
world.200401.3x21600x21600.B1.jpg 8e89d3871fbdaff5dc8ede580c9f04e2ce5498eee284505bed23427229f180ec
world.200401.3x21600x21600.B2.jpg 7221c0de3eedb184f94f7e2319ce6de73f62c82b27367fe191f5f88cb626859d
world.200401.3x21600x21600.C1.jpg 1e03fa28fd3d638e99fd9d350964d8ca2e4e0b4285148be57d7081417203082f
world.200401.3x21600x21600.C2.jpg 50f16c3af137e38e8fefb86beb732e35eb45549d8a69a7028d1deb38f6e17b1d
world.200401.3x21600x21600.D1.jpg 2a29d4ac59e60f5c8f8d94100f70c38516607c5242109b1b48c6cb7e34ec3e93
world.200401.3x21600x21600.D2.jpg f5e2366d9a79a81313a839e702c8aa620ce0201aa7f4e75bccb8cf5f451115cb
world.200402.3x21600x21600.A1.jpg 00a1fc049c50da3e69e6ba540e2e2e8214455073c9a3f8bfb7f9bf895f7c896f
world.200402.3x21600x21600.A2.jpg 1396f92a7de89abfa226acf4b94232b1111cc8eb03675060da9d1f691f3c4071
world.200402.3x21600x21600.B1.jpg d817a0747c6c85d80ed6e888e75bc56c0fa86c9187623e222a87472a33e5bbe9
world.200402.3x21600x21600.B2.jpg 5b3268f2d49eae7d3f12cd6694a8dc8adca56f30830fe55a31c1780d725761b6
world.200402.3x21600x21600.C1.jpg e937d30375aec54060b1916e788886942fdc4362e2a64bcebcc4a3b29c9e864f
world.200402.3x21600x21600.C2.jpg 8f375bd01443969c3e4d3e53fd4fc1e553e78a940ee387af73ba34621180d753
world.200402.3x21600x21600.D1.jpg 992144f1cdb8afb496b357ccff1d049cac43838e27c5ff2ccc5c094eb0c27995
world.200402.3x21600x21600.D2.jpg c10ac7eb90ed4dee3613e6a8ac9cfc4be68f853506166e81c1d48c719f060269
world.200403.3x21600x21600.A1.jpg 28d54db1428452e7250cf2a75d1ab82aa26fac8831290c2fa8a9ae08ea079c10
world.200403.3x21600x21600.A2.jpg 8de3f51e27f27639a226805a62b17f50bcbade3595435e5545f068c93375e864
world.200403.3x21600x21600.B1.jpg 04d7d7118f1b7fb37f308da68cd9e311eb9b8c0920c79cd95ab41986547b7dd6
world.200403.3x21600x21600.B2.jpg 6f696d87d0e227639af6671c5abd8ab9fe4574493cadefd572246583910ae224
world.200403.3x21600x21600.C1.jpg 120238fb5f29d3685aaa1a26194423adea19bd26bf5781550c37852573e0bc2b
world.200403.3x21600x21600.C2.jpg 5939731d8f1677490dedf80cc7153c1c13936ff15546fcf647ddd9aceb73e901
world.200403.3x21600x21600.D1.jpg c74ce51a78a7a058385bc0779fe2fb9446a5fc9fb82079a12d48260606fd4e4f
world.200403.3x21600x21600.D2.jpg 79577840e4a3fe458018dd77989c1c0a61498150bb62ec683837c47b8d062a9a
world.200404.3x21600x21600.A1.jpg 993d148cdbae790c9a4908c1d292b81ff3b85a1b2bfdaf82a6d56b35d96bf035
world.200404.3x21600x21600.A2.jpg cb105e494c8f82b1b02d7ccbef65e06038f3bb9968e7ea4a77c6c047da059ecd
world.200404.3x21600x21600.B1.jpg df6ba4cca1403dea3696e0614cc05d9823ce84da44be561502e88c060363eff8
world.200404.3x21600x21600.B2.jpg 8f15641e63f3520b1e188715258a866a65ecc170b5ba79a3046461eac2dfba73
world.200404.3x21600x21600.C1.jpg c2f06c539c182fe1206a8bcdb86abd50451d0f78ec905a02542745fb0255addb
world.200404.3x21600x21600.C2.jpg e892b4f40b447cd0c691ec05cb7575976b7f013bc42e64ad60e952a48a3940a8
world.200404.3x21600x21600.D1.jpg b4eb36215675adf5c610f0648bb8c0747364d5e65a91280878935d4a52eff57e
world.200404.3x21600x21600.D2.jpg d39bc15b5608d039b7ec4a12d657359ed4a7d790672874cde86f4f469e252973
world.200405.3x21600x21600.A1.jpg d59031bf900a16e71ab696551fc0c9c4d76e4a0ced034647a700fca80deb11e8
world.200405.3x21600x21600.A2.jpg a3698e369922d2b1a58796f121a7c904b74b4a63a83cb327c2cbbb352c8f3ade
world.200405.3x21600x21600.B1.jpg b5787874d6d2b7636b709ea394ea988714a85f13eac18e116f9fa7ebe26139e7
world.200405.3x21600x21600.B2.jpg 1ad9ef53e9b00b358de21cd439e1791e0451795b1ec663aed1149df8cb1fc1a0
world.200405.3x21600x21600.C1.jpg b3773bcc5ceb876f4a217db2145709f095f1209009c504fa0540370e3c338e5d
world.200405.3x21600x21600.C2.jpg 4d2cd09c5b1e54ff0ac4c8556750076f8fdc8e1c0513febfe996ef10312e0b22
world.200405.3x21600x21600.D1.jpg 035ed9a398c33fee0cd84cb2ad5647ab0fbd454208d170ecdd3ee5087e008b01
world.200405.3x21600x21600.D2.jpg a24ea5c3b4d8e007b6e6396ed9707aa67a0a395a22db394f44ce3b33c3026dd6
world.200406.3x21600x21600.A1.jpg df597db0ea202a4ed68a27e9023077bcb8a1c70f870503aa3d8d6595433b26da
world.200406.3x21600x21600.A2.jpg 14fc4556cf8c371291c2c1f6bb1ea6c99ca78f4009c10b370721942ca91382ae
world.200406.3x21600x21600.B1.jpg 2fd24d69ab7859164fa12885cbf808b7870725c5fc33cb79e63299bda5fda185
world.200406.3x21600x21600.B2.jpg ecec960dd81d2fe4653099eaf9e09a9ca2ce9b45a9783c473321d52c0e7503e7
world.200406.3x21600x21600.C1.jpg e85aa5230be16689b52dc5b4b3b70fb47c2eb830acd242c54ee75ab879050de6
world.200406.3x21600x21600.C2.jpg 37ba0e21027ec9e207d97f5d52d3768c91525efbd73969c5fb06376696aed2cf
world.200406.3x21600x21600.D1.jpg 12b98d5892bc4b3e9822dbd134702da88d85d521e25778c1ebef225112a267bd
world.200406.3x21600x21600.D2.jpg 669ef6b76fcf2009bd7eedcaa1101c7c4f30d17314fd82ec679ac4abb0d1b0c0
world.200407.3x21600x21600.A1.jpg 045bdba424fb4ab5a385b6282fe36d1ee43ceb336630bc9d1197db8d08038456
world.200407.3x21600x21600.A2.jpg 6d4d048ee6f3aaf28f4b8bbf727d9d635217d81171783111ae09b706e8a7d108
world.200407.3x21600x21600.B1.jpg 4fe552a037a000ff778df08900f185e491534f2b2a8f1779a85512f3ac8fd625
world.200407.3x21600x21600.B2.jpg ba7f8e4b9ef4858e14d74b5a7d69be142524f6838775ed0ec00296ca26c89e99
world.200407.3x21600x21600.C1.jpg 18c4b869510f63bb2261182e26e5c072faee7bc6553842bf9d52175da539e956
world.200407.3x21600x21600.C2.jpg 15fe50659ddb7b3f6395a76d7d880bfa1c78c7c957b9ed3b57dda60cac0866a1
world.200407.3x21600x21600.D1.jpg d2358197c6cbc479051141a8455ee456425c6479e94498888338813daecade68
world.200407.3x21600x21600.D2.jpg 5a5b804bacae0dd4303753a8bd35f26187270374205ab1a85ddab9ad2040cf9d
world.200408.3x21600x21600.A1.jpg 80351fd9ce7eb7f2fbd827fdc5f23526429baefe6eaf091876042fc94c80013c
world.200408.3x21600x21600.A2.jpg b996913af7858f94365ced0e189579a706c30495cde85cfcee1967a63a46fd8b
world.200408.3x21600x21600.B1.jpg 654dc2c927ba44830edfbd843d4dff0264f03f8016eff89260de5b7b766fb963
world.200408.3x21600x21600.B2.jpg 10ba13cd1d1751d16f7f8c375900a6f3dad826a7dba95486410154fb72fa4224
world.200408.3x21600x21600.C1.jpg 3d7fe4fa9bb2c56d233e6e01e9212348604d9b6490f472710745a3b9ea4cd5cc
world.200408.3x21600x21600.C2.jpg 725bced59b4a90ed14d0ff05bc3b0526fe12f65a891a959afe7d496860accbed
world.200408.3x21600x21600.D1.jpg 20f5b09793b0bdb949e9a3a996efa6eb6eacf8c98e40c646ea1f3be3059def5b
world.200408.3x21600x21600.D2.jpg 00a840df7a226fec4cdb82847cf6d877782bf0f1f3167ede2083b633d3361310
world.200409.3x21600x21600.A1.jpg a8a71afa554fb5810756d42b71ad6e18c6fbfdb16176adc91654793b0211deff
world.200409.3x21600x21600.A2.jpg f158edd3ec90b78405d230482ccdbfe40d777877b5b1ef2eefbed2071c17baa7
world.200409.3x21600x21600.B1.jpg 42167660a4f09cbbf5219682967a14510ba9c44a9e0ecffd1aaacd28b5f8fdb4
world.200409.3x21600x21600.B2.jpg 78036a95153a5db851c568a29567518d0f61a2b5c06135780981c3f208a3950a
world.200409.3x21600x21600.C1.jpg 905c30a23836312bbb19f0087ff2e18fa54dca606b06e30bb12ddfb0340ec46e
world.200409.3x21600x21600.C2.jpg 2f2e84bdb740ea408e9709c77d78bd87d63dbfc726c9c91d0c41c3510daca46d
world.200409.3x21600x21600.D1.jpg 54fa2c1b6417e05cc2af635abe88b1254af51e035285a787ba79e85d8ba29cf6
world.200409.3x21600x21600.D2.jpg 739fcda45577910b4c6f2d71693e133a14f4a10b14ac37456b190f6dc4505be9
world.200410.3x21600x21600.A1.jpg 0578984d7b37979587d58eb274de1d107a61bedd453d6762aa5df1eba78a8a8c
world.200410.3x21600x21600.A2.jpg a3132f72c63f78f37020faafa871d31616e94f3673a4760d8a2b1567d4de5dd5
world.200410.3x21600x21600.B1.jpg 7515176ed467c16049680eca30a4973155e53e9f0ab0ba209b14b1a19974211b
world.200410.3x21600x21600.B2.jpg 4bf0e010d844ac29a5602cbab96b69a351c78d97f3f5455a652cf801fd783d4a
world.200410.3x21600x21600.C1.jpg 02cc6a2f699bf16a40dd652410eb1aa24cf93dbe8395c1fd2ba38978560a278f
world.200410.3x21600x21600.C2.jpg 6964e8c97b66432ea7c917d2b144b2210d9dd9b46d55304e9fda5f9bc7db21c5
world.200410.3x21600x21600.D1.jpg 8ae0622dc19e3d02413120ada7cecbd3ae9dab20980acf70471f13c5a6af1257
world.200410.3x21600x21600.D2.jpg c5cb23e3d4e1b45c5019ef38984cc9a851242df0321248fc8e9370a97579b447
world.200411.3x21600x21600.A1.jpg 0431cdb10c77ff309837b11b228d2bca5a56badcd109ea1a5bc2751da5f54ad9
world.200411.3x21600x21600.A2.jpg f9b4b6dd2e6f104ef1a0a6d69a88cc639a8c171e4d6fef214afcf777c58b24e2
world.200411.3x21600x21600.B1.jpg e2eb1b81c9884cb9cbb9fc583d6bcdf41bfa0fb94132073b12494990bbaeda37
world.200411.3x21600x21600.B2.jpg 17cf75b5931e2c8b7a3a74b1f8f5d9504a92853f48afde425704487d016fbdb0
world.200411.3x21600x21600.C1.jpg 6d19ac865ae48cb39eceea447d246bb84077c316565737088f92fb5723f6182b
world.200411.3x21600x21600.C2.jpg b5f1fb519b56d784127e44cd661ea0053c3a571db30f7a54aa128b5ab33741af
world.200411.3x21600x21600.D1.jpg f83fa6f494ec8cbfdc527befde834dbe28ee3513b6982c02cf2088a3d6101edf
world.200411.3x21600x21600.D2.jpg 9cb66f1666d2e7540faab834dd488d6a12c954d901a1cffc9238d9fca712f305
world.200412.3x21600x21600.A1.jpg 40150990562535ce70bd9ef8271b1493ced90d351101c115a63c79e28764c474
world.200412.3x21600x21600.A2.jpg d4feffe2584e754a3b7fe7ba22ab0ee85f99d27f8452e8b72bc5f931a25f647a
world.200412.3x21600x21600.B1.jpg 115ad94094e501556aab585bf5ecf371cd6d180f187d3d260db445b5fd8a90dc
world.200412.3x21600x21600.B2.jpg b26573ae3bb0784c60ad9684a457a2e9532dbbade15688c0bad6276d2a94e88b
world.200412.3x21600x21600.C1.jpg 103062deb2d87b5fbbe6e0fbe704c53fd2f66f676d2cc6e8de7b8e680659d18b
world.200412.3x21600x21600.C2.jpg c67b3a314d57fb80218557871f2424f13791dd6aced67f9fe83bad5058e5f7e1
world.200412.3x21600x21600.D1.jpg 6499c86513d02077cf309b2b65344af246bb9b2006017a3aecc3e5da4cb0f906
world.200412.3x21600x21600.D2.jpg eb545d1a728133b065c5466b668c63abb7402de1bd0bbf4b67e2a9095869f368
EOF
)
echo "$months" | while read -r n month sum; do
original="$root/source/world.2004$n.3x21600x10800.jpg"
if [ ! -f "$original" ]; then
echo "fetching $month"
curl -fsSL "$base/$month/world.2004$n.3x21600x10800.jpg" -o "$original.part"
mv "$original.part" "$original"
fi
echo "$sum $original" | sha256sum -c --quiet -
resized="$root/bmng-2004-$n.jpg"
if [ ! -f "$resized" ]; then
echo "resizing $month"
# Resample in linear light, then back to sRGB, so averaging is of reflectance.
magick "$original" -colorspace RGB -filter Lanczos -resize 16384x8192! \
-colorspace sRGB -quality 95 "$resized"
fi
done
for n in $sharp; do
case "$n" in
0[1-9] | 1[0-2]) ;;
*)
echo "--sharp takes months 01 to 12, not $n" >&2
exit 1
;;
esac
month=$(echo "$months" | awk -v n="$n" '$1 == n { print $2 }')
for t in A1 B1 C1 D1 A2 B2 C2 D2; do
name="world.2004$n.3x21600x21600.$t.jpg"
original="$root/source/$name"
if [ ! -f "$original" ]; then
echo "fetching $month $t"
curl -fsSL "$base/$month/$name" -o "$original.part"
mv "$original.part" "$original"
fi
sum=$(echo "$sharp_sums" | awk -v f="$name" '$1 == f { print $2 }')
echo "$sum $original" | sha256sum -c --quiet -
done
tiles="$root/sharp-2004-$n.tiles"
if [ ! -f "$tiles" ]; then
echo "tiling $month"
(cd "$root/../.." && cargo run --quiet --release -p resolved-cli -- earth-tiles \
--source "$root/source" --month "$n" --out "$tiles.part")
mv "$tiles.part" "$tiles"
fi
done
echo "Earth images in $root"