From 160ed6adcc7d8e4d147fc0e4971618943a80f072 Mon Sep 17 00:00:00 2001 From: Chris Langfield <34426450+chris-langfield@users.noreply.github.com> Date: Mon, 26 Feb 2024 11:08:31 -0500 Subject: [PATCH] drop in ibldsp (#729) Co-authored-by: chris-langfield --- brainbox/behavior/dlc.py | 2 +- brainbox/metrics/electrode_drift.py | 2 +- examples/archive/ibllib/synchronisation_ephys.py | 4 ++-- examples/loading_data/loading_raw_ephys_data.ipynb | 4 ++-- examples/one/histology/coverage_map.py | 2 +- ibllib/ephys/ephysqc.py | 2 +- ibllib/ephys/sync_probes.py | 4 ++-- ibllib/io/extractors/camera.py | 2 +- ibllib/io/extractors/ephys_fpga.py | 10 +++++----- ibllib/io/extractors/fibrephotometry.py | 2 +- ibllib/io/extractors/training_audio.py | 4 ++-- ibllib/io/extractors/training_wheel.py | 2 +- ibllib/io/extractors/video_motion.py | 2 +- ibllib/io/raw_daq_loaders.py | 8 ++++---- ibllib/pipes/ephys_preprocessing.py | 2 +- ibllib/pipes/ephys_tasks.py | 2 +- ibllib/pipes/histology.py | 2 +- ibllib/plots/figures.py | 4 ++-- ibllib/plots/misc.py | 2 +- ibllib/tests/test_ephys.py | 2 +- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/brainbox/behavior/dlc.py b/brainbox/behavior/dlc.py index c7c42be92..bf85302e0 100644 --- a/brainbox/behavior/dlc.py +++ b/brainbox/behavior/dlc.py @@ -9,7 +9,7 @@ import scipy.interpolate as interpolate from scipy.stats import zscore -from neurodsp.smooth import smooth_interpolate_savgol +from ibldsp.smooth import smooth_interpolate_savgol from iblutil.numerical import bincount2D import brainbox.behavior.wheel as bbox_wheel diff --git a/brainbox/metrics/electrode_drift.py b/brainbox/metrics/electrode_drift.py index 3b2ac3bc1..f82ae9e55 100644 --- a/brainbox/metrics/electrode_drift.py +++ b/brainbox/metrics/electrode_drift.py @@ -1,6 +1,6 @@ import numpy as np -from neurodsp import smooth, utils, fourier +from ibldsp import smooth, utils, fourier from iblutil.numerical import bincount2D diff --git a/examples/archive/ibllib/synchronisation_ephys.py b/examples/archive/ibllib/synchronisation_ephys.py index b3580477f..e2ab8e4fb 100644 --- a/examples/archive/ibllib/synchronisation_ephys.py +++ b/examples/archive/ibllib/synchronisation_ephys.py @@ -1,4 +1,4 @@ -import neurodsp.utils +import ibldsp.utils import spikeglx import ibllib.io.extractors.ephys_fpga @@ -15,7 +15,7 @@ # if the data is needed as well, loop over the file # raw data contains raw ephys traces, while raw_sync contains the 16 sync traces -wg = neurodsp.utils.WindowGenerator(sr.ns, BATCH_SIZE_SAMPLES, overlap=1) +wg = ibldsp.utils.WindowGenerator(sr.ns, BATCH_SIZE_SAMPLES, overlap=1) for first, last in wg.firstlast: rawdata, rawsync = sr.read_samples(first, last) wg.print_progress() diff --git a/examples/loading_data/loading_raw_ephys_data.ipynb b/examples/loading_data/loading_raw_ephys_data.ipynb index 572c8de12..979e01c4c 100644 --- a/examples/loading_data/loading_raw_ephys_data.ipynb +++ b/examples/loading_data/loading_raw_ephys_data.ipynb @@ -236,7 +236,7 @@ "metadata": {}, "outputs": [], "source": [ - "from neurodsp.voltage import destripe\n", + "from ibldsp.voltage import destripe\n", "# Reminder : If not done before, remove first the sync channel from raw data\n", "# Apply destriping algorithm to data\n", "destriped = destripe(raw_ap, fs=sr_ap.fs)" @@ -445,7 +445,7 @@ "source": [ "## Useful modules\n", "* [ibllib.io.spikeglx](https://int-brain-lab.github.io/ibl-neuropixel/_autosummary/spikeglx.html)\n", - "* [ibllib.voltage.dsp](https://int-brain-lab.github.io/ibl-neuropixel/_autosummary/neurodsp.voltage.html)\n", + "* [ibllib.voltage.dsp](https://int-brain-lab.github.io/ibl-neuropixel/_autosummary/ibldsp.voltage.html)\n", "* [brainbox.io.spikeglx.stream](https://int-brain-lab.github.io/iblenv/_autosummary/brainbox.io.spikeglx.html#brainbox.io.spikeglx.stream)\n", "* [viewephys](https://github.com/oliche/viewephys) to visualise raw data snippets (Note: this package is not within `ibllib` but standalone)" ] diff --git a/examples/one/histology/coverage_map.py b/examples/one/histology/coverage_map.py index 31d60aa74..71ecfb213 100644 --- a/examples/one/histology/coverage_map.py +++ b/examples/one/histology/coverage_map.py @@ -1,7 +1,7 @@ import matplotlib.pyplot as plt import numpy as np from one.api import ONE -from neurodsp.utils import fcn_cosine +from ibldsp.utils import fcn_cosine import iblatlas.atlas as atlas from ibllib.pipes.histology import coverage diff --git a/ibllib/ephys/ephysqc.py b/ibllib/ephys/ephysqc.py index 6b8607ce9..65ec99f7e 100644 --- a/ibllib/ephys/ephysqc.py +++ b/ibllib/ephys/ephysqc.py @@ -11,7 +11,7 @@ from iblutil.util import Bunch import spikeglx import neuropixel -from neurodsp import fourier, utils, voltage +from ibldsp import fourier, utils, voltage from tqdm import tqdm from brainbox.io.spikeglx import Streamer diff --git a/ibllib/ephys/sync_probes.py b/ibllib/ephys/sync_probes.py index c02926fb6..3f3411479 100644 --- a/ibllib/ephys/sync_probes.py +++ b/ibllib/ephys/sync_probes.py @@ -199,7 +199,7 @@ def sync_probe_front_times(t, tref, sr, display=False, type='smooth', tol=2.0): to the sampling rate of digital channels. The residual is fit using frequency domain smoothing """ - import neurodsp.fourier + import ibldsp.fourier CAMERA_UPSAMPLING_RATE_HZ = 300 PAD_LENGTH_SECS = 60 STAT_LENGTH_SECS = 30 # median length to compute padding value @@ -214,7 +214,7 @@ def sync_probe_front_times(t, tref, sr, display=False, type='smooth', tol=2.0): res_filt = np.pad(res_upsamp, lpad, mode='median', stat_length=CAMERA_UPSAMPLING_RATE_HZ * STAT_LENGTH_SECS) fbounds = [0.001, 0.002] - res_filt = neurodsp.fourier.lp(res_filt, 1 / CAMERA_UPSAMPLING_RATE_HZ, fbounds)[lpad[0]:-lpad[1]] + res_filt = ibldsp.fourier.lp(res_filt, 1 / CAMERA_UPSAMPLING_RATE_HZ, fbounds)[lpad[0]:-lpad[1]] tout = np.arange(0, np.max(tref) + SYNC_SAMPLING_RATE_SECS, 20) sync_points = np.c_[tout, np.polyval(pol, tout) + np.interp(tout, t_upsamp, res_filt)] if display: diff --git a/ibllib/io/extractors/camera.py b/ibllib/io/extractors/camera.py index a44010821..5a2786b49 100644 --- a/ibllib/io/extractors/camera.py +++ b/ibllib/io/extractors/camera.py @@ -10,7 +10,7 @@ import matplotlib.pyplot as plt from iblutil.util import range_str -import neurodsp.utils as dsp +import ibldsp.utils as dsp from ibllib.plots import squares, vertical_lines from ibllib.io.video import assert_valid_label, VideoStreamer from iblutil.numerical import within_ranges diff --git a/ibllib/io/extractors/ephys_fpga.py b/ibllib/io/extractors/ephys_fpga.py index 009f68c52..e44239117 100644 --- a/ibllib/io/extractors/ephys_fpga.py +++ b/ibllib/io/extractors/ephys_fpga.py @@ -44,7 +44,7 @@ from packaging import version import spikeglx -import neurodsp.utils +import ibldsp.utils import one.alf.io as alfio from iblutil.util import Bunch from iblutil.spacer import Spacer @@ -160,11 +160,11 @@ def _sync_to_alf(raw_ephys_apfile, output_path=None, save=False, parts=''): file_ftcp = Path(output_path).joinpath(f'fronts_times_channel_polarity{uuid.uuid4()}.bin') # loop over chunks of the raw ephys file - wg = neurodsp.utils.WindowGenerator(sr.ns, int(SYNC_BATCH_SIZE_SECS * sr.fs), overlap=1) + wg = ibldsp.utils.WindowGenerator(sr.ns, int(SYNC_BATCH_SIZE_SECS * sr.fs), overlap=1) fid_ftcp = open(file_ftcp, 'wb') for sl in wg.slice: ss = sr.read_sync(sl) - ind, fronts = neurodsp.utils.fronts(ss, axis=0) + ind, fronts = ibldsp.utils.fronts(ss, axis=0) # a = sr.read_sync_analog(sl) sav = np.c_[(ind[0, :] + sl.start) / sr.fs, ind[1, :], fronts.astype(np.double)] sav.tofile(fid_ftcp) @@ -775,7 +775,7 @@ def _extract(self, sync=None, chmap=None, sync_collection='raw_ephys_data', bpod_start = self.bpod_trials['intervals'][:, 0] if len(t_trial_start) > len(bpod_start) / 2: # if least half the trial start TTLs detected _logger.warning('Attempting to get protocol period from aligning trial start TTLs') - fcn, *_ = neurodsp.utils.sync_timestamps(bpod_start, t_trial_start) + fcn, *_ = ibldsp.utils.sync_timestamps(bpod_start, t_trial_start) buffer = 2.5 # the number of seconds to include before/after task start, end = fcn(self.bpod_trials['intervals'].flat[[0, -1]]) tmin = min(sync['times'][0], start - buffer) @@ -1202,7 +1202,7 @@ def sync_bpod_clock(bpod_trials, fpga_trials, sync_field): bpod_fpga_timestamps[i] = trials[sync_field] # Sync the two timestamps - fcn, drift, ibpod, ifpga = neurodsp.utils.sync_timestamps(*bpod_fpga_timestamps, return_indices=True) + fcn, drift, ibpod, ifpga = ibldsp.utils.sync_timestamps(*bpod_fpga_timestamps, return_indices=True) # If it's drifting too much throw warning or error _logger.info('N trials: %i bpod, %i FPGA, %i merged, sync %.5f ppm', diff --git a/ibllib/io/extractors/fibrephotometry.py b/ibllib/io/extractors/fibrephotometry.py index e9cb60321..d11a5856e 100644 --- a/ibllib/io/extractors/fibrephotometry.py +++ b/ibllib/io/extractors/fibrephotometry.py @@ -25,7 +25,7 @@ from ibllib.io.extractors.base import BaseExtractor from ibllib.io.raw_daq_loaders import load_channels_tdms, load_raw_daq_tdms from ibllib.io.extractors.training_trials import GoCueTriggerTimes -from neurodsp.utils import rises, sync_timestamps +from ibldsp.utils import rises, sync_timestamps _logger = logging.getLogger(__name__) diff --git a/ibllib/io/extractors/training_audio.py b/ibllib/io/extractors/training_audio.py index 8d14fb00d..a3c57ac15 100644 --- a/ibllib/io/extractors/training_audio.py +++ b/ibllib/io/extractors/training_audio.py @@ -9,8 +9,8 @@ from scipy.io import wavfile -from neurodsp.utils import WindowGenerator -from neurodsp import fourier +from ibldsp.utils import WindowGenerator +from ibldsp import fourier import ibllib.io.raw_data_loaders as ioraw from ibllib.io.extractors.training_trials import GoCueTimes diff --git a/ibllib/io/extractors/training_wheel.py b/ibllib/io/extractors/training_wheel.py index 2f1aded8c..1d77d42e2 100644 --- a/ibllib/io/extractors/training_wheel.py +++ b/ibllib/io/extractors/training_wheel.py @@ -4,7 +4,7 @@ import numpy as np from scipy import interpolate -from neurodsp.utils import sync_timestamps +from ibldsp.utils import sync_timestamps from ibllib.io.extractors.base import BaseBpodTrialsExtractor, run_extractor_classes import ibllib.io.raw_data_loaders as raw from ibllib.misc import structarr diff --git a/ibllib/io/extractors/video_motion.py b/ibllib/io/extractors/video_motion.py index 482aaf44b..929f18b88 100644 --- a/ibllib/io/extractors/video_motion.py +++ b/ibllib/io/extractors/video_motion.py @@ -15,7 +15,7 @@ from pathlib import Path from joblib import Parallel, delayed, cpu_count -from neurodsp.utils import WindowGenerator +from ibldsp.utils import WindowGenerator from one.api import ONE import ibllib.io.video as vidio from iblutil.util import Bunch diff --git a/ibllib/io/raw_daq_loaders.py b/ibllib/io/raw_daq_loaders.py index 8ac58c3e7..54aa92cba 100644 --- a/ibllib/io/raw_daq_loaders.py +++ b/ibllib/io/raw_daq_loaders.py @@ -6,7 +6,7 @@ import nptdms import numpy as np -import neurodsp.utils +import ibldsp.utils import one.alf.io as alfio import one.alf.exceptions as alferr from one.alf.spec import to_alf @@ -134,7 +134,7 @@ def load_sync_tdms(path, sync_map, fs=None, threshold=2.5, floor_percentile=10): logger.info(f'estimated analogue channel DC Offset approx. {np.mean(offset):.2f}') analogue -= offset ttl = analogue > threshold - ind, sign = neurodsp.utils.fronts(ttl.astype(int)) + ind, sign = ibldsp.utils.fronts(ttl.astype(int)) try: # attempt to get the times from the meta data times = np.vstack([ch.time_track() for ch in raw_channels]) times = times[tuple(ind)] @@ -276,8 +276,8 @@ def extract_sync_timeline(timeline, chmap=None, floor_percentile=10, threshold=N step = threshold.get(label) if isinstance(threshold, dict) else threshold if step is None: step = np.max(raw - offset) / 2 - iup = neurodsp.utils.rises(raw - offset, step=step, analog=True) - idown = neurodsp.utils.falls(raw - offset, step=step, analog=True) + iup = ibldsp.utils.rises(raw - offset, step=step, analog=True) + idown = ibldsp.utils.falls(raw - offset, step=step, analog=True) pol = np.r_[np.ones_like(iup), -np.ones_like(idown)].astype('i1') ind = np.r_[iup, idown] diff --git a/ibllib/pipes/ephys_preprocessing.py b/ibllib/pipes/ephys_preprocessing.py index 9cfaa22e3..d13906e15 100644 --- a/ibllib/pipes/ephys_preprocessing.py +++ b/ibllib/pipes/ephys_preprocessing.py @@ -18,7 +18,7 @@ import packaging.version import one.alf.io as alfio -from neurodsp.utils import rms +from ibldsp.utils import rms import spikeglx from ibllib.misc import check_nvidia_driver diff --git a/ibllib/pipes/ephys_tasks.py b/ibllib/pipes/ephys_tasks.py index 7affc7139..925839073 100644 --- a/ibllib/pipes/ephys_tasks.py +++ b/ibllib/pipes/ephys_tasks.py @@ -10,7 +10,7 @@ import pandas as pd import spikeglx import neuropixel -from neurodsp.utils import rms +from ibldsp.utils import rms import one.alf.io as alfio from ibllib.misc import check_nvidia_driver diff --git a/ibllib/pipes/histology.py b/ibllib/pipes/histology.py index ccf7ade22..a07b99985 100644 --- a/ibllib/pipes/histology.py +++ b/ibllib/pipes/histology.py @@ -11,7 +11,7 @@ from ibllib.ephys.spikes import probes_description as extract_probes from ibllib.qc import base -from neurodsp.utils import fcn_cosine +from ibldsp.utils import fcn_cosine _logger = logging.getLogger(__name__) diff --git a/ibllib/plots/figures.py b/ibllib/plots/figures.py index 34a444e9b..369709db1 100644 --- a/ibllib/plots/figures.py +++ b/ibllib/plots/figures.py @@ -12,7 +12,7 @@ import scipy.signal import matplotlib.pyplot as plt -from neurodsp import voltage +from ibldsp import voltage from ibllib.plots.snapshot import ReportSnapshotProbe, ReportSnapshot from one.api import ONE import one.alf.io as alfio @@ -614,7 +614,7 @@ def raw_destripe(raw, fs, t0, i_plt, n_plt, ''' # Import - from neurodsp import voltage + from ibldsp import voltage from ibllib.plots import Density # Init fig diff --git a/ibllib/plots/misc.py b/ibllib/plots/misc.py index 2a561ae8d..022e0c43f 100644 --- a/ibllib/plots/misc.py +++ b/ibllib/plots/misc.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt import scipy -import neurodsp as dsp +import ibldsp as dsp def wiggle(w, fs=1, gain=0.71, color='k', ax=None, fill=True, linewidth=0.5, t0=0, clip=2, sf=None, diff --git a/ibllib/tests/test_ephys.py b/ibllib/tests/test_ephys.py index 5e024c6f9..d852b34f5 100644 --- a/ibllib/tests/test_ephys.py +++ b/ibllib/tests/test_ephys.py @@ -7,7 +7,7 @@ from one.api import ONE import neuropixel -from neurodsp import voltage +from ibldsp import voltage from ibllib.ephys import ephysqc, spikes from ibllib.tests import TEST_DB