@stim_analyze 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/tcsh
  2. # try to find reasonable random event related timing given the experimental
  3. # parameters
  4. # ---------------------------------------------------------------------------
  5. # some experiment parameters (most can be inserted directly into the
  6. # make_random_timing.py command)
  7. set num_stim = 4
  8. set num_runs = 3
  9. set pre_rest = 10 # min rest before first stim (for magnet steady state)
  10. set post_rest = 12 # min rest after last stim (for trailing BOLD response)
  11. set min_rest = 2 # minimum rest after each stimulus
  12. set tr = 2.0 # used in 3dDeconvolve, if not make_random_timing.py
  13. # (options that take multiple values can also take just one if they are
  14. # all the same, such as with this example)
  15. #
  16. # set stim_durs = "2.25 2.25 2.25 2.25"
  17. # set stim_reps = "12 12 12 12"
  18. # set run_lengths = "300 300 300"
  19. set stim_durs = 0.75
  20. set stim_reps = 12
  21. set run_lengths = 300
  22. set labels = "label1 label2 label3 label4"
  23. # ---------------------------------------------------------------------------
  24. # execution parameters
  25. set iterations = 100 # number of iterations to compare
  26. set seed = 1234567 # initial random seed
  27. set outdir = stim_results # directory that all results are under
  28. set LCfile = NSD_sums # file to store norm. std. dev. sums in
  29. # set pattern = LC # search pattern for LC[0], say
  30. set pattern = 'norm. std.' # search pattern for normalized stdev vals
  31. # ===========================================================================
  32. # start the work
  33. # ===========================================================================
  34. # ------------------------------------------------------------
  35. # recreate $outdir each time
  36. if ( -d $outdir ) then
  37. echo "** removing output directory, $outdir ..."
  38. \rm -fr $outdir
  39. endif
  40. echo "++ creating output directory, $outdir ..."
  41. mkdir $outdir
  42. if ( $status ) then
  43. echo "failure, cannot create output directory, $outdir"
  44. exit
  45. endif
  46. # move into the output directory and begin work
  47. cd $outdir
  48. # create empty LC file
  49. echo -n "" > $LCfile
  50. echo -n "iteration (of $iterations): 0000"
  51. # ------------------------------------------------------------
  52. # run the test many times
  53. foreach iter (`count -digits 4 1 $iterations`)
  54. # make some other random seed
  55. @ seed = $seed + 1
  56. # create randomly ordered stimulus timing files
  57. # (consider: -tr_locked -save_3dd_cmd tempfile)
  58. make_random_timing.py -num_stim $num_stim -stim_dur $stim_durs \
  59. -num_runs $num_runs -run_time $run_lengths \
  60. -num_reps $stim_reps -prefix stimes.$iter \
  61. -pre_stim_rest $pre_rest -post_stim_rest $post_rest \
  62. -min_rest $min_rest \
  63. -stim_labels $labels \
  64. -seed $seed \
  65. -tr $tr \
  66. -show_timing_stats \
  67. -save_3dd_cmd cmd.3dd.$iter \
  68. >& out.mrt.$iter
  69. # consider: sed 's/GAM/"TENT(0,15,7)"/' tempfile > cmd.3dd.$iter
  70. # rm -f tempfile
  71. # now evaluate the stimulus timings
  72. tcsh cmd.3dd.$iter >& out.3dD.$iter
  73. # save the sum of the 3 LC values
  74. set nums = ( `awk -F= '/'"$pattern"'/ {print $2}' out.3dD.${iter}` )
  75. # make a quick ccalc command
  76. set sstr = $nums[1]
  77. foreach num ( $nums[2-] )
  78. set sstr = "$sstr + $num"
  79. end
  80. set num_sum = `ccalc -expr "$sstr"`
  81. echo -n "$num_sum = $sstr : " >> $LCfile
  82. echo "iteration $iter, seed $seed" >> $LCfile
  83. echo -n "\b\b\b\b$iter"
  84. end
  85. echo ""
  86. echo "done, results are in '$outdir', LC sums are in '$LCfile'"
  87. echo consider the command: "sort -n $outdir/$LCfile | head -1"
  88. # note that if iter 042 seems to be the best, consider these commands:
  89. #
  90. # cd stim_results
  91. # set iter = 042
  92. # timing_tool.py -multi_timing stimes.${iter}_0* \
  93. # -run_len $run_lengths -multi_stim_dur $stim_durs \
  94. # -multi_show_isi_stats
  95. # tcsh cmd.3dd.$iter
  96. # 1dplot X.xmat.1D'[6..$]'
  97. # 1dplot sum_ideal.1D
  98. #
  99. # - timing_tool.py will give useful statistics regarding ISI durations
  100. # (should be similar to what is seen in output file out.mrt.042)
  101. # - run cmd.3dd.$iter to regenerate that X martix (to create actual regressors)
  102. # - the first 1dplot command will show the actual regressors
  103. # (note that 6 = 2*$num_runs)
  104. # - the second will plot the sum of the regressor (an integrity check)
  105. # (note that sum_ideal.1D is produced by cmd.3dd.$iter, along with X.xmat.1D)