------------------------------------------------
 The SessionsTools -> Combine 3D Phase Stats
 menu averages fourier-analyzed 3D stats
------------------------------------------------
This panel creates a new scan directory that will
contain averaged 3D fourier-based statistics.

Configure Buttons--Make CombineDir, Unset Dir

First carefully choose a name for the average
directory in the entry to the right of the Make
CombineDir button.  Clicking Make CombineDir
creates that directory.  If the directory already
exists, it will be re-used rather than
re-created.

To ignore an existing 3D phase average directory,
use Unset Dir.  The files in the unset directory
will not be altered and any saved parameters will
re-appear if you click Make CombineDir with that
directory name again.

The 3D stats files are combined voxel-by-voxel,
which ignores the funct=>struct transformation
matrix (register.dat).  The transformation matrix
for the combined file is copied from the *first*
stats set in the combine list.  This
transformation matrix gets used when the combined
file is PAINT'ed.  Be sure to re-COMBINE in order
to redo this copy operation if you go back and
touch up the transformation matrix from the
firstan input stat set (adjustments to later stat
sets in the list are ignored) and you want the
that modified transformation matrix to be used
for the PAINT in this panel.

Choosing Stat Files to Average

A list of currently available fourier-analyzed
functional scans can be found in the "Select to
Add" dropdown combobox.  Selecting one of them
will add it to the "ScansToCombine" list.  To
delete (or re-order) a directory from that list,
select it in the list and then use the Delete or
Backspace key.

Reversing Phase of Stat Files

If scans to be combined do not have the same
phase direction (e.g., clockwise vs. counter-
clockwise direction of the moving sector in a
polar angle mapping experiment), the phase of one
or more scans can be reversed by selecting the
scan to be reversed, and then typing Return (or
double-clicking).  "Reversing the phase" means
taking the negative of the phase angle calculated
for each voxel.  This is equivalent to reversing
the direction of time in the time domain.

Combine Operations

Now select a combine operation.  The operation
'phaseaverage' calculates the voxel-by-voxel
vector average of the the complex-valued data
(separately average real and imaginary
components).  The operation 'phasecancel'
calculates the voxel-by-voxel angular average
and then separately averages the amplitudes
(separately average phase and amplitude
components).  In the first case, if two vectors
with large amplitude have very different angles,
the amplitude of their vector average will be
small; in the second case, it will be large.
Thus, the 'phaseaverage' operation more strongly
penalizes voxels with inconsistent phase in the
component scans.  Currently, the 'phasecancel'
operation can only combine two scans.

Offset

The measured response phase consists of a
stimulus phase plus a hemodynamic delay phase.
If scans are combined with opposite directions of
phase, the hemodynamic delay phase can be
subtracted out.  However, if the operation
'phaseaverage' is used, this will reduce the
amplitude of the vector average (there is no
effect of a hemodynamic delay on the
'phasecancel' operation and no effect of a
non-zero offset in this panel).  To avoid this
reduction in amplitude, an estimated average
hemodynamic delay (in units 0.0 to 1.0, where 1.0
equals one full stimulus cycle) can be applied
prior to the 'phaseaverage' operation.

Action Button--COMBINE

This button performs the 3D phase average of
the fourier-analyzed data sets that you have
selected and writes the result into the current
sig average directory as a new set of 3D files.

Action Button--PAINT

This button samples the combined data onto the
surface specified in "Surface for Sampling 3D
Data" in the Fourier panel.  The result is four
new files, two for each hemisphere, which consist
of the real and imaginary components of the
combined Fourier statistics (*.w files) which can
be directly displayed on the surface with View
Functional Data panel.  Note that this button
generates files for both hemispheres, regardless
of which hemisphere is currently selected.

Input and Output Files

 infiles (Fourier-analyzed files--complex data):

   -----------------------------------------
   session1/scandir1/scanname1_r_%03d.bfloat 
   session1/scandir1/scanname1_i_%03d.bfloat 
   -----------------------------------------
   session1/scandir2/scanname1_r_%03d.bfloat 
   session1/scandir2/scanname1_i_%03d.bfloat 
   -----------------------------------------
   ...


 outfiles (3D files--complex data):

   ---------------------------------------------
   currentsession/sigavg/scanname1_r_%03d.bfloat 
   currentsession/sigavg/scanname1_i_%03d.bfloat 
   ---------------------------------------------

 outfiles (paint files--complex data):

   ----------------------------------------
   currentsession/sigavg/scanname1_r-rh.w
   currentsession/sigavg/scanname1_i-lh.w
   ----------------------------------------
   currentsession/sigavg/scanname1_r-lh.w
   currentsession/sigavg/scanname1_i-lh.w
   ----------------------------------------

