Back to home page

EIC code displayed by LXR

 
 

    


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

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 dat.py
0023 ========
0024 
0025 
0026 
0027 
0028 """
0029 
0030 import os, logging, numpy as np
0031 log = logging.getLogger(__name__)
0032 
0033 
0034 class Dat(object):
0035     """
0036     For interactive exploration of dimension > 3  arrays
0037     """
0038     def __init__(self, a, ina=None, jna=None, kna=None ):
0039         self.a = a
0040 
0041         if ina is None:
0042             ina = np.arange(0, a.shape[0] ).astype("|S16")
0043         if jna is None:
0044             jna = np.arange(0, a.shape[1] ).astype("|S16")
0045         if kna is None:
0046             kna = np.arange(0, a.shape[2] ).astype("|S16")
0047 
0048         self.ina = ina
0049         self.kna = kna
0050         self.jna = jna
0051 
0052         self.ijk = 0,0,0 
0053         self.sli = slice(0,None,1)
0054 
0055     def __getitem__(self, sli):
0056         self.sli = sli
0057         return self
0058 
0059     def _get_d(self):
0060         return self.a[self.i,self.j,self.k][self.sli]
0061     d = property(_get_d)
0062 
0063     def __repr__(self):
0064         return "\n".join(map(repr, [self.ijk, self.name, self.d]))
0065 
0066     def _get_name(self):
0067         return ",".join([self.ina[self.i], self.jna[self.j], self.kna[self.k]])
0068     name = property(_get_name)
0069 
0070     def _set_i(self, _i):
0071         assert _i < self.a.shape[0]
0072         self._i = _i
0073     def _get_i(self): 
0074         return self._i
0075     i = property(_get_i, _set_i)
0076 
0077     def _set_j(self, _j):
0078         assert _j < self.a.shape[1]
0079         self._j = _j
0080     def _get_j(self): 
0081         return self._j
0082     j = property(_get_j, _set_j)
0083 
0084     def _set_k(self, _k):
0085         assert _k < self.a.shape[2]
0086         self._k = _k
0087     def _get_k(self): 
0088         return self._k
0089     k = property(_get_k, _set_k)
0090 
0091     def _set_ijk(self, *ijk):
0092         assert len(ijk) == 1 and len(ijk[0]) == 3
0093         self.i = ijk[0][0]
0094         self.j = ijk[0][1]
0095         self.k = ijk[0][2]
0096     def _get_ijk(self):
0097         return (self.i, self.j, self.k)
0098     ijk = property(_get_ijk, _set_ijk)
0099 
0100 
0101 
0102 
0103 
0104 
0105 if __name__ == '__main__':
0106     from opticks.ana.main import opticks_main 
0107     ok = opticks_main()
0108 
0109     a = np.load(os.path.expandvars("$IDPATH/GBndLib/GBndLib.npy"))
0110     d = Dat(a, None, "omat osur isur imat".split(), "g0 g1".split())
0111 
0112     print(d)
0113 
0114