vu-cog-sci / nideconv Goto Github PK
View Code? Open in Web Editor NEWfit response shapes from signal time-courses
License: MIT License
fit response shapes from signal time-courses
License: MIT License
pip install git+https://github.com/VU-Cog-Sci/nideconv
on Win10 command line results in:
Collecting pymc3
Using cached pymc3-3.9.2-py3-none-any.whl (1.9 MB)
Collecting pystan
Using cached pystan-2.19.1.1.tar.gz (16.2 MB)
ERROR: Command errored out with exit status 1:
command: 'C:\Users\Michl\Anaconda3\envs\MRI\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Michl\AppData\Local\Temp\pip-install-3xi56cdq\pystan\setup.py'"'"'; file='"'"'C:\Users\Michl\AppData\Local\Temp\pip-install-3xi56cdq\pystan\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Michl\AppData\Local\Temp\pip-pip-egg-info-0_lovt0b'
cwd: C:\Users\Michl\AppData\Local\Temp\pip-install-3xi56cdq\pystan
Complete output (5 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Michl\AppData\Local\Temp\pip-install-3xi56cdq\pystan\setup.py", line 122, in
from Cython.Build.Inline import _get_build_extension
ModuleNotFoundError: No module named 'Cython'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I am able to install it from older commits.
After installing Cython manually, pystan fails building a wheel. The error is absurdly long, so I dont post it here.
I followed the installation instructions. bids package was missing after I completed instructions (created env, installed prerequisites.)
It seems bids should be added to prerequisites.
Should try to develop a way of setting up contrasts between time-courses, so that the time-courses are for the contrast between two factors. This would be awesome.
I could only run fmriprep with skipping bids validation. I want to extract TS on ROI.
I get the error below.
Should invalid_filters="allow" flag be modifiable via the get_fmriprep_timeseries function arguments as a workaround for this?
/miniconda3/envs/nideconv/lib/python3.9/site-packages/bids/layout/layout.py", line 619, in get
raise ValueError(msg + "If you're sure you want to impose "
ValueError: 'extensions' is not a recognized entity. Did you mean ['extension']? If you're sure you want to impose this constraint, set invalid_filters='allow'.
Dear Experts,
After fitting the model with g_model.fit(), how can a user extract the parameter estimates?
For example, when I fit a canonical HRF I would like to extract the parameter estimate by which this canonical HRF is weighted for each condition.
Similarly, if I fit a Fourier series with 9 waves, I would expect 9 parameters per condition per individual.
The reason I want to do this is that I am trying to get to a measure of response for each condition and individual. One way of doing this would be to calculate the integral for the timeseries of each condition for each individual. But I would also like to try the more common approach used in neuroimaging of extracting parameter estimates.
Thank you very much!
I add each trial_type as event to the GroupResponseFitter and get a tuple error when trying to add the first event.
Same issue when I use data of a single subject or when data of multiple subjects is concatenated.
For:
g_model = nideconv.GroupResponseFitter(data_allsubs, design_allsubs, 1/.7,
concatenate_runs=False, confounds=confounds_allsubs)
for _, key in enumerate(design_allsubs['trial_type'].unique()):
print(key)
g_model.add_event(key, interval=[0, 19.6], basis_set='fourier', n_regressors=7)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-109-21c17ee79f72> in <module>
1 for _, key in enumerate(design_allsubs['trial_type'].unique()):
2 print(key)
----> 3 g_model.add_event(key, interval=[0, 19.6], basis_set='fourier', n_regressors=7)
~/anaconda3/envs/fMRI_NRosT/lib/python3.7/site-packages/nideconv/group_analysis.py in add_event(self, event, basis_set, interval, n_regressors, covariates, add_intercept, **kwargs)
143 n_regressors=n_regressors,
144 durations=durations,
--> 145 covariates=covariate_matrix)
146
147
~/anaconda3/envs/fMRI_NRosT/lib/python3.7/site-packages/nideconv/response_fitter.py in add_event(self, event_name, onset_times, basis_set, interval, n_regressors, durations, covariates, **kwargs)
130 covariates=covariates,
131 fitter=self,
--> 132 **kwargs)
133
134 self._add_regressor(ev)
~/anaconda3/envs/fMRI_NRosT/lib/python3.7/site-packages/nideconv/regressors.py in __init__(self, name, fitter, basis_set, interval, n_regressors, onset_times, durations, covariates)
196
197 if covariates is None:
--> 198 self.covariates = pd.DataFrame({'intercept': np.ones(self.onset_times.shape[0])})
199 else:
200 self.covariates = pd.DataFrame(covariates)
IndexError: tuple index out of range
Dear Experts,
Thank you very much for this very useful and elegant library!
I have a question about how the time series is/should be scaled before input in the analysis.
Since the fMRI signal is unitless, the various tools that people use for fMRI GLMs (FSL, SPM etc.), have all their own different ways of scaling the time series data before fitting the GLM. For example, FSL makes the average time series values across the whole brain = 10,000, whereas SPM sets this mean to 100.
Recently, I have also found that softwares like FSL featquery and SPM marsbar have pretty complicated ways of calculating the % signal change in response to a condition or a contrast based on a GLM, while taking into account the scaling that was applied before.
Besides what is done in these toolboxes, when working with region of interest data, different people seem to do different things. For example, some people scale the raw ROI signal to "percent signal change": scaled_signal = signal/mean * 100. Others use z-scores: scaled_signal= signal-mean/standard deviation.
My question to you is: what scaling is done in nideconv before fitting the GLM? Also, does the convolved response to the condition have units such as "% signal change"? If so, how are they calculated? I ask this because I noticed that in your documentation, "percent signal change" is referenced in the plot here: https://nideconv.readthedocs.io/en/latest/tutorials/plot_what_is_deconvolution.html , but then is never used again in the subsequent plots or tutorials.
Similarly, I would like to know if any scaling is done in the functions you provide to extract the BOLD time series, before fitting the GLM.
If the tool does not do any scaling, is there one that you would recommend?
Thank you very much!
Yours sincerely,
Leonardo Tozzi
Following the examples on readthedocs.io I get an error when applying the get_timecourses()
functions to the fitted objects.
The betas can not be grouped by event type
when returned (line 436 in regressors.py
).
Hi Gilles,
The response_fytter.get_timecourses() function gives a value shape error when using the legendre polynomials basis set. I'm attaching a document with the code I've used for setting it up and the traceback of the error.
The shape implies that there might be doubling up of oversampling (using the default oversample_design_matrix=20). At the end of the doc there's adapted code where I've removed that and it seems to work.
A related minor issue is that it seems that the confounds need to be removed again after the regression for the response_fytter.get_timecourses() function to work.
Cheers,
Bronagh
Hey,
Just a heads-up that import pystan
is import stan
with python>3.9 and pystan>3.0 in https://github.com/VU-Cog-Sci/nideconv/blob/master/nideconv/hierarchical_bayes/backends.py.
See: facebook/prophet#401 (comment)
Jurjen
Right now GroupResponseFitter doesn't return time courses per run when I do grf.get_timecourses(). Instead, it gives the same output as get_subjectwise_timecourses, which it shouldn't.
Dear developers (hi Tomas)
my installation on a Mac M3
Python 3.9.19 (main, Mar 21 2024, 12:07:41)
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
conda create --name nideconv
conda activate nideconv
conda install numpy scikit-learn pystan
pip install git+https://github.com/VU-Cog-Sci/nideconv
fails with the following messages:
pip install git+https://github.com/VU-Cog-Sci/nideconv
Collecting git+https://github.com/VU-Cog-Sci/nideconv
Cloning https://github.com/VU-Cog-Sci/nideconv to /private/var/folders/k8/w6f23_rx489b8ttd_trmscwc0000gn/T/pip-req-build-99el_gp1
Running command git clone --filter=blob:none --quiet https://github.com/VU-Cog-Sci/nideconv /private/var/folders/k8/w6f23_rx489b8ttd_trmscwc0000gn/T/pip-req-build-99el_gp1
Resolved https://github.com/VU-Cog-Sci/nideconv to commit bdee405
Preparing metadata (setup.py) ... done
Requirement already satisfied: cython in ./anaconda3/envs/nideconv/lib/python3.9/site-packages (from nideconv==0.1rc6) (3.0.10)
Requirement already satisfied: numpy in ./anaconda3/envs/nideconv/lib/python3.9/site-packages (from nideconv==0.1rc6) (1.26.4)
Requirement already satisfied: scipy in ./anaconda3/envs/nideconv/lib/python3.9/site-packages (from nideconv==0.1rc6) (1.12.0)
Collecting sklearn (from nideconv==0.1rc6)
Downloading sklearn-0.0.post12.tar.gz (2.6 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [15 lines of output]
The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
rather than 'sklearn' for pip commands.
Here is how to fix this error in the main use cases:
- use 'pip install scikit-learn' rather than 'pip install sklearn'
- replace 'sklearn' by 'scikit-learn' in your pip requirements files
(requirements.txt, setup.py, setup.cfg, Pipfile, etc ...)
- if the 'sklearn' package is used by one of your dependencies,
it would be great if you take some time to track which package uses
'sklearn' instead of 'scikit-learn' and report it to their issue tracker
- as a last resort, set the environment variable
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True to avoid this error
More information is available at
https://github.com/scikit-learn/sklearn-pypi-package
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
I also tried with setting the environment variable
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True
but got the same results.
Can you help?
Best,
Jens
This is a mess. We have to make some checks and balances that correct misuse.
Hi,
Thank you for building this tool! I'm using fMRI and was wondering if it is possible to export deconvolved timeseries using deconv. I have input timeseries and onsets for one subject and fit using 'fir'.
Thank you very much, appreciate your answer.
Best,
The master
-branch now is very dated. It should be updated, including documentation.
concatenated response fitters don't allow the getting of rsq values, bc get_rsq function doesn't keep track of whether a concatenatedresponsefitter or a normal responsefitter did the actual fitting... Will look at this more together with @gjheij.
We need to have a catchy name for this package.
Current candidates:
@mszinte , @tknapen , @daanvanes @mccoy4b: any thoughts?
People at HBM attended me to the fact that deconvolution
in nideconv
can be a bit confusing, because it's not really what the package is designed to do. Maybe we should come up with a new name again or regress to `response_fitter.
I encountered a bug in which fitting a model leads to an emtpy model. I've created a jupyter notebook to demonstrate the issue. see starting at In [7]
here: bug_report.pdf
I debug stepped into the GroupResponseFitter and to me it appears as everything works correctly so my assumption is something goes wrong when fitting?
When creating a time course plot of multiple event types, they will get different colours in the plot but the lines in the legend will all have the same colour.
Hi,
The events I want to fit are quite short. Most of them have a duration of less than 1 second (I use response time as duration as the stimuli were on screen until a response was given). So far, I used FIRDeconvolution to model my data, and there I got reasonable results. Now, I tried to use nideconv to do the same, but it didn't really work. After diving into the module, I realized that my design matrix contains only 0s for all regressors that are shorter than 1 second.
Just for trying it out, I replaced line 279 in regressor.get_timecourse with this line:
dt = int(math.ceil(d * self.sample_rate * oversample))
# after importing math
to make sure that my events at least last for one timepoint, and this seems to help to get at least some results out of the deconvolution. Whether it works properly, I can't say though (e.g. running fytter.get_rsq()
still gives NaN
).
I also noticed that the oversample_design_matrix
keyword in the init of the fytter
doesn't seem to really do anything in that part of the deconvolution, that is, when I dropped the shell in regressor.get_timecourse
, the variable oversample
was set to 1
, even though I initialized the fitter with the default of 20
. Is that intentional, or do I misunderstand what that variable is supposed to be doing?
Eduard
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.