コード例 #1
0
ファイル: lib_gershgorin.py プロジェクト: pab2163/afni
def gershgoriny_dist_from_I_aff12_file(fname):
    '''Input a file of an aff12 matrix (either MATRIX or ONELINE format).
    Must have exactly 12 numbers.

    See help of 'gershgoriny_dist_from_I_aff12()' for what happens
    next.

    Output is one scalar number.

    '''

    # read in, and get into proper shape with a transposition
    x = LAD.Afni1D(fname)
    x.transpose()

    if len(x.mat) == 3 and len(x.mat[0]) == 4:
        # then we have a MATRIX-format aff12.1D param already, and we
        # are all set to go
        out = gershgoriny_dist_from_I_aff12(x.mat)

    elif len(x.mat) == 1 and len(x.mat[0]) == 12:
        # then we have a ONELINE-format aff12.1D param, and we have to
        # reshape it
        M = [[0.0] * 4 for row in range(3)]
        for i in range(3):
            M[i][:] = x.mat[0][4 * i:4 * (i + 1)]
        dist_gershgorin = gershgoriny_dist_from_I_aff12(M)
    else:
        print("** ERROR: Input matrix in {} has some problems! Doesn't look\n"
              "   like an aff12.1D format (ONELINE, 1x12; MATRIX, 3x4)\n"
              "".format(fname))
        sys.exit(3)

    return dist_gershgorin
コード例 #2
0
ファイル: read_matlab_files.py プロジェクト: pab2163/afni
   def process_matlab_file(self, fname, index=0):
      """process matlab files
      """

      try:
         import scipy.io
         import numpy
      except:
         print('** missing library: scipy.io')
         print('   (please install scipy)')
         return 1

      if not os.path.isfile(fname):
         print("** missing file '%s'" % fname)
         return 1

      mfile = scipy.io.loadmat(fname)
      if mfile == None: return 1

      # prepare output prefix
      prefix = self.prefix
      if prefix != '' and len(self.infiles) > 1:
         prefix = '%s.%02d' % (self.prefix, index+1)

      klist = [key for key in list(mfile.keys()) if key[0:2] != '__']
      maxlen = max([len(key) for key in klist])

      if self.verb:
         if self.verb > 1: print()
         print('-- file %s has %d key(s)' % (fname, len(klist)))

      for key in klist:
         obj = mfile[key]
         if self.verb > 1:
            if type(obj) is numpy.ndarray:
               shstr = ' shape %s' % str(obj.shape)
            else:
               shstr = ''
            print('   %-*s %s%s' % (maxlen, key, type(obj), shstr))

         # maybe write any numpy data
         if prefix != '' and type(obj) is numpy.ndarray:
            # convert object to Afni1D and transpose
            olist = obj.tolist()
            adata = LD.Afni1D(from_mat=1, matrix=olist, verb=self.verb)
            adata.transpose()

            # if model, break apart, else just write
            if key == 'model' and adata.nvec >= 2:
               self.write_model_files(adata, prefix)
            else:
               ofile = '%s.%s.1D'%(prefix,key)
               print('++ writing ndarry to %s' % ofile)
               adata.write(ofile, overwrite=self.overwrite)

      return 0
コード例 #3
0
ファイル: read_matlab_files.py プロジェクト: pab2163/afni
   def write_model_files(self, adata, prefix):
      """break model matrix into many 1D files
      """

      if adata.nvec < 1: return 0

      for ind in range(adata.nvec):
         avec = LD.Afni1D(from_mat=1, matrix=[adata.mat[ind]], verb=self.verb)
         ofile = '%s.model.%02d.1D' % (prefix, ind+1)
         print('++ writing model file %s' % ofile)
         avec.write(ofile, overwrite=self.overwrite)

      return 0
コード例 #4
0
ファイル: quick.alpha.vals.py プロジェクト: pab2163/afni
    print(help_str)
    sys.exit(0)

an = 1
niter = 0
if sys.argv[an] == '-niter':
    if an + 2 >= narg:
        print(usage_str)
        sys.exit(1)
    niter = int(sys.argv[an + 1])
    print('-- using niter = %d' % niter)
    an += 2

infile = sys.argv[an]

mdata = LAD.Afni1D(infile, verb=0)
if not mdata.ready:
    print('** failed to read maxdata file %s' % infile)
    sys.exit(1)
try:
    mdata = [int(round(m)) for m in mdata.mat[0]]
except:
    print('** failed to process integers from maxdata file %s' % infile)
    sys.exit(1)

mdata.sort()
cmax = mdata[-1]
mlen = len(mdata)

if niter > 0 and niter > mlen:
    print('** have input niter (%d) > mlen(%d)' % (niter, mlen))