Back to home page

EIC code displayed by LXR

 
 

    


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

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 ncensus.py : Event Census wih array shape dumping 
0023 =====================================================
0024 
0025 Example output:
0026 
0027 .. code-block:: py
0028 
0029     In [12]: run ncensus.py
0030     INFO:__main__:dump .npy with abbrev rs 
0031     INFO:__main__: path           /usr/local/env/opticks/BoxInBox/rstorch/--save.npy shape (500000, 10, 1, 4) 
0032     INFO:__main__: path               /usr/local/env/opticks/BoxInBox/rstorch/-1.npy shape (500000, 10, 1, 4) 
0033     INFO:__main__: path                /usr/local/env/opticks/BoxInBox/rstorch/1.npy shape (5000000, 1, 4) 
0034     INFO:__main__: path              /usr/local/env/opticks/dayabay/rscerenkov/1.npy shape (6128410, 1, 4) 
0035     INFO:__main__: path                 /usr/local/env/opticks/dayabay/rstorch/1.npy shape (500000, 10, 1, 4) 
0036     INFO:__main__: path                    /usr/local/env/opticks/DPIB/rstorch/4.npy shape (5000000, 1, 4) 
0037     INFO:__main__: path                  /usr/local/env/opticks/G4Gun/rsg4gun/-1.npy shape (0, 10, 1, 4) 
0038     INFO:__main__: path                 /usr/local/env/opticks/juno/rscerenkov/1.npy shape (9812580, 1, 4) 
0039     INFO:__main__: path          /usr/local/env/opticks/juno_backup/rscerenkov/1.npy shape (9812580, 1, 4) 
0040     INFO:__main__: path               /usr/local/env/opticks/PmtInBox/rstorch/-1.npy shape (500000, 10, 1, 4) 
0041     INFO:__main__: path               /usr/local/env/opticks/PmtInBox/rstorch/-2.npy shape (500000, 10, 1, 4) 
0042     INFO:__main__: path               /usr/local/env/opticks/PmtInBox/rstorch/-4.npy shape (500000, 10, 1, 4) 
0043     INFO:__main__: path               /usr/local/env/opticks/PmtInBox/rstorch/-5.npy shape (500000, 10, 1, 4) 
0044     INFO:__main__: path               /usr/local/env/opticks/PmtInBox/rstorch/-6.npy shape (500000, 10, 1, 4) 
0045     INFO:__main__: path                /usr/local/env/opticks/PmtInBox/rstorch/1.npy shape (5000000, 1, 4) 
0046     INFO:__main__: path                /usr/local/env/opticks/PmtInBox/rstorch/2.npy shape (5000000, 1, 4) 
0047     INFO:__main__: path                /usr/local/env/opticks/PmtInBox/rstorch/4.npy shape (5000000, 1, 4) 
0048     INFO:__main__: path                /usr/local/env/opticks/PmtInBox/rstorch/5.npy shape (5000000, 1, 4) 
0049     INFO:__main__: path                /usr/local/env/opticks/PmtInBox/rstorch/6.npy shape (5000000, 1, 4) 
0050     INFO:__main__: path                /usr/local/env/opticks/rainbow/rstorch/-5.npy shape (1000000, 10, 1, 4) 
0051     INFO:__main__: path                /usr/local/env/opticks/rainbow/rstorch/-6.npy shape (1000000, 10, 1, 4) 
0052     INFO:__main__: path                 /usr/local/env/opticks/rainbow/rstorch/5.npy shape (10000000, 1, 4) 
0053     INFO:__main__: path                 /usr/local/env/opticks/rainbow/rstorch/6.npy shape (10000000, 1, 4) 
0054     INFO:__main__: path                /usr/local/env/opticks/reflect/rstorch/-1.npy shape (10000, 10, 1, 4) 
0055     INFO:__main__: path                 /usr/local/env/opticks/reflect/rstorch/1.npy shape (100000, 1, 4) 
0056     INFO:__main__:dump .npy with abbrev ps 
0057     INFO:__main__: path           /usr/local/env/opticks/BoxInBox/pstorch/--save.npy shape (500000, 1, 4) 
0058     INFO:__main__: path               /usr/local/env/opticks/BoxInBox/pstorch/-1.npy shape (500000, 1, 4) 
0059     INFO:__main__: path                /usr/local/env/opticks/BoxInBox/pstorch/1.npy shape (500000, 1, 4) 
0060     INFO:__main__: path              /usr/local/env/opticks/dayabay/pscerenkov/1.npy shape (612841, 1, 4) 
0061     INFO:__main__: path                 /usr/local/env/opticks/dayabay/pstorch/1.npy shape (500000, 1, 4) 
0062     INFO:__main__: path                    /usr/local/env/opticks/DPIB/pstorch/4.npy shape (500000, 1, 4) 
0063     ...
0064 
0065 """
0066 
0067 import os, logging
0068 log = logging.getLogger(__name__)
0069 import numpy as np
0070 
0071 from opticks.ana.base import opticks_environment
0072 
0073 class Census(object):
0074     def __init__(self, base):
0075         self.base = os.path.expandvars(base)
0076 
0077     def dump(self, abbrev="rs"):
0078         self.abbrev = abbrev
0079         log.info("dump .npy with abbrev %s " % abbrev )
0080         self.recurse(self.base, 0 )
0081 
0082     def recurse(self, bdir, depth):
0083         """
0084         
0085         """
0086         for name in os.listdir(bdir):
0087             path = os.path.join(bdir, name)
0088             if os.path.islink(path):
0089                 log.info("skip link %s " % path) 
0090             elif os.path.isdir(path):
0091                 self.recurse(path, depth+1)  
0092             else:
0093                 root, fext = os.path.splitext(name) 
0094                 if fext == ".npy":
0095                     self.visit_npy(path, depth)
0096                 pass
0097             pass
0098         pass
0099 
0100     def visit_npy(self, path, depth):
0101         elems = path.split("/")
0102         sub = elems[-2]
0103         ab = sub[:2]
0104         log.debug(" path %30s depth %d sub %s ab %s" % (path, depth, sub, ab))
0105         if ab == self.abbrev:
0106             ary = np.load(path) 
0107             log.info(" path %60s shape %s " % (path, repr(ary.shape)))
0108         pass
0109 
0110 
0111 
0112 if __name__ == '__main__':
0113     logging.basicConfig(level=logging.INFO)
0114     opticks_environment() 
0115 
0116     c = Census("$OPTICKS_EVENT_BASE/source/evt")
0117 
0118     c.dump("rs")
0119     c.dump("ps")
0120 
0121 
0122 
0123