-
Notifications
You must be signed in to change notification settings - Fork 3
/
cyverse_plotclip.sh
52 lines (46 loc) · 1.38 KB
/
cyverse_plotclip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
WORKING_FOLDER=$(pwd)
# Get the image file
if [[ "${1}" == "" ]]; then
echo "Image to clip to plots is not specified"
exit 1
fi
SOURCE_FILE="${1}"
# Get the geometry file
if [[ "${2}" == "" ]]; then
echo "The plot geometry GeoJSON file is not specified"
exit 2
fi
PLOTGEOMETRY_FILE="${2}"
# Search for YAML files that can be used as metadata
OPTIONS=""
while IFS= read -r -d '' ONE_FILE; do
case "${ONE_FILE: -4}" in
".yml")
OPTIONS=${OPTIONS}" --metadata ${ONE_FILE}"
;;
esac
case "${ONE_FILE: -5}" in
".json")
if [[ "${PLOTGEOMETRY_FILE}" != "${ONE_FILE}" ]]; then
OPTIONS=${OPTIONS}" --metadata ${ONE_FILE}"
fi
;;
".yaml")
OPTIONS=${OPTIONS}" --metadata ${ONE_FILE}"
;;
esac
done < <(find "${WORKING_FOLDER}" -type f -print0)
echo "Clipping image '${WORKING_FOLDER}/${SOURCE_FILE}' using geometries from '${WORKING_FOLDER}/${PLOTGEOMETRY_FILE}'"
echo " Options: '${OPTIONS}'"
echo "{" >"/scif/apps/src/jx-args.json"
{
echo "\"PLOTCLIP_SOURCE_FILE\": \"${WORKING_FOLDER}/${SOURCE_FILE}\","
echo "\"PLOTCLIP_PLOTGEOMETRY_FILE\": \"${WORKING_FOLDER}/${PLOTGEOMETRY_FILE}\","
echo "\"PLOTCLIP_WORKING_FOLDER\": \"${WORKING_FOLDER}/plot_clip\","
echo "\"PLOTCLIP_OPTIONS\": \"${OPTIONS}\""
echo "}"
} >>"/scif/apps/src/jx-args.json"
echo "JSON Args file:"
cat "/scif/apps/src/jx-args.json"
scif run plotclip