示例#1
0
 def table(self, cu, hex_=False):
     assert len(cu.shape) == 2 and cu.shape[1] == 2
     for msk, cnt in sorted(cu, key=lambda _: _[1], reverse=True):
         label = ihex_(msk) if hex_ else int(msk)
         log.debug("Index msk %d cnt %d label %s " % (msk, cnt, label))
         print "%20s %10d : %40s " % (label, int(cnt), self(msk))
     pass
示例#2
0
    def label(self, arg):
        """
        :param i: integer code
        :return: abbreviation sequence string 

        ::

            In [6]: from opticks.ana.histype import HisType
            In [7]: af = HisType()

            In [4]: af.label(0xccd)        # hexint 
            Out[4]: 'TO BT BT'

            In [5]: af.label("TO BT BT")   # already a label 
            Out[5]: 'TO BT BT'

            In [6]: af.label("ccd")        # hexstring  (NB without 0x)
            Out[6]: 'TO BT BT'

            In [7]: af.label(".ccd")       # hexstring with wildcard continuation char "."
            Out[7]: 'TO BT BT ..'

        """
        if type(arg) is list or issubclass(arg.__class__, np.ndarray):
            return list(map(lambda _: self.label(_), arg))
        pass

        i = None
        wildcard = type(arg) == str and arg[0] == "."
        if wildcard:
            arg = arg[1:]

        if type(arg) is int:
            i = arg
        elif type(arg) is np.uint64:
            i = arg
        elif type(arg) is str:
            if self.hexstr.match(arg):
                i = int(arg, 16)
            else:
                return arg
            pass
        else:
            log.fatal("unexpected argtype %s %s " % (arg, repr(type(arg))))
            assert 0
        pass

        xs = ihex_(i)[::-1]  # top and tailed hex string in reverse order
        seq = list(map(lambda _: int(_, 16), xs))
        #log.debug("label xs %s seq %s " % (xs, repr(seq)) )
        d = self.code2abbr
        elem = list(map(lambda _: d.get(_, '?%s?' % _), seq))
        if wildcard:
            elem += [".."]

        return self.delim.join(elem)
示例#3
0
文件: seq.py 项目: hanswenzel/opticks
    def line(self, n):
        iseq = int(self.cu[n,0]) 
        imsk = int(self.msks[n])

        if self.dbgseq > 0 and ( self.dbgseq & iseq ) != self.dbgseq:
           return None 
        pass
    
        if self.dbgmsk > 0:
           pick = (self.dbgmsk & imsk) == self.dbgmsk   # 
           if not pick: 
               return None 

        if self.smry == False:
            xs = "%0.4d %16s" % (n, ihex_(iseq))        
        else:
            xs = "%0.4d " % (n)        
        pass
      
        vals = map(lambda _:" %7s " % _, self.cu[n,1:] ) 

        idif = self.idif[n] if len(vals) == 2 else None
        idif = " %4d " % idif if idif is not None else " " 


        label = self.labels[n]
        if self.smry == False:
            nstep = "[%-2d]" % self.label2nstep[label]
        else:
            nstep = "" 
        pass

        # show only lines with chi2 contrib greater than cmx
        if self.c2 is not None:
            if self.cmx > 0 and self.c2[n] < self.cmx:
                return None
            pass
        pass

        # show only lines with zero counts
        if self.c2 is not None:
            if self.dbgzero and self.cu[n,1] > 0 and self.cu[n,2] > 0:
                return None
            pass
        pass

        if self.c2 is not None:
            sc2 = " %10.2f " % (self.c2[n])
        else:
            sc2 = ""
        pass

        if self.ab is not None and self.smry == False:
            sab = " %10.3f +- %4.3f " % ( self.ab[n,0], self.ab[n,1] )
        else:
            sab = ""
        pass

        if self.ba is not None and self.smry == False:
            sba = " %10.3f +- %4.3f " % ( self.ba[n,0], self.ba[n,1] )
        else:
            sba = ""
        pass


        if self.total is not None:
             frac = float(self.cu[n,1])/float(self.total)
             frac = " %10.3f   " % frac
        else:
             frac = ""
        pass
        cols = [xs+" "] + [frac] + vals + [idif] + ["   "]+ [sc2, sab, sba, nstep, label]
        return " ".join(filter(lambda _:_ != "", cols)) 
示例#4
0
    def line(self, n, key=False, smry=False):
        """
        :param n: 0-based line number
        :param key: when True returns column labels, ignoring n
        :param smry: when True presents less columns 
        :return str: formatted line of sequence table 
        """
        iseq = int(self.cu[n, 0])
        imsk = int(self.msks[n])

        if self.dbgseq > 0 and (self.dbgseq & iseq) != self.dbgseq:
            return None
        pass

        if self.dbgmsk > 0:
            pick = (self.dbgmsk & imsk) == self.dbgmsk  #
            if not pick:
                return None
            pass
        pass

        if smry == False:
            xn = self.xn_fmt % (n)
            k_xn = self.k_xn_fmt % ("n")
        else:
            xn = self.xn_fmt % (n)
            k_xn = self.k_xn_fmt % ("n")
        pass

        if smry == False:
            xs = self.k_xs_fmt % (ihex_(iseq))
            k_xs = self.k_xs_fmt % ("iseq")
        else:
            xs = self.k_xs_fmt % (ihex_(iseq))
            k_xs = self.k_xs_fmt % ("iseq")
        pass

        #cfo_debug = self.cfo_line(n)
        cfo_debug = ""
        k_cfo_debug = ""

        vals = list(map(lambda _: self.k_xv_fmt % _, self.cu[n, 1:]))
        keys = "abcdefghijklmnopqrstuvwxyz"
        k_vals = list(
            map(lambda _: self.k_xv_fmt % keys[_], range(len(self.cu[n, 1:]))))

        idif = self.idif[n] if len(vals) == 2 else None
        idif = self.idif_fmt % idif if idif is not None else " "
        k_idif = self.k_idif_fmt % "a-b" if idif is not None else " "

        label = self.k_label_fmt % self.labels[n]
        k_label = self.k_label_fmt % "label"

        if smry == False:
            nstep = "[%-2d]" % self.label2nstep[label]
            k_nstep = "[ns]"
        else:
            nstep = ""
            k_nstep = ""
        pass

        # show only lines with chi2 contrib greater than cmx
        if self.c2 is not None:
            if self.cmx > 0 and self.c2[n] < self.cmx:
                return None
            pass
        pass

        # show only lines with zero counts
        if self.c2 is not None:
            if self.dbgzero and self.cu[n, 1] > 0 and self.cu[n, 2] > 0:
                return None
            pass
        pass

        if self.c2 is not None:
            sc2 = self.sc2_fmt % (self.c2[n])
            k_sc2 = self.k_sc2_fmt % "(a-b)^2/(a+b)"
        else:
            sc2 = ""
            k_sc2 = ""
        pass

        if self.ab is not None and smry == False:
            sab = " %10.3f +- %5.3f " % (self.ab[n, 0], self.ab[n, 1])
            k_sab = " %10s    %5s " % ("a/b", "")
        else:
            sab = ""
            k_sab = ""
        pass

        if self.ba is not None and smry == False:
            sba = " %10.3f +- %5.3f " % (self.ba[n, 0], self.ba[n, 1])
            k_sba = " %10s    %5s " % ("b/a", "")
        else:
            sba = ""
            k_sba = ""
        pass

        if self.total is not None:
            frac = float(self.cu[n, 1]) / float(self.total)
            frac = " %10.3f   " % frac
            k_frac = " %10s   " % "frac"
        else:
            frac = ""
            k_frac = ""
        pass

        cols = [cfo_debug, xn, xs, frac] + vals + [
            self.div1, idif, self.div2, sc2, sab, sba, nstep, self.div3, label
        ]
        k_cols = [k_cfo_debug, k_xn, k_xs, k_frac] + k_vals + [
            self.div1, k_idif, self.div2, k_sc2, k_sab, k_sba, k_nstep,
            self.div3, k_label
        ]

        u_cols = k_cols if key == True else cols
        return "".join(filter(lambda _: _ != "", u_cols))
示例#5
0
def seqmat_(i, abbrev=True):
    mi = iabmat_() if abbrev else imat_()
    x = ihex_(i)
    return " ".join(map(lambda _: mi[int(_, 16)], x[::-1]))
示例#6
0
def seqhis_(i, abbrev=True):
    fi = iabflags_() if abbrev else iflags_()
    x = ihex_(i)
    return " ".join(map(lambda _: fi[int(_, 16)], x[::-1]))
示例#7
0
 def __call__(self, i):
     x = ihex_(i)
     log.debug("seqhis %s " % x)
     return " ".join(
         map(lambda _: self.fi.get(int(_, 16), '?%s?' % int(_, 16)),
             x[::-1]))