-
Notifications
You must be signed in to change notification settings - Fork 5
/
produce_op_assets.sh
executable file
·126 lines (93 loc) · 4.3 KB
/
produce_op_assets.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
set -e -o pipefail
FORECAST_NAME="$1"
REGION="$2"
OUTPUT_DIR="results/forecasts/$FORECAST_NAME"
LOG_DIR="log/forecasts/$FORECAST_NAME"
FORECAST_FILE="results/predict/${FORECAST_NAME}.nc"
HEMI=`echo $FORECAST_NAME | sed -r 's/^.+_(north|south)$/\1/'`
if [ $# -lt 1 ] || [ "$1" == "-h" ]; then
echo "$0 <forecast name w/hemi> [region]"
exit 1
fi
[ ! -z $REGION ] && REGION="-r $REGION"
if ! [[ $HEMI =~ ^(north|south)$ ]]; then
echo "Hemisphere from $FORECAST_NAME not available, raise an issue"
exit 1
fi
function produce_docs {
local DIR=$1
cp template_LICENSE.md ${DIR}/LICENSE.md
cp template_README.md ${DIR}/README.md
}
function rename_gfx {
GFX_DIR="$1"
F_PREFIX="$2"
F_GLOB="$3"
for NOM in $( find $GFX_DIR -name "${F_PREFIX}${F_GLOB}" ); do
NOM_FILENAME=`basename $NOM`
mv -v $NOM ${GFX_DIR}/${NOM_FILENAME#${F_PREFIX}}
done
}
for WORKING_DIR in "$OUTPUT_DIR" "$LOG_DIR"; do
if [ -d $WORKING_DIR ]; then
echo "Output directory $WORKING_DIR already exists, removing"
rm -rv $OUTPUT_DIR
fi
done
echo "Making $OUTPUT_DIR"
mkdir -p $OUTPUT_DIR
for DATE_FORECAST in $( cat ${FORECAST_NAME}.csv ); do
DATE_DIR="$OUTPUT_DIR/$DATE_FORECAST"
echo "Making $DATE_DIR for forecast date $DATE_FORECAST"
mkdir -p $DATE_DIR
echo "Producing single output file for date forecast"
python -c 'import xarray; xarray.open_dataset("'$FORECAST_FILE'").sel(time=slice("'$DATE_FORECAST'", "'$DATE_FORECAST'")).to_netcdf("'$DATE_DIR'/'$DATE_FORECAST'.nc")'
echo "Producing geotiffs from that file"
icenet_output_geotiff -o $DATE_DIR $FORECAST_FILE $DATE_FORECAST 1..93
rename_gfx $DATE_DIR "${FORECAST_NAME}.${DATE_FORECAST}." '*.tiff'
echo "Producing movie file of raw video"
icenet_plot_forecast $REGION -o $DATE_DIR -l 1..93 -f mp4 $HEMI $FORECAST_FILE $DATE_FORECAST
rename_gfx $DATE_DIR "${FORECAST_NAME}.${DATE_FORECAST}." '*.mp4'
echo "Producing stills for manual composition (with coastlines)"
icenet_plot_forecast $REGION -o $DATE_DIR -l 1..93 $HEMI $FORECAST_FILE $DATE_FORECAST
ffmpeg -framerate 5 -pattern_type glob -i ${DATE_DIR}'/'${FORECAST_NAME}'.*.png' -c:v libx264 ${DATE_DIR}/${FORECAST_NAME}.mp4
rename_gfx $DATE_DIR "${FORECAST_NAME}.${DATE_FORECAST}." '*.png'
echo "Producing movie and stills of ensemble standard deviation in predictions"
icenet_plot_forecast $REGION -s -o $DATE_DIR -l 1..93 -f mp4 $HEMI $FORECAST_FILE $DATE_FORECAST
rename_gfx $DATE_DIR "${FORECAST_NAME}.${DATE_FORECAST}." '*.stddev.mp4'
icenet_plot_forecast $REGION -s -o $DATE_DIR -l 1..93 $HEMI $FORECAST_FILE $DATE_FORECAST
ffmpeg -framerate 5 -pattern_type glob -i ${DATE_DIR}'/'${FORECAST_NAME}'.*.stddev.png' -c:v libx264 ${DATE_DIR}/${FORECAST_NAME}.stddev.mp4
rename_gfx $DATE_DIR "${FORECAST_NAME}.${DATE_FORECAST}." '*.stddev.png'
produce_docs $DATE_DIR
# TODO: copy docs to root folder
# TODO: copy plot/ content for whole domain
echo "Producing binary accuracy plots (these are meaningless forecasting into the future w.r.t the OSISAF data)"
SIC_FILENAME="./data/osisaf/${HEMI}/siconca/`date +%Y`.nc"
# Get the most recent day, sorry for ignoring all timezone information
SIC_LATEST=`python -c 'import xarray; print(str(xarray.open_dataset("'$SIC_FILENAME'").time.values[-1])[0:10])'`
if [[ `date --date="$SIC_LATEST" +%s` -gt `date --date="$DATE_FORECAST + 1 day" +%s` ]]; then
echo "We have necessary SIC data ($SIC_LATEST) for forecast date $DATE_FORECAST"
for THRESHOLD in 0.15 0.5 0.8 0.9; do
icenet_plot_bin_accuracy $REGION -e -b -t $THRESHOLD \
-o ${DATE_DIR}/bin_accuracy.${THRESHOLD}.png \
$HEMI $FORECAST_FILE $DATE_FORECAST
done
icenet_plot_metrics $REGION -e -b -s \
-o ${DATE_DIR}/ \
$HEMI $FORECAST_FILE $DATE_FORECAST
icenet_plot_sic_error $REGION \
-o ${DATE_DIR}/${DATE_FORECAST}.sic_error.mp4 \
$HEMI $FORECAST_FILE $DATE_FORECAST
icenet_plot_sie_error $REGION -e -b \
-o ${DATE_DIR}/${DATE_FORECAST}.sie_error.25.png \
$HEMI $FORECAST_FILE $DATE_FORECAST
else
echo "We do not have observational SIC data ($SIC_LATEST) for plotting \
forecast date $DATE_FORECAST"
fi
# Future uses - probably via another workflow:
# rsync to local destinations?
# Azure blob storage upload using az
done
echo "Done, enjoy your forecasts in $OUTPUT_DIR"