Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #64

Open
wants to merge 33 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5db013f
fix-62-63
alejoe91 Mar 7, 2024
10b17df
Fix register_button
alejoe91 Mar 8, 2024
ce02754
data_processing.py -> data_loader.py
alejoe91 Mar 8, 2024
4cee522
fix data loader import
alejoe91 Mar 8, 2024
4674634
Add unit name annotation in load_spiketrains
alejoe91 Mar 8, 2024
17dc78d
Add trial columns only if needed
alejoe91 Mar 9, 2024
8a32e86
Add trial columns only if needed2
alejoe91 Mar 9, 2024
278e086
Re-copy actions after failures
alejoe91 Mar 9, 2024
370123e
Re-copy actions after failures 2
alejoe91 Mar 9, 2024
fa7b780
Remove excess spikes
alejoe91 Mar 13, 2024
cee3c45
Merge branch 'bug-fixes' of github.com:CINPLA/expipe-plugin-cinpla in…
alejoe91 Mar 13, 2024
aa3b828
Add print statement
alejoe91 Mar 14, 2024
aeda526
fix registration with depth
alejoe91 Mar 14, 2024
6219b9c
Add log for adjustment and annotate tabs
alejoe91 Mar 14, 2024
78898b1
Remove excess spikes at the right place!
alejoe91 Mar 15, 2024
95d7ae7
Raise error for multiple experiments/openephys folders
alejoe91 Mar 15, 2024
3a0eab4
Sort actions in widget
alejoe91 Mar 15, 2024
ebd4b02
Fix spike train loader
alejoe91 Mar 15, 2024
c526f51
Set include_events to True and fix load_spiketrain for tetrodes
alejoe91 Apr 5, 2024
3ee8a8d
add tools for processing, unit tracking and notebook registration
lepmik Apr 6, 2024
5a449ca
correct channel avg
lepmik Apr 6, 2024
f9caf63
Speed up import time
alejoe91 Apr 8, 2024
e924703
bug in unit retrieval pluss some cleanup
lepmik Apr 15, 2024
6541759
bugfix
lepmik Apr 16, 2024
367f33f
Processing+Curation: extract waveforms from all spikes
alejoe91 Jun 6, 2024
1898ca4
set t[0] in tracking to zero
lepmik Jun 11, 2024
b3aad4e
redo last commit and make read unit id faster
lepmik Jun 11, 2024
87e12aa
possibility to get specific group
lepmik Jun 11, 2024
991f7fd
subtract relative session start time for all timestamps (session star…
lepmik Jun 14, 2024
9b1637e
remove session time subtraction
lepmik Jun 14, 2024
66447c7
bugfix
lepmik Jun 17, 2024
3497a51
Remove units with less than n_components spikes
alejoe91 Jun 20, 2024
dc8c5b6
Pin scikit-learn and fix tests
alejoe91 Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"neuroconv>=0.4.6",
"pyopenephys>=1.2.0",
"spikeinterface[full,widgets]>=0.100.0",
"scikit-learn<1.5.0",
"pynwb>=2.5.0",
"neuroconv>=0.4.6",
"ipywidgets>=8.1.1",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pyopenephys>=1.2.0
tbb>=2021.11.0
spikeinterface[full,widgets]>=0.100.0
pynwb>=2.6.0
neuroconv>=0.4.6
neuroconv>=0.4.6
3 changes: 0 additions & 3 deletions src/expipe_plugin_cinpla/cli/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from expipe_plugin_cinpla.cli.utils import validate_depth, validate_position, validate_angle, validate_adjustment


import spikeinterface.sorters as ss


def attach_to_register(cli):
### OpenEphys ###
@cli.command("openephys", short_help="Register an open-ephys recording-action to database.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import spikeinterface as si
import spikeinterface.extractors as se

from pynwb import NWBHDF5IO
from .utils import _get_data_path
from .scripts.utils import _get_data_path


def get_data_path(action):
Expand Down Expand Up @@ -92,6 +91,8 @@ def load_leds(data_path):
x1, y1, t1, x2, y2, t2, stop_time: tuple
The x and y positions of the red and green LEDs, the timestamps and the stop time
"""
from pynwb import NWBHDF5IO

io = NWBHDF5IO(str(data_path), "r")
nwbfile = io.read()

Expand Down Expand Up @@ -130,6 +131,10 @@ def load_lfp(data_path, channel_group=None, lim=None):
LFP: neo.AnalogSignal
The LFP signal
"""
from pynwb import NWBHDF5IO
# get the session start time
io = NWBHDF5IO(str(data_path), "r")
nwbfile = io.read()
recording_lfp = se.read_nwb_recording(
str(data_path), electrical_series_path="processing/ecephys/LFP/ElectricalSeriesLFP"
)
Expand Down Expand Up @@ -190,10 +195,11 @@ def load_epochs(data_path, label_column=None):
epochs: neo.Epoch
The trials as NEO epochs
"""
from pynwb import NWBHDF5IO

with NWBHDF5IO(str(data_path), "r") as io:
nwbfile = io.read()
trials = nwbfile.trials.to_dataframe()

start_times = trials["start_time"].values * pq.s
stop_times = trials["stop_time"].values * pq.s
durations = stop_times - start_times
Expand Down Expand Up @@ -248,6 +254,10 @@ def load_spiketrains(data_path, channel_group=None, lim=None):
spiketrains: list of NEO spike trains
The spike trains
"""
from pynwb import NWBHDF5IO
# get the session start time
io = NWBHDF5IO(str(data_path), "r")
nwbfile = io.read()
recording = se.read_nwb_recording(str(data_path), electrical_series_path="acquisition/ElectricalSeries")
sorting = se.read_nwb_sorting(str(data_path), electrical_series_path="acquisition/ElectricalSeries")

Expand All @@ -260,22 +270,25 @@ def load_spiketrains(data_path, channel_group=None, lim=None):
unit_id for unit_index, unit_id in enumerate(sorting.unit_ids) if groups[unit_index] == channel_group
]
sptr = []
# build neo pbjects
# build neo objects
for unit in unit_ids:
times = sorting.get_unit_spike_train(unit, return_times=True) * pq.s
spike_times = sorting.get_unit_spike_train(unit, return_times=True)
# subtract the session start time
spike_times = spike_times * pq.s
if lim is None:
times = recording.get_times() * pq.s
t_start = times[0]
t_stop = times[-1]
else:
t_start = pq.Quantity(lim[0], "s")
t_stop = pq.Quantity(lim[1], "s")
mask = (times >= t_start) & (times <= t_stop)
times = times[mask]
mask = (spike_times >= t_start) & (spike_times <= t_stop)
spike_times = spike_times[mask]

st = neo.SpikeTrain(
times=times, t_start=t_start, t_stop=t_stop, sampling_rate=sorting.sampling_frequency * pq.Hz
times=spike_times, t_start=t_start, t_stop=t_stop, sampling_rate=sorting.sampling_frequency * pq.Hz
)
st.annotations.update({"name": unit})
for p in sorting.get_property_keys():
st.annotations.update({p: sorting.get_unit_property(unit, p)})
sptr.append(st)
Expand Down Expand Up @@ -313,7 +326,7 @@ def load_unit_annotations(data_path, channel_group=None):
]

for unit in unit_ids:
annotations = {}
annotations = {"name": unit}
for p in sorting.get_property_keys():
annotations.update({p: sorting.get_unit_property(unit, p)})
units.append(annotations)
Expand Down
180 changes: 0 additions & 180 deletions src/expipe_plugin_cinpla/imports.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# import click
# from expipe.cliutils.misc import lazy_import

import expipe
from pathlib import Path

# @lazy_import
# def expipe():
# import expipe
# return expipe

# @lazy_import
# def pathlib():
# import pathlib
# return pathlib

local_root, _ = expipe.config._load_local_config(Path.cwd())
if local_root is not None:
Expand All @@ -23,171 +11,3 @@ class P:
config = {}

project = P


# @lazy_import
# def pd():
# import pandas as pd
# return pd

# @lazy_import
# def dt():
# import datetime as dt
# return dt

# @lazy_import
# def yaml():
# import yaml
# return yaml

# @lazy_import
# def ipywidgets():
# import ipywidgets
# return ipywidgets

# @lazy_import
# def pyopenephys():
# import pyopenephys
# return pyopenephys

# # @lazy_import
# # def openephys_io():
# # from expipe_io_neuro.openephys import openephys as openephys_io
# # return openephys_io

# @lazy_import
# def pyintan():
# import pyintan
# return pyintan

# @lazy_import
# def pyxona():
# import pyxona
# return pyxona

# @lazy_import
# def platform():
# import platform
# return platform

# @lazy_import
# def csv():
# import csv
# return csv

# @lazy_import
# def json():
# import json
# return json

# # @lazy_import
# # def axona():
# # from expipe_io_neuro import axona
# # return axona

# @lazy_import
# def os():
# import os
# return os

# @lazy_import
# def shutil():
# import shutil
# return shutil

# @lazy_import
# def datetime():
# import datetime
# return datetime

# @lazy_import
# def subprocess():
# import subprocess
# return subprocess

# @lazy_import
# def tarfile():
# import tarfile
# return tarfile

# @lazy_import
# def paramiko():
# import paramiko
# return paramiko

# @lazy_import
# def getpass():
# import getpass
# return getpass

# @lazy_import
# def tqdm():
# from tqdm import tqdm
# return tqdm

# @lazy_import
# def scp():
# import scp
# return scp

# @lazy_import
# def neo():
# import neo
# return neo

# @lazy_import
# def exdir():
# import exdir
# import exdir.plugins.quantities
# return exdir

# @lazy_import
# def pq():
# import quantities as pq
# return pq

# @lazy_import
# def logging():
# import logging
# return logging

# @lazy_import
# def np():
# import numpy as np
# return np

# @lazy_import
# def copy():
# import copy
# return copy

# @lazy_import
# def scipy():
# import scipy
# import scipy.io
# return scipy

# @lazy_import
# def glob():
# import glob
# return glob

# @lazy_import
# def el():
# import elephant as el
# return el

# @lazy_import
# def sys():
# import sys
# return sys

# @lazy_import
# def pprint():
# import pprint
# return pprint

# @lazy_import
# def collections():
# import collections
# return collections
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ def add_to_nwbfile(
rising = rising[:-1]

if len(rising) == len(falling):
nwbfile.add_trial_column(
name="channel",
description="Open Ephys channel",
)
nwbfile.add_trial_column(
name="processor",
description="Open Ephys processor that recorded the event",
)
if nwbfile.trials is None:
nwbfile.add_trial_column(
name="channel",
description="Open Ephys channel",
)
nwbfile.add_trial_column(
name="processor",
description="Open Ephys processor that recorded the event",
)
start_times = times[rising].rescale("s").magnitude
stop_times = times[falling].rescale("s").magnitude
for start, stop in zip(start_times, stop_times):
Expand Down
17 changes: 9 additions & 8 deletions src/expipe_plugin_cinpla/nwbutils/nwbwidgetsunitviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
import numpy as np
import ipywidgets as widgets
from ipywidgets import Layout, interactive_output
from pynwb.misc import Units
from pynwb.behavior import SpatialSeries

import matplotlib.pyplot as plt

from nwbwidgets.view import default_neurodata_vis_spec


color_wheel = plt.rcParams["axes.prop_cycle"].by_key()["color"]


class UnitWaveformsWidget(widgets.VBox):
def __init__(
self,
units: Units,
units: "pynwb.misc.Units",
):
super().__init__()

Expand Down Expand Up @@ -55,7 +51,7 @@ def on_unit_change(self, change):
self.unit_group_text.value = f"Group: {unit_group}"


def show_unit_waveforms(units: Units, unit_index=None, ax=None):
def show_unit_waveforms(units: "pynwb.mis.Units", unit_index=None, ax=None):
"""
TODO: add docstring

Expand Down Expand Up @@ -105,8 +101,8 @@ def show_unit_waveforms(units: Units, unit_index=None, ax=None):
class UnitRateMapWidget(widgets.VBox):
def __init__(
self,
units: Units,
spatial_series: SpatialSeries = None,
units: "pynwb.mis.Units",
spatial_series: "SpatialSeries" = None,
):
super().__init__()

Expand Down Expand Up @@ -186,6 +182,8 @@ def on_unit_change(self, change):
self.unit_group_text.value = f"Group: {unit_group}"

def get_spatial_series(self):
from pynwb.behavior import SpatialSeries

spatial_series = dict()
nwbfile = self.units.get_ancestor("NWBFile")
for item in nwbfile.all_children():
Expand Down Expand Up @@ -265,6 +263,9 @@ def show_unit_rate_maps(self, unit_index=None, spatial_series_selector=None, num


def get_custom_spec():
from pynwb.misc import Units
from nwbwidgets.view import default_neurodata_vis_spec

custom_neurodata_vis_spec = default_neurodata_vis_spec.copy()

# remove irrelevant widgets
Expand Down
Loading
Loading