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

ibldsp drop in replacement #729

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion brainbox/behavior/dlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion brainbox/metrics/electrode_drift.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
4 changes: 2 additions & 2 deletions examples/archive/ibllib/synchronisation_ephys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import neurodsp.utils
import ibldsp.utils
import spikeglx
import ibllib.io.extractors.ephys_fpga

Expand All @@ -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()
4 changes: 2 additions & 2 deletions examples/loading_data/loading_raw_ephys_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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)"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/one/histology/coverage_map.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ibllib/ephys/ephysqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ibllib/ephys/sync_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ibllib/io/extractors/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions ibllib/io/extractors/ephys_fpga.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion ibllib/io/extractors/fibrephotometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
4 changes: 2 additions & 2 deletions ibllib/io/extractors/training_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ibllib/io/extractors/training_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ibllib/io/extractors/video_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ibllib/io/raw_daq_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion ibllib/pipes/ephys_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ibllib/pipes/ephys_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ibllib/pipes/histology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
4 changes: 2 additions & 2 deletions ibllib/plots/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ibllib/plots/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ibllib/tests/test_ephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading