【发布时间】:2021-04-22 19:26:27
【问题描述】:
Unidata/MetPy 在Plotting AWS-hosted NEXRAD Level 2 Data 上有一个示例。它从以下内容开始:
import boto3
import botocore
from botocore.client import Config
import matplotlib.pyplot as plt
from metpy.io import Level2File
from metpy.plots import add_timestamp, ctables
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
s3 = boto3.resource('s3', config=Config(signature_version=botocore.UNSIGNED,
user_agent_extra='Resource'))
bucket = s3.Bucket('noaa-nexrad-level2')
for obj in bucket.objects.filter(Prefix='2019/06/26/KVWX/KVWX20190626_221105_V06'):
print(obj.key)
# Use MetPy to read the file
f = Level2File(obj.get()['Body'])
这适用于他们选择的车站和时间。如果我更改日期和时间并重新运行最后几行:
for obj in bucket.objects.filter(Prefix='2005/06/26/KVWX/KVWX20050626_221551'):
print(obj.key)
# Use MetPy to read the file
f = Level2File(obj.get()['Body'])
它打印出一个有效的密钥:
2005/06/26/KVWX/KVWX20050626_221551.gz
但 Level2File 给出以下错误信息:
Message 15 left data -- Used: 0 Avail: 16271
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-4-415bcd3f289e> in <module>
3
4 # Use MetPy to read the file
----> 5 f = Level2File(obj.get()['Body'])
/opt/conda/lib/python3.8/site-packages/metpy/io/nexrad.py in __init__(self, filename, has_volume_header)
196
197 # Now we're all initialized, we can proceed with reading in data
--> 198 self._read_data()
199
200 vol_hdr_fmt = NamedStruct([('version', '9s'), ('vol_num', '3s'),
/opt/conda/lib/python3.8/site-packages/metpy/io/nexrad.py in _read_data(self)
258 decoder = f'_decode_msg{msg_hdr.msg_type:d}'
259 if hasattr(self, decoder):
--> 260 getattr(self, decoder)(msg_hdr)
261 else:
262 log.warning('Unknown message: %d', msg_hdr.msg_type)
/opt/conda/lib/python3.8/site-packages/metpy/io/nexrad.py in _decode_msg13(self, msg_hdr)
475 self.clutter_filter_bypass_map['data'].append(az_data)
476
--> 477 if offset != len(data):
478 log.warning('Message 13 left data -- Used: %d Avail: %d', offset, len(data))
479
UnboundLocalError: local variable 'offset' referenced before assignment
我怀疑这是由于不同日期范围的格式差异造成的。有没有办法使用Level2File读取第二次扫描?
提前感谢您的帮助!
【问题讨论】: