简体   繁体   English

h5py 的问题-“数据集”object 没有属性“值”

[英]Problems with h5py - 'Dataset' object has no attribute 'value'

I'm currently trying to read in data from a h5py file and running into problems when attempting to slice and the metadata within to then input into a dictionary.我目前正在尝试从 h5py 文件中读取数据,并在尝试切片和其中的元数据然后输入字典时遇到问题。 The code is taken straight from NSF Neon tutorials where the entire script can be found.代码直接取自NSF Neon 教程,可以在其中找到整个脚本。

I'm particularly having trouble with this area of the function;我对 function 的这个区域特别有问题;

  #Extract the reflectance & wavelength datasets
    refl = hdf5_file[sitename]['Reflectance']
    reflData = refl['Reflectance_Data']
    reflRaw = refl['Reflectance_Data'].value ##This is causing - Dataset' object has no attribute 'value'
    
   #Create dictionary containing relevant metadata information
    metadata = {}
    metadata['map info'] = refl['Metadata']['Coordinate_System']['Map_Info'].value ##As above
    metadata['wavelength'] = refl['Metadata']['Spectral_Data']['Wavelength'].value 

From looking at this previous question on stack it seems that .value has be deprecated with recent releases with h5py.堆栈上的这个先前的问题来看,似乎.value在最近的 h5py 版本中已被弃用。 Referencing that post, instead of;引用该帖子,而不是;

reflRaw = refl['Reflectance_Data'].value

I've tried我试过了

  • reflRaw = refl['Reflectance_Data'][:]

    For this Python accuses me of 'Illegal slicing argument for scalar dataspace'对于这个 Python 指责我“标量数据空间的非法切片参数”

  • reflRaw = refl['Reflectance_Data'][()]

    This just hangs for 30 seconds and then eventually shows a blank matplotlib plot这只会挂起 30 秒,然后最终显示空白 matplotlib plot

Not sure how to proceed here.不知道如何在这里进行。 These tutorials are relatively recent so I'm not sure how they managed to get .value working if it's been deprecated in al recent h5py releases.这些教程是相对较新的,所以我不确定如果 .value 在最近的 h5py 版本中已被弃用,他们是如何设法让.value工作的。

Any help appreciated任何帮助表示赞赏

As the answer you linked shows, the correct syntax for newer versions of h5py is to replace .value with [()] .正如您链接的答案所示,较新版本的 h5py 的正确语法是将.value替换为[()] Doing this worked for me in your example.在您的示例中,这样做对我有用。 I'm not sure what you mean when you say the function returns a blank matplotlib plot, since it's only meant to return 2 arrays - which, again, it does when I run it. I'm not sure what you mean when you say the function returns a blank matplotlib plot, since it's only meant to return 2 arrays - which, again, it does when I run it.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM