File indexing completed on 2026-04-09 07:48:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 """
0022 hismask.py: HisMask
0023 ========================
0024
0025 ::
0026
0027 In [12]: from opticks.ana.hismask import HisMask
0028 In [13]: hm = HisMask()
0029 In [16]: hm.label(2114)
0030 Out[16]: 'BT|SD|SI'
0031
0032
0033
0034
0035
0036 """
0037 import os, datetime, logging, sys
0038 log = logging.getLogger(__name__)
0039 import numpy as np
0040
0041 from opticks.ana.base import PhotonMaskFlags
0042 from opticks.ana.seq import MaskType, SeqTable, SeqAna
0043 from opticks.ana.nbase import count_unique_sorted
0044 from opticks.ana.nload import A
0045
0046
0047 class HisMask(MaskType):
0048 """
0049 """
0050 def __init__(self):
0051 log.debug("HisMask.__init__")
0052 flags = PhotonMaskFlags()
0053 MaskType.__init__(self, flags, flags.abbrev)
0054 log.debug("HisMask.__init__ DONE")
0055
0056
0057 def test_HisMask(af):
0058 label = "TO BT SD"
0059 mask = af.code(label)
0060 label2 = af.label(mask)
0061 log.info( " %30s -> %d -> %10s " % (label, mask, label2 ))
0062
0063 def test_HisMask_SeqTable(aa, af):
0064 hflags = aa[:,3,3].view(np.uint32)
0065 cu = count_unique_sorted(hflags)
0066 st = SeqTable(cu, af)
0067 print(st)
0068
0069 def test_HisMask_SeqAna(aa, af):
0070 hflags = aa[:,3,3].view(np.uint32)
0071 sa = SeqAna(hflags, af)
0072 print(sa.table)
0073
0074
0075 if __name__ == '__main__':
0076 from opticks.ana.main import opticks_main
0077
0078 ok = opticks_main()
0079
0080 af = HisMask()
0081 test_HisMask(af)
0082
0083 try:
0084 ht = A.load_("ht",ok.src,ok.tag,ok.det, pfx=ok.pfx)
0085 log.info("loaded ht %s %s shape %s " % (ht.path, ht.stamp, repr(ht.shape)))
0086
0087 test_HisMask_SeqAna(ht, af)
0088 except IOError as err:
0089 log.warning("no ht")
0090
0091 try:
0092 ox = A.load_("ox",ok.src,ok.tag,ok.det, pfx=ok.pfx)
0093 log.info("loaded ox %s %s shape %s " % (ox.path, ox.stamp, repr(ox.shape)))
0094
0095 test_HisMask_SeqAna(ox, af)
0096 except IOError as err:
0097 log.warning("no ht")
0098
0099
0100
0101
0102
0103