Skip to content

Commit

Permalink
Added satellite name and channel info. Refs: #268
Browse files Browse the repository at this point in the history
  • Loading branch information
spanezz committed Jun 4, 2021
2 parents dd2c114 + d0b7567 commit 36b971a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
37 changes: 37 additions & 0 deletions conf/scan/grib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
import datetime


METEOSAT_NAMES = {
55: "MSG1",
56: "MSG2",
57: "MSG3",
70: "MSG4",
}

METEOSAT_CHAN_NAMES = {
6: "VIS006",
8: "VIS008",
16: "IR016",
39: "IR039",
62: "WV062",
73: "WV073",
87: "IR087",
97: "IR907",
108: "IR108",
120: "IR120",
134: "IR134",
7: "HRV",
}


def scan_grib2(grib, md):
# Reference time
md["reftime"] = {
Expand Down Expand Up @@ -190,6 +213,20 @@ def scan_grib2(grib, md):
grib["scaledValueOfUpperLimit"],
)

if grib["satelliteSeries"] == 333:
# Meteosat satellites
sat_name = METEOSAT_NAMES.get(grib["satelliteNumber"])
if sat_name is not None:
proddef["sat"] = sat_name

if grib["instrumentType"] == 207:
# Data from the SEVIRI instrument
ch_name = METEOSAT_CHAN_NAMES.get(
int(round(10 * 1.0 / (grib["scaledValueOfCentralWaveNumber"] * 0.000001)))
)
if ch_name is not None:
proddef["ch"] = ch_name

md["proddef"] = {
"style": "GRIB",
"value": proddef,
Expand Down
57 changes: 56 additions & 1 deletion python/tests/test_scan_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_issue264(self):
self.assertNotIn("timerange", md)
self.assertEqual(md["area"], "GRIB(tn=90)")
# issue201: set pl and pt
self.assertEqual(md["proddef"], "GRIB(tod=0)")
self.assertEqual(md["proddef"], "GRIB(ch=WV073, sat=MSG4, tod=0)")
self.assertEqual(md["reftime"], "2021-03-05T23:00:00Z")
self.assertEqual(md["run"], "MINUTE(23:00)")

Expand Down Expand Up @@ -395,3 +395,58 @@ def test_cosmo_nudging(self):
mds = self.read("inbound/cosmo/fcproc_3.grib2")
self.assertEqual(mds[0]["timerange"], "Timedef(48h, 1, 24h)")
self.assertEqual(mds[0]["proddef"], "GRIB(tod=1)")

def test_meteosat(self):
"""
Check scanning meteosat GRIB images
"""
# See issue #268
# More test data can be found at https://github.com/ARPA-SIMC/qc_sample_data/blob/master/satellite/grib/

mds = self.read("inbound/meteosat/MSG4_IR_016.grib")
self.assertEqual(len(mds), 1)
md = mds[0]
self.assertEqual(md["origin"], "GRIB2(00098, 00000, 000, 255, 254)")
self.assertEqual(md["product"], "GRIB2(00098, 003, 000, 000, 004, 000)")
self.assertEqual(md["level"], "GRIB2S( -, -, -)")
self.assertNotIn("timerange", md)
self.assertEqual(md["area"], "GRIB(tn=90)")
self.assertEqual(md["proddef"], "GRIB(ch=IR016, sat=MSG4, tod=0)")
self.assertEqual(md["reftime"], "2020-02-23T11:00:00Z")
self.assertEqual(md["run"], "MINUTE(11:00)")

mds = self.read("inbound/meteosat/MSG4_IR_039.grib")
self.assertEqual(len(mds), 1)
md = mds[0]
self.assertEqual(md["origin"], "GRIB2(00098, 00000, 000, 255, 254)")
self.assertEqual(md["product"], "GRIB2(00098, 003, 000, 000, 004, 000)")
self.assertEqual(md["level"], "GRIB2S( -, -, -)")
self.assertNotIn("timerange", md)
self.assertEqual(md["area"], "GRIB(tn=90)")
self.assertEqual(md["proddef"], "GRIB(ch=IR039, sat=MSG4, tod=0)")
self.assertEqual(md["reftime"], "2020-02-23T11:00:00Z")
self.assertEqual(md["run"], "MINUTE(11:00)")

mds = self.read("inbound/meteosat/MSG4_VIS006.grib")
self.assertEqual(len(mds), 1)
md = mds[0]
self.assertEqual(md["origin"], "GRIB2(00098, 00000, 000, 255, 254)")
self.assertEqual(md["product"], "GRIB2(00098, 003, 000, 000, 004, 000)")
self.assertEqual(md["level"], "GRIB2S( -, -, -)")
self.assertNotIn("timerange", md)
self.assertEqual(md["area"], "GRIB(tn=90)")
self.assertEqual(md["proddef"], "GRIB(ch=VIS006, sat=MSG4, tod=0)")
self.assertEqual(md["reftime"], "2020-02-23T11:00:00Z")
self.assertEqual(md["run"], "MINUTE(11:00)")

mds = self.read("inbound/meteosat/MSG4_WV_062.grib")
self.assertEqual(len(mds), 1)
md = mds[0]
self.assertEqual(md["origin"], "GRIB2(00098, 00000, 000, 255, 254)")
self.assertEqual(md["product"], "GRIB2(00098, 003, 000, 000, 004, 000)")
self.assertEqual(md["level"], "GRIB2S( -, -, -)")
self.assertNotIn("timerange", md)
self.assertEqual(md["area"], "GRIB(tn=90)")
self.assertEqual(md["proddef"], "GRIB(ch=WV062, sat=MSG4, tod=0)")
self.assertEqual(md["reftime"], "2020-02-23T11:00:00Z")
self.assertEqual(md["run"], "MINUTE(11:00)")
Binary file added test/data/meteosat/MSG4_IR_016.grib
Binary file not shown.
Binary file added test/data/meteosat/MSG4_IR_039.grib
Binary file not shown.
Binary file added test/data/meteosat/MSG4_VIS006.grib
Binary file not shown.
Binary file added test/data/meteosat/MSG4_WV_062.grib
Binary file not shown.

0 comments on commit 36b971a

Please sign in to comment.