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 mattype.py : 
0023 ===============================
0024 
0025 
0026 Testing material mechanics
0027 
0028 * round tripping codes 
0029 
0030 ::
0031 
0032     In [24]: s = "MO Py MO MO Py OV Vm MO"
0033 
0034     In [25]: mt.code(s)
0035     Out[25]: 1304315108
0036 
0037     In [26]: c = mt.code(s)
0038 
0039     In [27]: "%x" % c
0040     Out[27]: '4dbe44e4'
0041 
0042     In [30]: type(c)
0043     Out[30]: int
0044 
0045 
0046     In [23]: run material.py
0047     MO Py MO MO Py OV Vm MO : 4dbe44e4 : MO Py MO MO Py OV Vm MO
0048                                   -1 
0049                      ee4        0.954         476939       [3 ] MO Py Py
0050                       44        0.038          18876       [2 ] MO MO
0051                      444        0.007           3573       [3 ] MO MO MO
0052                     ee44        0.001            521       [4 ] MO MO Py Py
0053                     4444        0.000             58       [4 ] MO MO MO MO
0054                    44e44        0.000             22       [5 ] MO MO Py MO MO
0055                    ee444        0.000              4       [5 ] MO MO MO Py Py
0056                   44ee44        0.000              2       [6 ] MO MO Py Py MO MO
0057               44e5dbe444        0.000              1       [10] MO MO MO Py OV Vm Bk Py MO MO
0058                  44ee444        0.000              1       [7 ] MO MO MO Py Py MO MO
0059                   444e44        0.000              1       [6 ] MO MO Py MO MO MO
0060                    44444        0.000              1       [5 ] MO MO MO MO MO
0061                     eee4        0.000              1       [4 ] MO Py Py Py
0062                               500000         1.00 
0063 
0064 
0065 """
0066 import os, sys, datetime, logging
0067 log = logging.getLogger(__name__)
0068 import numpy as np
0069 
0070 from opticks.ana.base import Abbrev, ItemList 
0071 from opticks.ana.seq import SeqType, SeqAna
0072 from opticks.ana.proplib import PropLib
0073 from opticks.ana.nload import A
0074 
0075 SEQHIS = 0
0076 SEQMAT = 1
0077 
0078 def test_roundtrip(mt):
0079     """
0080     ::
0081 
0082        MO Py MO MO Py OV Vm MO : 4dbe44e4 : MO Py MO MO Py OV Vm MO
0083 
0084     """
0085     s = "MO Py MO MO Py OV Va MO"
0086     #s = "Ml Px Ml Ml Px Om Vm Ml"   ## huh why the capital casing not working ? These are first last 
0087     i = mt.code(s)
0088     l = mt.label(i)
0089     print("%s : %x : %s" % (s, i, l ))
0090     assert l == s, (l,s) 
0091 
0092 class MatType(SeqType):
0093     """
0094     MatType specializes SeqType by providing it with 
0095     material codes and abbreviations.
0096 
0097     ::
0098 
0099         In [17]: flags.code2name
0100         Out[17]: 
0101         {1: 'GdDopedLS',
0102          2: 'LiquidScintillator',
0103          3: 'Acrylic',
0104          4: 'MineralOil',
0105        
0106         In [18]: abbrev.abbr2name
0107         Out[18]: 
0108         {'AS': 'ADTableStainlessSteel',
0109          'Ac': 'Acrylic',
0110          'Ai': 'Air',
0111          'Al': 'Aluminium',
0112          'Bk': 'Bialkali',
0113          'Dw': 'DeadWater',
0114 
0115 
0116     simon:opticksdata blyth$ find . -name abbrev.json
0117     ./export/DayaBay/GMaterialLib/abbrev.json
0118     ./resource/GFlags/abbrev.json
0119     simon:opticksdata blyth$ 
0120 
0121 
0122     Formerly used "$OPTICKS_DETECTOR_DIR/GMaterialLib/abbrev.json"
0123     but that makes no sense in direct workflow, so now
0124     "$GEOCACHE/GMaterialLib/GPropertyLibMetadata.json"
0125 
0126     """
0127     def __init__(self, reldir=None):
0128         material_names = ItemList("GMaterialLib", reldir=reldir)
0129         material_abbrev = Abbrev("$KEYDIR/GMaterialLib/GPropertyLibMetadata.json")
0130         SeqType.__init__(self, material_names, material_abbrev)
0131 
0132 
0133 if __name__ == '__main__':
0134     from opticks.ana.main import opticks_main
0135     ok = opticks_main()
0136 
0137     #mn = ItemList("GMaterialLib")
0138     #ab = Abbrev("$OPTICKS_DETECTOR_DIR/GMaterialLib/abbrev.json")
0139 
0140     mt = MatType()
0141     test_roundtrip(mt)
0142 
0143     try:
0144         ph = A.load_("ph",ok.src,ok.tag,ok.det, pfx=ok.pfx)
0145     except IOError as err:
0146         log.fatal(err)
0147         sys.exit(1) 
0148 
0149     log.info("loaded ph %s %s %s " % ( ph.path, ph.stamp, repr(ph.shape)))
0150 
0151     seqmat = ph[:,0,1]
0152     ma = SeqAna.for_evt(mt, ok.tag, ok.src, ok.det, pfx=ok.pfx, offset=SEQMAT)
0153     print(ma.table)
0154 
0155 
0156 
0157