Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 
0003 import os, numpy as np
0004 from opticks.ana.fold import Fold
0005 from opticks.ana.pvplt import *
0006 
0007 TEST = os.environ["TEST"]
0008 OPTS = os.environ["OPTS"] 
0009 
0010 def test_AroundCylinder(t):
0011     """
0012     With OPTS 'TR,tr,R,T,r,t'
0013 
0014         np.all( a0 == a[:,0] )  
0015         np.all( a1 == a[:,1] )  
0016 
0017     """
0018     vopt = OPTS.split(",")
0019     
0020     assert vopt[0] == "TR" 
0021     assert vopt[1] == "tr" 
0022 
0023     a = t.AroundCylinder
0024     a0t = a[:,0].transpose(0,2,1)
0025     a1t = a[:,1].transpose(0,2,1)
0026 
0027     trs = a1t    ## arrows pointing inwards
0028     #trs = a0t   ## surpise "starfish"
0029 
0030     radius = 5. 
0031     O = np.array( [0,0,0] )
0032     Z = np.array( [0,0,1] )
0033 
0034     arrows = []
0035     for i in range(len(trs)):
0036         arr = pv.Arrow(direction=Z)
0037         arr.transform(trs[i])
0038         arrows.append(arr)
0039     pass
0040     cyl = pv.Cylinder(direction=Z, center=O, radius=radius ) 
0041 
0042     pl = pvplt_plotter()
0043     pl.add_mesh(cyl, style="wireframe")
0044     for arr in arrows:
0045         pl.add_mesh(arr)
0046     pass
0047     pl.show()
0048 
0049 
0050 
0051 
0052 def test_AroundSphere(t):
0053     a = t.AroundSphere 
0054 
0055     a0t = a[:,0].transpose(0,2,1)
0056     a1t = a[:,1].transpose(0,2,1)
0057 
0058     trs = a1t   ## arrows pointing radially inwards from sphere surface
0059     #trs = a0t    ## arrows pointing out from S-pole
0060 
0061     radius = 5. 
0062 
0063     O = np.array( [0,0,0] )
0064     Z = np.array( [0,0,1] )
0065 
0066     arrows = []
0067     for i in range(len(trs)):
0068         arr = pv.Arrow(direction=Z)
0069         arr.transform(trs[i])
0070         arrows.append(arr)
0071     pass
0072     sph = pv.Sphere(center=O, radius=radius ) 
0073 
0074     pl = pvplt_plotter()
0075     pl.add_mesh(sph, style="wireframe")
0076     for arr in arrows:
0077         pl.add_mesh(arr)
0078     pass
0079     pl.show()
0080 
0081 
0082 
0083 
0084 
0085 
0086 if __name__ == '__main__':
0087     t = Fold.Load()
0088     print(t)
0089     print("TEST:%s" % TEST)
0090 
0091     if TEST == "AroundCylinder":
0092         test_AroundCylinder(t)
0093     elif TEST == "AroundSphere":
0094         test_AroundSphere(t)
0095     pass
0096 
0097