class_docstr: A class which has the ability of reading in design matrix in .1D file,
      generated by AFNI's 3dDeconvolve.
  
  Parameters
  ----------
  
  fname: string, the address of the file to read.
  
  include_orth: Boollean, whether to include "orthogonal" regressors in
      the nuisance regressors which are usually head motion parameters.
      All the columns of design matrix are still going to be read in,
      but the attribute cols_used will reflect whether these orthogonal
      regressors are to be included for furhter analysis.
      Note that these are not entered into design_task attribute which
      include only regressors related to task conditions.
  
  include_pols: Boollean, whether to include polynomial regressors in
      the nuisance regressors which are used to capture slow drift of
      signals.
  
  Attributes
  ----------
  
  design: 2d array. The design matrix read in from the csv file.
  
  design_task: 2d array. The part of design matrix corresponding to
      task conditions.
  
  n_col: number of total columns in the design matrix.
  
  column_types: 1d array. the types of each column in the design matrix.
      0 for orthogonal regressors (usually head motion parameters),
      -1 for polynomial basis (capturing slow drift of signals),
      values > 0 for stimulus conditions
  
  n_basis: scalar. The number of polynomial bases in the designn matrix.
  
  n_stim: scalar. The number of stimulus conditions.
  
  n_orth: scalar. The number of orthogoanal regressors (usually head
      motions)
  
  StimLabels: list. The names of each column in the design matrix.
class_docstr_tok: ["A","class","which","has","the","ability","of","reading","in","design","matrix","in",".1D","file",",","generated","by","AFNI","'s","3dDeconvolve",".","Parameters","--","--","--","--","--","fname",":","string",",","the","address","of","the","file","to","read",".","include_orth",":","Boollean",",","whether","to","include","``","orthogonal","''","regressors","in","the","nuisance","regressors","which","are","usually","head","motion","parameters",".","All","the","columns","of","design","matrix","are","still","going","to","be","read","in",",","but","the","attribute","cols_used","will","reflect","whether","these","orthogonal","regressors","are","to","be","included","for","furhter","analysis",".","Note","that","these","are","not","entered","into","design_task","attribute","which","include","only","regressors","related","to","task","conditions",".","include_pols",":","Boollean",",","whether","to","include","polynomial","regressors","in","the","nuisance","regressors","which","are","used","to","capture","slow","drift","of","signals",".","Attributes","--","--","--","--","--","design",":","2d","array",".","The","design","matrix","read","in","from","the","csv","file",".","design_task",":","2d","array",".","The","part","of","design","matrix","corresponding","to","task","conditions",".","n_col",":","number","of","total","columns","in","the","design","matrix",".","column_types",":","1d","array",".","the","types","of","each","column","in","the","design","matrix",".","0","for","orthogonal","regressors","(","usually","head","motion","parameters",")",",","-1","for","polynomial","basis","(","capturing","slow","drift","of","signals",")",",","values",">","0","for","stimulus","conditions","n_basis",":","scalar",".","The","number","of","polynomial","bases","in","the","designn","matrix",".","n_stim",":","scalar",".","The","number","of","stimulus","conditions",".","n_orth",":","scalar",".","The","number","of","orthogoanal","regressors","(","usually","head","motions",")","StimLabels",":","list",".","The","names","of","each","column","in","the","design","matrix","."]
code: def read_afni(self, fname):
      # Read design file written by AFNI
      self.n_basis = 0
      self.n_stim = 0
      self.n_orth = 0
      self.StimLabels = []
      self.design = np.loadtxt(fname, ndmin=2)
      with open(fname) as f:
          all_text = f.read()
  
      find_n_column = re.compile(
          r'^#[ ]+ni_type[ ]+=[ ]+"(?P<n_col>\d+)[*]', re.MULTILINE
      )
      n_col_found = find_n_column.search(all_text)
      if n_col_found:
          self.n_col = int(n_col_found.group("n_col"))
          if self.n_col != np.size(self.design, axis=1):
              warnings.warn(
                  "The number of columns in the design matrix"
                  + "does not match the header information"
              )
              self.n_col = np.size(self.design, axis=1)
      else:
          self.n_col = np.size(self.design, axis=1)
  
      self.column_types = np.ones(self.n_col)
      # default that all columns are conditions of interest
  
      find_ColumnGroups = re.compile(
          r'^#[ ]+ColumnGroups[ ]+=[ ]+"(?P<CGtext>.+)"', re.MULTILINE
      )
      CG_found = find_ColumnGroups.search(all_text)
      if CG_found:
          CG_text = re.split(",", CG_found.group("CGtext"))
          curr_idx = 0
          for CG in CG_text:
              split_by_at = re.split("@", CG)
              if len(split_by_at) == 2:
                  # the first tells the number of columns in this condition
                  # the second tells the condition type
                  n_this_cond = int(split_by_at[0])
                  self.column_types[
                      curr_idx : curr_idx + n_this_cond
                  ] = int(split_by_at[1])
                  curr_idx += n_this_cond
              elif len(split_by_at) == 1 and not re.search(
                  r"\..", split_by_at[0]
              ):
                  # Just a number, and not the type like '1..4'
                  self.column_types[curr_idx] = int(split_by_at[0])
                  curr_idx += 1
              else:  # must be a single stimulus condition
                  split_by_dots = re.split(r"\..", CG)
                  n_this_cond = int(split_by_dots[1])
                  self.column_types[
                      curr_idx : curr_idx + n_this_cond
                  ] = 1
                  curr_idx += n_this_cond
          self.n_basis = np.sum(self.column_types == -1)
          self.n_stim = np.sum(self.column_types > 0)
          self.n_orth = np.sum(self.column_types == 0)
  
      find_StimLabels = re.compile(
          r'^#[ ]+StimLabels[ ]+=[ ]+"(?P<SLtext>.+)"', re.MULTILINE
      )
      StimLabels_found = find_StimLabels.search(all_text)
      if StimLabels_found:
          self.StimLabels = re.split(
              r"[ ;]+", StimLabels_found.group("SLtext")
          )
      else:
          self.StimLabels = []
  
imports: import numpy
  import re
  import warnings
  import os.path
  import psutil
  from .fmrisim import generate_stimfunction, _double_gamma_hrf, convolve_hrf
  from scipy.fftpack import fft, ifft
  import logging
label_desc: Use image node_id 2 for calling the ReadDesign obj's underlying member method code with example usage: obj.read_afni(fname) without return types