I’m trying to perform a ‘moving accumulation’ (the best descriptor I can think of at the moment). I think similar to ‘3dcalc -accumulate’ but I want to do this discretely. For example, I would like to sum every two values along time. And repeat the calculation for all 3D. In matlab, the most simple, equivalent command I could think of for a single timeseries was (timeseries of 190 points):
I read through the 3dcalc documentation and could not clearly see how this could be done. Any guidance or help with this would be greatly appreciated. Thank you!
You should be able to get this done with either 3dcalc or 3dTsmooth.
this command uses relative indexing for the ‘b’ dataset.
The “a-l” uses the “minus ell” to refer to the previous time index
for the following time index instead, use “a+l” (“a plus ell”)
3dcalc -a epi_r1+orig -b a-l -expr ‘a+b’ -prefix rm_3dcalc_sum2.nii.gz -overwrite
make a single column of the temporal kernel
(must have an odd number, so put 0 on the 3rd line for the following time index coefficient)
cat > sum2.1D
3dTsmooth -custom sum2.1D -prefix rm_tsmooth_sum2.nii.gz epi_r1+orig.
Thank you very much for answering this! I have a question about the 3dcalc operation:
I don’t to repeat indices if they’ve already been summed. e.g. I want to only sum points 1 & 2, then 3 &4, 5& 6, and so on. Not 1 & 2, then 2&3, then 3&4, etc. as is done in the above setting. Thus my new data set would have a reduced time length of n_t/2 where n_t is the number of time points in the original data set. In the 3dcalc, is it possible to make the ‘b’ data set to be ‘2*a-l’. That is an invalid operation, I’ve come to find, but something like that would be great.
I suppose I could try to collect every 2nd point of the output data set from the above command you listed with 3dcalc, but I’m not sure how to do that either.
Thank you for your help!
I just figured out a way to do it:
3dcalc -a epi_r1+‘orig[0…(2)]’ -b epi_r1+‘orig[1…(2)]’ -expr ‘a+b’ -prefix rm_3dcalc_sum2.nii.gz -overwrite
I might eventually want to sum ever 3 or 4 points together which I can add variables ‘c’ and ‘d’ and the adjusted above notation to do it. But if there’s any more simple way to do it, would be interested to know. Thank you again for your time!
It occurred to me after I posted that you might really want something like that instead. You can extract every other volume (either evens or odds) from the first method’s results, or do the extraction all within 3dcalc in one step. Averaging and differences this way are relatively simple. Similar kinds of commands are often needed for ASL processing:
Ah, thank you for the link! I do very much appreciate that.
All the best!