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读取第二次扫描
提前感谢您的帮助
这个错误是由于MetPy中的一个小错误和这个特定文件(或者可能是这个时间范围内的文件)中的一些我以前没有见过的奇怪之处的组合。读取这些数据(希望所有的兄弟姐妹)是由this pull request确定的。该修复程序将包含在即将发布的MetPy 1.0.1中
相关问题 更多 >
编程相关推荐