简体   繁体   中英

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. The code is taken straight from NSF Neon tutorials where the entire script can be found.

I'm particularly having trouble with this area of the 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. 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'

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

    This just hangs for 30 seconds and then eventually shows a blank 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.

Any help appreciated

As the answer you linked shows, the correct syntax for newer versions of h5py is to replace .value with [()] . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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