Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Jul 19, 2024
2 parents a4b1ee8 + 117bb09 commit 59cf7ea
Show file tree
Hide file tree
Showing 26 changed files with 609 additions and 94 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -40,4 +40,6 @@ jobs:
run: |
pytest --doctest-modules --ignore=$MODULE_NAME/tests $MODULE_NAME
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
54 changes: 38 additions & 16 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
message: >-
If you use this software, please cite it using the metadata from this file.
type: software
title: 'neurodsp: neuro digital signal processing'
authors:
- given-names: 'Thomas'
family-names: 'Donoghue'
orcid: 'https://orcid.org/0000-0001-5911-0472'
- given-names: 'Ryan'
family-names: 'Hammonds'
orcid: 'https://orcid.org/0000-0002-5032-3241'
- given-names: 'Scott'
family-names: 'Cole'
orcid: 'https://orcid.org/0000-0002-6168-9951'
- given-names: 'Richard'
family-names: 'Gao'
orcid: 'https://orcid.org/0000-0001-5916-6433'
- given-names: 'Bradley'
family-names: 'Voytek'
orcid: 'https://orcid.org/0000-0003-1640-2525'
repository-code: 'https://github.com/neurodsp-tools/neurodsp'
url: 'https://neurodsp-tools.github.io/'
license: Apache-2.0
preferred-citation:
type: article
authors:
- family-names: "Cole"
given-names: "Scott"
orcid: "https://orcid.org/0000-0002-6168-9951"
- family-names: "Donoghue"
given-names: "Thomas"
orcid: "https://orcid.org/0000-0001-5911-0472"
- family-names: "Gao"
given-names: "Richard"
orcid: "https://orcid.org/0000-0001-5916-6433"
- family-names: "Voytek"
given-names: "Bradley"
orcid: "https://orcid.org/0000-0003-1640-2525"
doi: "10.21105/joss.01272"
journal: "Journal of Open Source Software"
- given-names: 'Scott'
family-names: 'Cole'
orcid: 'https://orcid.org/0000-0002-6168-9951'
- given-names: 'Thomas'
family-names: 'Donoghue'
orcid: 'https://orcid.org/0000-0001-5911-0472'
- given-names: 'Richard'
family-names: 'Gao'
orcid: 'https://orcid.org/0000-0001-5916-6433'
- given-names: 'Bradley'
family-names: 'Voytek'
orcid: 'https://orcid.org/0000-0003-1640-2525'
doi: '10.21105/joss.01272'
journal: 'Journal of Open Source Software'
month: 4
title: "NeuroDSP: A package for neural digital signal processing"
title: 'NeuroDSP: A package for neural digital signal processing'
issue: 36
volume: 4
year: 2019
Expand Down
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Spectral Power
compute_spectrum_welch
compute_spectrum_wavelet
compute_spectrum_medfilt
compute_spectrum_multitaper

Spectral Measures
~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 5 additions & 2 deletions neurodsp/aperiodic/autocorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import numpy as np
from scipy.optimize import curve_fit

from neurodsp.utils.decorators import multidim

###################################################################################################
###################################################################################################

@multidim()
def compute_autocorr(sig, max_lag=1000, lag_step=1, demean=True):
"""Compute the signal autocorrelation (lagged correlation).
Parameters
----------
sig : array 1D
sig : array
Time series to compute autocorrelation over.
max_lag : int, optional, default: 1000
Maximum delay to compute autocorrelations for, in samples.
Expand All @@ -24,7 +27,7 @@ def compute_autocorr(sig, max_lag=1000, lag_step=1, demean=True):
-------
timepoints : 1d array
Time points, in samples, at which autocorrelations are computed.
autocorrs : 1d array
autocorrs : array
Autocorrelation values, for across time lags.
Examples
Expand Down
20 changes: 11 additions & 9 deletions neurodsp/aperiodic/dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

from neurodsp.utils.data import split_signal
from neurodsp.utils.checks import check_param_options
from neurodsp.utils.decorators import multidim

###################################################################################################
###################################################################################################

@multidim(select=[0])
def compute_fluctuations(sig, fs, n_scales=10, min_scale=0.01, max_scale=1.0, deg=1, method='dfa'):
"""Compute a fluctuation analysis on a signal.
Parameters
----------
sig : 1d array
sig : array
Time series.
fs : float
Sampling rate, in Hz.
Expand All @@ -38,9 +40,9 @@ def compute_fluctuations(sig, fs, n_scales=10, min_scale=0.01, max_scale=1.0, de
-------
t_scales : 1d array
Time-scales over which fluctuation measures were computed.
fluctuations : 1d array
fluctuations : array
Average fluctuation at each scale.
result : float
result : float or 1d array
Slope of line in log-log when plotting time scales against fluctuations.
This is the alpha value for DFA, or the Hurst exponent for rescaled range.
Expand Down Expand Up @@ -101,20 +103,20 @@ def compute_fluctuations(sig, fs, n_scales=10, min_scale=0.01, max_scale=1.0, de

return t_scales, fluctuations, result


@multidim()
def compute_rescaled_range(sig, win_len):
"""Compute rescaled range of a given time series at a given scale.
Parameters
----------
sig : 1d array
sig : array
Time series.
win_len : int
Window length for each rescaled range computation, in samples.
Returns
-------
rs : float
rs : float or 1d array
Average rescaled range over windows.
Notes
Expand All @@ -140,13 +142,13 @@ def compute_rescaled_range(sig, win_len):

return rs


@multidim()
def compute_detrended_fluctuation(sig, win_len, deg=1):
"""Compute detrended fluctuation of a time series at the given window length.
Parameters
----------
sig : 1d array
sig : array
Time series.
win_len : int
Window length for each detrended fluctuation fit, in samples.
Expand All @@ -155,7 +157,7 @@ def compute_detrended_fluctuation(sig, win_len, deg=1):
Returns
-------
det_fluc : float
det_fluc : float or 1d array
Measured detrended fluctuation, as the average error fits of the window.
Notes
Expand Down
8 changes: 5 additions & 3 deletions neurodsp/aperiodic/irasa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
from scipy.optimize import curve_fit

from neurodsp.spectral import compute_spectrum, trim_spectrum
from neurodsp.utils.decorators import multidim

###################################################################################################
###################################################################################################

@multidim(select=[0])
def compute_irasa(sig, fs, f_range=None, hset=None, thresh=None, **spectrum_kwargs):
"""Separate aperiodic and periodic components using IRASA.
Parameters
----------
sig : 1d array
sig : array
Time series.
fs : float
The sampling frequency of sig.
Expand All @@ -36,9 +38,9 @@ def compute_irasa(sig, fs, f_range=None, hset=None, thresh=None, **spectrum_kwar
-------
freqs : 1d array
Frequency vector.
psd_aperiodic : 1d array
psd_aperiodic : array
The aperiodic component of the power spectrum.
psd_periodic : 1d array
psd_periodic : array
The periodic component of the power spectrum.
Notes
Expand Down
4 changes: 2 additions & 2 deletions neurodsp/burst/dualthresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def detect_bursts_dual_threshold(sig, fs, dual_thresh, f_range=None,
Parameters
----------
sig : 1d array
sig : array
Time series.
fs : float
Sampling rate, in Hz.
Expand All @@ -44,7 +44,7 @@ def detect_bursts_dual_threshold(sig, fs, dual_thresh, f_range=None,
Returns
-------
is_burst : 1d array
is_burst : array
Boolean indication of where bursts are present in the input signal.
True indicates that a burst was detected at that sample, otherwise False.
Expand Down
4 changes: 3 additions & 1 deletion neurodsp/filt/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
from neurodsp.filt.fir import filter_signal_fir
from neurodsp.filt.iir import filter_signal_iir
from neurodsp.utils.checks import check_param_options
from neurodsp.utils.decorators import multidim

###################################################################################################
###################################################################################################

@multidim(pass_2d_input=True)
def filter_signal(sig, fs, pass_type, f_range, filter_type=None,
print_transitions=False, plot_properties=False, return_filter=False,
**filter_kwargs):
"""Apply a bandpass, bandstop, highpass, or lowpass filter to a neural signal.
Parameters
----------
sig : 1d or 2d array
sig : array
Time series to be filtered.
fs : float
Sampling rate, in Hz.
Expand Down
4 changes: 2 additions & 2 deletions neurodsp/filt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ def remove_filter_edges(sig, filt_len):
Parameters
----------
sig : 1d array
sig : array
Filtered signal to have edge artifacts removed from.
filt_len : int
Length of the filter that was applied.
Returns
-------
sig : 1d array
sig : array
Filter signal with edge artifacts switched to NaNs.
Examples
Expand Down
1 change: 1 addition & 0 deletions neurodsp/plts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

## Define default values for aesthetics
# These are all custom style arguments
SUPTITLE_FONTSIZE = 24
TITLE_FONTSIZE = 20
LABEL_SIZE = 16
TICK_LABELSIZE = 16
Expand Down
78 changes: 78 additions & 0 deletions neurodsp/plts/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
"""Utility functions for plots."""

from copy import deepcopy
from functools import wraps
from os.path import join as pjoin

import matplotlib.pyplot as plt

from neurodsp.plts.settings import SUPTITLE_FONTSIZE

###################################################################################################
###################################################################################################

def subset_kwargs(kwargs, label):
"""Subset a set of kwargs from a dictionary.
Parameters
----------
kwargs : dict
Dictionary of keyword arguments.
label : str
Label to use to subset.
Any entries with label in the key will be subset from the kwargs dict.
Returns
-------
kwargs : dict
The kwargs dictionary, with subset items removed.
subset : dict
The collection of subset kwargs.
"""

kwargs = deepcopy(kwargs)

subset = {}
for key in list(kwargs.keys()):
if label in key:
subset[key] = kwargs.pop(key)

return kwargs, subset


def check_ax(ax, figsize=None):
"""Check whether a figure axes object is defined, define if not.
Expand Down Expand Up @@ -77,3 +109,49 @@ def save_figure(file_name, file_path=None, close=False, **save_kwargs):

if close:
plt.close()


def make_axes(n_rows, n_cols, figsize=None, row_size=4, col_size=3.6,
wspace=None, hspace=None, title=None, **plt_kwargs):
"""Make a subplot with multiple axes.
Parameters
----------
n_rows, n_cols : int
The number of rows and columns axes to create in the figure.
figsize : tuple of float, optional
Size to make the overall figure.
If not given, is estimated from the number of axes.
row_size, col_size : float, optional
The size to use per row / column.
Only used if `figsize` is None.
wspace, hspace : float, optional
Parameters for spacing between subplots.
These get passed into `plt.subplots_adjust`.
title : str, optional
A super title to add to the figure.
**plt_kwargs
Extra arguments to pass to `plt.subplots`.
Returns
-------
axes : 1d array of AxesSubplot
Collection of axes objects.
"""

if not figsize:
figsize = (n_cols * col_size, n_rows * row_size)

plt_kwargs, title_kwargs = subset_kwargs(plt_kwargs, 'title')

_, axes = plt.subplots(n_rows, n_cols, figsize=figsize, **plt_kwargs)

if wspace or hspace:
plt.subplots_adjust(wspace=wspace, hspace=hspace)

if title:
plt.suptitle(title,
fontsize=title_kwargs.pop('title_fontsize', SUPTITLE_FONTSIZE),
**title_kwargs)

return axes
Loading

0 comments on commit 59cf7ea

Please sign in to comment.