Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:16

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 analytic_cf_triangulated.py
0023 ------------------------------
0024 
0025 Plot analytic shapes and mesh vertices together.
0026 Making the problem of vacumm volume vertices very plain.
0027 
0028 
0029 """
0030 
0031 import os, logging
0032 import numpy as np
0033 
0034 import matplotlib.pyplot as plt
0035 
0036 from opticks.ana.base import opticks_environment
0037 from opticks.ana.pmt.plot import Pmt, PmtPlot, one_plot
0038 from opticks.ana.mergedmesh import MergedMesh
0039 from opticks.ana.debug.dae import DAE
0040 
0041 log = logging.getLogger(__name__)
0042 
0043 
0044 X = 0
0045 Y = 1
0046 Z = 2
0047 
0048 ZX = [Z,X]
0049 ZY = [Z,Y]
0050 XY = [X,Y]
0051 
0052 
0053 def plot_vertices(fig, mm, N=5):
0054     N = 5
0055     for i in range(N):
0056         ax = fig.add_subplot(1,N,i, aspect='equal')
0057         ax.set_xlim(-120,120)
0058         ax.set_ylim(-200,150)
0059         rz = mm.rz_(i)
0060         ax.plot(rz[:,0], rz[:,1], "o")
0061     pass
0062 
0063 
0064 def solids_plot(fig, pmt, mm, solids=range(5)):
0065 
0066     if len(solids)>4:
0067         ny,nx = 3,2 
0068     else:
0069         ny,nx = 2,2 
0070 
0071     for i,solid in enumerate(solids):
0072         pts = pmt.parts(solid)
0073         ax = fig.add_subplot(nx,ny,i+1, aspect='equal')
0074         pp = PmtPlot(ax, pmt, axes=ZX) 
0075         pp.plot_shape(pts, clip=True)
0076         pp.limits()
0077 
0078         rz = mm.rz_(i)
0079         z = rz[:,1]
0080         r = rz[:,0]
0081         zedge = z[z>-150].min() 
0082 
0083         log.info("i %s z[z>-150].min() %s " % (i,zedge) )
0084         ax.plot(z, r, "o")
0085     pass
0086 
0087 
0088 
0089 if __name__ == '__main__':
0090     logging.basicConfig(level=logging.INFO)
0091     np.set_printoptions(precision=4, linewidth=200)
0092 
0093     opticks_environment() 
0094 
0095     plt.ion()
0096     plt.close()
0097 
0098     idfold = os.path.dirname(os.path.dirname(os.path.expandvars("$IDPATH")))
0099 
0100     base = os.path.expandvars("$IDPATH/GMergedMesh/1")
0101     #base = os.path.expandvars("$IDPATH_DPIB_ALL/GMergedMesh/0")
0102     #base = os.path.expandvars("$IDPATH_DPIB_PMT/GMergedMesh/0")
0103 
0104     if base.startswith(idfold):
0105         name = base[len(idfold)+1:]
0106     else:
0107         name = base 
0108 
0109 
0110     mm = MergedMesh(base=base)
0111     if base.find("export/dpib")>-1:
0112         mm.node_offset = 1
0113     else:
0114         mm.node_offset = 0
0115     pass
0116 
0117 
0118     pmt = Pmt()
0119     ALL, PYREX, VACUUM, CATHODE, BOTTOM, DYNODE = None,0,1,2,3,4
0120     pts = pmt.parts(ALL)
0121 
0122     fig = plt.figure() 
0123     fig.suptitle("analytic vs triangulated : %s " % name )
0124 
0125     one_plot(fig, pmt, pts, axes=ZX, clip=True)
0126 
0127     #solids_plot(fig, pmt, mm, solids=range(5))
0128 
0129     #plot_vertices(fig, mm)
0130 
0131     plt.show()
0132 
0133     print mm.nodeinfo.view(np.int32)
0134 
0135 
0136     path_0 = DAE.standardpath()
0137     dae_0 = DAE(path_0)
0138 
0139     a = dae_0.float_array("pmt-hemi-vac0xc21e248-Pos-array")
0140 
0141     r = np.linalg.norm(a[:,:2], 2, 1) * np.sign(a[:,0] )
0142     z = a[:,2]
0143     print z[z>-150].min()
0144 
0145     ax = fig.add_subplot(2,3,6, aspect='equal')
0146     ax.plot(z, r, "o")
0147 
0148 
0149