Using h5py to import HDF5 files
The file 'LIGO_data.hdf5'
is already in your working directory.
In this exercise, you'll import it using the h5py
library.
You'll also print out its datatype to confirm you have imported
it correctly. You'll then study the structure of the file in order
to see precisely what HDF groups it contains.
You can find the LIGO data plus loads of documentation and tutorials here. There is also a great tutorial on Signal Processing with the data here.
This is a part of the course
“Introduction to Importing Data in Python”
Exercise instructions
- Import the package
h5py
. - Assign the name of the file to the variable
file
. - Load the file as read only into the variable
data
. - Print the datatype of
data
. - Print the names of the groups in the HDF5 file
'LIGO_data.hdf5'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import packages
import numpy as np
import ____
# Assign filename: file
# Load file: data
data = h5py.File(____, ____)
# Print the datatype of the loaded file
# Print the keys of the file
for key in ____:
print(____)