Grib
grib
GRIB2 message index over range requests, and decoding of single messages.
A GRIB2 file is a plain concatenation of self-contained messages (one field:
variable x level x step), each starting with GRIB and announcing its own
length. When no inventory is published (ARPEGE open data), the index is built
by reading only the first KiB of every message. The walk is inherently
sequential (each length gives the next offset), so the file is split into
segments walked in parallel: each segment starts at the first GRIB
signature found in a window at its nominal offset, and the chain of lengths
must land exactly on the next segment's start — otherwise the segment is
re-walked from the previous verified message, so a false signature inside
compressed data cannot corrupt the index.
Decoding needs ecCodes (pip install 'barograph-met[grib]').
GribFormatError
GribIndex
dataclass
Messages of one GRIB2 file, looked up by (parameter, level, step).
Source code in packages/barograph-met/src/baro/met/grib.py
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 | |
build(store, key, *, executor=None, segments=32)
classmethod
Walk the message headers of key (in parallel segments when an executor is given).
Source code in packages/barograph-met/src/baro/met/grib.py
find(param, level_type, level, step_h)
The message of param at level and step_h, if any.
Source code in packages/barograph-met/src/baro/met/grib.py
from_json(text)
classmethod
Rebuild an index serialised by :meth:to_json.
Source code in packages/barograph-met/src/baro/met/grib.py
levels(param, level_type, step_h=None)
Levels of param, optionally only those published at step_h.
Source code in packages/barograph-met/src/baro/met/grib.py
save(path)
steps()
to_json()
Serialise the index.
GribIndexStore
Message indexes of the files of one store: memory, then directory, else built.
An index is built once per process even when several readers ask for it at the same time; a saved index that is damaged, stale (the file size changed) or for another key is rebuilt.
Source code in packages/barograph-met/src/baro/met/grib.py
get(key, executor=None)
Index of key.
Source code in packages/barograph-met/src/baro/met/grib.py
GribMessage
dataclass
Where one GRIB2 message is and what it holds (variable, level, step).
Source code in packages/barograph-met/src/baro/met/grib.py
param
property
(discipline, category, number) identifying the variable.
decode_message(buf)
Values (lat, lon) of a regular lat/lon message, lat descending, lon ascending.
Longitudes are unwrapped (a 328E..42E grid gives 328..402).
Source code in packages/barograph-met/src/baro/met/grib.py
fetch_messages(store, key, messages, executor)
Download the given messages (one range request each).
Source code in packages/barograph-met/src/baro/met/grib.py
parse_header(prefix, offset)
Parse sections 0, 3, 4 and 5 of a GRIB2 message from its first bytes.