cosanlab / nltools

Python toolbox for analyzing imaging data
https://nltools.org
MIT License
121 stars 44 forks source link

onsets_to_dim doesn't work properly for first several values #373

Closed chuanjigao closed 3 years ago

chuanjigao commented 3 years ago

Hi, Thank you for this excellent tool! I find it very useful. I have a question about the onsets_to_dim function:

I have this onsets pd Dataframe:

Onset Duration Stim 0.000 0 hoot 6.140 0 hoop 12.280 0 rim 24.560 0 soap 36.839 0 limb 42.979 0 coop 49.119 0 gene 61.399 0 rug ...

I want to construct a individual stimulus least square all design matrix using onsets_to_dm: tr = 3.07 n_tr = 180 dm = onsets_to_dm(onsets, sampling_freq=1/tr, run_length=n_tr)

However, the returned dm doesn't have indicators for first four stimuli: 'hoot', 'hoop', 'rim', 'soap', which means it's all zeros for the first four columns. But it marked starting from the fifth: 'limb' correctly. I appreciate if you can kindly point out what I'm missing here? Thank you, Chuanji

chuanjigao commented 3 years ago

Just post this in case someone has similar questions. It seems the reason why I did't have first one or two events marked in dm is because of onset = 0 and also the rounded down. Another way to get a design matrix object is to build a pandas dataframe (e.g., dm_pandas) yourself first, then input to Design_Matrix function (as shown in the source code of onsets_to_dm) if you want to get these convolve settings etc.: dm = Design_Matrix(dm_pandas, sampling_freq = 1/tr).