Created
September 5, 2019 00:17
-
-
Save larsoner/2ce47a365f008db6cf686680e5ad4889 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import json | |
| import numpy as np | |
| from expyfun.io import read_hdf5 | |
| from expyfun.analyze import decimals_to_binary | |
| # make the blank trigger pulses | |
| fs = 44100. | |
| trig_on_dur = 10e-3 | |
| trig_pause_dur = 10e-3 | |
| trig_on_len = int(fs * trig_on_dur) | |
| trig_pause_len = int(fs * trig_pause_dur) | |
| tube_len_meters = 11. * 25.4 * 1e-3 | |
| tube_delay = tube_len_meters / 343. | |
| tube_delay_len = int(np.round(tube_delay * fs)) | |
| run_file = 'CALIBRATION' | |
| with io.open('CALIBRATION', 'r', encoding='utf-8-sig') as fid: | |
| runs = json.load(fid) | |
| n_run_bits = np.maximum(1, int(np.ceil(np.log2(len(runs))))) | |
| data = dict() | |
| data_fn = [r['fn_stim'] for r in runs] | |
| print('Loading data for %i runs...' % len(runs)), | |
| for r in runs: | |
| if r['fn_stim'] not in data.keys(): | |
| data[r['fn_stim']] = read_hdf5(r['fn_stim']) | |
| print('%i unique data files loaded.' % len(data)) | |
| fs = data[data_fn[0]]['fs'] | |
| n_tok_bits = int(np.ceil(np.log2(np.max([d['x'].shape[0] | |
| for d in data.values()])))) | |
| trig_blanks = np.tile(np.atleast_2d( | |
| np.concatenate((np.ones(trig_on_len), np.zeros(trig_pause_len)))), | |
| [1 + n_run_bits + n_tok_bits, 1]) | |
| # write the stamp INCLUDING THE 1 TRIGGER | |
| ri, tok = 1, 2 # XXX arbitrary values here, in practice span some range and depend on the trial | |
| stamp = [1] | |
| stamp += [1 << (b + 2) for b in | |
| decimals_to_binary([ri, tok], [n_run_bits, n_tok_bits])] | |
| stamp = [b << 8 for b in stamp] | |
| trig = np.ravel(np.atleast_2d(stamp).T * trig_blanks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment