Python SpacePy 库 CDF 文件纪元到日期时间 'Function Undefined' 错误

Python SpacePy Library CDF File Epoch to Datetime 'Function Undefined' Error

我目前正在进行与 NASA THEMIS 卫星全天成像仪数据库相关的研究。数据库文件为 .cdf 格式,因此我在 Linux CentOS 7 上使用 Python 3.7.3 SpacePy 库来读取这些 CDF 文件并提取数据。我在 Linux 终端中使用 Python3 控制台。

>>> import spacepy
# Defining the CDF Object File
>>> cdf = pycdf.CDF('/projectnb/burbsp/big/SATELLITE/themis/data/thg/l1/asi/gill/2008/01/thg_l1_asf_gill_2008011403_v01.cdf')
# Reading the CDF Object File Components
>>> print(cdf)

range_epoch:CDF_EPOCH [2] 
thg_asf_gill: CDF_UINT2 [1198, 256, 256]
thg_asf_gill_column: CDF_UINT2 [256] NRV
thg_asf_gill_epoch: CDF_EPOCH [1198]
thg_asf_gill_epoch0: CDF_EPOCH [] NRV
thg_asf_gill_row: CDF_UINT2 [256] NRV
thg_asf_gill_tend: CDF_REAL8 [1198]
thg_asf_gill_time: CDF_REAL8 [1198]

我特别感兴趣的是在 CDF 文件中提取单个纪元的日期和时间。根据SpacePy library,纪元到日期时间的转换是由这个函数定义的:

spacepy.pycdf.epoch_to_datetime(epoch)

我使用相同的函数来提取 .cdf 文件中第一个纪元的日期时间,方法是:

>>> spacepy.pycdf.epoch_to_datetime(cdf['thg_asf_gill'][0,:,:])

结果,我得到这个错误:

AttributeError: module 'spacepy.pycdf' has no attribute 'epoch_to_datetime'

我试图通过为函数分配一个变量来处理错误,但我得到了同样的错误,所以这一定是函数本身的问题,或者我可能遗漏了什么。如果有人以前遇到过这个问题并且知道出了什么问题,那将对我有很大帮助!

GreenMatt帮我解决后,原来是语法相关的问题,函数应该写成:

spacepy.pycdf.Library.epoch_to_datetime(epoch)

也可以这样写:

pycdf.Library.epoch_to_datetime(epoch)

我发现有一种更简单的方法来提取时间。显然 NASA 已经将日期时间作为对象之一包含在 .cdf 文件中,它是扩展名为 _epoch 的对象。因此,提取日期时间的一种快速方法是编写(在我的例子中):

# Extracting datetime of the first epoch from the .cdf file
>>> epoch = cdf['thg_asf_gill_epoch'][0]
>>> print(epoch)
2008-01-14 03:00:00.067000

如您所见,它给出了小时、分钟、秒和微秒等...因此,这是准确了解您提取的数据片段的日期时间的好方法。希望这能帮助任何可能像我一样被困在未来的人!感谢@GreenMatt 的帮助。