File indexing completed on 2026-04-09 07:48:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 """
0022 MergedMesh
0023 ~~~~~~~~~~~~
0024
0025 Enables access to geocache data.
0026
0027 .. code-block:: py
0028
0029 In [37]: filter(lambda _:_.find("IAV") > -1, vn.pv.names)
0030 Out[37]:
0031 ['__dd__Geometry__AD__lvLSO--pvIAV0xc2d0348',
0032 '__dd__Geometry__AD__lvIAV--pvGDS0xbf6ab00',
0033 '__dd__Geometry__AD__lvIAV--pvOcrGdsInIAV0xbf6b0e0',
0034 '__dd__Geometry__AD__lvLSO--pvIAV0xc2d0348',
0035 '__dd__Geometry__AD__lvIAV--pvGDS0xbf6ab00',
0036 '__dd__Geometry__AD__lvIAV--pvOcrGdsInIAV0xbf6b0e0']
0037
0038 In [38]: mm.center_extent
0039 Out[38]:
0040 array([[ -16520. , -802110. , -7125. , 7710.562],
0041 [ -16520. , -802110. , 3892.9 , 34569.875],
0042 [ -12840.846, -806876.25 , 5389.855, 22545.562],
0043 ...,
0044 [ -12195.957, -799312.625, -7260. , 5000. ],
0045 [ -17081.184, -794607.812, -7260. , 5000. ],
0046 [ -16519.908, -802110. , -12410. , 7800.875]], dtype=float32)
0047
0048 In [39]: mm.center_extent.shape
0049 Out[39]: (12230, 4)
0050
0051
0052 Exercise:
0053
0054 * add methods to enable access the center and extent of a
0055 volume from its name
0056
0057 * determine the coordinates of the centers of the IAVs
0058 in the three DayaBay sites
0059
0060 """
0061 import os, logging, numpy as np
0062 from opticks.ana.base import ItemList
0063 from opticks.ana.nbase import vnorm
0064
0065 log = logging.getLogger(__name__)
0066
0067 class MergedMesh(object):
0068 def __init__(self, base):
0069 mdir = os.path.expandvars(base)
0070 log.info("ready buffers from %s " % mdir)
0071 stems = []
0072 for name in os.listdir(mdir):
0073 stem, ext = os.path.splitext(name)
0074 log.debug(" name %s ext [%s] " % (name, ext))
0075 if ext == ".npy":
0076 path = os.path.join(mdir,name)
0077 log.debug("path %s " % path )
0078 os.system("ls -l %s " % path)
0079 a = np.load(path)
0080 log.debug(" stem %s shape %s " % (stem, repr(a.shape)))
0081 setattr(self, stem, a)
0082 stems.append(stem)
0083 else:
0084 pass
0085 pass
0086 pass
0087 self.stems = stems
0088
0089 def vertices_(self, i):
0090 """
0091 nodeinfo[:,1] provides the vertex counts, to convert a node index
0092 into a vertex range potentially with a node numbering offset need
0093 to add up all vertices prior to the one wish to access
0094
0095 ::
0096
0097 In [6]: imm.nodeinfo
0098 Out[6]:
0099 array([[ 720, 362, 3199, 3155],
0100 [ 672, 338, 3200, 3199],
0101 [ 960, 482, 3201, 3200],
0102 [ 480, 242, 3202, 3200],
0103 [ 96, 50, 3203, 3200]], dtype=uint32)
0104
0105
0106 """
0107 no = self.node_offset
0108 v_count = self.nodeinfo[0:no+i, 1]
0109 v_offset = v_count.sum()
0110 v_number = self.nodeinfo[no+i, 1]
0111 log.info("no %s v_count %s v_number %s v_offset %s " % (no, repr(v_count), v_number, v_offset))
0112 return self.vertices[v_offset:v_offset+v_number]
0113
0114 def rz_(self, i):
0115 v = self.vertices_(i)
0116
0117 r = vnorm(v[:,:2])
0118
0119 rz = np.zeros((len(v),2), dtype=np.float32)
0120 rz[:,0] = r*np.sign(v[:,0])
0121 rz[:,1] = v[:,2]
0122 return rz
0123
0124 def __repr__(self):
0125 return "\n".join( map(lambda stem:" %20s : %s " % (stem, repr(getattr(self,stem,None).shape)), self.stems))
0126
0127
0128
0129 class VolumeNames(object):
0130 def __init__(self):
0131 self.lv = ItemList(txt="LVNames", offset=0)
0132 self.pv = ItemList(txt="PVNames", offset=0)
0133
0134 if __name__ == '__main__':
0135 logging.basicConfig(level=logging.INFO)
0136 mm = MergedMesh("$IDPATH/GMergedMesh/0")
0137 vn = VolumeNames()
0138
0139 log.info("check: mm and vn ")
0140
0141
0142