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] - Add IRASA #212

Merged
merged 8 commits into from Aug 1, 2020
Merged

[ENH] - Add IRASA #212

merged 8 commits into from Aug 1, 2020

Conversation

TomDonoghue
Copy link
Member

Add an implementation of IRASA.

Note - this implementation is inspired by / draws from the one in YASA:
https://github.com/raphaelvallat/yasa/blob/master/yasa/spectral.py#L326

Reviews / ToDos:

  • @elybrand : if you feel like you have a sense of IRASA, can you check the implementation for technical sound-ness?
    • also, I wanted to add the implementation so you can play with it. Feel free to 'explore' it for a while before proper reviewing
  • @ryanhammonds : can you check the code elements & double check it is well organized to fit into NDSP
    • so far, there are no tests, so if you could add some code tests that would be great!
  • @rdgao : tagging you in since you've played with IRASA a bit - but nothing in particular needed!
    • thought you might be interested in checking it out / sanity checking the implementation!

Some quickstart code to try it (it seems to work in the simple case):

from neurodsp.aperiodic.irasa import *

from neurodsp.sim import sim_combined
from neurodsp.spectral import compute_spectrum, trim_spectrum
from neurodsp.plts import plot_power_spectra

n_seconds, fs = 10, 1000
sim_components = {'sim_powerlaw': {'exponent' : -2},
                  'sim_oscillation': {'freq' : 10}}
sig = sim_combined(n_seconds=n_seconds, fs=fs, components=sim_components)
f1, p1 = trim_spectrum(*compute_spectrum(sig, fs), [1, 30])

freqs, psd_ap, psd_pe = irasa(sig, fs, noverlap=int(2*fs))
b0, b1 = fit_irasa(freqs, psd_ap)

print('Estimated intercept & slope: {:1.3f}, {:1.3f}'.format(b0, b1))
plot_power_spectra([f1, freqs], [p1, psd_ap], labels=['Original', 'IRASA-AP'])

Creates this output:
Screen Shot 2020-07-23 at 2 00 48 PM

@TomDonoghue TomDonoghue added the 2.2 Updates to go into a 2.2.0 release label Jul 23, 2020
@ryanhammonds
Copy link
Member

@TomDonoghue Everything here looks good to me. I pushed tests updates.

Copy link
Contributor

@elybrand elybrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: there was a bug in my spline code.

So I was going to suggest following what Wen and Liu do for upsampling and downsampling, which is to use cubic splines to interpolate. I decided to try and implement this to compare against what is currently done using scipy.signal.resample_poly which filters and then imputes with zeroes. I was a bit surprised to find that the cubic spline method basically performs identically to the current way of upsampling and downsampling. I benchmarked on sum of sinusoids models with various central frequencies and the two methods differed very slightly but imperceptibly so. I did notice some interesting behavior with IRASA but I'll post that in an issue.

Anyways, I think what's currently implemented is good.

@TomDonoghue
Copy link
Member Author

Okay, this all looks sounds good to me!

@elybrand - thanks for the dive into the resampling! I was curious about the resampling approach here, and glad to see the different approaches seem equivalent! This is a a really nice sanity check to have.
@ryanhammonds - thanks for adding the tests! I mildly updated organization, if you want to sanity check that!

Some notes for myself:
This should be merged after #167. After that PR is merged, rebase here, and revisit for conflicts and check / update here for test signals updates; aperiodic init file; API listing, then this can also be merged.

@ryanhammonds
Copy link
Member

@TomDonoghue I went though your updates and everything looks good to me.

@TomDonoghue
Copy link
Member Author

This all seems good then - merging in!

@TomDonoghue TomDonoghue merged commit 875d000 into master Aug 1, 2020
@TomDonoghue TomDonoghue deleted the irasa branch August 1, 2020 03:48
@ryanhammonds ryanhammonds mentioned this pull request May 3, 2021
26 tasks
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.

None yet

3 participants