Skip to main content

Scripts for controlling devices/running experiments/analyzing data

Project description

SciScripts

Scripts for controlling devices/running experiments/analyzing data

Installation

$ pip install --user sciscripts

Or if you plan to contribute to the code / want to change the code and see the results on the fly / want the most up-to-date version:

$ git clone https://gitlab.com/malfatti/SciScripts/
$ cd SciScripts/
$ pip install --user asdf h5py matplotlib numpy pandas pyserial rpy2 scipy sounddevice
$ pip install --user -e .

Dependencies

  1. System:
    • Linux
    • xdpyinfo
  2. Python:
    • asdf
    • h5py
    • matplotlib
    • numpy
    • pandas
    • pyserial
    • rpy2
    • scipy
    • sounddevice

Also, some environment variables are expected to be set. You can add it to ~/.bashrc, or ~/.profile, or wherever your desktop environment searches for exported variables:

export DATAPATH=~/Data
export ANALYSISPATH=~/Analysis

changing the path to where you find appropriate.

Examples

Here is a walkthrough for the Example.py script.

Load data from an open-ephys recording folder:

In [1]: import numpy as np

In [2]: from sciscripts.IO import IO

In [3]: from sciscripts.Analysis import Analysis

In [4]: from sciscripts.Analysis.Plot import Plot

In [5]: Data, Rate = IO.DataLoader('DataSet/2018-08-13_13-25-45_1416')
Loading recording1 ...
Loading recording2 ...
Loading recording3 ...
Loading recording4 ...
Loading recording5 ...
Loading recording6 ...
Loading recording7 ...
Loading recording8 ...
Converting to uV...

In [6]: Data.keys()                     # Get open-ephys recording processors
Out[6]: dict_keys(['100'])

Select a recording and filter it:

In [7]: Rec0 = Data['100']['0']['0'][:,:16]  # Work with the 1st rec, 1st experiment and 1st 16ch

In [8]: Rate0 = Rate['100']['0']  # Rate for the 1st experiment

In [9]: Time0 = np.arange(Rec0.shape[0])/Rate0

In [10]: Rec0Theta = Analysis.FilterSignal(Rec0, Rate0, Frequency=[4,12], FilterOrder=2)
Filtering channel 1 ...
Filtering channel 2 ...
Filtering channel 3 ...
Filtering channel 4 ...
Filtering channel 5 ...
Filtering channel 6 ...
Filtering channel 7 ...
Filtering channel 8 ...
Filtering channel 9 ...
Filtering channel 10 ...
Filtering channel 11 ...
Filtering channel 12 ...
Filtering channel 13 ...
Filtering channel 14 ...
Filtering channel 15 ...
Filtering channel 16 ...

In [11]: Rec0Gamma = Analysis.FilterSignal(Rec0, Rate0, Frequency=[30,100], FilterOrder=3)
Filtering channel 1 ...
Filtering channel 2 ...
Filtering channel 3 ...
Filtering channel 4 ...
Filtering channel 5 ...
Filtering channel 6 ...
Filtering channel 7 ...
Filtering channel 8 ...
Filtering channel 9 ...
Filtering channel 10 ...
Filtering channel 11 ...
Filtering channel 12 ...
Filtering channel 13 ...
Filtering channel 14 ...
Filtering channel 15 ...
Filtering channel 16 ...

Plot all channels from raw and filtered data:

In [12]: Plot.AllCh(Rec0[:int(Rate0*0.05),:], Save=True, File='Plot1', Ext=['png'])

In [13]: # Set plot window for each band
    ...: Window = int(Rate0)
    ...: 
    ...: # Plot
    ...: plt = Plot.Return('plt')
    ...: Fig, Axes = plt.subplots(1,3)
    ...: Axes[0] = Plot.AllCh(Rec0[:Window,:], Time0[:Window], Ax=Axes[0], lw=0.7)
    ...: Axes[1] = Plot.AllCh(Rec0Theta[:Window,:], Time0[:Window], Ax=Axes[1], lw=0.7)
    ...: Axes[2] = Plot.AllCh(Rec0Gamma[:Window,:], Time0[:Window], Ax=Axes[2], lw=0.7)
    ...: 
    ...: # Set labels
    ...: AxArgs = {'xlabel': 'Time [s]'}
    ...: for Ax in Axes: 
    ...:    Plot.Set(Ax=Ax, AxArgs=AxArgs)
    ...: 
    ...: Axes[0].set_ylabel('Voltage [µv]')
    ...: Axes[0].set_title('Raw signal')
    ...: Axes[1].set_title('Theta [4-12Hz]')
    ...: Axes[2].set_title('Gamma [30-100Hz]')
    ...:
    ...: Plot.Set(Fig=Fig)
    ...: Fig.savefig('Plot2.png')
    ...: plt.show()

Scripts using this package for real experiments and analysis can be found here and here, respectively.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sciscripts-3.0.3.tar.gz (266.1 kB view hashes)

Uploaded Source

Built Distribution

sciscripts-3.0.3-py3-none-any.whl (133.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page