Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 """
0003 smear_normal.py
0004 ===============
0005 
0006 """
0007 
0008 import os, numpy as np
0009 from opticks.ana.fold import Fold
0010 MODE=int(os.environ.get("MODE","0")) 
0011 
0012 if MODE in [1,2,3]:
0013     from opticks.ana.pvplt import *
0014     import matplotlib.pyplot as mp
0015 pass
0016 
0017 SIZE = np.array([1280, 720])
0018 
0019 TEST = os.environ.get("TEST", "")
0020 CHECK = os.environ.get("CHECK", "SmearNormal_SigmaAlpha")
0021 
0022 if __name__ == '__main__':
0023     f = Fold.Load(symbol="f")
0024     print(repr(f))
0025 
0026     is_mock = not getattr(f, CHECK, None ) is None
0027     if not is_mock: CHECK = "q"
0028 
0029     q = getattr(f, CHECK)
0030     assert len(q.shape) == 2
0031     assert q.shape[1] == 4
0032 
0033     a = q[:,:3]
0034 
0035     m = getattr(f, "%s_meta" % CHECK ) 
0036 
0037     source = m.source[0] if hasattr(m,'source') else "NO-source-metadata" 
0038     value = m.value[0] if hasattr(m,'value') else None
0039     valuename = m.valuename[0] if hasattr(m,'valuename') else None
0040 
0041     label = "%s " % source 
0042     label += " white %s:%s " % ( valuename, value )
0043     
0044 
0045     if MODE == 3:
0046         pl = pvplt_plotter(label=label)
0047         pvplt_viewpoint( pl )
0048 
0049         pos = np.array( [[0,0,0]] )
0050         vec = np.array( [[0,0,1]] ) 
0051         pvplt_lines( pl, pos, vec )
0052 
0053         pl.add_points( a , color="white" )
0054 
0055         cpos = pl.show()
0056 
0057     elif MODE == 2:
0058          
0059         fig, ax = mp.subplots(figsize=SIZE/100.)
0060         fig.suptitle(label)
0061         ax.set_aspect("equal")
0062 
0063         ax.scatter( a[:,0], a[:,1], s=0.1, c="b" )
0064         fig.show()
0065  
0066     elif MODE == 1:
0067 
0068         nrm = np.array( [0,0,1], dtype=np.float32 )  ## unsmeared normal is +Z direction  
0069         ## dot product with Z direction picks Z coordinate 
0070         ## so np.arccos should be the final alpha 
0071 
0072         angle = np.arccos(np.dot( a, nrm )) 
0073 
0074         bins = np.linspace(0,0.4,100)  
0075         h_angle = np.histogram(angle, bins=bins )[0] 
0076 
0077         fig, ax = mp.subplots(figsize=SIZE/100.)
0078         fig.suptitle(label)
0079 
0080         if not h_angle is None:ax.plot( bins[:-1], h_angle,  drawstyle="steps-post", label="h_angle" )
0081         ax.legend() 
0082 
0083         fig.show()
0084     pass
0085 pass
0086 
0087