Skip to content

Commit

Permalink
ENH: Properly handle NEXRAD varying moments
Browse files Browse the repository at this point in the history
The moments vary from sweep to sweep, but we were always reading 6
pointers rather than looking at the encoded value. This would have
bitten us when they started shipping a 7th moment with Build 19.
  • Loading branch information
dopplershift committed Dec 21, 2019
1 parent 954eec5 commit 41bf376
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/metpy/io/nexrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,10 @@ def _decode_msg31(self, msg_hdr):
msg_start = self._buffer.set_mark()
data_hdr = self._buffer.read_struct(self.msg31_data_hdr_fmt)

# Read all the data block pointers separately. This simplifies just
# iterating over them
ptrs = self._buffer.read_binary(6, '>L')
# Read all the data block pointers separately. This makes it easy to loop and to
# handle the arbitrary numbers. We subtract 3 for the VOL, ELV, and RAD blocks that
# are required to be present (and can't be read like the data)
ptrs = self._buffer.read_binary(data_hdr.num_data_blks - 3, '>L')

if data_hdr.compression:
log.warning('Compressed message 31 not supported!')
Expand Down
18 changes: 10 additions & 8 deletions tests/io/test_nexrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@
# 1999 file tests old message 1
# KFTG tests bzip compression and newer format for a part of message 31
# KTLX 2015 has missing segments for message 18, which was causing exception
level2_files = [('KTLX20130520_201643_V06.gz', datetime(2013, 5, 20, 20, 16, 46), 17),
('KTLX19990503_235621.gz', datetime(1999, 5, 3, 23, 56, 21), 16),
('Level2_KFTG_20150430_1419.ar2v', datetime(2015, 4, 30, 14, 19, 11), 12),
('KTLX20150530_000802_V06.bz2', datetime(2015, 5, 30, 0, 8, 3), 14),
('KICX_20170712_1458', datetime(2017, 7, 12, 14, 58, 5), 14),
('TDAL20191021021543V08.raw.gz', datetime(2019, 10, 21, 2, 15, 43), 10)]
level2_files = [('KTLX20130520_201643_V06.gz', datetime(2013, 5, 20, 20, 16, 46), 17, 4, 6),
('KTLX19990503_235621.gz', datetime(1999, 5, 3, 23, 56, 21), 16, 1, 3),
('Level2_KFTG_20150430_1419.ar2v', datetime(2015, 4, 30, 14, 19, 11), 12, 4, 6),
('KTLX20150530_000802_V06.bz2', datetime(2015, 5, 30, 0, 8, 3), 14, 4, 6),
('KICX_20170712_1458', datetime(2017, 7, 12, 14, 58, 5), 14, 4, 6),
('TDAL20191021021543V08.raw.gz', datetime(2019, 10, 21, 2, 15, 43), 10, 1, 3)]


# ids here fixes how things are presented in pycharm
@pytest.mark.parametrize('fname, voltime, num_sweeps', level2_files,
@pytest.mark.parametrize('fname, voltime, num_sweeps, mom_first, mom_last', level2_files,
ids=[i[0].replace('.', '_') for i in level2_files])
def test_level2(fname, voltime, num_sweeps):
def test_level2(fname, voltime, num_sweeps, mom_first, mom_last):
"""Test reading NEXRAD level 2 files from the filename."""
f = Level2File(get_test_data(fname, as_file_obj=False))
assert f.dt == voltime
assert len(f.sweeps) == num_sweeps
assert len(f.sweeps[0][0][-1]) == mom_first
assert len(f.sweeps[-1][0][-1]) == mom_last


def test_level2_fobj():
Expand Down

0 comments on commit 41bf376

Please sign in to comment.