File indexing completed on 2026-04-09 07:48:50
0001
0002 """
0003
0004 https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
0005
0006
0007 """
0008 import math
0009 import numpy as np
0010 from scipy.interpolate import interp1d
0011 from scipy.interpolate import CubicSpline
0012 from opticks.ana.mlib import GMaterialLib
0013 mlib = GMaterialLib()
0014
0015 import matplotlib.pyplot as plt
0016
0017 if __name__ == '__main__':
0018
0019 names = []
0020 for name in mlib.names:
0021 a = mlib("%s.RINDEX" % name )
0022 one_value = np.all(a == a[0])
0023 print("name:%-20s mn:%10.4f mx:%10.4f %s " % (name, a.min(), a.max(), "one-value" if one_value else "-"))
0024 if one_value: continue
0025 pass
0026 names.append(name)
0027 pass
0028 print(names)
0029 names = ["LS"]
0030
0031 fig, axs = plt.subplots(len(names), sharex=True)
0032 if len(names) == 1: axs = [axs]
0033 for i in range(len(names)):
0034 ax = axs[i]
0035 name = names[i]
0036 ri = mlib("%s.RINDEX" % name)
0037
0038
0039
0040
0041
0042
0043 interp = CubicSpline( mlib.nm, ri )
0044
0045 ax.plot(mlib.nm, ri)
0046
0047 nm_10 = np.linspace( mlib.nm[0], mlib.nm[-1], len(mlib.nm)*10 )
0048 ri_10 = interp(nm_10)
0049
0050
0051
0052
0053
0054 ax.scatter(nm_10, ri_10, s=4.0)
0055 ax.text(1,1, name, ha='right', va='top', transform=ax.transAxes )
0056 ax.scatter(mlib.nm, ri, s=8.0, c='r')
0057 pass
0058 fig.show()
0059
0060
0061
0062