-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbufr_generic.py
67 lines (50 loc) · 1.57 KB
/
bufr_generic.py
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
from arkimet.scan.bufr import Scanner, read_area_fixed, read_proddef
from arkimet.scan import timedef
def read_timerange(msg):
# Set timerange
p1_list = {d["trange"].p1 for d in msg.query_data()}
if len(p1_list) > 1:
raise Exception("BUFR message has contradictory forecasts {}".format(
p1_list
))
p1 = p1_list.pop() if p1_list else 0
unit = timedef.UNIT_SECOND
for d, u in (
(3600, timedef.UNIT_HOUR),
(60, timedef.UNIT_MINUTE),
):
if p1 % d == 0:
p1 = p1 // d
unit = u
break
return {
"style": "Timedef",
"step_len": p1,
"step_unit": unit,
"stat_type": 255,
"stat_len": 0,
"stat_unit": 255,
}
def is_generic(md):
product = md.to_python("product")
return product.get("type") == 255 and product.get("subtype") == 255
def scan(msg, md):
# Set area and proddef
area = read_area_fixed(msg)
proddef = read_proddef(msg)
if area:
md["area"] = {"style": "GRIB", "value": area}
if proddef:
md["proddef"] = {"style": "GRIB", "value": proddef}
# Set product based on report name
if msg.report:
product = md.to_python("product")
product["value"]["t"] = msg.report
md["product"] = product
md["timerange"] = read_timerange(msg)
def scan_temp(msg, md):
# Add timerange to generic with rep_memo=temp
if is_generic(md):
md["timerange"] = read_timerange(msg)
Scanner.register("generic", scan)
Scanner.register("temp", scan_temp, priority=1)