Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 
0003 """
0004 QMultiFilmLUTTest.py
0005 ================
0006 
0007 ::
0008 
0009     QMultiFilmLUTTest 
0010     ipython -i tests/QMultiFilmLUTTest.py
0011 
0012 """
0013 import os, logging, numpy as np
0014 log = logging.getLogger(__name__)
0015 #from opticks.ana.nload import stamp_
0016 
0017 import matplotlib.pyplot as plt
0018 import matplotlib.cm  as cm
0019 import matplotlib as mpl
0020 class QMultiFilmTest(object):
0021     BASE = os.path.expandvars("${TMP}/QMultiFilmTest") 
0022     def __init__(self):
0023         mpl.rcParams['font.size'] = 15
0024         #path = os.path.join(self.BASE,"src.npy")
0025         #self.src = np.load(path)
0026         pass
0027     def test_all_lookup(self):
0028         src = self.src
0029         for pmtcatIdx in range(src.shape[0]):
0030             for resIdx in range(src.shape[1]):
0031                 dst_file_name = "pmtcat_{}resolution_{}.npy".format(pmtcatIdx,resIdx)
0032                 self.subsrc = self.src[pmtcatIdx,resIdx ,:,:,:]
0033                 self.test_lookup(dst_file_name)         
0034         
0035     def test_lookup(self, dst_file_name):
0036         path = os.path.join(self.BASE,dst_file_name)
0037         dst = np.load(path)
0038         print("dst.shape = {} dst = {} , src.shape = {}".format(dst.shape, dst , self.src.shape))
0039         
0040         subsrc = self.subsrc
0041         fig, axs = plt.subplots(3,4,figsize=(12,8))
0042         #for i in range(2):
0043         for j in range(4):
0044             plt.cla()
0045             origin = subsrc[:,:,j]
0046             gen = dst[:,:,j]
0047             diff = gen - origin
0048             imx = axs[0,j].imshow(origin)
0049             plt.colorbar(mappable=imx, ax=axs[0,j])
0050             imy = axs[1,j].imshow(gen) 
0051             plt.colorbar(mappable=imy, ax=axs[1,j])
0052             imz = axs[2,j].imshow(diff)
0053             plt.colorbar(mappable=imz, ax=axs[2,j])
0054         #fig.show()
0055         #fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap),ax=axs)
0056         plt.suptitle(dst_file_name + " Rs_Ts_Rp_Tp",fontsize = 16 )
0057         plt.show()
0058 
0059     def test_mock_lookup(self):
0060         path = os.path.join(self.BASE,"test_texture.npy")
0061         input_arr = np.load(path)
0062         print("input_arr shape = {}".format(input_arr.shape))
0063         
0064         path = os.path.join(self.BASE,"gpu_texture_interp.npy")
0065         res_arr = np.load(path)
0066         print("res_arr shape = {}".format(res_arr.shape))
0067       
0068          
0069         a_Rs = input_arr[:,:,1,0]  
0070         a_Ts = input_arr[:,:,1,1]  
0071         a_Rp = input_arr[:,:,1,2]  
0072         a_Tp = input_arr[:,:,1,3]  
0073         b_Rs = res_arr[:,:,0]
0074         b_Ts = res_arr[:,:,1]
0075         b_Rp = res_arr[:,:,2]
0076         b_Tp = res_arr[:,:,3]
0077 
0078         fig,ax = plt.subplots( figsize=(8,6) )
0079         ax.scatter(a_Rs,a_Rs - b_Rs,label= r"$R_s$",s=4,color='b')
0080         ax.scatter(a_Ts,a_Ts - b_Ts,label= r"$T_s$",s=4,color='g')
0081         ax.scatter(a_Rp,a_Rp - b_Rp,label= r"$R_p$",s=4,color='r')
0082         ax.scatter(a_Tp,a_Tp - b_Tp,label= r"$T_p$",s=4,color='m')
0083 
0084         ax.legend() 
0085         ax.set_xlabel("Calculation value")
0086         ax.set_ylabel("Difference")
0087         ax.tick_params(left= True, bottom = True, right =True, top= True, which = "both", direction = "in")
0088         ax.tick_params(left= True, bottom = True, right =True, top=True, which = "both", width = 1.5)
0089         ax.tick_params(left= True, bottom = True, right =True, top= True, which = "minor", length = 6)
0090         ax.tick_params(left= True, bottom = True, right =True, top= True, which = "major", length = 12)
0091         ax.minorticks_on()
0092         
0093         ax.grid(axis="both",linestyle="--")
0094         ax.spines['bottom'].set_linewidth(1.5)
0095         ax.spines['top'].set_linewidth(1.5)
0096         ax.spines['left'].set_linewidth(1.5)
0097         ax.spines['right'].set_linewidth(1.5)
0098         plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
0099     
0100         fig_dir = "fig"
0101         if not os.path.exists(fig_dir):
0102             os.makedirs(fig_dir)
0103         pdf_name = "{}/wv_128_aoi_256_interp.pdf".format(fig_dir)
0104         plt.savefig("{}".format(pdf_name))
0105         print("save as {}".format(pdf_name))
0106 
0107         plt.show()
0108 
0109 
0110         fig,ax = plt.subplots( figsize=(8,6) )
0111         bins = np.logspace(-5,0,50)
0112         ax.hist((a_Rs - b_Rs).flatten(), bins, label= r"$R_s$",histtype ="step", color='b',linewidth = 2)
0113         ax.hist((a_Ts - b_Ts).flatten(), bins, label= r"$T_s$",histtype ="step", color='g',linewidth = 2)
0114         ax.hist((a_Rp - b_Rp).flatten(), bins, label= r"$R_p$",histtype ="step", color='r',linewidth = 2)
0115         ax.hist((a_Tp - b_Tp).flatten(), bins, label= r"$T_p$",histtype ="step", color='m',linewidth = 2)
0116         ax.legend() 
0117         ax.set_xlabel("Difference")
0118         ax.set_xscale("log")
0119         ax.set_ylabel("Entry")
0120         ax.set_yscale("log")
0121         ax.tick_params(left= True, bottom = True, right =True, top= True, which = "both", direction = "in")
0122         ax.tick_params(left= True, bottom = True, right =True, top=True, which = "both", width = 1.5)
0123         ax.tick_params(left= True, bottom = True, right =True, top= True, which = "minor", length = 6)
0124         ax.tick_params(left= True, bottom = True, right =True, top= True, which = "major", length = 12)
0125         ax.minorticks_on()
0126         
0127         ax.grid(axis="both",linestyle="--")
0128         ax.spines['bottom'].set_linewidth(1.5)
0129         ax.spines['top'].set_linewidth(1.5)
0130         ax.spines['left'].set_linewidth(1.5)
0131         ax.spines['right'].set_linewidth(1.5)
0132         
0133         fig_dir = "fig"
0134         if not os.path.exists(fig_dir):
0135             os.makedirs(fig_dir)
0136         pdf_name = "{}/wv_128_aoi_256_difference_distribution.pdf".format(fig_dir)
0137         plt.savefig("{}".format(pdf_name))
0138         print("save as {}".format(pdf_name))
0139         plt.show()
0140 if __name__ == '__main__':
0141     logging.basicConfig(level=logging.INFO)
0142     t = QMultiFilmTest()
0143     #t.test_all_lookup()
0144     t.test_mock_lookup()
0145 
0146     
0147 
0148