Commit d5348842 authored by Alex Fout's avatar Alex Fout

renamed season_start and season_end to pre_test and post_test to be more...

renamed season_start and season_end to pre_test and post_test to be more consistent with the data we have.
parent 984efa97
......@@ -22,13 +22,13 @@ class Patient(object):
:param pid: identifier of patient (a number)
:type pid: string
"""
self.pid = pid
self.season_start = None
self.season_end = None
self.concussions = []
self.pid = str(pid)
self.pre_test = None
self.post_test = None
self.intermediate_tests = []
self.n_concussions = 0
self.columns = ["fp1", "fp2", "f3", "f4", "f7", "f8", "c3", "c4", "p3", "p4", "o1", "o2", "t3", "t4", "t5", "t6", "fz", "cz", "pz"]
self.load_all(pid)
self.load_all(self.pid)
def load_all(self, pid):
"""
......@@ -38,37 +38,52 @@ class Patient(object):
:type pid: string
"""
if not os.path.exists(os.path.join(data_directory, pid + "a" + ".raw")):
if not os.path.exists(os.path.join(data_directory, pid + "a.raw")):
print("First file: {0}a.raw not found, not loading.".format(pid))
return
# load each patient session
let = "a"
i = 0
while os.path.exists(os.path.join(data_directory, pid + let + ".raw")):
if let == "a":
# first file is beginning of season
self.season_start = self.load_session(pid + let)
self.pre_test = self.load_session(pid + let, "_pretest")
else:
# middle files are cuncussive events
self.concussions.append(self.load_session(pid + let))
self.intermediate_tests.append(self.load_session(pid + let, "_interm_" + str(i)))
i += 1
let = chr(ord(let) + 1) # next letter
# last file is end of season
self.season_end = self.concussions[-1]
self.concussions = self.concussions[:-1]
if len(self.intermediate_tests) > 0:
self.post_test = self.intermediate_tests[-1]
if self.post_test is not None:
self.post_test.id = pid + "_post_test"
self.intermediate_tests = self.intermediate_tests[:-1]
# count number of concussions
self.n_concussions = len(self.concussions)
self.n_concussions = len(self.intermediate_tests)
def load_session(self, filename):
def load_session(self, filename, suffix=""):
"""
:param filename: file prefix, as in: <prefix>.raw and <prefix>.art
:type filename: string
:param suffix: optional suffix for the id of the eeg session
:type suffix: string
:return: an EEGSession object which has a pandas data frame for each of Session.raw and Session.art
:rtype: EEGSession
"""
raw = pd.read_csv(os.path.join(data_directory, filename + ".raw"), names=self.columns)
raw["time"] = pd.Series([i/256. for i in range(len(raw.index))])
artifacts = pd.read_csv(os.path.join(data_directory, filename + ".art"), names=self.columns)
return EEGSession(raw, artifacts)
try:
raw = pd.read_csv(os.path.join(data_directory, filename + ".raw"), names=self.columns, dtype=np.float64)
raw["time"] = pd.Series([i/256. for i in range(len(raw.index))])
except:
print("Can't load data file: {}".format(filename + ".raw"))
return None
try:
artifacts = pd.read_csv(os.path.join(data_directory, filename + ".art"), names=self.columns, dtype=np.float64)
except:
print("Can't load data file: {}".format(filename + ".art"))
return None
return EEGSession(filename + suffix, raw, artifacts)
def main():
......@@ -78,22 +93,22 @@ def main():
"""
pid = sys.argv[1]
patient = Patient(pid)
if patient.season_start is not None:
print("season start: {}".format(len(patient.season_start.raw)))
for i in range(len(patient.concussions)):
print("concussion {}: {}".format(i, len(patient.concussions[i].raw)))
print("season end: {}".format(len(patient.season_end.raw)))
prep.stft(patient.season_start)
examples = patient.season_start.get_examples()
if patient.pre_test is not None:
print("season start: {}".format(len(patient.pre_test.raw)))
for i in range(len(patient.intermediate_tests)):
print("concussion {}: {}".format(i, len(patient.intermediate_tests[i].raw)))
print("season end: {}".format(len(patient.post_test.raw)))
prep.stft(patient.pre_test)
examples = patient.pre_test.get_examples()
emb = Embedding("pca")
emb.train(examples)
emb_examples = emb.embed(examples)
#patient.season_start.extract_windows()
#patient.season_start.plot_windows(windows=np.arange(10), channels=["c3", "cz", "c4", "p3", "pz", "p4"])
prep.extractWaves(patient.season_start, n=4001, samplingRate=256, wave='alpha')
patient.season_start.extract_windows()
patient.season_start.plot_windows(windows=np.arange(10), channels=["c3", "cz", "c4", "p3", "pz", "p4"])
prep.extractWaves(patient.pre_test, n=4001, samplingRate=256, wave='alpha')
patient.pre_test.extract_windows()
patient.pre_test.plot_windows(windows=np.arange(10), channels=["c3", "cz", "c4", "p3", "pz", "p4"])
#patient.season_start.plot_channels(channels=["c3", "cz", "c4", "p3", "pz", "p4"], end=256)
import pdb; pdb.set_trace()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment