def setup(): global DIRPATH DIRPATH = tempfile.mkdtemp() # Create DAT file. raw_data = create_trace(nsamples, nchannels) for start, end in excerpts(nsamples, nexcerpts=10, excerpt_size=10): raw_data[start:end] += np.random.randint(low=-10000, high=10000, size=(10, nchannels)) raw_data.tofile(op.join(DIRPATH, dat_filename)) # Create PRM file. prm = get_params(**{ 'raw_data_files': dat_filename, 'experiment_name': name, 'nchannels': nchannels, 'sample_rate': sample_rate, 'detect_spikes': 'positive', 'prb_file': prb_filename, }) prm_contents = pydict_to_python(prm) with open(op.join(DIRPATH, prm_filename), 'w') as f: f.write(prm_contents) # Create PRB file. prb_contents = """ nchannels = %NCHANNELS% channel_groups = {0: { 'channels': list(range(nchannels)), 'graph': [(i, i + 1) for i in range(nchannels - 1)], } }""".replace('%NCHANNELS%', str(nchannels)).replace(' ', '') with open(op.join(DIRPATH, prb_filename), 'w') as f: f.write(prb_contents)
def _load_files_info(prm_filename, dir=None): dir_, filename = op.split(prm_filename) dir = dir or dir_ basename, ext = op.splitext(filename) if ext == '': ext = '.prm' prm_filename = op.join(dir, basename + ext) assert op.exists(prm_filename) # Load PRM file. prm = get_params(prm_filename) nchannels = prm.get('nchannels') assert nchannels > 0 # Find PRB path in PRM file, and load it. prb_filename = prm.get('prb_file') if not op.exists(prb_filename): prb_filename = op.join(dir, prb_filename) prb = load_probe(prb_filename) # Find raw data source. data = prm.get('raw_data_files') if isinstance(data, basestring): if data.endswith('.dat'): data = [data] if isinstance(data, list): for i in range(len(data)): if not op.exists(data[i]): data[i] = op.join(dir, data[i]) experiment_name = prm.get('experiment_name') return dict(prm=prm, prb=prb, experiment_name=experiment_name, nchannels=nchannels, data=data, dir=dir)
def setup(): global DIRPATH DIRPATH = tempfile.mkdtemp() # Create DAT file. raw_data = create_trace(nsamples, nchannels) for start, end in excerpts(nsamples, nexcerpts=10, excerpt_size=10): raw_data[start:end] += np.random.randint(low=-10000, high=10000, size=(10, nchannels)) raw_data.tofile(op.join(DIRPATH, dat_filename)) # Create PRM file. prm = get_params( **{ 'raw_data_files': dat_filename, 'experiment_name': name, 'nchannels': nchannels, 'sample_rate': sample_rate, 'detect_spikes': 'positive', 'prb_file': prb_filename, }) prm_contents = pydict_to_python(prm) with open(op.join(DIRPATH, prm_filename), 'w') as f: f.write(prm_contents) # Create PRB file. prb_contents = """ nchannels = %NCHANNELS% channel_groups = {0: { 'channels': list(range(nchannels)), 'graph': [(i, i + 1) for i in range(nchannels - 1)], } }""".replace('%NCHANNELS%', str(nchannels)).replace(' ', '') with open(op.join(DIRPATH, prb_filename), 'w') as f: f.write(prb_contents)
def test_get_params(): assert get_params(sample_rate=1).get('filter_butter_order', None) == 3 assert get_params(sample_rate=1, filter_butter_order=1)['filter_butter_order'] == 1