-
Notifications
You must be signed in to change notification settings - Fork 3
/
ffiness_images.sh
executable file
·86 lines (74 loc) · 2.55 KB
/
ffiness_images.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
#!/bin/bash
export GRASS_FONT="DejaVu Sans:Book"
eval `g.region -g`
# we need more than 500 because of whitespace and trimming
DESIRED_WIDTH=560
DESIRED_HEIGHT=`python -c "print $DESIRED_WIDTH / float($cols) * $rows"`
# Paul Tol's Alternative Scheme for Qualitative Data
# main colors
C1=#4477AA
C2=#66CCEE
C3=#228833
C4=#CCBB44
C5=#EE6677
C6=#AA3377
# gray from the middle (also black suggested)
C7=#BBBBBB
# most different colors from the main palette
C8=#332288
C9=#44AA99
C10=#999933
LINE_WIDTH=3
YTICS="0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8"
LEGEND_POS=80,95
CATS=`v.category zones -g op=print | sort -g | uniq`
# zone colors according to category (max 10 categories)
ZONE_COLORS=""
> legend.txt # ensures empty existing file
for C in ${COLORS//,/ }; do echo "1|legend/line|5|ps|$C|$C|$LINE_WIDTH|line|1"; done
for CAT in $CATS
do
eval "COLOR=\$C$CAT"
ZONE_COLORS+="$COLOR,"
echo "$CAT|legend/line|5|ps|$COLOR|$COLOR|$LINE_WIDTH|line|1" >> legend.txt
done
ZONE_COLORS=${ZONE_COLORS%?}
CELL_START=1
CELL_END=46
CELL_RES=3 # in feet
CELLS_TO_M=`python -c "print($CELL_RES / 3.28084)"`
seq $CELL_START 1 $CELL_END > x.txt
COMMON_OPTIONS="width=$LINE_WIDTH ytics=$YTICS x_scale=$CELLS_TO_M -x" # y_range=0,0.6
set -e
for F in 0 1 2 3 4 5
do
MAP=ff_${F}_slice
for CAT in ${CATS}
do
v.db.select zones sep="\n" \
col=`g.list rast p="${MAP}_*" sep=_average,`_average \
-c where="cat = ${CAT}" > file_${MAP}_cat_${CAT}.txt
d.mon start=cairo output=zonal_plot_${MAP}_${CAT}.png \
width=$DESIRED_WIDTH height=$DESIRED_HEIGHT
d.erase # previous image is not cleaned
d.linegraph x_file=x.txt y_file=file_${MAP}_cat_${CAT}.txt $COMMON_OPTIONS
d.mon stop=cairo
done
d.mon start=cairo output=zonal_plot_${MAP}.png \
width=$DESIRED_WIDTH height=$DESIRED_HEIGHT
d.erase # previous image is not cleaned
d.linegraph x_file=x.txt \
y_file=`ls file_${MAP}_cat_*.txt -1v | tr '\n' ',' | sed 's/\(.*\),/\1/'` \
$COMMON_OPTIONS y_color=$ZONE_COLORS
d.legend.vect at=$LEGEND_POS input=legend.txt
d.text text="Height in meters" color=black align=cc at=52,11 size=6
d.text text="Fragmentation class percentage" color=black align=uc at=0,55 size=6 rotation=90
d.mon stop=cairo
done
# combine images
GEOMETRY="+12+4"
# combine abs surface and rel into one
# trim white edges
mogrify -trim zonal_plot_ff_4_slice.png zonal_plot_ff_5_slice.png
montage zonal_plot_ff_4_slice.png zonal_plot_ff_5_slice.png \
-geometry $GEOMETRY -tile 2x zonal_plot_ff_slice_percentage.png