-
Notifications
You must be signed in to change notification settings - Fork 3
/
count_cats_figure.sh
executable file
·101 lines (86 loc) · 3.02 KB
/
count_cats_figure.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
#!/bin/bash
# set up temporary region
WIND_OVERRIDE=count_category_explanation_region
g.region -u save=$WIND_OVERRIDE
export WIND_OVERRIDE
r.in.ascii input=- output=count_categories_explanation_cells <<EOF
north: 7
south: 0
east: 7
west: 0
rows: 7
cols: 7
* * * * * 1 *
* * * * * * *
* * * 1 * 1 *
* * 1 * * * *
1 1 1 1 * * 1
* 1 1 * * * 1
* * * * * * 1
EOF
# set region to the raster and one cell bellow
g.region raster=count_categories_explanation_cells
# create grid which only overlaps the region
v.mkgrid map=count_categories_explanation_grid position=region
# set region to the raster and one cell bellow
g.region s=s-1
export GRASS_FONT="DejaVu Sans:Book"
eval `g.region -g`
DESIRED_WIDTH=500
DESIRED_HEIGHT=`python -c "print $DESIRED_WIDTH / float($cols) * $rows"`
FONT_SIZE=7
GRID_WIDTH=3
SURFACE_WIDTH=12
GRID_COLOR=126:126:126
SURFACE_COLOR=0:29:90
v.in.ascii input=- format=standard -n output=count_categories_explanation_line <<EOF
L 7 1
0 3
0 3
2 3
2 4
6 4
6 3
7 3
1 1
EOF
r.colors map=count_categories_explanation_cells rules=- <<EOF
1 #ff9200
EOF
d.mon start=cairo output=count_categories_simple.png width=$DESIRED_WIDTH height=$DESIRED_HEIGHT
d.erase # previous image is not cleaned
d.rast map=count_categories_explanation_cells
d.vect map=count_categories_explanation_grid \
color=$GRID_COLOR fill_color=none width=$GRID_WIDTH
# TODO: replace by geographical coordinates
d.text text="1" at=7.3,7.3 align=cc color=black size=$FONT_SIZE
d.text text="2" at=21.6,7.3 align=cc color=black size=$FONT_SIZE
d.text text="3" at=35.9,7.3 align=cc color=black size=$FONT_SIZE
d.text text="2" at=50.1,7.3 align=cc color=black size=$FONT_SIZE
d.text text="0" at=64.4,7.3 align=cc color=black size=$FONT_SIZE
d.text text="2" at=78.7,7.3 align=cc color=black size=$FONT_SIZE
d.text text="3" at=92.7,7.3 align=cc color=black size=$FONT_SIZE
d.mon stop=cairo
d.mon start=cairo output=count_categories_surface.png width=$DESIRED_WIDTH height=$DESIRED_HEIGHT
d.erase # previous image is not cleaned
d.rast map=count_categories_explanation_cells
d.vect map=count_categories_explanation_grid \
color=$GRID_COLOR fill_color=none width=$GRID_WIDTH
d.vect map=count_categories_explanation_line color=$SURFACE_COLOR width=$SURFACE_WIDTH
# TODO: replace by geographical coordinates
d.text text="1" at=7.3,7.3 align=cc color=black size=$FONT_SIZE
d.text text="2" at=21.6,7.3 align=cc color=black size=$FONT_SIZE
d.text text="2" at=35.9,7.3 align=cc color=black size=$FONT_SIZE
d.text text="1" at=50.1,7.3 align=cc color=black size=$FONT_SIZE
d.text text="0" at=64.4,7.3 align=cc color=black size=$FONT_SIZE
d.text text="0" at=78.7,7.3 align=cc color=black size=$FONT_SIZE
d.text text="3" at=92.7,7.3 align=cc color=black size=$FONT_SIZE
d.mon stop=cairo
# trim bottom
mogrify -trim count_categories_simple.png count_categories_surface.png
# combine into one
montage count_categories_simple.png count_categories_surface.png \
-geometry +6+2 -tile 2x count_categories.png
# remove temporary region
g.remove -f type=region name=$WIND_OVERRIDE
unset WIND_OVERRIDE