Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:48

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
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      #ok = opticks_main(src="torch", tag="10", det="PmtInBox")
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          #test_HisMask_SeqTable(ht, af)
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          #test_HisMask_SeqTable(ox, af)
0095          test_HisMask_SeqAna(ox, af)
0096      except IOError as err:
0097          log.warning("no ht")
0098 
0099 
0100     
0101 
0102 
0103