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_pydict_to_python(): pydict = dict(MYVAR1='myvalue1', MYVAR2=.123, MYVAR3=['myvalue3', .456]) python = pydict_to_python(pydict) assert python == """ MYVAR1 = 'myvalue1' MYVAR2 = 0.123 MYVAR3 = ['myvalue3', 0.456] """.replace(' ', '').strip()
def test_params_to_python(): params = dict(MYVAR1='myvalue1', MYVAR2=.123, MYVAR3=['myvalue3', .456], SAMPLE_RATE=1) python = pydict_to_python(params) assert python == """ MYVAR1 = 'myvalue1' MYVAR2 = 0.123 MYVAR3 = ['myvalue3', 0.456] SAMPLE_RATE = 1 """.replace(' ', '').strip()
def test_pydict_to_python(): pydict = dict( MYVAR1 = 'myvalue1', MYVAR2 = .123, MYVAR3 = ['myvalue3', .456]) python = pydict_to_python(pydict) assert python == """ MYVAR1 = 'myvalue1' MYVAR2 = 0.123 MYVAR3 = ['myvalue3', 0.456] """.replace(' ', '').strip()
def test_params_to_python(): params = dict( MYVAR1 = 'myvalue1', MYVAR2 = .123, MYVAR3 = ['myvalue3', .456], SAMPLE_RATE = 1) python = pydict_to_python(params) assert python == """ MYVAR1 = 'myvalue1' MYVAR2 = 0.123 MYVAR3 = ['myvalue3', 0.456] SAMPLE_RATE = 1 """.replace(' ', '').strip()
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)