【发布时间】:2021-12-18 10:03:11
【问题描述】:
这是this question in the astronomy SO 的后续问题。
按照this example in sunpy(与上面链接帖子中的答案非常相似),我正在尝试访问和下载跨越几十年 X 射线通量 (XRS) 的时间序列数据集。参数tstart 和tend 定义了要考虑的日期时间范围的边界。
使用sunpy 3.0.1,以下代码sn-p成功运行:
import datetime
from sunpy import timeseries as ts
from sunpy.net import Fido
from sunpy.net import attrs as a
tstart = datetime.datetime(2020, 6, 21, 1) # "2020-06-21 01:00"
tend = datetime.datetime(2020, 6, 21, 23) # "2020-06-21 23:00"
result = Fido.search(a.Time(tstart, tend), a.Instrument("XRS"), a.goes.SatelliteNumber(16))
goes_16_files = Fido.fetch(result)
goes_16 = ts.TimeSeries(goes_16_files, concat=True)
goes_table = goes_16.to_table()
goes_table.write('goes_16.csv', format='csv')
上面的示例获得了几乎一整天(tstart - tend ~ 1 天)的观察结果。但我想要跨越数年/数十年的完整数据集;我计划对所有 GOES 卫星(不仅仅是 16 号)重复上述程序。从wiki,我发现 GOES-16 于 2016 年 11 月 19 日 23:42 开始运行,并且仍然处于活动状态(即从未退役)。将代码中的tstart和tend替换为对应的范围会抛出错误而不是运行成功(如下图,使用与上面相同的导入):
tstart = datetime.datetime(2016, 11, 19, 23, 59, 59)
tend = datetime.datetime(2020, 6, 21, 23) #datetime.datetime.now() # "2020-06-21 23:00"
result = Fido.search(a.Time(tstart, tend), a.Instrument("XRS"), a.goes.SatelliteNumber(16))
goes_16_files = Fido.fetch(result)
goes_16 = ts.TimeSeries(goes_16_files, concat=True)
goes_table = goes_16.to_table()
goes_table.write('goes_16_re.csv', format='csv')
Files Downloaded: 7%|█▌ | 89/1227 [01:07<14:22, 1.32file/s]
Traceback (most recent call last):
File "/Users/T123/Desktop/testme123.py", line 11, in <module>
goes_table = goes_16.to_table()
AttributeError: 'list' object has no attribute 'to_table'
在上面的代码块中,唯一改变的是参数tstart。
这是 sunpy 中的错误吗?还是我做错了什么?如果它是相关的(因为some issues "appear" to be platform-specific),我在 macOS BigSur 11.2.1 上运行 python 3.9。
PS:我将astropy 作为这个问题的标签,因为 sunpy 的某些功能依赖于 astropy(并且因为没有 sunpy 标签)。如果这个问题有更合适的标签,请随时编辑它们。
【问题讨论】:
-
错误提示
goes_16是list那么您是否尝试将其打印出来进行检查?一般来说,这种探索性编码受益于使用交互式 shell(或 Jupyter notebook)而不是脚本文件。 -
我已尝试打印列表;它显示为一个包含 90 个条目的容器,看起来像
<sunpy.timeseries.sources.goes.XRSTimeSeries object at 0x7ffe57b99190>(但每个条目在内存中的地址不同)。我很困惑,因为 sunpy 在内部将其转换为列表,并且该方法适用于其他日期时间范围。因此,我不确定如何处理此错误。此外,还会显示这 90 个条目,当使用Fido下载的文件少于 20% 时会引发错误。在这种情况下,交互式 shell 有什么帮助?
标签: python-3.x error-handling download astropy