AFNI program: physio_calc.py

Output of -help



Overview ~1~

This program creates slice-based regressors for regressing out
components of estimated cardiac and respiratory signals, as well as
the respiration volume per time (RVT), RVTRRF and HRCRF.

Much of the calculations are based on the following papers about
estimating physiological regressors to be applied in FMRI analysis:

  Glover GH, Li TQ, Ress D (2000). Image-based method for
  retrospective correction of physiological motion effects in fMRI:
  RETROICOR. Magn Reson Med 44(1):162-7.

  Birn RM, Diamond JB, Smith MA, Bandettini PA (2006). Separating
  respiratory-variation-related fluctuations from
  neuronal-activity-related fluctuations in fMRI. Neuroimage
  31(4):1536-48.

  Birn RM, Smith MA, Jones TB, Bandettini PA (2008). The respiration
  response function: the temporal dynamics of fMRI signal fluctuations
  related to changes in respiration. Neuroimage 40(2):644-654.

  Chang C, Glover GH (2009). Relationship between respiration,
  end-tidal CO2, and BOLD signals in resting-state fMRI. Neuroimage
  47(4):1381-1393.

This code has been informed by earlier programs that estimated
RETROICOR and RVT regressors, namely 3dretroicor by Fred Tam,
RetroTS.m by Ziad Saad and RetroTS.py by J Zosky.  That being said, the
current code's implementation was written separately, to understand
the underlying processes and algorithms afresh, to modularize several
pieces, to refactorize others, and to produce more QC outputs and logs
of information.  Several steps in the eventual regressor estimation
depend on processes like peak- (and trough-) finding and outlier
rejection, which can be reasonably implemented in many ways.  We do
not expect exact matching of outcomes between this and the previous
versions.

Below, we use the following abbreviations a lot:
* "resp" refers to respiratory (breathing) input and results
* "card" refers to cardiac (heart rate) input and results

============================================================================

Options ~1~

The options are organized by category here. The general expectation is
for the user to use one or more options from the "Main ..."
categories, and the remaining options are available for additional
control, if needed. For example, the '-do_fix_* ..' options might be
very useful if there are weird features in the input physio data.

Note that some prefiltering and other processing parameters are _on_
by default, since they seem generally useful. But they could be turned
off, if preferable.


* Main input, physio datasets and parameters: at least one card or resp
  time series must be provided, along with timing information:

  -resp_file RF       :Path to one respiration data file

  -card_file CF       :Path to one cardiac data file

  -phys_file PF       :BIDS-formatted physio file in tab-separated format.
                       May be gzipped

  -phys_json PJ       :BIDS-formatted physio metadata JSON file. This is
                       required whenever -phys_file is used

  -freq F             :Physiological signal sampling frequency (in Hz)

  -start_time ST      :The start time for the physio time series, relative to
                       the initial MRI volume (in s) 
                       (def: None)


* Main EPI/FMRI dataset info, which can be provided in various ways
  (easiest: provide an EPI dataset via '-dset_epi ..'):

  -dset_epi DE        :Accompanying EPI/FMRI dset to which the physio
                       regressors will be applied, for obtaining the
                       volumetric parameters (namely, dset_tr, dset_nslice,
                       dset_nt)

  -dset_tr TR         :FMRI dataset's repetition time (TR), which defines the
                       time interval between consecutive volumes (in s)

  -dset_nt NT         :Integer number of time points to have in the output
                       (should likely match FMRI dataset's number of volumes)

  -dset_nslice NS     :Integer number of slices in FMRI dataset

  -dset_slice_times DST  :Slice time values (space separated list of numbers)

  -dset_slice_pattern SP  :Slice timing pattern code. 
                       Use '-disp_all_slice_patterns Yes' to see all allowed
                       patterns. Alternatively, one can enter the filename of
                       a file containing a single column of slice times.
                       (def: None)


* Main output options like directory and file naming:

  -out_dir OD         :Output directory name (can include path)

  -prefix P           :Prefix of output filenames, without path
                       (def: physio)


* Main choice of output regressor types, related control options, and formats:

  -regress_types_resp RTR
                      :Provide a list of one or more types of regressors
                       derived from the input respiratory physio data. This is
                       done by listing one or more codes from among the
                       following list: NONE, retro, rvt, rvtrrf 
                       (def: retro rvt)

  -regress_types_card RTC
                      :Provide a list of one or more types of regressors
                       derived from the input cardiac physio data. This is
                       done by listing one or more codes from among the
                       following list:   NONE, retro, hrcrf 
                       (def: retro)

  -rvt_shift_list RSL :Provide one or more values to specify how many and what
                       kinds of shifted copies of RVT are output as
                       regressors. Units are seconds, and including 0 may be
                       useful. Shifts could also be entered via
                       '-rvt_shift_linspace ..' 
                       (def: 0 1 2 3 4)

  -rvt_shift_linspace A B N
                      :Alternative to '-rvt_shift_list ..'. Provide three
                       space-separated values (start stop N) used to determine
                       how many and what kinds of shifted copies of RVT are
                       output as regressors, according to the Python-Numpy
                       function linspace(start, stop, N). Both start and stop
                       (units of seconds) can be negative, zero or positive.
                       Including 0 may be useful.  Example params: 0 4 5,
                       which lead to shifts of 0, 1, 2, 3 and 4 sec 
                       (def: None, use '-rvt_shift_list')

  -do_slibase_out DSO: Output the older style of physio output from the
                       RetroTS.py days, namely where all regressors are output
                       in a single slice-based regressor file, *slibase.1D;
                       NB: this is _not_ recommended, and only existing for 
                       comparisons to older formats.
                       Allowed values are: Yes, 1, No, 0
                       (def: 'No')


* Prefiltering: these options control input physio time series pre-processing
  (NB: some of these are now ON by default, because they seem generally
  useful, but they could be turned off):

  -do_fix_nan DFN     :Fix (= replace with interpolation) any NaN values in
                       the physio time series.
                       Allowed values are: Yes, 1, No, 0 
                       (def: 'No')

  -do_fix_null DFN    :Fix (= replace with interpolation) any null or missing
                       values in the physio time series.
                       Allowed values are: Yes, 1, No, 0 
                       (def: 'No')

  -do_fix_outliers DFO  :Fix (= replace with interpolation) any outliers in
                       the physio time series. 
                       Allowed values are: Yes, 1, No, 0
                       (def: 'No')

  -extra_fix_list EFL: List of one or more values that will also be considered
                       'bad' if they appear in the physio time series, and
                       replaced with interpolated values

  -remove_val_list RVL  :List of one or more values that will removed (not
                       interpolated: the time series will be shorter, if any
                       are found) if they appear in the physio time series;
                       this is necessary with some manufacturers' outputs, see
                       "Notes of input peculiarities," below

  -prefilt_max_freq PMF  :Allow for downsampling of the input physio time
                       series, by providing a maximum sampling frequency
                       (in Hz). This is applied just after badness checks.
                       Values <=0 mean that no downsampling will occur 
                       (def: 50)

  -prefilt_mode PM    :Filter input physio time series (after badness checks),
                       likely aiming at reducing noise; can be combined
                       usefully with prefilt_max_freq. Allowed modes:
                       none, median 
                       (def: median)

  -prefilt_win_card PWC  :Window size (in s) for card time series, if
                       prefiltering input physio time series with
                       '-prefilt_mode ..'; value must be >0
                       (def: 0.1, only used with prefiltering)

  -prefilt_win_resp PWR  :Window size (in s) for resp time series, if
                       prefiltering input physio time series with
                       '-prefilt_mode ..'; value must be >0 
                       (def: 0.25, only used with prefiltering)


* Processing parameters during some intermediate filtering stages:

  -min_bpm_resp MNR   :Set the minimum breaths per minute for respiratory proc
                       (def: 6.0)

  -max_bpm_resp MXR   :Set the maximum breaths per minute for respiratory proc
                       (def: 60.0)

  -min_bpm_card MNC   :Set the minimum beats per minute for cardiac proc
                       (def: 25.0)

  -max_bpm_card MXC   :Set the maximum beats per minute for cardiac proc
                       (def:250.0)


* User interaction: users can fix/check/update peak and trough estimates:

  -do_interact DI     :Enter into interactive mode as the last stage of
                       peak/trough estimation for the physio time series.
                       Allowed values are: Yes, 1, No, 0
                       (def: 'No')


* QC images properties, which can be adjusted if needed/desired:

  -img_verb IV        :Verbosity level for saving QC images during processing,
                       by choosing one integer: 0 - Do not save graphs 1 -
                       Save end results (card and resp peaks, final RVT) 2 -
                       Save end results and intermediate steps (bandpassing,
                       peak refinement, etc.) 
                       (def: 1)

  -img_figsize W H    :Figure dimensions used for QC images 
                       (def: depends on length of physio time series)

  -img_fontsize FS    :Font size used for QC images
                       (def: 10)

  -img_line_time LT   :Maximum time duration per line in the QC images, in
                       units of sec
                       (def: 120)

  -img_fig_line NL    :Maximum number of lines per fig in the QC images
                       (def: 8)

  -img_dot_freq DF    :Maximum number of dots per line in the QC images (to
                       save filesize and plot time), in units of dots per sec
                       (def: 50)

  -img_bp_max_f MF    :Maximum frequency in the bandpass QC images (i.e.,
                       upper value of x-axis), in units of Hz
                       (def: 5.0)


* Save current peaks to a separate file:

  -save_proc_peaks    :Write out the final set of peaks indices to a text file
                       called PREFIX_LABEL_proc_peaks_00.1D ('LABEL' is
                       'card', 'resp', etc.), which is a single column of the
                       integer values
                       (def: don't write them out)

  -save_proc_troughs  :Write out the final set of trough indices to a text
                       file called PREFIX_LABEL_proc_troughs_00.1D ('LABEL' is
                       'card', 'resp', etc.), which is a single column of the
                       integer values. The file is only output for LABEL 
                       types where troughs were estimated (e.g., resp).
                       (def: don't write them out)


* Load/read in previous peaks and troughs to use:

  -load_proc_peaks_resp LPR
                      :Load in a file of resp data peaks that have been saved
                       via '-save_proc_peaks'. This file is a single column of
                       integer values, which are indices of the peak locations
                       in the processed time series

  -load_proc_troughs_resp LTR
                      :Load in a file of resp data troughs that have been
                       saved via '-save_proc_troughs'. This file is a single
                       column of integer values, which are indices of the
                       trough locations in the processed time series

  -load_proc_peaks_card LPC
                      :Load in a file of card data peaks that have been saved
                       via '-save_proc_peaks'. This file is a single column of
                       integer values, which are indices of the peak locations
                       in the processed time series


* Sundry displays of help or further text display:

  -verb V             :Integer values to control verbosity level
                       (def: 0)

  -disp_all_slice_patterns DSP
                      :Display all allowed slice pattern names?
                       Allowed values are: Yes, 1, No, 0
                       (def: 'No')

  -disp_all_opts DAO  :Display all options for this program?
                       Allowed values are: Yes, 1, No, 0 
                       (def: 'No')

  -ver                :Display program version number

  -help               :Display help text in terminal

  -hview              :Display help text in a text editor (AFNI functionality)

============================================================================

Notes on usage ~1~

Physio data inputs ~2~

  At least one of the following sets of input option sets (shown one per
  line) must be used to provide input physio data (i.e., card, resp or 
  both time series):

    -card_file CF
    -resp_file RF
    -card_file CF  -resp_file RF
    -phys_file PF  -phys_json PJ

  If the sampling frequency (units: Hz) of the physio data is not
  provided by -phys_json, then it must be provided with this opt:

    -freq F

  Additionally, the starting time of the physio data relative to the
  start of the EPI data will be assumed to be 0.0 unless another value
  is provided by the user (units: sec; any value provided by the
  user/file should be <=0); this info can be provided either via the
  -phys_json file, or by this opt:

    -start_time ST

  The following table lists the relevant sampling and starting
  parameters that could be provided from _either_ a command line
  option (ARG/OPT) or a '-phys_json ..' file's keys (JSON KEY):

    ARG/OPT           JSON KEY               EPS VAL  
    -freq             SamplingFrequency      1.000e-03
    -start_time       StartTime              1.000e-03

  It is possible that these items could be provided by *both* the JSON
  file and the command line opt (e.g., due to JSON heterogeneity
  across a study).  In such events, this program checks to make sure
  any dually-provided values are consistent to within EPS VAL.

EPI/FMRI inputs and information ~2~

  EPI-related information is required to build regressors: TR, number
  of slices, number of time points, and slice timing info.  It is
  easiest to provide these items by just providing the EPI/FMRI dset
  directly with:

    -dset_epi DE

  But users could also provide that info separately, with:

    -dset_tr           TR
    -dset_nslice       NS
    -dset_nt           NT
    -dset_slice_times  DST    _or_   -dset_slice_pattern  SP

============================================================================

Prefiltering options for the physio time series ~1~

  Many physio time series contain noisy spikes or occasional blips.
  Since most physio processing algorithms rely on peak-/trough-finding,
  such spikes can be highly problematic. The effects of these can be
  reduced during processing with some "prefiltering".  At present, this
  includes using a moving median filter along the time series, to try to
  remove spiky things that are likely nonphysiological. This can be
  implemented by using this opt+arg:

      -prefilt_mode median

  An additional decision to make then becomes what width of filter to
  apply. That is, over how many points should the median be
  calculated?  The choice should balance being large enough to be
  stable with being small enough to not remove useful features (like
  real peaks, troughs or other time series changes). Users can specify
  a time interval for the card and resp data separately, because each
  has a different expected time scale of variability (and experimental
  design can affect this choice, as well).  So, the user can use:

      -prefilt_win_card  PWC
      -prefilt_win_resp  PWR

  ... providing PW? values in units of seconds. Because this seems
  generally useful to use, at present prefiltering is _on_ by default
  (with default parameters listed above in the options section). To
  turn these off, one could use:  '-prefilt_mode none'.

  Finally, physio time series are acquired with a variety of sampling
  frequencies.  These can easily range from 50 Hz to 2000 Hz (or more).
  That means 50 (or 2000) point estimates per second---which is a lot
  for most applications.  Consider that typical FMRI sampling intervals
  are TR = 1-2 sec or so, meaning that they have 0.5 or 1 point estimates
  per sec.  Additionally, many (human) cardiac cycles are roughly of
  order 1 per sec or so, and (human) respiration is at a much slower
  rate.  All this is to say, having a highly sampled physio time series
  can be unnecessary for most practical applications and analyses.  We
  can reduce computational cost and processing time by downsampling it
  near the beginning of processing. This would be done by specifying a
  max sampling frequency MAX_F for the input data, to downsample to (or 
  near to), via: 

      -prefilt_max_freq  PMF

  In general, at least for human applications, it seems hard to see
  why one would need more than 50 physio measures per
  second. Therefore, this sampling-related prefiltering is also on by
  default. To turn this off, one could use: '-prefilt_max_freq -1'.

  NB: The above prefiltering actions are all be applied _after_ any
  steps performed with '-do_fix_* ..' options, which help to find (and
  hopefully remove) other kinds of problematic, non-phyiosological
  features in the input time series.
 
============================================================================

User interaction for peak/trough editing ~1~

  This program includes functionality whereby the user can directly
  edit the peaks and troughs that have estimated. This includes
  adding, deleting or moving the points around, with the built-in
  constraint of keeping the points on the displayed physio time series
  line. It's actually kind of fun.

  To enter interactive mode during the runtime of the program, add this
  option:

    -do_interact Yes

  Then, at some stage during the processing, a Matplotlib panel will pop
  up, showing estimated troughs and/or peaks, which the user can edit if
  desired. Upon closing the pop-up panel, the final locations of
  peaks/troughs are kept and used for the remainder of the code's run.

  Key+mouse bindings being used:

            5  : refresh peak/trough interval band colors after editing
            4  : delete the vertex (peak or trough) nearest to mouse point
            3  : add a peak vertex
            2  : add a trough vertex
            1  : toggle vertex visibility+editability on and off
   Left-click  : select closest vertex, which can then be dragged along
                the reference line.

   Some additional Matplotlib keyboard shortcuts:
            f  : toggle fullscreen view of panel
            o  : toggle zoom-to-rectangle mode
            p  : toggle pan/zoom mode
            r  : reset panel view (not point edits, but zoom/scroll/etc.)
            q  : quit/close viewer (also Ctrl+w), when done editing


  For more on the Matplotlib panel navigation keypresses and tips, see:
  https://matplotlib.org/3.2.2/users/navigation_toolbar.html

  At present, there is no "undo" functionality. If you accidentally
  delete a point, you can add one back, or vice versa.

============================================================================

QC coloration in plots ~1~

  In several plots that estimated peaks/troughs, there is some
  automatic coloration to help guide the eye toward where there might
  be potential outliers in interval (ival) properties, extra
  peaks/troughs, missing peaks/troughs, etc.

  Note that because the heterogeneity of breathing and heartrate can
  be quite large, many of these are rough approximations and not
  necessarily signs of a problem---the user can+should decide that!

  Some QC items in plots:

    top band of red-blue : shows where interpeak intervals are relatively
                           large (redder) or smaller (bluer) compared to
                           the median (white) across the full range

    bottom band of red-blue : the same interpretation as the top band,
                              but for troughs

    yellow background    : (outlier ival) outlier interpeak/intertrough 
                           interval; highlights where an omnibus measure
                           of relative height+width between successive
                           extrema is large, relative to the distribution
                           of all intervals---but might only be a
                           _statistical_ outlier, not something
                           non-physiological

    magenta triangle     : (nonalt p) highlights nonalternating peaks; 
                           that is, where there are 2 or more peaks
                           without an intervening trough. Suggests
                           either extra peak(s) or missing trough(s)
                
    cyan triangle        : (nonalt t) equivalent to magenta triangle but 
                           for nonalternating troughs

    gray background      : not a QC issue at all, but just highlights
                           regions of physio data/plot that are outside of
                           where the EPI dataset occurs
  
  In the interactive mode, when the user hits the '5' key, all of the above
  QC properties are recalculated and updated in the plot.

  Several of these properties are also reported as counts and fractions 
  in the *review.txt file in the "extras/" output subdirectory.

============================================================================

Reload peaks/troughs from earlier physio_calc.py run ~1~

  It is possible to save estimated peak and trough values to a text file
  with this program, using:

     -save_proc_peaks
     -save_proc_troughs

  respectively.  These options tell the program to write *.1D files
  that contain the integer indices of the peaks or troughts within the
  processed time series. The output files are automatically named in
  the output directory.

  It is also possible to re-load those text files of integer indices
  back into the program, which might be useful when further editing of
  peaks/troughs is necessary, for example, via '-do_interact Yes'.

  To do this, you should basically run the same physio_calc.py command
  you initially ran to create the time points (same inputs, same
  '-prefilt_* ..' opts, etc.)  but perhaps with different output
  directory and/or prefix, and add the one or more of the following
  options:

     -load_proc_peaks_resp    LPR
     -load_proc_troughs_resp  LTR
     -load_proc_peaks_card    LPC

  Each of these takes a single argument, which is the appropriate file
  name to read in.

  **Note 1: it is important to keep all the same processing options
    from the original command even when reading in already-generated
    peaks and troughs. This is because prefiltering and start_time
    options can affect how the read-in indices are interpreted. It is
    important to maintain consistency. To facilitate recalling the
    earlier options, there should be a 'PREFIX_pc_cmd.tcsh' file that is
    saved among the outputs of a given physio_calc.py run.

  **Note 2: while reusing the same processing options is advised when
    loading in earlier outputs to use, it might help reduce confusion
    between those prior physio_calc.py outputs and the new results by
    changing the '-out_dir ..' and '-prefix ..'.

============================================================================

Notes on scanner-related peculiarities ~1~

  With Siemens physiological monitoring, values of 5000, 5003 and 6000
  can be used as trigger events to mark the beginning or end of
  something, like the beginning of a TR.  Based on the Siemens Matlab
  programs, the encoded meanings are:

      5000 = cardiac pulse on
      5003 = cardiac pulse off
      6000 = cardiac pulse off
      6002 = phys recording on
      6003 = phys recording off

  Moreover, it appears that these numbers are *inserted* into the
  series, in which case, the specified 500? and 600? values should be
  *removed* rather than replaced by an interpolation of the two adjacent
  values.  To do this, you can use something like the following option
  syntax:

      -remove_val_list 5000 5003 6000 6002 6003

============================================================================

Outputs overview ~1~

  The following are possible outputs to running this program. The
  number of images created varies based on user-controlled options. The
  *resp* files are only output if respiratory signal information were
  input, and similarly for *card* files with cardiac input.


Outputs in: OUT_DIR/ ~2~

  The main output files are the following text files, which contain
  regressors that can be provided to afni_proc.py for FMRI processing:

    PREFIX_physio_regress_slice.1D 
      :slice-based regressor file, which can be made up of any of the
       following card and/or resp regressors: retro.  This can be
       provided to afni_proc.py via '-ricor_regs ..'.

    PREFIX_physio_regress_volume.1D 
      :volume-based regressor file, which can be made up of any of the
       following card and/or resp regressors: rvt, rvtrrf, hrcrf.
       This can be provided to afni_proc.py via '-********** ..'.

  The following subdirectories contain useful supplementary information:

    PREFIX_physio_images/     
      :subdir holding QC images (see below)

    PREFIX_physio_extras/
      :subdir holding additional text files of interest (see below)


Outputs in: OUT_DIR/PREFIX_physio_extras/ ~2~

  Supplementary text files that may be of user. These include recording
  input options, as well as QC summaries of peak/trough properties.

    PREFIX_resp_review.txt
      :summary statistics and info for resp proc

    PREFIX_card_review.txt
      :summary statistics and info for card proc

    PREFIX_pc_cmd.tcsh
      :log/copy of the command used

    PREFIX_info.json 
      :reference dictionary of all command inputs after interpreting
       user options and integrating default values

  The following text files are only output when using the
  '-save_proc_peaks' and/or '-save_proc_troughs' option(s):

    PREFIX_card_peaks_00.1D
      :1D column file of peak indices for card data corresponding to
       card*final_peaks*svg image.

    PREFIX_resp_peaks_00.1D
      :1D column file of peak indices for resp data corresponding to
       resp*final_peaks*svg image.

    PREFIX_resp_troughs_00.1D
      :1D column file of trough indices for resp data, corresponding
       to resp*final_peaks*svg image.


Outputs in: OUT_DIR/PREFIX_physio_images/ ~2~

  QC images related to finding peaks and troughs, phase estimation,
  and regressor creation.  The number of files here will vary based on
  input data, regressors created, and verbosity of intermediate
  processing.  The main output QC images are:

    PREFIX_the_regressors_*.svg
      :QC images of all regressors estimated by physio_calc.py

    PREFIX_card_10_final*peaks*.svg
    PREFIX_resp_10_final*peaks*.svg
      :QC images of final peak estimation for card data processing.
       Colorbands highlight longer (red) and shorter (blue) intervals,
       compared to median (white). For more details, see 'How to
       interpret coloration...', below.

  The following intermediate QC images are only output with '-img_verb 2'
  or higher:

    PREFIX_card_0*.svg
    PREFIX_resp_0*.svg      
      :QC images of intermediate peak estimation for card and resp
       data processing

    PREFIX_card_bandpass*.svg
    PREFIX_resp_bandapss*.svg
      :QC images of intermediate peak/trough estimation during an
       initial bandpass stage; includes image of Fourier-transform
       spectrum, as well as bandpassed time series

    PREFIX_card_20_*.svg
    PREFIX_resp_20_*.svg
      :QC images of intermediate stages in either RVT- or CRF-based
       estimations

============================================================================

How to interpret coloration in *final_peaks* images ~1~

  The QC images contain images that are supposed to be helpful in
  interpreting the data.  Here are some notes on various aspects.

  When viewing physio time series, the interval that overlaps the FMRI
  dataset in time has a white background, while any parts that do not
  have a light gray background.  Essentially, only the overlap regions
  should affect regressor estimation---the parts in gray are useful to
  have as realistic boundary conditions, though.

  Peaks are always shown as downward pointing triangles, and troughs are
  upward pointing triangles.

  When viewing "final" peak and trough images, there will be color bands
  made of red/white/blue rectangles shown in the subplots.  These
  highlight the relative duration of a given interpeak interval (top
  band in the subplot) and/or intertrough interval (bottom intervals),
  relative to their median values across the entire time series.
  Namely:

     white : interval matches median
     blue  : interval is shorter than median (darker blue -> much shorter)
     red   : interval is longer than median (darker red -> much longer)

  The more intense colors mean that the interval is further than the median,
  counting in standard deviations of the interpeak or intertrough intervals.  
  This coloration is meant to help point out variability across time: this
  might reflect natural variability of the physio time series, or possibly
  draw attention to a QC issue like an out-of-place or missing extremum 
  (which could be edited in "interactive mode").

A note on previous physio estimation with RetroTS.py ~1~

  Note that the older RetroTS.py program for deriving physio-based
  regressors in AFNI output only a single slice-based file, the
  "*slibase.1D" file.  This contained even the non-slicewise defined
  regressors, simply entered in a slicewise format.  But the slicewise
  regression must be done before any other processing, rather than as
  part of the main regress block processing.  So, the present program
  outputs separate files for slice-based and volume-wise regressors, so
  that as many as possible volumetric regressors can be applied more
  appropriately in the regress block stage.

  *If* you would like the older format of all-physio-regressors-in-a-single-
  slicewise-file, you can add an option here for that:

     -do_slibase_out Yes 

  ... but this is not recommended and primarily exists just for testing
  purposes.  If you do want the older *_slibase.1D file output, it
  should _not_ be simultaneously included with the other
  *physio_regress*.1D files estimated here.

============================================================================

Examples ~1~

  1. Basic input example, only cardiac data
    
    physio_calc.py                                                     \
        -card_file           physiopy/test000c                         \
        -freq                400                                       \
        -dset_epi            DSET_MRI                                  \
        -out_dir             OUT_DIR                                   \
        -prefix              PREFIX

  2. Input of file+json pair; no EPI data input, so those parameters are
     provided separately; some badness checks are also added:
    
    physio_calc.py                                                     \
        -phys_file           physiopy/test003c.tsv.gz                  \
        -phys_json           physiopy/test003c.json                    \
        -dset_tr             2.2                                       \
        -dset_nt             34                                        \
        -dset_nslice         34                                        \
        -dset_slice_pattern  alt+z                                     \
        -do_fix_nan          Yes                                       \
        -extra_fix_list      5000                                      \
        -out_dir             OUT_DIR                                   \
        -prefix              PREFIX

  3. Another example, with both card and resp input; the types of regressors
     to estimate are also specified:

    physio_calc.py                                                     \
        -card_file           sub-005_ses-01_task-rest_physio-ECG.txt   \
        -resp_file           sub-005_ses-01_task-rest_physio-Resp.txt  \
        -freq                50                                        \
        -dset_tr             2.2                                       \
        -dset_nt             220                                       \
        -dset_nslice         33                                        \
        -dset_slice_pattern  alt+z                                     \
        -regress_types_resp  retro rvt                                 \
        -regress_types_card  retro hrcrf                               \
        -out_dir             OUT_DIR                                   \
        -prefix              PREFIX
    
============================================================================

written by: Peter Lauren, Richard Reynolds, Daniel Glen, and Paul 
            Taylor (SSCC, NIMH, NIH, USA)

additional input: Josh Dean and Dan Handwerker (SFIM, NIMH, NIH, USA)

============================================================================


This page auto-generated on Fri Oct 23 07:12:47 PM EDT 2026