-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsankey.tex
296 lines (253 loc) · 12.1 KB
/
sankey.tex
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
\documentclass[11pt]{article}
\usepackage{sankey}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{ifthen}
\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\selectcolormodel{cmyk} % Can be rbg or cmyk, cmyk is better for printing
\begin{tikzpicture}[remember picture, overlay, shift={(5,-5)}]
\begin{sankeydiagram}
%% \sankeyset{debug=true}
\colorlet{water}[rgb]{cyan!75!blue!50!white}
\colorlet{ice}[rgb]{gray!20!gray!20!gray!20}
%% \colorlet{air}[rgb]{gray!1!gray!1!gray!1}
\colorlet{air}{yellow!50}
\colorlet{red}[rgb]{red!50!orange!75!white}
\colorlet{black}[rgb]{black!100!black!100!black!100}
\colorlet{gray}[rgb]{black!30!black!30!black!30}
\sankeyset{
%% comment for gray outline
%% draw/.style={
%% draw=white,
%% line width=0pt,line cap=round,line join=round,
%% },
%% comment for gray outline
draw/.style={
draw=black,
line width=0.1mm,line cap=round,line join=round,
},
start style=arrow,end style=arrow,
%% fill/.style={fill=yellow!10,line width=0pt,draw=yellow!10},
ratio=1mm/60,
minimum radius=0mm,
water/.style={fill/.style={draw=water,line width=0pt,fill=water,},},
ice/.style={fill/.style={draw=ice,line width=0pt,fill=ice,},},
air/.style={fill/.style={draw=air,line width=0pt,fill=air,},},
black/.style={fill/.style={draw=black,line width=0pt,fill=black,},},
red/.style={fill/.style={fill=none, top color=red, bottom color=red},},
ice-to-water/.style={fill/.style={fill=none, left color=ice, right color=water},},
ice-to-air/.style={fill/.style={fill=none, left color=ice, right color=air},},
ice-to-black/.style={fill/.style={fill=none, left color=ice, right color=black},},
ice-to-air-vert/.style={fill/.style={fill=none, top color=ice, bottom color=air},},
ice-to-water-vert/.style={fill/.style={fill=none, bottom color=ice, top color=water},},
water-to-air-vert/.style={fill/.style={fill=none, right color=water, left color=air},},
water-to-air/.style={fill/.style={fill=none, left color=water, right color=air},},
air-to-ice/.style={fill/.style={fill=none, left color=air, right color=ice},},
red-to-ice/.style={fill/.style={fill=none, left color=red, right color=ice},},
water-to-ice/.style={fill/.style={fill=none, left color=water, right color=ice},},
black-to-ice/.style={fill/.style={fill=none, bottom color=ice, top color=black},},
in-black/.style={draw/.style={draw=gray,thick=3},},
out-red/.style={draw/.style={draw=red,thick=3},},
out-blue/.style={draw/.style={draw=water,thick=3},},
debug label/.style={
overlay,
draw,
font=\tiny,
text=debug color,text opacity=1,
inner sep=.1em,
fill=white,fill opacity=0.5,
rounded corners=.1em,
%% node contents={\name: \qty},
node contents={\qty},
%% node contents={\name},
},
}
% storage of labels
\newcommand\LabSet[2]{% node name, label
\expandafter\edef\csname#1@Lab\endcsname{#2}}
\newcommand\Lab[1]{% node name
\csname#1@Lab\endcsname}
% storage of quantities
\newcommand\QSet[2]{% node name, quantity
\expandafter\edef\csname#1@Q\endcsname{\fpeval{#2}}}
\newcommand\Q[1]{% node name
\csname#1@Q\endcsname}
% all nodes with their name, label and quantity
\newcommand\qq[1]{\sankeygetnodeqty{#1}}
\newcommand\labelleft[1]{ % valname
\node[font=\tiny, anchor=east]
at ([yshift=0mm,xshift=-3mm]#1.center) {\Lab{v#1}: \qq{#1}};
}
\newcommand\labelright[2]{ % valname
\node[font=\tiny, anchor=west]
at ([yshift=0mm,xshift=3mm]#1.center) {\qq{#1}: \Lab{#2}};
}
\newcommand\labelbold[2]{ % valname
\node[font=\tiny, anchor=west]
at ([yshift=0mm,xshift=3mm]#1.center) {\textbf{\qq{#1}: \Lab{#2}}};
}
\sankeyset{
def data/.code args={#1/#2/#3}{% node name/label/values
\LabSet{#1}{#2}
\QSet{#1}{#3}
\typeout{#1: \Q{#1} Gt (\Lab{#1})}
},
def data/.list={
%% INSERT_CSV_HERE
%% COMPUTED
{vSMBin/SMB Inputs/\Q{vSF}+\Q{vRF}+\Q{vCD}+\Q{vDP}},
{vINPUT/Inputs/\Q{vSMBin}+\Q{vFRONTADV}+\Q{vSHELFFREEZE}},
{vSMBout/SMB Outputs/\Q{vSU}+\Q{vRU}+\Q{vEV}},
{vDYN/Dynamics/\Q{vCALV}+\Q{vFRONTMELT}+\Q{vSHELFMELT}+\Q{vFRONTRET}+\Q{vGZRET}+\Q{vBMB}},
{vOUTPUT/Outputs/\Q{vSMBout}+\Q{vDYN}},
{vSMB/SMB/\Q{vSMBin}-\Q{vSMBout}},
{vML/Mass loss/\Q{vOUTPUT}-\Q{vINPUT}},
{vMG/Mass gain/\Q{vINPUT}-\Q{vOUTPUT}}
},
}
\sankeyset{ice} % default color until otherwise specified
\newcommand\yoff{3mm}
\sankeynode{name=SF, quantity=\Q{vSF}}
\sankeynode{name=DP, quantity=\Q{vDP}, at={[yshift=\yoff]SF.north}, anchor=right}
\sankeynode{name=CD, quantity=\Q{vCD}, at={[yshift=\yoff]DP.north}, anchor=right}
\sankeynode{name=RF, quantity=\Q{vRF}, at={[yshift=\yoff]CD.north}, anchor=right}
\sankeystart{SF}; \labelleft{SF}
\sankeystart[air]{DP}; \labelleft{DP}
\sankeystart{CD}; \labelleft{CD}
\sankeystart[water]{RF}; \labelleft{RF}
\sankeynode{name=SMBIN, quantity=\Q{vSF}+\Q{vDP}+\Q{vCD}+\Q{vRF},
at={[xshift=15mm, yshift=0mm]SF.right}, anchor=right,
forked={\Q{vRF}/RFi, \Q{vCD}/CDi, \Q{vDP}/DPi, \Q{vSF}/SFi}}
\sankeyoutin{SF}{SFi}
\sankeydubins[minimum radius=3mm,air-to-ice]{DP}{DPi}
\sankeydubins[minimum radius=3mm]{CD}{CDi}
\sankeydubins[minimum radius=3mm,water-to-ice]{RF}{RFi}
\sankeynode{name=SHELFFREEZE, quantity=\Q{vSHELFFREEZE},
at={[yshift=-\yoff]SF.south}, anchor=left}
\ifthenelse{\Q{vML} > \Q{vMG}} { % mass loss
\sankeynode{name=f1, at={[xshift=30mm, yshift=\yoff]SHELFFREEZE.south}, anchor=right,
quantity=\qq{SMBIN}+\Q{vFRONTADV}+\Q{vSHELFFREEZE}+\Q{vML}+\Q{vRFZ},
forked={\Q{vRFZ}/RFZi, \Q{vFRONTADV}/FG, \Q{vML}/MLi,
\qq{SMBIN}/SMBINi, \Q{vSHELFFREEZE}/SHELFFREEZEi}}
} { % mass gain edge case
\sankeynode{name=f1, at={[xshift=30mm, yshift=\yoff]SHELFFREEZE.south}, anchor=right,
quantity=\qq{SMBIN}+\Q{vFRONTADV}+\Q{vSHELFFREEZE}+\Q{vRFZ},
forked={\Q{vRFZ}/RFZi, \Q{vFRONTADV}/FG, \qq{SMBIN}/SMBINi, \Q{vSHELFFREEZE}/SHELFFREEZEi}}
}
\sankeyoutin{SMBIN}{SMBINi}
\sankeyadvance{f1}{15mm}
\ifnum \numexpr\Q{vSHELFFREEZE} > 0
\labelleft{SHELFFREEZE}
\sankeystart[water]{SHELFFREEZE}
\sankeydubins[water-to-ice]{SHELFFREEZE}{SHELFFREEZEi}
\fi
\ifthenelse{\Q{vML} > \Q{vMG}} { % mass loss
\sankeyfork{f1}{\Q{vRFZ}/RFZo, \Q{vSU}/SU, \Q{vRU}+\Q{vEV}/RUEV,
\Q{vCALV}/CALV, \Q{vFRONTMELT}/FRONTMELT, \Q{vSHELFMELT}/SHELFMELT,
\Q{vFRONTRET}/FRONTRET, \Q{vGZRET}/GZ, \Q{vBMB}/BMB}
}{ % mass gain edge case (AQ_east)
\sankeyfork{f1}{\Q{vRFZ}/RFZo, \Q{vSU}/SU, \Q{vRU}+\Q{vEV}/RUEV,
\Q{vCALV}/CALV, \Q{vFRONTMELT}/FRONTMELT, \Q{vSHELFMELT}/SHELFMELT,
\Q{vFRONTRET}/FRONTRET, \Q{vGZRET}/GZ, \Q{vBMB}/BMB, \Q{vMG}/MG}
}
\sankeyturnleft{RFZo}{1}
\sankeydubins[minimum radius=5mm,ice-to-water-vert]{RFZo}{RFZi}
\node[font=\tiny, anchor=east]
at ([yshift=+1.5mm,xshift=1mm]RFZo.north) {\Lab{vRFZ}: \qq{RFZi}};
\ifthenelse{\Q{vFRONTMELT} > \Q{vSHELFMELT}} { % Greenland
%% Discharge splits to FRONTMELT (straight) & CALV (above).
%% SHELFMELT below FRONTMELT. FRONTRET below SHELFMELT.
\sankeyadvance{FRONTMELT}{20mm}
\sankeynode{name=SHELFMELTa,quantity=\qq{SHELFMELT},
at={[yshift=-\yoff, xshift=10mm]FRONTMELT.right}}
\sankeynode{name=FRONTRETa, quantity=\qq{FRONTRET},
at={[yshift=-\yoff]SHELFMELTa.right}}
\sankeyadvance[ice-to-water]{FRONTMELT}{10mm}
\sankeynode{name=CALVa, quantity=\qq{CALV},
at={[yshift=\yoff,xshift=0mm]FRONTMELT.left}, anchor=right}
\sankeyset{water}
\sankeyadvance{FRONTMELT}{10mm}; \sankeyend{FRONTMELT}
\labelright{FRONTMELT}{vFRONTMELT}
} {
% Antarctica
%% Discharge splits to SHELFMELT (straight) & CALV (above).
%% No FRONTMELT. Then FRONTRET
\sankeyadvance{SHELFMELT}{10mm}
\sankeynode{name=SHELFMELTa, quantity=\qq{SHELFMELT},
at={[yshift=0, xshift=20mm]SHELFMELT.right}, anchor=right}
\sankeynode{name=FRONTRETa, quantity=\qq{FRONTRET},
at={[yshift=-\yoff]SHELFMELT.right}}
\sankeynode{name=CALVa, quantity=\qq{CALV},
at={[yshift=\yoff,xshift=0mm]SHELFMELTa.left}, anchor=right}
\sankeynode{name=FRONTRETa, quantity=\qq{FRONTRET},
at={[yshift=-\yoff]SHELFMELTa.right}, anchor=left}
}
\sankeyset{ice}
\sankeyoutin[ice-to-water]{SHELFMELT}{SHELFMELTa}
\sankeyadvance[water]{SHELFMELTa}{10mm}; \sankeyend[water]{SHELFMELTa}
\labelright{SHELFMELTa}{vSHELFMELT}
%% \sankeynode{name=FRONTRETa, quantity=\qq{FRONTRET}, at={[yshift=-\yoff]SHELFMELTa.right}}
\sankeyoutin[out-blue]{FRONTRET}{FRONTRETa};
\sankeynode{name=GZa, quantity=\qq{GZ}, at={[yshift=-\yoff]FRONTRETa.right}, anchor=left}
\sankeynode{name=BMBa, quantity=\qq{BMB}, at={[yshift=-\yoff]GZa.right}, anchor=left}
\sankeyoutin[ice-to-water]{BMB}{BMBa}; \sankeyadvance[water]{BMBa}{10mm};
\sankeyend[water]{BMBa}; \labelright{BMBa}{vBMB}
\sankeyoutin[ice-to-water]{GZ}{GZa}; \sankeyadvance[water]{GZa}{10mm};
\sankeyend[water]{GZa}; \labelbold{GZa}{vGZRET}
\sankeyadvance[out-blue]{FRONTRETa}{10mm};
\sankeyend[out-blue]{FRONTRETa}; \labelbold{FRONTRETa}{vFRONTRET}
\sankeyadvance{CALV}{5mm};
\sankeyoutin{CALV}{CALVa};
%% SMB outputs
\sankeynode{name=RUEVa, quantity=\qq{RUEV}, at={[yshift=\yoff]CALVa.left}, anchor=right}
\sankeyoutin[ice-to-water]{RUEV}{RUEVa}
\sankeyfork{RUEVa}{\Q{vEV}/EV, \Q{vRU}/RU}
\sankeynode{name=EVa, quantity=\qq{EV},
at={[yshift=\yoff,xshift=5mm]RUEVa.left}, anchor=left, angle=45}
\sankeyoutin[water-to-air]{EV}{EVa}; \sankeyadvance[air]{EVa}{1mm}
\sankeyend[air]{EVa};
\node[font=\tiny, anchor=west] at ([yshift=0mm,xshift=\yoff]EVa.west) {\qq{EVa}: \Lab{vEV}};
\sankeyadvance[water]{RU}{10mm}; \sankeyend[water]{RU}; \labelright{RU}{vRU}
\sankeynode{name=SUa, quantity=\qq{SU}, at={[xshift=-6mm]EVa.left}, anchor=right, angle=45}
\sankeydubins[minimum radius=6mm,ice-to-air]{SU}{SUa}; \sankeyend[air]{SUa}
\node[font=\tiny, anchor=west] at ([yshift=4mm,xshift=\yoff]SUa.west) {\qq{SUa}: \Lab{vSU}};
\sankeyadvance{CALVa}{10mm}; \sankeyend{CALVa}; \labelright{CALVa}{vCALV}
\ifthenelse{\Q{vMG} < \Q{vML}} { % mass loss
\sankeynode{name=ML, quantity=\Q{vML},
at={[yshift=6mm]RF.north}, anchor=right, angle=-45}
\node[font=\tiny, anchor=east]
at ([xshift=-3mm,yshift=2mm]ML.west) {\textbf{Mass Loss: \qq{ML}}};
% frontal advance next to drawdown (mass loss)
\sankeynode{name=FRONTADVi, quantity=\Q{vFRONTADV},
at={[yshift=0mm,xshift=6mm]ML.left}, anchor=right, angle=-45}
\sankeystart[red]{ML}
\sankeyadvance[red]{ML}{5mm}
\sankeyoutin[red-to-ice]{ML}{MLi}
}{ % mass gain
\sankeynode{name=MGa, quantity=\qq{MG}, angle=-35,
at={[xshift=5mm,yshift=-3mm]MG.right}, anchor=right}
\node[font=\tiny, anchor=east]
at ([yshift=0mm,xshift=0mm]MGa.right) {Mass gain: \qq{MGa}};
\sankeyoutin[ice-to-black]{MG}{MGa}; \sankeyadvance[black]{MGa}{3mm}
\sankeyend[black]{MGa}
\sankeynode{name=FRONTADVi, quantity=\Q{vFRONTADV},
at={[xshift=-15mm,yshift=8mm]RFZi.right}, anchor=left, angle=-45}
}
\ifnum \numexpr\qq{FRONTADVi} > 0
\sankeystart[in-black]{FRONTADVi}
\sankeyoutin[in-black]{FRONTADVi}{FG}
\node[font=\tiny, anchor=east]
at ([xshift=-3mm,yshift=3mm]FRONTADVi.west) {Frontal advance: \qq{FRONTADVi}};
\fi
%% % fancy labels
%% \sankeynode[debug]{name=Discharge, at={[xshift=-10mm]DISCH.north}, anchor=left,
%% quantity=\Q{vDISCH}}
%% \sankeynode[debug]{name=SMB Inputs, at={[xshift=3mm]SMBIN.north}, anchor=left,
%% quantity=\Q{vSMBin}}
%% \sankeynode[debug]{name=SMB Outputs, at={[xshift=0mm]RFZo.south}, anchor=left,
%% quantity=\Q{vSMBout}}
\end{sankeydiagram}
\end{tikzpicture}
\end{document}