Skip to content

Commit

Permalink
Update image workflow and recipes
Browse files Browse the repository at this point in the history
I think these images was partly done manually since the downloader_image script had lots of issues.
  • Loading branch information
PaulWessel committed Sep 28, 2023
1 parent 83bf38c commit 5bcc3d6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ place-earth:
place-earth-age:
scripts/place_candidate.sh earth_age

# Uploads all Earth image datasets
place-earth-images:
make place-earth-day
make place-earth-night

place-earth-day:
scripts/place_candidate.sh earth_day

place-earth-night:
scripts/place_candidate.sh earth_night

# Uploads all Earth gravity/geodesy datasets
place-earth-grav:
make place-earth-edefl
Expand Down
3 changes: 2 additions & 1 deletion recipes/earth_day.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# format.
#
# SRC_FILE=BlueMarble_30s.tif
# SRC_TITLE=NASA_Blue_Marble_Earth_Day_View
# SRC_TITLE=Blue_Marble_Earth_Day_View
# SRC_RADIUS=6371.0087714
# SRC_REG=p
# SRC_REF="NASA"
# SRC_TYPE=image
#
# Destination: Specify output node registration, file prefix, and image format
Expand Down
3 changes: 2 additions & 1 deletion recipes/earth_night.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# format.
#
# SRC_FILE=BlackMarble_30s.tif
# SRC_TITLE=NASA_Black_Marble_Earth_Night_View
# SRC_TITLE=Black_Marble_Earth_Night_View
# SRC_RADIUS=6371.0087714
# SRC_REG=p
# SRC_REF="NASA"
# SRC_TYPE=image
#
# Destination: Specify output node registration, file prefix, and image format
Expand Down
2 changes: 1 addition & 1 deletion scripts/srv_downsampler.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env bash -e
# srv_downsampler.sh - Filter the highest resolution image or grids to lower resolution versions
#
# usage: srv_downsampler.sh <recipefile> [-n] [split].
Expand Down
59 changes: 45 additions & 14 deletions scripts/srv_downsampler_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env bash
# srv_downsampler_image.sh - Filter the highest resolution image to lower resolution versions
#
# usage: srv_downsampler_image.sh recipe [-f] [-n] [-x]
Expand All @@ -19,6 +19,13 @@

source scripts/filter_width_from_output_spacing.sh

# Hardwired settings for images
DST_OFFSET=0
DST_SCALE=1
DST_TILE_SIZE=0
DST_CPT=-
MARK=""

if [ $# -eq 0 ]; then
cat <<- EOF >&2
usage: srv_downsampler_image.sh <recipefile> [-f] [-n] [-x]"
Expand Down Expand Up @@ -64,13 +71,15 @@ mkdir -p ${TMP}
grep SRC_FILE $RECIPE | awk '{print $2}' > ${TMP}/par.sh
grep SRC_RADIUS $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep SRC_TITLE $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep SRC_REF $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep SRC_REG $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep DST_MODE $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep DST_PLANET $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep DST_PREFIX $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
grep DST_FORMAT $RECIPE | awk '{print $2}' >> ${TMP}/par.sh
source ${TMP}/par.sh

CITE=$(echo ${SRC_REF} | tr '_' ' ')
TITLE=$(echo ${SRC_TITLE} | tr '_' ' ')
# 4. Get the file name of the source file and output modifiers
SRC_BASENAME=$(basename ${SRC_FILE})
SRC_ORIG=${SRC_BASENAME}
Expand Down Expand Up @@ -120,31 +129,41 @@ while [ ! "X$1" == "X" ]; do
shift # So that $2 now is next arg or blank
done

# 9.0 Set info file here since no image tiling yet
INFOFILE=${DST_PLANET}/${DST_PREFIX}/${DST_PREFIX}_server.txt

# 9.1 Check if just reporting

if [ ${DST_BUILD} -eq 0 ]; then # Report variables
if [ ${DST_BUILD} -eq 1 ]; then # Start building info file
if [ -d ${DST_PLANET}/${DST_PREFIX} ]; then
if [ ${DST_FORCE} -eq 1 ]; then
rm -rf ${DST_PLANET}/${DST_PREFIX}
else
echo "Data set directory ${DST_PLANET}/${DST_PREFIX} already exists - aborting. Use -f to force removal instead."
exit -1
fi
fi
mkdir -p ${DST_PLANET}/${DST_PREFIX}
cat <<- EOF > ${INFOFILE}
#
# ${TITLE}
#
EOF
else # Just report parameters and tasks
cat <<- EOF
# Final parameters after processing ${RECIPE}:
SRC_ORIG ${SRC_ORIG}
SRC_FILE ${SRC_FILE}
SRC_REG ${SRC_REG}
DST_SPLIT ${DST_SPLIT}
TITLE ${SRC_TITLE}
INFOFILE ${INFOFILE}
TITLE ${TITLE}
CITE ${CITE}
# Processing steps to be taken if -n was not given:
EOF
else # Make files in given directory unless it exists and no -f
if [ -d ${DST_PLANET}/${DST_PREFIX} ]; then
if [ ${DST_FORCE} -eq 1 ]; then
rm -rf ${DST_PLANET}/${DST_PREFIX}
else
echo "Data set directory ${DST_PLANET}/${DST_PREFIX} already exists - aborting. Use -f to force removal instead."
exit -1
fi
fi
mkdir -p ${DST_PLANET}/${DST_PREFIX}
fi

# 9.2 Get the right projection ellipsoid/spheroid for this planetary body
Expand All @@ -154,6 +173,9 @@ else
DST_SPHERE=${DST_PLANET}
fi

# 9.4 Get creation date
creation_date=$(date +%Y-%m-%d)

# 10. Loop over all the resolutions found

while read RES UNIT TILE MASTER; do
Expand Down Expand Up @@ -183,13 +205,19 @@ while read RES UNIT TILE MASTER; do
echo "${DST_FILE} exist - skipping"
elif [ "X${MASTER}" = "Xmaster" ]; then # Just make a copy of the master to a new output file
echo "Convert ${SRC_FILE} to ${DST_FILE}"
SIZE=$(ls -lh ${SRC_FILE} | awk '{print $5}')
MSG="${TITLE} original at ${RES}x${RES} arc ${UNIT_NAME}"
if [ ${DST_BUILD} -eq 1 ]; then
cp ${SRC_FILE} ${DST_FILE}
printf "%s/server/%s/%s/\t%s_%s_%s\t%s\t%s\t%s\t%s\t%4s\t%s\t%s\t-\t-\t\t%s [%s]\n" \
"${MARK}" ${DST_PLANET} ${DST_PREFIX} ${DST_PREFIX} ${FTAG} ${SRC_REG} ${TAG} ${SRC_REG} ${DST_SCALE} ${DST_OFFSET} ${SIZE} ${DST_TILE_SIZE} ${creation_date} "${MSG}" "${CITE}" >> ${INFOFILE}
fi
else # Must down-sample to a lower resolution via spherical Gaussian filtering
# Get suitable Gaussian full-width filter rounded to nearest 0.1 km after adding 50 meters for noise
FILTER_WIDTH=$(filter_width_from_output_spacing ${INC})
FWR_SEC=$(gmt math -Q 2 2 SQRT MUL ${INC} MUL 3600 MUL RINT =)
FTAG="${IRES}${UNIT}"
MSG="${TITLE} at ${RES}x${RES} arc ${UNIT_NAME} reduced by Gaussian ${DST_MODE} r/g/b filtering (${FILTER_WIDTH} km fullwidth)"
if [ ${DST_BUILD} -eq 1 ]; then
printf "Down-filter ${SRC_FILE} to ${DST_FILE} FW = ${FILTER_WIDTH} km [${FWR_SEC}s] via layers "
gmt grdmix ${SRC_FILE} -D -G/tmp/tmp_%c.nc=ns
Expand All @@ -199,6 +227,9 @@ while read RES UNIT TILE MASTER; do
done
printf " > ${DST_FORMAT}\n"
gmt grdmix -C /tmp/tmp_filt_r.nc /tmp/tmp_filt_g.nc /tmp/tmp_filt_b.nc -G${DST_FILE} -Ni
SIZE=$(ls -lh ${DST_FILE} | awk '{print $5}')
printf "%s/server/%s/%s/\t%s_%s_%s\t%s\t%s\t%s\t%s\t%4s\t%s\t%s\t-\t-\t\t%s [%s]\n" \
"${MARK}" ${DST_PLANET} ${DST_PREFIX} ${DST_PREFIX} ${FTAG} ${SRC_REG} ${TAG} ${SRC_REG} ${DST_SCALE} ${DST_OFFSET} ${SIZE} ${DST_TILE_SIZE} ${creation_date} $"${MSG}" "${CITE}" >> ${INFOFILE}
else
echo "Down-filter ${SRC_FILE} to ${DST_FILE} via R, G, and B layers. FW = ${FILTER_WIDTH} km [${FWR_SEC}s]"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/srv_tiler.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env bash -e
# srv_tiler.sh - Split a large grid into suitable square tiles
#
# usage: srv_tiler.sh recipe [-n].
Expand Down

0 comments on commit 5bcc3d6

Please sign in to comment.