Exemple #1
0
    def get_TR_offset_stats(self, tr):
        """create a list of TR offsets (per-run and overall)

            tr : must be positive

         return: 8 values in a list:
                    min, mean, maxabs, stdev of absolute and fractional offsets
                 empty list on error
      """

        if not self.ready:
            print('** M Timing: nothing to compute ISI stats from')
            return []

        if self.nrows != len(self.data):
            print('** bad MTiming, nrows=%d, datalen=%d, failing...' % \
                  (self.nrows, len(self.data)))
            return []

        if tr < 0.0:
            print('** show_TR_offset_stats: invalid TR %s' % tr)
            return []

        tr = float(tr)  # to be sure

        # make a copy of format run x stim x [start,end], i.e. is 3-D
        tdata = self.get_start_end_timing()

        offsets = []  # stim offsets within given TRs
        for rind in range(self.nrows):
            run = tdata[rind]
            if len(run) == 0: continue

            roffsets = UTIL.interval_offsets([val[0] for val in run], tr)
            offsets.extend(roffsets)

        if len(offsets) < 1: return []

        # get overall stats (absolute and fractional)

        # absolute
        m0, m1, m2, s = UTIL.min_mean_max_stdev(offsets)
        offmn = m0
        offm = m1
        offs = s
        mn = abs(min(offsets))
        offmax = abs(max(offsets))
        if mn > offmax: offmax = mn

        # fractional
        for ind, val in enumerate(offsets):
            offsets[ind] = val / tr
        m0, m1, m2, s = UTIL.min_mean_max_stdev(offsets)

        del (offsets)

        return [offmn, offm, offmax, offs, m0, m1, offmax / tr, s]
Exemple #2
0
   def get_TR_offset_stats(self, tr):
      """create a list of TR offsets (per-run and overall)

            tr : must be positive

         return: 8 values in a list:
                    min, mean, maxabs, stdev of absolute and fractional offsets
                 empty list on error
      """

      if not self.ready:
         print '** M Timing: nothing to compute ISI stats from'
         return []

      if self.nrows != len(self.data):
         print '** bad MTiming, nrows=%d, datalen=%d, failing...' % \
               (self.nrows, len(self.data))
         return []

      if tr < 0.0:
         print '** show_TR_offset_stats: invalid TR %s' % tr
         return []

      # make a copy of format run x stim x [start,end], i.e. is 3-D
      tdata = self.get_start_end_timing()

      offsets   = []    # stim offsets within given TRs
      for rind in range(self.nrows):
         run  = tdata[rind]
         if len(run) == 0: continue

         roffsets = UTIL.interval_offsets([val[0] for val in run], tr)
         offsets.extend(roffsets)

      if len(offsets) < 1: return []

      # get overall stats (absolute and fractional)

      # absolute
      m0, m1, m2, s = UTIL.min_mean_max_stdev(offsets)
      offmn = m0; offm = m1; offs = s
      mn = abs(min(offsets))
      offmax = abs(max(offsets))
      if mn > offmax: offmax = mn       

      # fractional
      for ind, val in enumerate(offsets):
         offsets[ind] = val/tr
      m0, m1, m2, s = UTIL.min_mean_max_stdev(offsets)

      del(offsets)

      return [offmn, offm, offmax, offs, m0, m1, offmax/tr, s]
Exemple #3
0
   def get_TR_offset_stats_str(self, tr, mesg='', wlimit=0.4):
      """return a string to display statistics regarding within-TR
                offsets of stimuli

            tr          : show mean/stdev for stimuli within TRs
                          (so 0 <= mean < tr)
            mesg        : display the user message in the output

         return status, stats string

                status > 0 : success, warnings were issued
                       = 0 : success, no warnings
                       < 0 : errors
      """

      if not self.ready:
         return 1, '** M Timing: nothing to compute ISI stats from'

      if self.nrows != len(self.data):
         return 1, '** bad MTiming, nrows=%d, datalen=%d, failing...' % \
                   (self.nrows, len(self.data))

      if tr < 0.0:
         return 1, '** show_TR_offset_stats: invalid TR %s' % tr

      off_means = []    # ... means per run
      off_stdev = []    # ... stdevs per run
      for rind in range(self.nrows):
         run  = self.data[rind]
         if len(run) == 0: continue

         # start with list of time remainders (offsets) within each TR
         roffsets = UTIL.interval_offsets([val for val in run], tr)

         m0, m1, m2, s = UTIL.min_mean_max_stdev(roffsets)
         off_means.append(m1)
         off_stdev.append(s)

      # if no events ere found, we're outta here
      if len(off_means) == 0:
         print 'file %s: no events?' % self.name
         return 0, ''

      # and get overall stats (absolute and fractional)
      offs = self.get_TR_offset_stats(tr)

      # print out offset info
      if mesg: mstr = '(%s) ' % mesg
      else:    mstr = ''

      rstr = '\nwithin-TR stimulus offset statistics %s:\n' % mstr

      hdr1 = '    overall:     '
      hdr2 = '    fractional:  '
      shdr = '                 '
      rv   = 0
      if self.nrows > 1:
         rstr += '                       per run\n'                        \
                 '                       ------------------------------\n' \
                 '    offset means       %s\n'                             \
                 '    offset stdevs      %s\n'                             \
                 '\n'                                                      \
                 % (float_list_string(off_means,ndec=3),
                    float_list_string(off_stdev,ndec=3))
      else: hdr1 = '    one run:     '

      rstr += '%smean = %.3f  maxoff = %.3f  stdev = %.4f\n'   \
              % (hdr1, offs[1], offs[2], offs[3])
      rstr += '%smean = %.3f  maxoff = %.3f  stdev = %.4f\n' \
              % (hdr2, offs[5], offs[6], offs[7])

      # a warning may be issued if the min is positive and the max is small
      if offs[6] == 0: rstr += '\n%s(stimuli are TR-locked)\n' % shdr
      elif wlimit > 0.0 and offs[4] > 0 and offs[6] < wlimit:
         rstr += '\n'                                                         \
            '%s** WARNING: small maxoff suggests (almost) TR-locked stimuli\n'\
            '%s   consider: timing_tool.py -round_times (if basis = TENT)\n'  \
            %(shdr,shdr)
         rv = 1

      # clean up, just to be kind
      del(off_means); del(off_stdev)

      return rv, rstr
Exemple #4
0
    def get_TR_offset_stats_str(self, tr, mesg='', wlimit=0.4):
        """return a string to display statistics regarding within-TR
                offsets of stimuli

            tr          : show mean/stdev for stimuli within TRs
                          (so 0 <= mean < tr)
            mesg        : display the user message in the output

         return status, stats string

                status > 0 : success, warnings were issued
                       = 0 : success, no warnings
                       < 0 : errors
      """

        if not self.ready:
            return 1, '** M Timing: nothing to compute ISI stats from'

        if self.nrows != len(self.data):
            return 1, '** bad MTiming, nrows=%d, datalen=%d, failing...' % \
                      (self.nrows, len(self.data))

        if tr < 0.0:
            return 1, '** show_TR_offset_stats: invalid TR %s' % tr

        off_means = []  # ... means per run
        off_stdev = []  # ... stdevs per run
        for rind in range(self.nrows):
            run = self.data[rind]
            if len(run) == 0: continue

            # start with list of time remainders (offsets) within each TR
            roffsets = UTIL.interval_offsets([val for val in run], tr)

            m0, m1, m2, s = UTIL.min_mean_max_stdev(roffsets)
            off_means.append(m1)
            off_stdev.append(s)

        # if no events ere found, we're outta here
        if len(off_means) == 0:
            print 'file %s: no events?' % self.name
            return 0, ''

        # and get overall stats (absolute and fractional)
        offs = self.get_TR_offset_stats(tr)

        # print out offset info
        if mesg: mstr = '(%s) ' % mesg
        else: mstr = ''

        rstr = '\nwithin-TR stimulus offset statistics %s:\n' % mstr

        hdr1 = '    overall:     '
        hdr2 = '    fractional:  '
        shdr = '                 '
        rv = 0
        if self.nrows > 1:
            rstr += '                       per run\n'                        \
                    '                       ------------------------------\n' \
                    '    offset means       %s\n'                             \
                    '    offset stdevs      %s\n'                             \
                    '\n'                                                      \
                    % (float_list_string(off_means,ndec=3),
                       float_list_string(off_stdev,ndec=3))
        else:
            hdr1 = '    one run:     '

        rstr += '%smean = %.3f  maxoff = %.3f  stdev = %.4f\n'   \
                % (hdr1, offs[1], offs[2], offs[3])
        rstr += '%smean = %.3f  maxoff = %.3f  stdev = %.4f\n' \
                % (hdr2, offs[5], offs[6], offs[7])

        # a warning may be issued if the min is positive and the max is small
        if offs[6] == 0: rstr += '\n%s(stimuli are TR-locked)\n' % shdr
        elif wlimit > 0.0 and offs[4] > 0 and offs[6] < wlimit:
            rstr += '\n'                                                         \
               '%s** WARNING: small maxoff suggests (almost) TR-locked stimuli\n'\
               '%s   consider: timing_tool.py -round_times (if basis = TENT)\n'  \
               %(shdr,shdr)
            rv = 1

        # clean up, just to be kind
        del (off_means)
        del (off_stdev)

        return rv, rstr