bufrust 1.0.0__cp313-cp313-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. bufrust/__init__.py +459 -0
  2. bufrust/_bufrust.cp313-win32.pyd +0 -0
  3. bufrust/definitions/ECCODES_LICENSE +202 -0
  4. bufrust/definitions/ECCODES_NOTICE +25 -0
  5. bufrust/definitions/bufr/tables/0/local/0/98/0/2/element.table +3 -0
  6. bufrust/definitions/bufr/tables/0/local/0/98/0/6/element.table +2 -0
  7. bufrust/definitions/bufr/tables/0/local/0/98/0/element.table +316 -0
  8. bufrust/definitions/bufr/tables/0/local/0/98/0/sequence.def +63 -0
  9. bufrust/definitions/bufr/tables/0/local/1/254/0/element.table +6 -0
  10. bufrust/definitions/bufr/tables/0/local/1/39/0/element.table +2 -0
  11. bufrust/definitions/bufr/tables/0/local/1/39/0/sequence.def +10 -0
  12. bufrust/definitions/bufr/tables/0/local/1/78/0/element.table +119 -0
  13. bufrust/definitions/bufr/tables/0/local/1/78/0/sequence.def +104 -0
  14. bufrust/definitions/bufr/tables/0/local/1/78/10/element.table +29 -0
  15. bufrust/definitions/bufr/tables/0/local/1/78/10/sequence.def +17 -0
  16. bufrust/definitions/bufr/tables/0/local/1/98/0/2/element.table +3 -0
  17. bufrust/definitions/bufr/tables/0/local/1/98/0/6/element.table +2 -0
  18. bufrust/definitions/bufr/tables/0/local/1/98/0/element.table +316 -0
  19. bufrust/definitions/bufr/tables/0/local/1/98/0/sequence.def +63 -0
  20. bufrust/definitions/bufr/tables/0/local/101/98/0/element.table +283 -0
  21. bufrust/definitions/bufr/tables/0/local/101/98/0/sequence.def +61 -0
  22. bufrust/definitions/bufr/tables/0/local/19-1/254/0/element.table +54 -0
  23. bufrust/definitions/bufr/tables/0/local/19-1/254/0/sequence.def +6 -0
  24. bufrust/definitions/bufr/tables/0/local/19-1/98/0/6/element.table +2 -0
  25. bufrust/definitions/bufr/tables/0/local/19-1/98/0/element.table +23 -0
  26. bufrust/definitions/bufr/tables/0/local/19-1/98/0/sequence.def +8 -0
  27. bufrust/definitions/bufr/tables/0/local/2/78/0/element.table +134 -0
  28. bufrust/definitions/bufr/tables/0/local/2/78/0/sequence.def +121 -0
  29. bufrust/definitions/bufr/tables/0/local/2/98/0/element.table +16 -0
  30. bufrust/definitions/bufr/tables/0/local/2/98/0/sequence.def +6 -0
  31. bufrust/definitions/bufr/tables/0/local/3/78/0/element.table +137 -0
  32. bufrust/definitions/bufr/tables/0/local/3/78/0/sequence.def +127 -0
  33. bufrust/definitions/bufr/tables/0/local/3/98/0/element.table +22 -0
  34. bufrust/definitions/bufr/tables/0/local/3/98/0/sequence.def +14 -0
  35. bufrust/definitions/bufr/tables/0/local/4/78/0/element.table +146 -0
  36. bufrust/definitions/bufr/tables/0/local/4/78/0/sequence.def +159 -0
  37. bufrust/definitions/bufr/tables/0/local/4/98/0/element.table +16 -0
  38. bufrust/definitions/bufr/tables/0/local/5/78/0/element.table +148 -0
  39. bufrust/definitions/bufr/tables/0/local/5/78/0/sequence.def +159 -0
  40. bufrust/definitions/bufr/tables/0/local/6/78/0/element.table +197 -0
  41. bufrust/definitions/bufr/tables/0/local/6/78/0/sequence.def +172 -0
  42. bufrust/definitions/bufr/tables/0/local/7/78/0/element.table +306 -0
  43. bufrust/definitions/bufr/tables/0/local/7/78/0/sequence.def +288 -0
  44. bufrust/definitions/bufr/tables/0/local/8/78/0/element.table +353 -0
  45. bufrust/definitions/bufr/tables/0/local/8/78/0/sequence.def +344 -0
  46. bufrust/definitions/bufr/tables/0/local/8/78/3/element.table +353 -0
  47. bufrust/definitions/bufr/tables/0/local/8/78/3/sequence.def +344 -0
  48. bufrust/definitions/bufr/tables/0/wmo/0/element.table +421 -0
  49. bufrust/definitions/bufr/tables/0/wmo/0/sequence.def +156 -0
  50. bufrust/definitions/bufr/tables/0/wmo/13/element.table +1297 -0
  51. bufrust/definitions/bufr/tables/0/wmo/13/sequence.def +678 -0
  52. bufrust/definitions/bufr/tables/0/wmo/14/element.table +1460 -0
  53. bufrust/definitions/bufr/tables/0/wmo/14/sequence.def +785 -0
  54. bufrust/definitions/bufr/tables/0/wmo/15/element.table +1477 -0
  55. bufrust/definitions/bufr/tables/0/wmo/15/sequence.def +781 -0
  56. bufrust/definitions/bufr/tables/0/wmo/16/element.table +1471 -0
  57. bufrust/definitions/bufr/tables/0/wmo/16/sequence.def +762 -0
  58. bufrust/definitions/bufr/tables/0/wmo/17/element.table +1471 -0
  59. bufrust/definitions/bufr/tables/0/wmo/17/sequence.def +764 -0
  60. bufrust/definitions/bufr/tables/0/wmo/18/element.table +1481 -0
  61. bufrust/definitions/bufr/tables/0/wmo/18/sequence.def +737 -0
  62. bufrust/definitions/bufr/tables/0/wmo/19/element.table +1468 -0
  63. bufrust/definitions/bufr/tables/0/wmo/19/sequence.def +811 -0
  64. bufrust/definitions/bufr/tables/0/wmo/2/element.table +416 -0
  65. bufrust/definitions/bufr/tables/0/wmo/2/sequence.def +156 -0
  66. bufrust/definitions/bufr/tables/0/wmo/20/element.table +1468 -0
  67. bufrust/definitions/bufr/tables/0/wmo/20/sequence.def +811 -0
  68. bufrust/definitions/bufr/tables/0/wmo/21/element.table +1478 -0
  69. bufrust/definitions/bufr/tables/0/wmo/21/sequence.def +829 -0
  70. bufrust/definitions/bufr/tables/0/wmo/22/element.table +1488 -0
  71. bufrust/definitions/bufr/tables/0/wmo/22/sequence.def +868 -0
  72. bufrust/definitions/bufr/tables/0/wmo/23/element.table +1510 -0
  73. bufrust/definitions/bufr/tables/0/wmo/23/sequence.def +899 -0
  74. bufrust/definitions/bufr/tables/0/wmo/24/element.table +1510 -0
  75. bufrust/definitions/bufr/tables/0/wmo/24/sequence.def +902 -0
  76. bufrust/definitions/bufr/tables/0/wmo/25/element.table +1524 -0
  77. bufrust/definitions/bufr/tables/0/wmo/25/sequence.def +923 -0
  78. bufrust/definitions/bufr/tables/0/wmo/26/element.table +1558 -0
  79. bufrust/definitions/bufr/tables/0/wmo/26/sequence.def +946 -0
  80. bufrust/definitions/bufr/tables/0/wmo/27/element.table +1616 -0
  81. bufrust/definitions/bufr/tables/0/wmo/27/sequence.def +963 -0
  82. bufrust/definitions/bufr/tables/0/wmo/28/element.table +1642 -0
  83. bufrust/definitions/bufr/tables/0/wmo/28/sequence.def +972 -0
  84. bufrust/definitions/bufr/tables/0/wmo/29/element.table +1651 -0
  85. bufrust/definitions/bufr/tables/0/wmo/29/sequence.def +993 -0
  86. bufrust/definitions/bufr/tables/0/wmo/30/element.table +1652 -0
  87. bufrust/definitions/bufr/tables/0/wmo/30/sequence.def +1003 -0
  88. bufrust/definitions/bufr/tables/0/wmo/31/element.table +1691 -0
  89. bufrust/definitions/bufr/tables/0/wmo/31/sequence.def +1064 -0
  90. bufrust/definitions/bufr/tables/0/wmo/32/element.table +1691 -0
  91. bufrust/definitions/bufr/tables/0/wmo/32/sequence.def +1066 -0
  92. bufrust/definitions/bufr/tables/0/wmo/33/element.table +1699 -0
  93. bufrust/definitions/bufr/tables/0/wmo/33/sequence.def +1071 -0
  94. bufrust/definitions/bufr/tables/0/wmo/34/element.table +1699 -0
  95. bufrust/definitions/bufr/tables/0/wmo/34/sequence.def +1071 -0
  96. bufrust/definitions/bufr/tables/0/wmo/35/element.table +1716 -0
  97. bufrust/definitions/bufr/tables/0/wmo/35/sequence.def +1116 -0
  98. bufrust/definitions/bufr/tables/0/wmo/36/element.table +1731 -0
  99. bufrust/definitions/bufr/tables/0/wmo/36/sequence.def +1136 -0
  100. bufrust/definitions/bufr/tables/0/wmo/37/element.table +1734 -0
  101. bufrust/definitions/bufr/tables/0/wmo/37/sequence.def +1139 -0
  102. bufrust/definitions/bufr/tables/0/wmo/38/element.table +1743 -0
  103. bufrust/definitions/bufr/tables/0/wmo/38/sequence.def +1149 -0
  104. bufrust/definitions/bufr/tables/0/wmo/39/element.table +1747 -0
  105. bufrust/definitions/bufr/tables/0/wmo/39/sequence.def +1154 -0
  106. bufrust/definitions/bufr/tables/0/wmo/40/element.table +1789 -0
  107. bufrust/definitions/bufr/tables/0/wmo/40/sequence.def +1236 -0
  108. bufrust/definitions/bufr/tables/0/wmo/41/element.table +1830 -0
  109. bufrust/definitions/bufr/tables/0/wmo/41/sequence.def +1297 -0
  110. bufrust/definitions/bufr/tables/0/wmo/42/element.table +1834 -0
  111. bufrust/definitions/bufr/tables/0/wmo/42/sequence.def +1303 -0
  112. bufrust/definitions/bufr/tables/0/wmo/43/element.table +1838 -0
  113. bufrust/definitions/bufr/tables/0/wmo/43/sequence.def +1309 -0
  114. bufrust/definitions/bufr/tables/0/wmo/44/element.table +1845 -0
  115. bufrust/definitions/bufr/tables/0/wmo/44/sequence.def +1312 -0
  116. bufrust/definitions/bufr/tables/0/wmo/45/element.table +1856 -0
  117. bufrust/definitions/bufr/tables/0/wmo/45/sequence.def +1340 -0
  118. bufrust/definitions/bufr/tables/0/wmo/6/element.table +704 -0
  119. bufrust/definitions/bufr/tables/0/wmo/6/sequence.def +318 -0
  120. bufrust/definitions/bufr/tables/3/local/1/98/0/element.table +308 -0
  121. bufrust/definitions/bufr/tables/3/local/1/98/0/sequence.def +63 -0
  122. bufrust/definitions/bufr/tables/3/wmo/11/element.table +1297 -0
  123. bufrust/definitions/bufr/tables/3/wmo/11/sequence.def +678 -0
  124. bufrust/definitions/bufr/tables/3/wmo/6/element.table +704 -0
  125. bufrust/definitions/bufr/tables/3/wmo/6/sequence.def +318 -0
  126. bufrust/py.typed +1 -0
  127. bufrust-1.0.0.dist-info/METADATA +397 -0
  128. bufrust-1.0.0.dist-info/RECORD +131 -0
  129. bufrust-1.0.0.dist-info/WHEEL +4 -0
  130. bufrust-1.0.0.dist-info/licenses/LICENSE +201 -0
  131. bufrust-1.0.0.dist-info/sboms/bufrust.cyclonedx.json +1111 -0
bufrust/__init__.py ADDED
@@ -0,0 +1,459 @@
1
+ """Friendly Python interface for the Rust BUFR edition 4 decoder."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from importlib.resources import files
7
+ from pathlib import Path
8
+ from typing import Any, Iterable, Iterator
9
+
10
+ from ._bufrust import (
11
+ BufrMessage as RawMessage,
12
+ DecodedValue,
13
+ Descriptor,
14
+ ElementDefinition,
15
+ SequenceDefinition,
16
+ TableSet,
17
+ decode_values as _decode_values,
18
+ decode_values_with_definitions as _decode_values_with_definitions,
19
+ decode_values_with_tables as _decode_values_with_tables,
20
+ expand_descriptors,
21
+ parse_all_bytes as _parse_all_bytes,
22
+ parse_all_file,
23
+ parse_bytes as _parse_bytes,
24
+ parse_file,
25
+ )
26
+
27
+ __version__ = "1.0.0"
28
+
29
+
30
+ class BufrustError(ValueError):
31
+ """Raised by the high-level Python convenience API."""
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class Message:
36
+ """A single BUFR message plus its original bytes."""
37
+
38
+ raw: RawMessage
39
+ data: bytes
40
+ index: int = 0
41
+ path: str | None = None
42
+ definitions: str | None = None
43
+ table_dir: str | None = None
44
+
45
+ def decode(
46
+ self,
47
+ *,
48
+ definitions: str | Path | None = None,
49
+ table_dir: str | Path | None = None,
50
+ ) -> list[DecodedValue]:
51
+ """Decode Section 4 values for this message."""
52
+
53
+ definitions = _coalesce_path(definitions, self.definitions)
54
+ table_dir = _coalesce_path(table_dir, self.table_dir)
55
+ if definitions is None and table_dir is None:
56
+ definitions = builtin_definitions_path()
57
+ if definitions is not None:
58
+ return _decode_values_with_definitions(self.data, definitions)
59
+ if table_dir is not None:
60
+ return _decode_values(self.data, table_dir)
61
+ raise BufrustError("decode() needs definitions=... or table_dir=...")
62
+
63
+ def decode_with_tables(self, tables: TableSet) -> list[DecodedValue]:
64
+ """Decode Section 4 values with an already loaded TableSet."""
65
+
66
+ return _decode_values_with_tables(self.data, tables)
67
+
68
+ @property
69
+ def descriptors(self) -> list[int]:
70
+ """Unexpanded Section 3 descriptor codes."""
71
+
72
+ return list(self.raw.unexpanded_descriptors)
73
+
74
+ @property
75
+ def metadata(self) -> dict[str, Any]:
76
+ """Message metadata as a plain dictionary."""
77
+
78
+ fields = [
79
+ "total_length",
80
+ "edition",
81
+ "section1_length",
82
+ "master_table_number",
83
+ "originating_centre",
84
+ "originating_subcentre",
85
+ "update_sequence_number",
86
+ "local_section_present",
87
+ "data_category",
88
+ "international_data_subcategory",
89
+ "local_data_subcategory",
90
+ "master_tables_version_number",
91
+ "local_tables_version_number",
92
+ "typical_year",
93
+ "typical_month",
94
+ "typical_day",
95
+ "typical_hour",
96
+ "typical_minute",
97
+ "typical_second",
98
+ "section2_length",
99
+ "section3_length",
100
+ "number_of_subsets",
101
+ "observed_data",
102
+ "compressed_data",
103
+ "section4_length",
104
+ "section4_data_offset",
105
+ "section4_data_length",
106
+ ]
107
+ out = {field: getattr(self.raw, field) for field in fields}
108
+ out["message_index"] = self.index
109
+ if self.path is not None:
110
+ out["path"] = self.path
111
+ return out
112
+
113
+ def to_dict(self, *, decode: bool = False, **decode_options: Any) -> dict[str, Any]:
114
+ """Convert metadata, descriptors, and optionally decoded values to dictionaries."""
115
+
116
+ out = {
117
+ "metadata": self.metadata,
118
+ "descriptors": self.descriptors,
119
+ }
120
+ if decode:
121
+ out["values"] = values_to_dicts(self.decode(**decode_options))
122
+ return out
123
+
124
+ def to_dataframe(self, **decode_options: Any):
125
+ """Decode values into a pandas DataFrame if pandas is installed."""
126
+
127
+ return values_to_dataframe(
128
+ self.decode(**decode_options),
129
+ number_of_subsets=self.raw.number_of_subsets,
130
+ message_index=self.index,
131
+ )
132
+
133
+ def __repr__(self) -> str:
134
+ return (
135
+ "Message("
136
+ f"index={self.index}, edition={self.raw.edition}, "
137
+ f"subsets={self.raw.number_of_subsets}, "
138
+ f"compressed={self.raw.compressed_data})"
139
+ )
140
+
141
+
142
+ class Dataset:
143
+ """A BUFR file or byte buffer containing one or more messages."""
144
+
145
+ def __init__(
146
+ self,
147
+ data: bytes,
148
+ *,
149
+ path: str | None = None,
150
+ definitions: str | Path | None = None,
151
+ table_dir: str | Path | None = None,
152
+ ) -> None:
153
+ self.data = bytes(data)
154
+ self.path = path
155
+ self.definitions = _path_str(definitions)
156
+ self.table_dir = _path_str(table_dir)
157
+ raw_messages = _parse_all_bytes(self.data)
158
+ chunks = _split_message_bytes(self.data)
159
+ if len(raw_messages) != len(chunks):
160
+ raise BufrustError("internal split mismatch while reading BUFR messages")
161
+ self.messages = [
162
+ Message(
163
+ raw=raw,
164
+ data=chunk,
165
+ index=index,
166
+ path=path,
167
+ definitions=self.definitions,
168
+ table_dir=self.table_dir,
169
+ )
170
+ for index, (raw, chunk) in enumerate(zip(raw_messages, chunks))
171
+ ]
172
+
173
+ @classmethod
174
+ def from_file(
175
+ cls,
176
+ path: str | Path,
177
+ *,
178
+ definitions: str | Path | None = None,
179
+ table_dir: str | Path | None = None,
180
+ ) -> "Dataset":
181
+ """Read BUFR messages from a file path."""
182
+
183
+ path = Path(path)
184
+ return cls(
185
+ path.read_bytes(),
186
+ path=str(path),
187
+ definitions=definitions,
188
+ table_dir=table_dir,
189
+ )
190
+
191
+ def decode(
192
+ self,
193
+ message: int = 0,
194
+ *,
195
+ definitions: str | Path | None = None,
196
+ table_dir: str | Path | None = None,
197
+ ) -> list[DecodedValue]:
198
+ """Decode one message by index."""
199
+
200
+ return self.messages[message].decode(definitions=definitions, table_dir=table_dir)
201
+
202
+ def decode_all(
203
+ self,
204
+ *,
205
+ definitions: str | Path | None = None,
206
+ table_dir: str | Path | None = None,
207
+ ) -> list[list[DecodedValue]]:
208
+ """Decode every message in the dataset."""
209
+
210
+ definitions = _coalesce_path(definitions, self.definitions)
211
+ table_dir = _coalesce_path(table_dir, self.table_dir)
212
+ if table_dir is not None:
213
+ tables = TableSet.from_eccodes(table_dir)
214
+ return [message.decode_with_tables(tables) for message in self.messages]
215
+
216
+ definitions = definitions or builtin_definitions_path()
217
+ cache: dict[tuple[int, int, int, int, int], TableSet] = {}
218
+ decoded = []
219
+ for message in self.messages:
220
+ raw = message.raw
221
+ key = (
222
+ raw.master_table_number,
223
+ raw.master_tables_version_number,
224
+ raw.local_tables_version_number,
225
+ raw.originating_centre,
226
+ raw.originating_subcentre,
227
+ )
228
+ tables = cache.get(key)
229
+ if tables is None:
230
+ tables = TableSet.from_definitions(definitions, raw)
231
+ cache[key] = tables
232
+ decoded.append(message.decode_with_tables(tables))
233
+ return decoded
234
+
235
+ @property
236
+ def metadata(self) -> list[dict[str, Any]]:
237
+ """Metadata for all messages."""
238
+
239
+ return [message.metadata for message in self.messages]
240
+
241
+ @property
242
+ def descriptors(self) -> list[list[int]]:
243
+ """Unexpanded descriptors for all messages."""
244
+
245
+ return [message.descriptors for message in self.messages]
246
+
247
+ def to_dict(self, *, decode: bool = False, **decode_options: Any) -> dict[str, Any]:
248
+ """Convert the dataset to dictionaries."""
249
+
250
+ return {
251
+ "path": self.path,
252
+ "message_count": len(self.messages),
253
+ "messages": [
254
+ message.to_dict(decode=decode, **decode_options)
255
+ for message in self.messages
256
+ ],
257
+ }
258
+
259
+ def to_dataframe(self, message: int | None = None, **decode_options: Any):
260
+ """Decode one or all messages into a pandas DataFrame if pandas is installed."""
261
+
262
+ if message is not None:
263
+ return self.messages[message].to_dataframe(**decode_options)
264
+ decoded = self.decode_all(**decode_options)
265
+ try:
266
+ import pandas as pd
267
+ except ImportError as exc:
268
+ raise BufrustError("to_dataframe() requires pandas") from exc
269
+ frames = [
270
+ values_to_dataframe(
271
+ values,
272
+ number_of_subsets=message.raw.number_of_subsets,
273
+ message_index=message.index,
274
+ )
275
+ for message, values in zip(self.messages, decoded)
276
+ ]
277
+ return pd.concat(frames, ignore_index=True) if frames else pd.DataFrame()
278
+
279
+ def __iter__(self) -> Iterator[Message]:
280
+ return iter(self.messages)
281
+
282
+ def __getitem__(self, index: int) -> Message:
283
+ return self.messages[index]
284
+
285
+ def __len__(self) -> int:
286
+ return len(self.messages)
287
+
288
+ def __repr__(self) -> str:
289
+ source = f", path={self.path!r}" if self.path else ""
290
+ return f"Dataset(messages={len(self.messages)}{source})"
291
+
292
+
293
+ def open(
294
+ path: str | Path,
295
+ *,
296
+ definitions: str | Path | None = None,
297
+ table_dir: str | Path | None = None,
298
+ ) -> Dataset:
299
+ """Open a BUFR file and return a Dataset."""
300
+
301
+ return Dataset.from_file(path, definitions=definitions, table_dir=table_dir)
302
+
303
+
304
+ def loads(
305
+ data: bytes | bytearray | memoryview,
306
+ *,
307
+ definitions: str | Path | None = None,
308
+ table_dir: str | Path | None = None,
309
+ ) -> Dataset:
310
+ """Load BUFR messages from bytes and return a Dataset."""
311
+
312
+ return Dataset(bytes(data), definitions=definitions, table_dir=table_dir)
313
+
314
+
315
+ def load(
316
+ source: str | Path | bytes | bytearray | memoryview,
317
+ *,
318
+ definitions: str | Path | None = None,
319
+ table_dir: str | Path | None = None,
320
+ ) -> Dataset:
321
+ """Open a path or bytes-like object."""
322
+
323
+ if isinstance(source, (bytes, bytearray, memoryview)):
324
+ return loads(source, definitions=definitions, table_dir=table_dir)
325
+ return open(source, definitions=definitions, table_dir=table_dir)
326
+
327
+
328
+ def values_to_dicts(values: Iterable[DecodedValue]) -> list[dict[str, Any]]:
329
+ """Convert decoded values to plain dictionaries."""
330
+
331
+ return [
332
+ {
333
+ "descriptor": value.descriptor,
334
+ "name": value.name,
335
+ "value": value.value,
336
+ "raw": value.raw,
337
+ "text": value.text,
338
+ }
339
+ for value in values
340
+ ]
341
+
342
+
343
+ def values_to_dataframe(
344
+ values: Iterable[DecodedValue],
345
+ *,
346
+ number_of_subsets: int | None = None,
347
+ message_index: int | None = None,
348
+ ):
349
+ """Convert decoded values to a long-form pandas DataFrame."""
350
+
351
+ try:
352
+ import pandas as pd
353
+ except ImportError as exc:
354
+ raise BufrustError("values_to_dataframe() requires pandas") from exc
355
+
356
+ rows = values_to_dicts(values)
357
+ if number_of_subsets and rows and len(rows) % number_of_subsets == 0:
358
+ values_per_subset = len(rows) // number_of_subsets
359
+ for offset, row in enumerate(rows):
360
+ row["subset"] = offset // values_per_subset
361
+ row["position"] = offset % values_per_subset
362
+ else:
363
+ for offset, row in enumerate(rows):
364
+ row["subset"] = None
365
+ row["position"] = offset
366
+ if message_index is not None:
367
+ for row in rows:
368
+ row["message"] = message_index
369
+ return pd.DataFrame(rows)
370
+
371
+
372
+ def builtin_definitions_path() -> str:
373
+ """Return the bundled ecCodes-style BUFR definitions directory."""
374
+
375
+ return str(files(__package__).joinpath("definitions"))
376
+
377
+
378
+ def tables_for_message(
379
+ message: Message | RawMessage,
380
+ *,
381
+ definitions: str | Path | None = None,
382
+ ) -> TableSet:
383
+ """Load the table set selected by a message header.
384
+
385
+ Uses the bundled WMO definitions by default. Pass ``definitions=`` to use
386
+ an external ecCodes definitions root instead.
387
+ """
388
+
389
+ raw = message.raw if isinstance(message, Message) else message
390
+ return TableSet.from_definitions(
391
+ _path_str(definitions) or builtin_definitions_path(),
392
+ raw,
393
+ )
394
+
395
+
396
+ def _split_message_bytes(data: bytes) -> list[bytes]:
397
+ chunks = []
398
+ offset = 0
399
+ while offset < len(data):
400
+ start = data.find(b"BUFR", offset)
401
+ if start < 0:
402
+ break
403
+ if start + 8 > len(data):
404
+ raise BufrustError("truncated BUFR header")
405
+ total_length = int.from_bytes(data[start + 4 : start + 7], "big")
406
+ end = start + total_length
407
+ if end > len(data):
408
+ raise BufrustError("truncated BUFR message")
409
+ chunks.append(data[start:end])
410
+ offset = end
411
+ return chunks
412
+
413
+
414
+ def _path_str(path: str | Path | None) -> str | None:
415
+ return None if path is None else str(path)
416
+
417
+
418
+ def _coalesce_path(value: str | Path | None, default: str | None) -> str | None:
419
+ return _path_str(value) if value is not None else default
420
+
421
+
422
+ read = open
423
+ get = open
424
+ parse_bytes = _parse_bytes
425
+ parse_all_bytes = _parse_all_bytes
426
+ decode_values = _decode_values
427
+ decode_values_with_definitions = _decode_values_with_definitions
428
+ decode_values_with_tables = _decode_values_with_tables
429
+ BufrMessage = RawMessage
430
+
431
+ __all__ = [
432
+ "BufrustError",
433
+ "Dataset",
434
+ "Message",
435
+ "RawMessage",
436
+ "BufrMessage",
437
+ "DecodedValue",
438
+ "Descriptor",
439
+ "ElementDefinition",
440
+ "SequenceDefinition",
441
+ "TableSet",
442
+ "builtin_definitions_path",
443
+ "decode_values",
444
+ "decode_values_with_definitions",
445
+ "decode_values_with_tables",
446
+ "expand_descriptors",
447
+ "get",
448
+ "load",
449
+ "loads",
450
+ "open",
451
+ "parse_all_bytes",
452
+ "parse_all_file",
453
+ "parse_bytes",
454
+ "parse_file",
455
+ "read",
456
+ "tables_for_message",
457
+ "values_to_dataframe",
458
+ "values_to_dicts",
459
+ ]
Binary file
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2005- ECMWF
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,25 @@
1
+ ECMWF ecCodes
2
+ (C) Copyright 2005- ECMWF.
3
+
4
+ This product includes software developed at ECMWF (http://www.ecmwf.int).
5
+
6
+ Parts of the definitions provided by WMO (https://public.wmo.int/en)
7
+
8
+ Microsoft Visual Studio support provided with the help of
9
+ Finnish Meteorological Institute (FMI).
10
+
11
+ Adaptive Entropy Coding (CCSDS) provided by
12
+ The Max-Planck-Institute for Meteorology and Deutsches Klimarechenzentrum GmbH.
13
+
14
+ IBM POWER optimisations were developed at
15
+ The Max-Planck-Institute for Meteorology.
16
+
17
+ Decoding double array optimisations provided by
18
+ Norwegian Meteorological Institute.
19
+
20
+ OpenMP API Support provided by Eric Millin.
21
+
22
+ Fortran source code for grib_typeSizes.f90 from Robert Pincus
23
+ Cooperative Institue for Meteorological Satellite Studies
24
+ University of Wisconsin
25
+
@@ -0,0 +1,3 @@
1
+ #code|abbreviation|type|name|unit|scale|reference|width|crex_unit|crex_scale|crex_width
2
+ 002201|simulatedSatelliteInstrument|long|SIMULATED SATELLITE INSTRUMENT|FLAG TABLE|0|0|4|NA|0|0
3
+ 008193|timeQualifier|long|TIME QUALIFIER|CODE TABLE|0|0|0|NA|0|0
@@ -0,0 +1,2 @@
1
+ #code|abbreviation|type|name|unit|scale|reference|width|crex_unit|crex_scale|crex_width
2
+ 002201|simulatedSatelliteInstrument|flag|SIMULATED SATELLITE INSTRUMENT|FLAG TABLE|0|0|4|NA|0|0