AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
Daniel Glen
January 29, 2008 12:59PM
There are a couple ways to accomplish this, but it requires a short script. Here's an example using 3dTstat to calculate a mean for groups of sub-bricks and then 3dTcat to put the separate volumes back together. You might consider changing that to a median across sub-bricks if you like. Just change the one line in the script.

Also you can use 3dTsmooth to smooth across time, and that will compress better for screen display. Another alternative is to use 3dTsmooth and then 3dcalc using a dataset with a counted sub-brick list as input. These links do some similar extractions and time selections that might be of interest.

[afni.nimh.nih.gov]
[afni.nimh.nih.gov]

#!/bin/tcsh
# extract_time.csh
if ("$1" == '' || "$1" == "-help" || "$1" == "-h") then
echo "Usage: A script to reduce a 3D+time dataset by computing "
echo " a mean sub-brick every n-interval sub-bricks from an AFNI dataset"
echo ""
echo " `basename $0` nth-interval <dsetname>"
echo ""
echo "The output dataset is saved as dsetprefix_extract+orig"
echo ""
goto END
endif

set interval = $1

set dset = `@GetAfniPrefix $2`
set outdset = ${dset}_extract
set nvals = `3dnvals ${2}`
@ nvals--
set TR = `3dAttribute "TAXIS_FLOATS" ${2} |awk '{print $2}'`
set TR = `ccalc "${TR} * ${interval}"`
# statistical operation - 'mean', 'median' or other option for 3dTstat
set stattype = 'mean'

# remove any existing output and temporary files
rm -f temp_${dset}_${stattype}*
rm -f $outdset+orig.*

echo "Extracting sub-brick volumes from $2"
echo "taking mean every ${interval}th sub-brick"
foreach subbrick (`count 0 $nvals $interval`)
@ endval = $subbrick + $interval - 1
if ($endval > $nvals) then
@ endval = $nvals
endif
3dTstat -"${stattype}" -prefix temp_${dset}_${stattype}_${subbrick} \
${2}".[${subbrick}..${endval}]"
end

# put all the separate time points into a single dataset
3dTcat -prefix ${outdset} temp_${dset}_${stattype}*.HEAD

# update the TR with the expanded TR
3drefit -TR ${TR} ${outdset}+orig

# clean up - remove temporary files
rm -f temp_${dset}_${stattype}*

END:

Subject Author Posted

What is a quick way to "bin" data from a time series

Jim Bjork January 29, 2008 10:24AM

Re: What is a quick way to "bin" data from a time series

Daniel Glen January 29, 2008 12:59PM

Re: What is a quick way to "bin" data from a time series

Jim Bjork January 29, 2008 02:30PM

Re: What is a quick way to "bin" data from a time series

Daniel Glen January 29, 2008 02:47PM

Re: What is a quick way to "bin" data from a time series

Jim Bjork January 29, 2008 04:25PM

Re: What is a quick way to "bin" data from a time series

Daniel Glen January 29, 2008 04:34PM