def test_Fs_is_persisted(): Fs = 1234.0 with UnlinkingTempfile(".f32") as tmp_fn: eeg = F32(tmp_fn, "w+", shape=(1,1), Fs=Fs) eeg.close() eeg2 = F32(tmp_fn) assert_equal(Fs, eeg2.Fs)
def _internal_write_and_read_back(data): with UnlinkingTempfile(".f32") as tmp_fn: eeg = F32(tmp_fn, "w+", shape=data.shape) eeg[:,:] = data eeg.close() eeg2 = F32(tmp_fn) read_data = np.array(eeg2[:]) assert_array_almost_equal(data, read_data)
def test_filtered_reading(): with UnlinkingTempfile(".f32") as tmp_fn: data = np.random.random((100,1)) eeg = F32(tmp_fn, "w+", shape=data.shape) eeg[:,:] = data eeg.close() eeg_filtered = F32filtered(tmp_fn, lambda x: 3*x) read_data = eeg_filtered[:] assert_array_almost_equal(data, read_data/3)
# -*- coding: utf-8 -*- """Calculate ERP-data on some generated data. ..hint:: Generation of the data might take some time...""" import matplotlib.pyplot as plt from eegpy.example_data.generated import simple_erp_like_data from eegpy import F32 from eegpy.analysis.timefreq import ERPAnalyzer from eegpy.temp import UnlinkingTempfile with UnlinkingTempfile(".f32") as temp_fn: # create some example data data, events = simple_erp_like_data() eeg = F32(temp_fn, "w+", cNames=["A", "B", "C"], shape=data.shape, Fs=250.) eeg[:, :] = data # plot whole 'eeg' with events plt.subplot(211) plt.plot(eeg[:, :], "k-") for event in events.all_events: plt.axvline(event, color="r", lw=2., alpha=0.5) # analyze ERPs analyzer = ERPAnalyzer(eeg, (-300, +600), baseline=(-200, 0)) for condition in events.keys(): analyzer.add_condition(condition, events[condition]) # plot ERPs relative_times = analyzer.times_to_trigger
# -*- coding: utf-8 -*- import os import numpy as np from eegpy import F32 from eegpy.temp import UnlinkingTempfile with UnlinkingTempfile("f32") as filename: channel_names = ["F3", "Fz", "F3", "C3", "Cz", "C4", "P3", "Pz", "P4"] eeg = F32(filename, "w+", shape=(10000, len(channel_names)), cNames=channel_names, Fs=250.) eeg[:, :] = np.random.random((10000, len(channel_names))) eeg[:, 0] *= 5 print eeg.channel_names print eeg.shape print eeg.num_datapoints, eeg.num_channels print eeg.Fs eeg.close()
def test_tempfile_is_unlinked(self): with UnlinkingTempfile() as fn: with open(fn, "w") as fh: fh.write("Test") assert_true(os.path.exists(fn)) assert_false(os.path.exists(fn))
def test_dir_is_used(self): dir_ = "/path/to/somewhere" with UnlinkingTempfile(dir=dir_) as fn: assert_equal(os.path.normpath(dir_), os.path.normpath(os.path.split(fn)[0]))
def test_prefix_is_used(self): with UnlinkingTempfile(prefix="xyz") as fn: file_part = os.path.split(fn)[1] assert_true(file_part.startswith("xyz"))
def test_suffix_is_used(self): with UnlinkingTempfile(suffix=".xyz") as fn: assert_true(fn.endswith(".xyz"))
def test_file_is_never_created(self): with UnlinkingTempfile() as fn: assert_false(os.path.exists(fn)) assert_false(os.path.exists(fn))
def test_channel_names_are_automatically_created(): with UnlinkingTempfile(".f32") as tmp_fn: eeg = F32(tmp_fn, "w+", shape=(1,10)) assert_equal(10, len(eeg.channel_names)) for ch in eeg.channel_names: assert_false(ch=="")
def _internal_write(data): with UnlinkingTempfile(".f32") as tmp_fn: eeg = F32(tmp_fn, "w+", shape=data.shape) eeg[:,:] = data eeg.close() assert_true(os.path.getsize(tmp_fn) > 1024)