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  

|
May 08, 2018 10:56AM
Hi Rick,

Thank you very much for the very quick and helpful response! The script works like a charm now, but I still have a couple of questions.

A bit of background concerning the study:

- four conditions NMA NMS HMA HMS for a total of 160 stimuli
- 4 functional runs with 40 stimuli each + 56 null events of 10 secs (14 x run)
- TR = 2
- each stimulus comprises a video clip of 10 s + a response time (2 s)
- each stimulus starts with a fixation cross (500 - 4000m, jittered)

I am trying to employ @stim_analyze to maximize the efficiency of my design, but I have some questions I have been unable to solve:

1) What is the best way to model the response time (2s) after each video? Shall I add this as a separate condition? (at the moment I included this in the stimuli duration -12s total- but I really do not think this is optimal)

2) At the moment I did not model explicitly the null events or the fixation cross, but I simply "added" their duration in the run length. Is this correct?

3) I am a bit at loss in interpreting the outcome of 1dplot X.xmat.1D (attached); I understand that the first 4 rows are the 4 conditions, and then there are six rows for each run, but I do not understand what the x axis measures and why six rows per run?

4) out of curiosity: what exactly is a seed (i.e., how is the sequence randomization built from it)?

Thanks in advance for your valuable input.

Laura

############## SCRIPT ###############################

# /bin/tcsh

# try to find reasonable random event related timing given the experimental
# parameters

# ---------------------------------------------------------------------------
# some experiment parameters (most can be inserted directly into the
# make_random_timing.py command)

set num_stim = 4
set num_runs = 4
set pre_rest = 0 # min rest before first stim (for magnet steady state)
set post_rest = 10 # min rest after last stim (for trailing BOLD response)
set min_rest = 0.5 # minimum rest after each stimulus
set max_rest = 4 # max rest after each stimulus
set tr = 2.0 # used in 3dDeconvolve, if not make_random_timing.py

# (options that take multiple values can also take just one if they are
# all the same, such as with this example)

set stim_durs = "12 12 12 12"
set stim_reps = "10 10 10 10" # = 40 stimuli x condition
set run_lengths = "690 690 690 690"
set labels = "NMA NMS HMA HMS"

# ---------------------------------------------------------------------------
# execution parameters
set iterations = 1000 # number of iterations to compare
set seed = 1234567 # initial random seed
set outdir = /home/lama/stim_results # directory that all results are under
set LCfile = NSD_sums # file to store norm. std. dev. sums in

# set pattern = LC # search pattern for LC[0], say
set pattern = 'norm. std.' # search pattern for normalized stdev vals


# ===========================================================================
# start the work
# ===========================================================================

# ------------------------------------------------------------
# recreate $outdir each time

if ( -d $outdir ) then
echo "** removing output directory, $outdir ..."
\rm -fr $outdir
endif

echo "++ creating output directory, $outdir ..."
mkdir $outdir
if ( $status ) then
echo "failure, cannot create output directory, $outdir"
exit
endif

# move into the output directory and begin work
cd $outdir

# create empty LC file
echo -n "" > $LCfile

echo -n "iteration (of $iterations): 0000"

# ------------------------------------------------------------
# run the test many times

foreach iter(`count -digits 4 1 $iterations`)

# make some other random seed

@ seed = $seed + 1

# create randomly ordered stimulus timing files
# (consider: -tr_locked -save_3dd_cmd tempfile)

make_random_timing.py -num_stim $num_stim -stim_dur $stim_durs \
-num_runs $num_runs -run_time $run_lengths \
-num_reps $stim_reps -prefix stimes.$iter \
-pre_stim_rest $pre_rest -post_stim_rest $post_rest \
-min_rest $min_rest \
-max_rest $max_rest \
-stim_labels $labels \
-seed $seed \
-tr $tr \
-show_timing_stats \
-save_3dd_cmd cmd.3dd.$iter \
>& out.mrt.$iter

# consider: sed 's/GAM/"TENT(0,15,7)"/' tempfile > cmd.3dd.$iter
# rm -f tempfile

# now evaluate the stimulus timings

tcsh cmd.3dd.$iter >& out.3dD.$iter

# save the sum of the 3 LC values
set nums = ( `awk -F= '/'"$pattern"'/ {print $2}' out.3dD.${iter}` )

# make a quick ccalc command
set sstr = $nums[1]
foreach num ( $nums[2-] )
set sstr = "$sstr + $num"
end
set num_sum = `ccalc -expr "$sstr"`

echo -n "$num_sum = $sstr : " >> $LCfile
echo "iteration $iter, seed $seed" >> $LCfile

echo -n "\b\b\b\b$iter"
end

echo ""
echo "done, results are in '$outdir', LC sums are in '$LCfile'"
echo consider the command: "sort -n $outdir/$LCfile | head -1"

echo check summary stats with timing_tool.py

# note that if iter 0594 seems to be the best, consider these commands:

timing_tool.py -multi_timing stimes.${iter}_0* \
-run_len $run_lengths -multi_stim_dur $stim_durs \
-multi_show_isi_stats

# run 3d deconvolve
tcsh cmd.3dd.$iter

# plot results
1dplot X.xmat.1D '[6..$]'
1dplot sum_ideal.1D



Edited 1 time(s). Last edit at 05/09/2018 07:50AM by Laura Verga.
Attachments:
open | download - X.xmat.1d.png (20.5 KB)
Subject Author Posted

foreach error in @stim_analyze script

Laura Verga May 02, 2018 11:13AM

Re: foreach error in @stim_analyze script

rick reynolds May 02, 2018 05:31PM

Re: foreach error in @stim_analyze script Attachments

Laura Verga May 08, 2018 10:56AM

Re: foreach error in @stim_analyze script

rick reynolds May 14, 2018 10:12AM

Re: foreach error in @stim_analyze script

rick reynolds May 14, 2018 10:40AM

Re: foreach error in @stim_analyze script

Laura Verga June 04, 2018 08:39AM

Re: foreach error in @stim_analyze script

Laura Verga June 05, 2018 04:57AM

Re: foreach error in @stim_analyze script

rick reynolds June 05, 2018 04:34PM

Re: foreach error in @stim_analyze script

Laura Verga June 06, 2018 04:45AM

Re: foreach error in @stim_analyze script

rick reynolds June 08, 2018 09:12AM

Re: foreach error in @stim_analyze script

Laura Verga June 15, 2018 11:24AM