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

[ENH] Plot spectra accepts 2d arrays #269

Merged
merged 3 commits into from
Jul 30, 2021
Merged

[ENH] Plot spectra accepts 2d arrays #269

merged 3 commits into from
Jul 30, 2021

Conversation

ryanhammonds
Copy link
Member

@ryanhammonds ryanhammonds commented Jul 29, 2021

Before, plot_power_spectra only accepted 1d array or list of 1d array for freqs and powers. This adds support for 2d arrays. The requirement to call .tolist() on a 2d power array for plotting to work felt strange - espcially since compute_spectrum returns 2d arrays for 2d inputs.

import numpy as np
from neurodsp.sim import sim_oscillation
from neurodsp.spectral import compute_spectrum
from neurodsp.plts import plot_power_spectra

n_seconds = 10
fs = 1000
freqs = [10, 20]

# Simulate 2d array
sigs = np.zeros((2, n_seconds * fs))

for ind, freq in enumerate(freqs):
    sigs[ind] = sim_oscillation(n_seconds, fs, freq)

freqs, powers = compute_spectrum(sigs, fs)

# Freqs: list of 1d array
plot_power_spectra([freqs, freqs], powers)

# Freqs: 2d array
plot_power_spectra(np.array([freqs, freqs]), powers)

# Powers: list of 1d array
plot_power_spectra(freqs, [powers[0], powers[1]])

# Powers: 2d array
plot_power_spectra(freqs, powers)

@TomDonoghue
Copy link
Member

This looks like a super sensible and nice update! I left one small comment on the docs, otherwise, LGTM!

@TomDonoghue TomDonoghue added the 2.2 Updates to go into a 2.2.0 release label Jul 30, 2021
@ryanhammonds ryanhammonds merged commit c8e2691 into main Jul 30, 2021
@ryanhammonds ryanhammonds mentioned this pull request Jul 30, 2021
26 tasks
@ryanhammonds ryanhammonds deleted the plot branch July 30, 2021 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.2 Updates to go into a 2.2.0 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants