In [1]:
# %load explore-eeghdf-files-basics.py
# Here is an example of how to do basic exploration of what is in the eeghdf file. I show how to discover the fields in the file and to plot them.
#
# I have copied the stacklineplot from my python-edf/examples code to help with display. Maybe I will put this as a helper or put it out as a utility package to make it easier to install.
from __future__ import print_function, division, unicode_literals
%matplotlib inline
# %matplotlib notebook
import matplotlib
import matplotlib.pyplot as plt
#import seaborn
import pandas as pd
import numpy as np
import h5py
from pprint import pprint
import stacklineplot
# matplotlib.rcParams['figure.figsize'] = (18.0, 12.0)
matplotlib.rcParams['figure.figsize'] = (12.0, 8.0)
In [2]:
hdf = h5py.File('./archive/YA2741BS_1-1+.eeghdf') # 5mo boy
In [3]:
pprint(list(hdf.items()))
pprint(list(hdf['patient'].attrs.items()))
In [4]:
rec = hdf['record-0']
pprint(list(rec.items()))
pprint(list(rec.attrs.items()))
years_old = rec.attrs['patient_age_days']/365
pprint("age in years: %s" % years_old)
In [5]:
signals = rec['signals']
labels = rec['signal_labels']
electrode_labels = [str(s,'ascii') for s in labels]
numbered_electrode_labels = ["%d:%s" % (ii, str(labels[ii], 'ascii')) for ii in range(len(labels))]
In [6]:
# plot 10s epochs (multiples in DE)
ch0, ch1 = (0,19)
DE = 2 # how many 10s epochs to display
epoch = 53; ptepoch = 10*int(rec.attrs['sample_frequency'])
dp = int(0.5*ptepoch)
# stacklineplot.stackplot(signals[ch0:ch1,epoch*ptepoch+dp:(epoch+DE)*ptepoch+dp],seconds=DE*10.0, ylabels=electrode_labels[ch0:ch1], yscale=0.3)
print("epoch:", epoch)
In [18]:
# search identified spasms at 1836, 1871, 1901, 1939
stacklineplot.show_epoch_centered(signals, 1836,
epoch_width_sec=15,
chstart=0, chstop=19, fs=rec.attrs['sample_frequency'],
ylabels=electrode_labels, yscale=3.0)
In [8]:
annot = rec['edf_annotations']
#print(list(annot.items()))
#annot['texts'][:]
In [9]:
signals.shape
Out[9]:
In [10]:
antext = [s.decode('utf-8') for s in annot['texts'][:]]
starts100ns = [xx for xx in annot['starts_100ns'][:]]
len(starts100ns), len(antext)
Out[10]:
In [11]:
import pandas as pd
In [12]:
df = pd.DataFrame(data=antext, columns=['text'])
df['starts100ns'] = starts100ns
df['starts_sec'] = df['starts100ns']/10**7
In [13]:
df # look at the annotations
Out[13]:
In [14]:
df[df.text.str.contains('sz',case=False)]
Out[14]:
In [15]:
df[df.text.str.contains('seizure',case=False)] # find the seizure
Out[15]:
In [16]:
df[df.text.str.contains('spasm',case=False)] # find the seizure
Out[16]:
In [17]:
list(annot.items())
Out[17]:
In [ ]:
2.6*10**12 /10
In [ ]:
In [ ]:
In [ ]: