|
| 1 | +from datetime import datetime |
| 2 | +from uuid import uuid4 |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +from dateutil import tz |
| 6 | + |
| 7 | +from pynwb import NWBHDF5IO, NWBFile, TimeSeries |
| 8 | + |
| 9 | + |
| 10 | +nwbfile = NWBFile( |
| 11 | + session_description="Mouse exploring an open field", # required |
| 12 | + identifier=str(uuid4()), # required |
| 13 | + session_start_time=datetime(2018, 4, 25, 2, 30, 3, tzinfo=tz.gettz("US/Pacific")), # required |
| 14 | + experimenter=[ |
| 15 | + "Baggins, Bilbo", |
| 16 | + ], # optional |
| 17 | + ) |
| 18 | + |
| 19 | +waveforms_list = [ |
| 20 | + np.array([ # unit 1 |
| 21 | + [ # electrode 1 |
| 22 | + [1, 2, 3, 4, 5], # spike time 1 [sample 1, sample 2, ...] |
| 23 | + [2, 3, 4, 5, 6], # spike time 2 |
| 24 | + ], |
| 25 | + [ # electrode 2 |
| 26 | + [3, 4, 5, 6, 7], # spike time 1 [sample 1, sample 2, ...] |
| 27 | + [2, 3, 4, 5, 6], # spike time 2 |
| 28 | + ], |
| 29 | + ]), |
| 30 | + np.array([ # unit 2 |
| 31 | + [ # electrode 1 |
| 32 | + [10, 20, 30, 40, 50], # spike time 1 [sample 1, sample 2, ...] |
| 33 | + ], |
| 34 | + [ # electrode 2 |
| 35 | + [100, 200, 300, 400, 500], # spike time 1 [sample 1, sample 2, ...] |
| 36 | + ], |
| 37 | + ]), |
| 38 | +] |
| 39 | +# mean and sd across spike times |
| 40 | +waveform_mean_list = [np.mean(i, axis=1) for i in waveforms_list] |
| 41 | +waveform_sd_list = [np.std(i, axis=1) for i in waveforms_list] |
| 42 | + |
| 43 | +electrodes_list = [[1, 2], [3]] |
| 44 | +for unit_id in range(2): |
| 45 | + nwbfile.add_unit( |
| 46 | + id=unit_id, |
| 47 | + electrodes=electrodes_list[unit_id], |
| 48 | + waveforms=waveforms_list[unit_id], |
| 49 | + waveform_mean=waveform_mean_list[unit_id], # does not support different number of electrodes |
| 50 | + waveform_sd=waveform_sd_list[unit_id], # does not support different number of electrodes |
| 51 | + ) |
| 52 | + |
| 53 | + breakpoint() |
| 54 | + |
| 55 | +with NWBHDF5IO("temp.nwb", "w") as io: |
| 56 | + io.write(nwbfile) |
0 commit comments