MetPy Level2File 错误 - 赋值前引用了局部变量 'offset'
MetPy Level2File error - local variable 'offset' referenced before assignment
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 中。
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 中。