diff --git a/src/metpy/io/nexrad.py b/src/metpy/io/nexrad.py index 9efce8f8b21..33ddb6bdbbb 100644 --- a/src/metpy/io/nexrad.py +++ b/src/metpy/io/nexrad.py @@ -545,12 +545,17 @@ def _decode_msg18(self, msg_hdr): attr = f'VCPAT{num}' dat = self.rda[attr] vcp_hdr = self.vcp_fmt.unpack_from(dat, 0) - off = self.vcp_fmt.size - els = [] - for _ in range(vcp_hdr.num_el_cuts): - els.append(self.vcp_el_fmt.unpack_from(dat, off)) - off += self.vcp_el_fmt.size - self.rda[attr] = vcp_hdr._replace(els=els) + # At some point these got changed to spares, so only try to parse the rest if + # it looks like the right data. + if vcp_hdr.num == num and 0 < 2 * vcp_hdr.size_hw <= len(dat): + off = self.vcp_fmt.size + els = [] + for _ in range(vcp_hdr.num_el_cuts): + els.append(self.vcp_el_fmt.unpack_from(dat, off)) + off += self.vcp_el_fmt.size + self.rda[attr] = vcp_hdr._replace(els=els) + else: # Otherwise this is just spare and we should dump + self.rda.pop(attr) msg31_data_hdr_fmt = NamedStruct([('stid', '4s'), ('time_ms', 'L'), ('date', 'H'), ('az_num', 'H'), diff --git a/src/metpy/static-data-manifest.txt b/src/metpy/static-data-manifest.txt index dafa9ea2bd6..8ae130d3c2a 100644 --- a/src/metpy/static-data-manifest.txt +++ b/src/metpy/static-data-manifest.txt @@ -5,6 +5,7 @@ CAM_test.nc ab62e6dca907c34eb44b842c67eb3eb817127306feb3524fa6d83670b628727c GFS_global.nc feae73f72340ee9e8b04fca92f182638a99316ad7262152809b7ccb9b6691e10 GFS_test.nc b69ae13179428667f6bc14dada1d5f9af4d3737b2b76a79a6001664e1525df3c HI-REGIONAL_4km_3.9_20160616_1715.gini 30896dda51c9f933027d8086f0a86543efce12ea90a52981eccbce2e0ce1529e +KJKL_20240227_102059 9344358cb53f2f9449b5a984d40a7dee8048fe6ecbb7fe219ab2420f8ee18776 KICX_20170712_1458 94bd4f795832f056f7489a5562acf76de9a9cab1694549562cc3154abb22527c KLTX20050329_100015.gz cad6ad8df707ad63c9ddb7306de869186241dd821517daf21ae0a80f4ce0a58d KTLX19990503_235621.gz 7a097251bb7a15dbcdec75812812e41a86c5eb9850f55c3d91d120c2c61e046e diff --git a/tests/io/test_nexrad.py b/tests/io/test_nexrad.py index 46f0cf98863..2ab1bb02eaf 100644 --- a/tests/io/test_nexrad.py +++ b/tests/io/test_nexrad.py @@ -109,6 +109,12 @@ def test_msg15(): assert f.clutter_filter_map['datetime'] == datetime(2013, 5, 19, 5, 15, 0, 0) +def test_msg18_novcps(): + """Check handling of message type 18 with VCP info now spares does not crash.""" + f = Level2File(get_test_data('KJKL_20240227_102059', as_file_obj=False)) + assert 'VCPAT11' not in f.rda + + def test_single_chunk(caplog): """Check that Level2File copes with reading a file containing a single chunk.""" # Need to override the test level set above