微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MetPy Level2File 错误 - 分配前引用了局部变量“偏移量”

如何解决MetPy Level2File 错误 - 分配前引用了局部变量“偏移量”

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 中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。