Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

plug_stats.c File Reference

#include "afni.h"

Go to the source code of this file.


Defines

#define NUM_METHOD_STRINGS   (sizeof(method_strings)/sizeof(char *))
#define METH_MEAN   0
#define METH_SLOPE   1
#define METH_SIGMA   2
#define METH_CVAR   3

Functions

char * STATS_main (PLUGIN_interface *)
void STATS_tsfunc (double tzero, double tdelta, int npts, float ts[], double ts_mean, double ts_slope, void *ud, float *val)
DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface * PLUGIN_init (int ncall)

Variables

char helpstring []
char * method_strings [] = { "Mean" , "Slope" , "Sigma" , "CVar" }
PLUGIN_interface * global_plint = NULL

Define Documentation

#define METH_CVAR   3
 

Definition at line 38 of file plug_stats.c.

Referenced by STATS_tsfunc().

#define METH_MEAN   0
 

Definition at line 35 of file plug_stats.c.

Referenced by STATS_tsfunc().

#define METH_SIGMA   2
 

Definition at line 37 of file plug_stats.c.

Referenced by STATS_tsfunc().

#define METH_SLOPE   1
 

Definition at line 36 of file plug_stats.c.

Referenced by STATS_tsfunc().

#define NUM_METHOD_STRINGS   (sizeof(method_strings)/sizeof(char *))
 

Definition at line 33 of file plug_stats.c.

Referenced by PLUGIN_init(), and STATS_main().


Function Documentation

DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface* PLUGIN_init int    ncall
 

Definition at line 68 of file plug_stats.c.

References ANAT_ALL_MASK, FUNC_FIM_MASK, global_plint, helpstring, method_strings, NUM_METHOD_STRINGS, PLUTO_add_hint(), PLUTO_set_sequence(), and STATS_main().

00069 {
00070    PLUGIN_interface * plint ;     /* will be the output of this routine */
00071 
00072    if( ncall > 0 ) return NULL ;  /* only one interface */
00073 
00074    /*---------------- set titles and call point ----------------*/
00075 
00076    plint = PLUTO_new_interface( "3D+t Statistic" ,
00077                                 "Voxel Statistics of 3D+time Dataset" ,
00078                                 helpstring ,
00079                                 PLUGIN_CALL_VIA_MENU , STATS_main  ) ;
00080 
00081    PLUTO_add_hint( plint , "Voxel Statistics of 3D+time Dataset" ) ;
00082 
00083    PLUTO_set_sequence( plint , "A:newdset:statistics" ) ;
00084 
00085    global_plint = plint ;  /* make global copy */
00086 
00087    /*--------- 1st line: Input dataset ---------*/
00088 
00089    PLUTO_add_option( plint ,
00090                      "Input" ,  /* label at left of input line */
00091                      "Input" ,  /* tag to return to plugin */
00092                      TRUE       /* is this mandatory? */
00093                    ) ;
00094 
00095    PLUTO_add_dataset(  plint ,
00096                        "3D+time" ,        /* label next to button   */
00097                        ANAT_ALL_MASK ,    /* take any anat datasets */
00098                        FUNC_FIM_MASK ,    /* only allow fim funcs   */
00099                        DIMEN_4D_MASK |    /* need 3D+time datasets  */
00100                        BRICK_ALLREAL_MASK /* need real-valued datasets */
00101                     ) ;
00102 
00103    PLUTO_add_hint( plint , "Choose input dataset" ) ;
00104 
00105    /*---------- 2nd line: other inputs ----------*/
00106 
00107    PLUTO_add_option( plint ,
00108                      "Input" ,  /* label at left of input line */
00109                      "Input" ,  /* tag to return to plugin */
00110                      TRUE       /* is this mandatory? */
00111                    ) ;
00112 
00113    PLUTO_add_hint( plint , "Control parameters" ) ;
00114 
00115    PLUTO_add_string( plint ,
00116                      "Method" ,           /* label next to chooser button */
00117                      NUM_METHOD_STRINGS , /* number of strings to choose among */
00118                      method_strings ,     /* list of strings to choose among */
00119                      0                    /* index of default string */
00120                    ) ;
00121 
00122    PLUTO_add_hint( plint , "Choose statistic to compute" ) ;
00123 
00124    PLUTO_add_number( plint ,
00125                      "Ignore" ,  /* label next to chooser */
00126                      0 ,         /* smallest possible value */
00127                      20 ,        /* largest possible value */
00128                      0 ,         /* decimal shift (none in this case) */
00129                      3 ,         /* default value */
00130                      FALSE       /* allow user to edit value? */
00131                    ) ;
00132 
00133    PLUTO_add_hint( plint , "Number of points to ignore at start of time series" ) ;
00134 
00135    /*---------- 3rd line: Output dataset ----------*/
00136 
00137    PLUTO_add_option( plint ,
00138                      "Output" ,  /* label at left of input line */
00139                      "Output" ,  /* tag to return to plugin */
00140                      TRUE        /* is this mandatory? */
00141                    ) ;
00142 
00143    PLUTO_add_string( plint ,
00144                      "Prefix" ,  /* label next to textfield */
00145                      0,NULL ,    /* no fixed strings to choose among */
00146                      19          /* 19 spaces for typing in value */
00147                    ) ;
00148 
00149    PLUTO_add_hint( plint , "Name of output dataset" ) ;
00150 
00151    /*--------- done with interface setup ---------*/
00152 
00153    return plint ;
00154 }

char * STATS_main PLUGIN_interface *   
 

Definition at line 162 of file plug_stats.c.

References method_strings, NUM_METHOD_STRINGS, PLUTO_add_dset(), PLUTO_find_dset(), PLUTO_prefix_ok(), PLUTO_string_index(), and STATS_tsfunc().

Referenced by PLUGIN_init().

00163 {
00164    MCW_idcode * idc ;                          /* input dataset idcode */
00165    THD_3dim_dataset * old_dset , * new_dset ;  /* input and output datasets */
00166    char * new_prefix , * str ;                 /* strings from user */
00167    int meth , ignore ;
00168 
00169    /*--------------------------------------------------------------------*/
00170    /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/
00171 
00172    /*--------- go to first input line ---------*/
00173 
00174    PLUTO_next_option(plint) ;
00175 
00176    idc      = PLUTO_get_idcode(plint) ;   /* get dataset item */
00177    old_dset = PLUTO_find_dset(idc) ;      /* get ptr to dataset */
00178    if( old_dset == NULL )
00179       return "*************************\n"
00180              "Cannot find Input Dataset\n"
00181              "*************************"  ;
00182 
00183    /*--------- go to next input line ---------*/
00184 
00185    PLUTO_next_option(plint) ;
00186 
00187    str  = PLUTO_get_string(plint) ;      /* get string item (the method) */
00188    meth = PLUTO_string_index( str ,      /* find it in list it is from */
00189                               NUM_METHOD_STRINGS ,
00190                               method_strings ) ;
00191 
00192    ignore = PLUTO_get_number(plint) ;    /* get number item */
00193 
00194    /*--------- go to next input line ---------*/
00195 
00196    PLUTO_next_option(plint) ;
00197 
00198    new_prefix = PLUTO_get_string(plint) ;   /* get string item (the output prefix) */
00199    if( ! PLUTO_prefix_ok(new_prefix) )      /* check if it is OK */
00200       return "************************\n"
00201              "Output Prefix is illegal\n"
00202              "************************"  ;
00203 
00204    /*------------- ready to compute new dataset -----------*/
00205 
00206    new_dset = PLUTO_4D_to_fim( old_dset ,             /* input dataset */
00207                                new_prefix ,           /* output prefix */
00208                                ignore ,               /* ignore count */
00209                                1 ,                    /* detrend = ON */
00210                                STATS_tsfunc ,         /* timeseries processor */
00211                                (void *) meth          /* data for tsfunc */
00212                              ) ;
00213 
00214    PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ;
00215 
00216    return NULL ;  /* null string returned means all was OK */
00217 }

void STATS_tsfunc double    tzero,
double    tdelta,
int    npts,
float    ts[],
double    ts_mean,
double    ts_slope,
void *    ud,
float *    val
 

Definition at line 223 of file plug_stats.c.

References global_plint, METH_CVAR, METH_MEAN, METH_SIGMA, METH_SLOPE, PLUTO_popup_meter(), and PLUTO_set_meter().

Referenced by STATS_main().

00226 {
00227    int meth = (int) ud ;
00228    static int nvox , ncall ;
00229 
00230    /** is this a "notification"? **/
00231 
00232    if( val == NULL ){
00233 
00234       if( npts > 0 ){  /* the "start notification" */
00235 
00236          PLUTO_popup_meter( global_plint ) ;  /* progress meter  */
00237          nvox  = npts ;                       /* keep track of   */
00238          ncall = 0 ;                          /* number of calls */
00239 
00240       } else {  /* the "end notification" */
00241 
00242          PLUTO_set_meter( global_plint , 100 ) ; /* set meter to 100% */
00243 
00244       }
00245       return ;
00246    }
00247 
00248    /** OK, actually do some work **/
00249 
00250    switch( meth ){
00251 
00252       default:
00253       case METH_MEAN:  *val = ts_mean  ; break ;
00254 
00255       case METH_SLOPE: *val = ts_slope ; break ;
00256 
00257       case METH_CVAR:
00258       case METH_SIGMA:{
00259          register int ii ;
00260          register double sum ;
00261 
00262          sum = 0.0 ;
00263          for( ii=0 ; ii < npts ; ii++ ) sum += ts[ii] * ts[ii] ;
00264 
00265          sum = sqrt( sum/(npts-1) ) ;
00266 
00267          if( meth == METH_SIGMA )  *val = sum ;
00268          else if( ts_mean != 0.0 ) *val = sum / fabs(ts_mean) ;
00269          else                      *val = 0.0 ;
00270       }
00271    }
00272 
00273    /** set the progress meter to the % of completion **/
00274 
00275    ncall++ ;
00276    PLUTO_set_meter( global_plint , (100*ncall)/nvox ) ;
00277    return ;
00278 }

Variable Documentation

PLUGIN_interface* global_plint = NULL [static]
 

Definition at line 50 of file plug_stats.c.

Referenced by PLUGIN_init(), and STATS_tsfunc().

char helpstring[] [static]
 

Initial value:

  "Purpose: Compute mean, slope, or sigma of a 3D+time dataset.\n"
  "Input items are:\n"
  "   3d+time = 3D+time dataset to analyze\n"
  "   Method  = Mean, Slope, or Sigma = type of analysis to do\n"
  "   Ignore  = How many points to ignore at start\n"
  "\n"
  "Output: Prefix = Filename prefix for new dataset"

Definition at line 19 of file plug_stats.c.

Referenced by PLUGIN_init().

char* method_strings[] = { "Mean" , "Slope" , "Sigma" , "CVar" } [static]
 

Definition at line 31 of file plug_stats.c.

Referenced by PLUGIN_init(), and STATS_main().

 

Powered by Plone

This site conforms to the following standards: