PennLINC / xcpEngine

Official public repository for the XCP Engine. This tool is deprecated in favor of XCP-D and ASLPrep.
MIT License
66 stars 42 forks source link

Understanding interpolate and tmask #473

Open dhasegan opened 2 years ago

dhasegan commented 2 years ago

Describe the bug Hi, I am struggling to understand how tfilter and interpolate.py works. As described in this issue and based on what the code does, the tmask is set to 1 for timesteps to fix and its set to 0 for "good" timesteps that we will use for the interpolation.

At the same time, I look at my data and I have 12 timesteps at 0 and 1188 timesteps to be interpolated. And that is for all of my subjects and all tasks. I looked at my tasks and I definitely don't have that much motion.

Where can I find the script that generates the tmask?

dhasegan commented 2 years ago

here is my understanding after I analyzed core/functions/temporal_mask the script looks at the design file and loops for each of the framewise filters: confound2_framewise[2]=fds:0.278,dv:2 and it creates a final 1D file named {...}-nFlags.1D where it analyzes for each timepoints: value == 0 if the timepoint is within the threshold for both FD and DVARS value > 1 if the timepoint is greater the threshold for either FD or DVARS

I looked at my "-nFlags.1D" file:

nflags = '...-nFlags.1D'
d = np.loadtxt(nflags)
np.where(d == 1)

outputs:

(array([   1,    9,   10,   14,  462,  562,  793, 1007]),)

then the tmask is generated by doing a filter on this file:

'${XCPEDIR}/utils/tmask.R' -s ...-nFlags.1D -t 0.5 -o ..._tmask.1D -m 4

It seems that this gets inverted:

nflags = '..._tmask.1D'
d = np.loadtxt(nflags)
np.where(d == 0)

Output is:

(array([   0,    1,    9,   10,   11,   12,   13,   14,  462,  562,  793,
        1007]),)

Which makes sense because of the contiguous 4 timeframes, it adds 11,12,13 and 0.

Anyway, I start to believe that the tmask.R script that generates the ..._tmask.1D needs a -i flag to invert the results.