Package: pyopenephys
pyopenephysPython reader forOpen Ephys.InstallationIn order to install the pyopenephys package, open a terminal and run:pip install pyopenephysIf you want to install from sources and get the latest updates, clone the repo and install locally:gitclonehttps://github.com/CINPLA/pyopenephyscdpyopenephys
pythonsetup.pyinstall# use 'python setup.py develop' to install fixed bugsBasic UsagePyopenephys allows the user to load data recorded withOpen Ephys. Currently, only thebinary(recommended) andopenephys(support for this format will be dropped in future releases) are supported.The first step is creating aFileobject. It only requires to pass the paht to the recording folder.importpyopenephysfile=pyopenephys.File("path-to-recording-folder")The file object contains the different experiments (corresponding to different settings files) and each experiment contains a set of recordings.# all experimentsexperiments=file.experimentsprint(len(experiments))# recordings of first experimentexperiment=experiments[0]recordings=experiment.recordingsprint(len(experiments))# access first recordingrecording=recordings[0]Experiments store some useful information:experiment.datetimecontains the starting date and time of the experiment creationexperiment.sig_chainis a dictionary containing the processors and nodes in the signal chainexperiment.settingsis a dictionary with the parsed setting.xml fileexperiment.acquisition_systemcontains the system used to input continuous data (e.g. 'Rhythm FPGA')Recordings contain the actual data:recording.durationis the duration of the recording (in seconds)recording.sample_rateis the sampling frequency (in Hz)recording.analog_signalsis list ofAnalogSignalobjects, which in turn have asignal,times(in s), andchannel_idfields.recording.eventsis list ofEventDataobjects, which in turn have atimes(in s),channels,channel_states,full_words,processor,node_id, andmetadatafields.recording.trackingis list ofTrackingDataobjects , which in turn have atimes(in s),x,y,width,height,channels, andmetadatafields. Tracking data are recorded with theTrackingplugin (https://github.com/CINPLA/tracking-plugin) and are save inbinaryformat only (not inopenephysformat).recording.spiketrainsis list ofSpikeTrainobjects, which in turn have atimes,waveforms,electrode_indices,clustersandmetadatafields. Spiketrains are saved by theSpike Viewersink in the Open Ephys GUI, in combination with either theSpike DetectorandSpike Viewer.With a few lines of code, the data and relevant information can be easily parsed and accessed:importpyopenephysimportmatplotlib.pylabaspltfile=pyopenephys.File("path-to-recording-folder")# experiment 1 (0 in Python)experiment=file.experiments[0]# recording 1recording=experiment.recordings[0]print('Duration: ',recording.duration)print('Sampling Rate: ',recording.sample_rate)analog_signals=recording.analog_signalsevents_data=recording.eventsspiketrains=recording.spiketrains# tracking_data are accessible only using binary formattracking_data=recording.tracking# plot analog signal of channel 4signals=analog_signals[0]fig_an,ax_an=plt.subplots()ax_an.plot(signals.times,signals.signal[3])# plot raster for spike trainsfig_sp,ax_sp=plt.subplots()fori_s,spinenumerate(spiketrains):ax_sp.plot(sp.times,i_s*np.ones(len(sp.times)),'|')plt.show()