Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84fe825

Browse files
committed
Implement parsing of 4/ group (snowdepth)
1 parent 476c300 commit 84fe825

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

metar/Metar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class ParserError(Exception):
175175
[NSEW][EW]? (-[NSEW][EW]?)* )+))?
176176
( \s+MOV\s+(?P<dir>[NSEW][EW]?) )?\s+""",
177177
re.VERBOSE)
178+
SNOWDEPTH_RE = re.compile(r"""^4/(?P<snowdepth>\d\d\d)\s+""")
178179

179180
## translation of weather location codes
180181

@@ -342,6 +343,7 @@ def __init__( self, metarcode, month=None, year=None, utcdelta=None):
342343
self.precip_3hr = None # precipitation over the last 3 hours
343344
self.precip_6hr = None # precipitation over the last 6 hours
344345
self.precip_24hr = None # precipitation over the last 24 hours
346+
self.snowdepth = None # snow depth (distance)
345347
self._trend = False # trend groups present (bool)
346348
self._trend_groups = [] # trend forecast groups
347349
self._remarks = [] # remarks (list of strings)
@@ -879,6 +881,13 @@ def _handleAutoRemark( self, d ):
879881
self._remarks.append("Automated station")
880882
elif d['type'] == "2":
881883
self._remarks.append("Automated station (type 2)")
884+
885+
def _handleSnowDepthRemark(self, d):
886+
"""
887+
Parse the 4/ group snowdepth report
888+
"""
889+
self.snowdepth = distance(float(d['snowdepth']), 'IN')
890+
self._remarks.append(" snowdepth %s" % (self.snowdepth, ))
882891

883892
def _unparsedRemark( self, d ):
884893
"""
@@ -928,6 +937,7 @@ def _unparsedRemark( self, d ):
928937
(PRESS_3HR_RE, _handlePress3hrRemark),
929938
(TEMP_6HR_RE, _handleTemp6hrRemark),
930939
(TEMP_24HR_RE, _handleTemp24hrRemark),
940+
(SNOWDEPTH_RE, _handleSnowDepthRemark),
931941
(UNPARSED_RE, _unparsedRemark) ]
932942

933943
## functions that return text representations of conditions for output

test/test_metar.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ def report(trend_group, remarks=""):
412412
self.assertEqual( report('TEMPO 0306 RMK 402500072').trend(), 'TEMPO 0306' )
413413
self.assertEqual( report('TEMPO 0306 RMK 402500072').max_temp_24hr.value(), 25.0 )
414414

415+
def test_snowdepth(self):
416+
"""Check parsing of 4/ group snowdepth"""
417+
sample_metar = ("KDOV 040558Z 23004KT 1 1/2SM R01/2800FT -SN BR "
418+
"OVC006 M01/M01 A3015 RMK AO2A SLP213 P0000 4/001 "
419+
"60010 T10071007 10017 "
420+
"21009 55016 VISNO RWY19 CHINO RWY19 $")
421+
m = Metar.Metar(sample_metar)
422+
self.assertEquals(m.snowdepth.value(), 1)
423+
415424
def test_310_parse_sky_conditions(self):
416425
"""Check parsing of sky conditions"""
417426

0 commit comments

Comments
 (0)