def check_pdgcode(self): cu = count_unique_sorted(self.pdgCode) print(cu) fmt = " %7d : %10s : %d " for typ, npc in cu: print(fmt % (typ, self.epdg(typ), npc)) pass
def __init__(self, aseq, af, cnames=["noname"], dbgseq=0, dbgmsk=0, dbgzero=False, cmx=0, smry=False): """ :param aseq: photon length sequence array :param af: instance of SeqType subclass, which knows what the codes mean :: In [10]: sa.aseq A([ 9227469, 9227469, 147639405, ..., 9227469, 9227469, 19661], dtype=uint64) In [11]: sa.aseq.shape Out[11]: (1000000,) """ cu = count_unique_sorted(aseq) self.smry = smry self.af = af self.dbgseq = dbgseq self.dbgmsk = dbgmsk self.dbgzero = dbgzero self.cmx = cmx self.table = SeqTable(cu, af, cnames=cnames, dbgseq=self.dbgseq, dbgmsk=self.dbgmsk, dbgzero=self.dbgzero, cmx=self.cmx, smry=self.smry) self.aseq = aseq self.cu = cu
def test_load_SeqTable(ok, af): try: ph = A.load_("ph", ok.src, ok.tag, ok.det, pfx=ok.pfx) except IOError as err: log.fatal(err) sys.exit(0) log.info("loaded ph %s %s shape %s " % (ph.path, ph.stamp, repr(ph.shape))) seqhis = ph[:, 0, 0] cu = count_unique_sorted(seqhis) ht = SeqTable(cu, af, smry=True) test_HistoryTable(ht, seqhis)
def check_counts(self): log.info("check_counts") i = self.i num_gensteps = len(i) num_photons = self.numPhotons.sum() print("num_gensteps : %d " % num_gensteps) print("num_photons : %d " % num_photons) cu = count_unique_sorted(self.ID) nph_tot = 0 ngs_tot = 0 fmt = " (%d)%-25s : ngs:%5d npho:%5d " for typ, ngs in cu: sel = i[:, 0, 0] == typ nph = i[sel][:, 0, 3].sum() nph_tot += nph ngs_tot += ngs print(fmt % (typ, self.enum(typ), ngs, nph)) pass print(fmt % (0, "TOTALS", ngs_tot, nph_tot))
from opticks.ana.nload import A from opticks.ana.nbase import count_unique_sorted cusfmt_ = lambda cus: "\n".join(["%16x %8d " % (q, n) for q, n in cus]) msk_ = lambda n: (1 << 4 * (n + 1)) - 1 # msk_(0)=0xf msk_(1)=0xff msk_(2)=0xfff if __name__ == '__main__': args = opticks_main(doc=__doc__, tag="1", src="torch", det="laser", c2max=2.0, tagoffset=0) np.set_printoptions(precision=4, linewidth=200, formatter={'int': hex}) log.info("tag %s src %s det %s c2max %s " % (args.utag, args.src, args.det, args.c2max)) dbg = False ph = A.load_("ph", args.src, args.utag, args.det, dbg, optional=True) seqhis = ph[:, 0, 0] for i in range(10): msk = msk_(i) sqh = seqhis & msk isqh = count_unique_sorted(sqh) print "%16x --------------- " % msk print cusfmt_(isqh)
129 3332332332332231 56 4 45.07 14.000 +- 1.871 0.071 +- 0.036 [16] Gd Ac LS LS Ac Ac LS Ac Ac LS Ac Ac LS Ac Ac Ac 135 2231111323443231 51 6 35.53 8.500 +- 1.190 0.118 +- 0.048 [16] Gd Ac LS Ac MO MO Ac LS Ac Gd Gd Gd Gd Ac LS LS . 1000000 1000000 2325.00/233 = 9.98 """ import os, sys, logging, numpy as np log = logging.getLogger(__name__) from opticks.ana.base import opticks_main from opticks.ana.evt import Evt from opticks.ana.nbase import count_unique_sorted if __name__ == '__main__': ok = opticks_main(det="concentric", src="torch", tag="1") #seq = "Gd Ac LS Ac MO MO MO" #seq = "TO BT BT BT BT DR AB" #seq = "TO BT BT BT BT SC AB" #seq = "Gd Ac LS Ac MO MO Ac LS Ac Gd Ac LS Ac MO MO MO" seq = "Gd Gd Gd Ac LS Ac MO MO Ac LS Ac Gd Ac LS Ac Ac" a = Evt(tag="%s" % ok.utag, src=ok.src, det=ok.det, args=ok, seqs=[seq]) b = Evt(tag="-%s" % ok.utag, src=ok.src, det=ok.det, args=ok, seqs=[seq]) a.history_table(slice(0, 20)) b.history_table(slice(0, 20)) acu = count_unique_sorted(a.seqhis[a.psel]) bcu = count_unique_sorted(b.seqhis[b.psel])
log = logging.getLogger(__name__) from opticks.ana.base import opticks_main from opticks.ana.evt import Evt from opticks.ana.hismask import HisMask from opticks.ana.nbase import count_unique_sorted if __name__ == '__main__': ok = opticks_main(det="concentric", src="torch", tag="1") hm = HisMask() e = Evt(tag="-%s" % ok.utag, src=ok.src, det=ok.det, args=ok, seqs=["PFLAGS_DEBUG"]) e.history_table(slice(0, 20)) cu_pflags = count_unique_sorted(e.pflags[e.psel]) cu_pflags2 = count_unique_sorted(e.pflags2[e.psel]) print "\n".join(["", "cu_pflags (masks from CRecorder)"] + map(lambda _: hm.label(_), cu_pflags[:, 0])) print cu_pflags print "\n".join(["", "cu_pflags2 (masks derived from seqhis)"] + map(lambda _: hm.label(_), cu_pflags2[:, 0])) print cu_pflags2 print e.psel_dindex()
def test_HisMask_SeqTable(aa, af): hflags = aa[:,3,3].view(np.uint32) cu = count_unique_sorted(hflags) st = SeqTable(cu, af) print(st)
class HisType(SeqType): def __init__(self): flags = PhotonCodeFlags() SeqType.__init__(self, flags, flags.abbrev) if __name__ == '__main__': from opticks.ana.main import opticks_main #args = opticks_main(src="torch", tag="10", det="PmtInBox") ok = opticks_main() af = HisType() try: ph = A.load_("ph", ok.src, ok.tag, ok.det, pfx=ok.pfx) except IOError as err: log.fatal(err) sys.exit(args.mrc) log.info("loaded ph %s %s shape %s " % (ph.path, ph.stamp, repr(ph.shape))) seqhis = ph[:, 0, 0] cu = count_unique_sorted(seqhis) ht = SeqTable(cu, af, smry=True) test_HistoryTable(ht, seqhis) #test_roundtrip(af)