File indexing completed on 2026-04-09 07:49:15
0001
0002
0003 import numpy as np
0004 import hashlib
0005 dig_ = lambda _:hashlib.md5(_).hexdigest()[:8]
0006
0007 from opticks.ana.fold import Fold
0008
0009 def reconstruct_mt(t):
0010 """
0011 :param t: Fold containing : optical, bd, bnd_names
0012 :return mt:
0013
0014 Vacuum ABSLENGTH of 1.e+09 within array triggers obnoxious array presentation
0015 to make less obnoxious reduce that : mt[16,0,:,1] = 1.e+06
0016 """
0017
0018 bd_ = "np.array( t.optical[:,:,0], dtype=np.int32 ) - 1"
0019 bd = eval(bd_)
0020
0021 print( bd_ )
0022 print( "bd.shape : %s " % str(bd.shape) )
0023
0024 assert np.all( bd == t.bd )
0025
0026 mbd = bd.copy()
0027 mbd[:,1] = -1
0028 mbd[:,2] = -1
0029
0030 name_bd = np.zeros( (len(t.bnd_names), 4 ), dtype="|S50" )
0031 for i in range(len(name_bd)): name_bd[i] = t.bnd_names[i].split("/")
0032 assert name_bd.shape == bd.shape
0033
0034
0035 num_mt = mbd.max()+1
0036 mt_shape = (num_mt,) + t.bnd.shape[-3:]
0037
0038 mt = np.zeros( mt_shape, dtype=t.bnd.dtype )
0039
0040 for i in range(num_mt):
0041 wr, wc = np.where( mbd == i )
0042 assert len(wr) == len(wc)
0043 assert len(wr) > 0
0044
0045 mt[i] = t.bnd[wr[0],wc[0]]
0046 dig = dig_(mt[i].data)
0047
0048 name = name_bd[wr[0],wc[0]]
0049
0050 print(" i %d wr : %s wc %s dig %s name %s " % ( i, str(wr), str(wc), dig, name ))
0051
0052 for j in range(len(wr)):
0053 other = t.bnd[wr[j],wc[j]]
0054 assert dig == dig_(other.data)
0055 other_name = name_bd[wr[j],wc[j]]
0056 assert name == other_name
0057 pass
0058 return mt
0059
0060
0061 if __name__ == '__main__':
0062 t = Fold.Load(symbol="t")
0063 print(repr(t))
0064
0065 mt = reconstruct_mt(t)
0066 mt[16,0,:,1] = 1.e+06
0067
0068 if np.all( t.mat[16,0,:,1] == 1e9 ):
0069 print("Vacuum 1e9 kludge reduce to 1e6 : because it causes obnoxious presentation")
0070 t.mat[16,0,:,1] = 1e6
0071 else:
0072 print("Not doing Vacuum kludge")
0073 pass
0074
0075 assert np.all( mt == t.mat )
0076