csv - Errors with opening file when reading a .hdf file with Python - Stack Overflow

admin2025-04-16  2

I have some data from NDACC that I want to read so that I can plot a graph. I've downloaded one file and named it groundbased_ftir.hdf. However, it just says that either the file doesn't exist, or that its unable to synchronously open (file signature not found).

import h5py

filename2='Data/ftirfrancenorthhemisphere.hdf'

with h5py.File(filename2,"r") as f:
   print("Keys: %s" % f.keys())

But that gives an error:

Unable to synchronously open file (File signature not found)

I then tried:

filename=pd.read_hdf('Data/groundbased_ftir.hdf', mode='r' , key'28078=9006')

But that gives an error that the file does not exist (even though it does).

I then tried to run it in IDL which worked, but I'm not sure how to extract the data I want, and if I can get the data as a .csv file.

I have some data from NDACC that I want to read so that I can plot a graph. I've downloaded one file and named it groundbased_ftir.hdf. However, it just says that either the file doesn't exist, or that its unable to synchronously open (file signature not found).

import h5py

filename2='Data/ftirfrancenorthhemisphere.hdf'

with h5py.File(filename2,"r") as f:
   print("Keys: %s" % f.keys())

But that gives an error:

Unable to synchronously open file (File signature not found)

I then tried:

filename=pd.read_hdf('Data/groundbased_ftir.hdf', mode='r' , key'28078=9006')

But that gives an error that the file does not exist (even though it does).

I then tried to run it in IDL which worked, but I'm not sure how to extract the data I want, and if I can get the data as a .csv file.

Share Improve this question edited Feb 3 at 19:26 Kovy Jacob 1,1198 silver badges24 bronze badges asked Feb 3 at 14:39 AraAra 112 bronze badges 1
  • Use a full path not a relative one. Python's current directory isn't what you think if you are getting a "file does not exist" error. Without the actual file can't tell you why you'd get the "unable to open" error. – Mark Tolonen Commented Feb 3 at 19:38
Add a comment  | 

1 Answer 1

Reset to default 0

Check The File Format

NDACC files might not always be in HDF5 format, they could be in an older HDF4 format.

If it's an HDF4 file, use pyhdf instead of h5py.

from pyhdf.SD import SD, SDC
file = SD('Data/ftirfrancenorthhemisphere.hdf', SDC.READ)
print(file.datasets())

Check The File Path

Check if the file actually exists in the specified directory.

import os
print(os.path.exists('Data/ftirfrancenorthhemisphere.hdf'))

If False, the path might be incorrect, try using the absolute path instead.

filename2 = r'C:\path_to_your_project\Data\ftirfrancenorthhemisphere.hdf'
转载请注明原文地址:http://www.anycun.com/QandA/1744766001a87315.html