-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
299 lines (274 loc) · 10.4 KB
/
index.html
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
297
298
299
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>nilsmagnus/grib/griblib</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/blood.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section>
<h1>griblib</h1>
<p>github.com/nilsmagnus/grib/griblib</p>
<p>Go Oslo @Vipps, 2019 march 5th</p>
</section>
<section>
<p>Nils Larsgård </p>
<p>
<p class="fragment" data-fragment-index="1">programmer</p>
<p class="fragment" data-fragment-index="2">consultant (kodemaker.no)</p>
<p class="fragment" data-fragment-index="3">java, kotlin, go</p>
</p>
</section>
<section>
<p>
<p class="fragment" data-fragment-index="1">started to go in 2013</p>
<p class="fragment" data-fragment-index="2">contributed to go, "mime/multipart" </p>
<p class="fragment" data-fragment-index="3">took over griblib after a massive PR </p>
</p>
</section>
<section>
<h3>Agenda</h3>
<ul>
<li class="fragment" data-fragment-index="1">grib specification</li>
<li class="fragment" data-fragment-index="2">griblib features</li>
<li class="fragment" data-fragment-index="3">profiling</li>
<li class="fragment" data-fragment-index="4">motivation</li>
</ul>
</section>
</section>
<section>
<section>
<p>What is griblib?</p>
<p class="fragment" data-fragment-index="1">library to parse grib2files</p>
<p class="fragment" data-fragment-index="2">implemented in go</p>
<p class="fragment" data-fragment-index="3">0 dependencies</p>
<pre class="fragment" data-fragment-index="4"><code data-trim data-noescape>
gribfile, err := os.Open("somegrib2file.grib2")
if err != nil {
b.Fatalf("Could not open test-file %v", err)
}
messages, err := griblib.ReadMessages(gribfile)
for _, message := range messages {
// do your thing
}
</code></pre>
</section>
<section>
<p class="fragment" data-fragment-index="1">"<span style="color:lightgreen">GRIB</span> (<span style="color:lightgreen">GRI</span>dded <span style="color:lightgreen">B</span>inary or <span style="color:green">G</span>eneral <span style="color:green">R</span>egularly-distributed <span style="color:green">I</span>nformation in <span style="color:green">B</span>inary form) is a concise data format commonly used in meteorology to store historical and forecast weather data." [<i>wikipedia</i>]</p>
<aside class="notes">
mention usage: meterological institutes around the world, this is the standard file-format
</aside>
</section>
<section>
<h3>
<span class="fragment" data-fragment-index="1">compressed</span>
<span class="fragment" data-fragment-index="3">binary</span>
<span class="fragment" data-fragment-index="2">data</span>
</h3>
<p>
<span class="fragment" data-fragment-index="5" style="color:red">Moisture</span>,
<span class="fragment" data-fragment-index="8">Momentum</span>,
<span class="fragment" data-fragment-index="4" style="color:red">Temperature</span>,
<span class="fragment" data-fragment-index="9">Mass</span>,
<span class="fragment" data-fragment-index="7">Short wave radiation</span>,
<span class="fragment" data-fragment-index="5">Long wave radiation</span>,
<span class="fragment" data-fragment-index="8" style="color:red">Cloud</span>,
<span class="fragment" data-fragment-index="5">Thermodynamic stability</span>,
<span class="fragment" data-fragment-index="9">Kinematic stability</span>,
<span class="fragment" data-fragment-index="5">Temperature probabilities</span>,
<span class="fragment" data-fragment-index="6">Moisture probabilities</span>,
<span class="fragment" data-fragment-index="7">Momentum probabilities</span>,
<span class="fragment" data-fragment-index="9">Aerosols</span>,
<span class="fragment" data-fragment-index="8">Trace gases</span>,
<span class="fragment" data-fragment-index="7">Radar</span>,
<span class="fragment" data-fragment-index="6">Nuclear radiology</span>,
<span class="fragment" data-fragment-index="9">Forecast Radar Imagery</span>
</p>
</section>
<section>
<p class="fragment" data-fragment-index="1">hourly forecasts(snapshots)</p>
<p class="fragment" data-fragment-index="2">observations, "actuals"</p>
<p class="fragment" data-fragment-index="3">c/fortran libraries are good</p>
</section>
</section>
<section>
<section>
<p>grib specification</p>
<p class="fragment" data-fragment-index="1">1 message contains Section[0-7]</p>
</section>
<section>
<h3>Section0</h3>
<table border="1" cellspacing="0" cellpadding="5" width="80%">
<tbody>
<tr>
<th style="text-align: center;">Byte</th>
<th style="text-align: center;">Content</th>
</tr>
<tr>
<td>
<center>1-4</center>
</td>
<td>'GRIB' (Coded)<br>
</td>
</tr>
<tr>
<td style="vertical-align: top; text-align: center;">5-6<br>
</td>
<td style="vertical-align: top;">Reserved<br>
</td>
</tr>
<tr>
<td style="vertical-align: top; text-align: center;">7<br>
</td>
<td style="vertical-align: top;">Discipline (From Table 0.0)<br>
</td>
</tr>
<tr>
<td>
<center>8</center>
</td>
<td>Edition number - 2 for GRIB2<br>
</td>
</tr>
<tr>
<td>
<center>9-16<br>
</center>
</td>
<td>Total length of GRIB message in octets (All sections);</td>
</tr>
</tbody>
</table>
</section>
<section>
Reading binary data in go
<pre><code data-trim data-noescape class="fragment" data-fragment-index="1">
import "encoding/binary"
</code><code data-trim data-noescape class="fragment" data-fragment-index="2">
type Section0 struct {
Indicator uint32 `json:"indicator"`
Reserved uint16 `json:"reserved"`
Discipline uint8 `json:"discipline"`
Edition uint8 `json:"edition"`
MessageLength uint64 `json:"messageLength"`
}
</code><code data-trim data-noescape class="fragment" data-fragment-index="3">
...
section0 := Section0{}
err := binary.Read(ioReader, binary.BigEndian, &section0)
</code></pre>
</section>
<section>
Same strategy for section[1-6]
</section>
</section>
<section>
<section>
<h1>section7</h1>
<p>is (possibly) compressed</p>
<p>defined in section 5(table 5.0)</p>
<p class="fragment" data-fragment-index="1">PNG, JPEG, Grids(complex, simple, spatial differencing), Spectrals, etc.</p>
</section>
<section>
<p>Grid Point Data - Complex Packing and Spatial Differencing</p>
<p class="fragment" data-fragment-index="1"><i>bitgroups</i> to describe the data</p>
<p class="fragment" data-fragment-index="2">[00101111][10110010][10010010][01001011]</p>
<p class="fragment" data-fragment-index="3">Width=3, Length=6:<br>
[
<span style="color:cyan">001</span>
<span style="color:yellow">011</span>
<span style="color:lightgreen">11][1</span>
<span style="color:cyan">011</span>
<span style="color:yellow">001</span>
<span style="color:lightgreen">0][10</span>
0010010][01001011]
</p>
</section>
<section>
<pre><code data-trim data-noescape>bit := uint((r.byte >> (7 - r.offset)) & 0x01)</code></pre>
</section>
<section>
Custom compression, custom performance
<p class="fragment" data-fragment-index="1">profiling and tuning with `go tool pprof`</p>
<p class="fragment" data-fragment-index="2" style="color:red">profile demonstration</p>
<p class="fragment" data-fragment-index="3">reduced memory usage from initial ~9Gb to ~3Gb</p>
<p class="fragment" data-fragment-index="4">reduced cpu-time in gc</p>
<p class="fragment" data-fragment-index="5">sacrificed readability over performance</p>
</section>
</section>
<section>
<section>
<h3>Ecosystem</h3>
<p>contributors</p>
<p>apps</p>
</section>
<section>
<p>☆ 10</p>
<img src="community.png" class="fragment" data-fragment-index="1" />
</section>
<section>
<p class="fragment" data-fragment-index="1">built in exports(csv,json,text,filters)</p>
<p class="fragment" data-fragment-index="2">supporting apps, influx-db-export</p>
</section>
<section>
<img src="leia-2.png" />
</section>
<section>
<p>machinelearning from forecast archive</p>
<p class="fragment" data-fragment-index="1">predict weather-correlated stuff</p>
<p class="fragment" data-fragment-index="2">forecast archives are not available back in time</p>
</section>
</section>
<section>
<section>
<h3>Summary</h3>
<ul>
<li class="fragment" data-fragment-index="1">grib is a specification of binary weather data</li>
<li class="fragment" data-fragment-index="2">griblib parses grib files</li>
<li class="fragment" data-fragment-index="3">go tools rock profiling</li>
<li class="fragment" data-fragment-index="4">make your own archive of gribfiles for past forecasts</li>
</ul>
</section>
<section>
<h1>Thank you</h1>
<ul>
<li>github.com/nilsmagnus/grib</li>
<li>nils@kodemaker.no</li>
<li>twitter.com/nils_magnus</li>
</ul>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>