Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 
0003 import numpy as np
0004 from numpy.linalg import multi_dot
0005 
0006 from opticks.ana.fold import Fold
0007 from opticks.CSG.CSGFoundry import CSGFoundry 
0008 from opticks.ana.eprint import eprint, epr
0009 from opticks.sysrap.stree import stree
0010 
0011 
0012 def check_inverse_pair(f, a_="inst", b_="iinst" ):
0013     """
0014     :param f: Fold instance
0015 
0016     * Now avoided clearing the identity by taking a copy 
0017     * This demonstrates the necessity for double precision transforms
0018 
0019     """
0020     a = getattr(f, a_).copy()
0021     b = getattr(f, b_).copy()
0022 
0023     a[:,:,3] = [0.,0.,0.,1.]
0024     b[:,:,3] = [0.,0.,0.,1.]
0025 
0026     assert len(a) == len(b)
0027 
0028     chk = np.zeros( (len(a), 4, 4) )   
0029     for i in range(len(a)): chk[i] = np.dot( a[i], b[i] )   
0030     chk -= np.eye(4)
0031 
0032     print("check_inverse_pair :  %s %s " % (a_, b_))
0033     print(chk.min(), chk.max())
0034 
0035 
0036 def compare_f_with_cf(f, cf ):
0037     print("\n[compare_f_with_cf")
0038     eprint("(cf.inst[:,:,:3] - f.inst_f4[:,:,:3]).max()", globals(), locals())  
0039     eprint("(cf.inst[:,:,:3] - f.inst_f4[:,:,:3]).min()", globals(), locals())  
0040     eprint("np.all( cf.inst[:,:,3].view(np.int32)  == f.inst_f4[:,:,3].view(np.int32))", globals(), locals()) 
0041     print("]compare_f_with_cf\n")
0042 
0043 
0044 def check_inst(f, cf):
0045     print("\n[check_inst(f,cf) : comparing f:stree inst(from U4Tree) with cf:CSGFoundry inst (via CSG_GGeo) ")
0046 
0047     eprint("np.abs(cf.inst[:,:,:3]-f.inst_f4[:,:,:3]).max()", globals(), locals() ) 
0048     w = epr("w = np.where( np.abs(cf.inst[:,:,:3]-f.inst_f4[:,:,:3]) > 0.0001 )",  globals(), locals() )
0049 
0050     check_inverse_pair(f, "inst", "iinst" )
0051     check_inverse_pair(f, "inst_f4", "iinst_f4" )
0052     compare_f_with_cf(f, cf ) 
0053 
0054     a_inst = cf.inst.copy() 
0055     b_inst = f.inst_f4.copy() 
0056 
0057     print("a_inst[-1]")
0058     print(a_inst[-1])
0059     print("b_inst[-1]")
0060     print(b_inst[-1])
0061 
0062     print("\n]check_inst(f,cf)")
0063 
0064 def check_sensor(st):
0065     """
0066     dsid = np.diff(sid) 
0067     np.where( dsid != 1 )    (array([17611, 43211]),)
0068 
0069     In [40]: sid[17607:17618]
0070     Out[40]: array([ 17607,  17608,  17609,  17610,  17611, 300000, 300001, 300002, 300003, 300004, 300005], dtype=int32)
0071 
0072     In [42]: sid[43205:43220]
0073     Out[42]: array([325593, 325594, 325595, 325596, 325597, 325598, 325599,  30000,  30001,  30002,  30003,  30004,  30005,  30006,  30007], dtype=int32)
0074 
0075     """
0076     ws = np.where( st.nds.sensor_id > -1 )[0]  
0077 
0078     sidx_ = st.nds.sensor_index[ws]   
0079     sidx = sidx_[np.argsort(sidx_)]  
0080     x_sidx = np.arange(len(sidx), dtype=np.int32) 
0081     assert np.all( sidx == x_sidx ), "check sensor_idx contiguous from 0"   
0082 
0083     sid = st.nds.sensor_id[ws]  
0084     usid = np.unique(sid)
0085     assert len(usid) == len(sid), "check sensor_id are all unique"
0086     
0087 
0088 
0089 
0090 if __name__ == '__main__':
0091 
0092     cf = CSGFoundry.Load()
0093     print(cf)
0094 
0095     f = Fold.Load(symbol="f")
0096     print(repr(f))
0097 
0098     g_fold = os.path.join(os.path.dirname(f.base), "GGeo/stree") 
0099     print("g_fold:%s" % g_fold)
0100     g = Fold.Load(g_fold,symbol="g") 
0101     print(repr(g))
0102 
0103     st = stree(f)
0104     print(repr(st))
0105 
0106     check_inst(f, cf)
0107     #check_sensor(st)
0108 
0109