def test_sample1(): """ Here's a thin non-absorbing layer, on top of a thick absorbing layer, with air on both sides. Plotting reflected intensity versus wavenumber, at two different incident angles. """ # list of layer thicknesses in nm d_list = [inf, 100, 300, inf] # list of refractive indices n_list = [1, 2.2, 3.3 + 0.3j, 1] # list of wavenumbers to plot in nm^-1 ks = linspace(0.0001, .01, num=400) # initialize lists of y-values to plot Rnorm = [] R45 = [] # coh_tmm(pol, n_list, d_list, th_0, lam_vac) for k in ks: # For normal incidence, s and p polarizations are identical. # I arbitrarily decided to use 's'. Rnorm.append(coh_tmm('s', n_list, d_list, 0, 1 / k)['R']) R45.append(unpolarized_RT(n_list, d_list, 45 * degree, 1 / k)['R']) kcm = ks * 1e7 #ks in cm^-1 rather than nm^-1 plt.figure() plt.plot(kcm, Rnorm, 'blue', kcm, R45, 'purple') plt.xlabel('k (cm$^{-1}$)') plt.ylabel('Fraction reflected') plt.title('Reflection of unpolarized light at 0$^\circ$ incidence (blue), ' '45$^\circ$ (purple)') plt.show() return 0
def unpolarized_RT_func( index_film, index_substrate, aoi, film_thickness, wavelength, ): return unpolarized_RT( n_list=[index_air, index_film, index_substrate], d_list=[np.inf, film_thickness, np.inf], th_0=aoi * degree, lam_vac=wavelength)['R']
def reflection_spectrum_from_input_parameter_set(input_parameter_set): angle_list = input_parameter_set[0] wavelength_list = input_parameter_set[1] nkt_list = input_parameter_set[2] result_array = [] for angle in angle_list: for wavelength in wavelength_list: result_array.append([ angle, wavelength, unpolarized_RT(nkt_list[0], nkt_list[1], angle, wavelength)['R'] ]) return sp.array(result_array)
def thick_slab_reflectance_tmm(polarization, index_substrate, aoi, wavelength): """ Reflection from a thick slab of material. Parameters ---------- polarization : str Light polarization, can be "s" or "p" or "mixed" index_substrate : (N,) ndarray Index of refraction of the slab of material evaluated at the wavelengths specified in the `wavelength` input. aoi : float Angle of incidence in degrees wavelength : (N,) ndarray wavelength in nm, must be the same length as index_substrate. Returns ------- """ wavelength = wavelength.astype('float') degree = pi / 180 R = np.zeros_like(wavelength) if polarization in ['s', 'p']: for j in range(len(R)): R[j] = coh_tmm(polarization, [1.0003, index_substrate[j]], [inf, inf], aoi * degree, wavelength[j])['R'] elif polarization == 'mixed': for j in range(len(R)): R[j] = unpolarized_RT([1.0003, index_substrate[j]], [inf, inf], aoi * degree, wavelength[j])['R'] else: raise Exception("polarization must be 's','p' or 'mixed'") return R
def thin_film_reflectance_tmm(polarization, index_film, index_substrate, film_thickness, aoi, wavelength, vectorize=False): """ Calculate reflection from a thin film on a substrate. dimensions in nm. Parameters ---------- polarization index_film index_substrate film_thickness aoi wavelength vectorize Returns ------- """ degree = pi / 180 wavelength = wavelength.astype('float') d_list = [np.inf, film_thickness, np.inf] index_air = 1.0003 R = np.zeros_like(wavelength) if polarization in ['s', 'p']: for j in range(len(R)): n_list = [1.0003, index_film[j], index_substrate[j]] R[j] = coh_tmm(polarization, n_list, d_list, aoi * degree, wavelength[j])['R'] elif polarization == 'mixed': if vectorize: def unpolarized_RT_func( index_film, index_substrate, aoi, film_thickness, wavelength, ): return unpolarized_RT( n_list=[index_air, index_film, index_substrate], d_list=[np.inf, film_thickness, np.inf], th_0=aoi * degree, lam_vac=wavelength)['R'] unpolarized_RT_vectorized = np.vectorize(unpolarized_RT_func) R = unpolarized_RT_vectorized(index_film, index_substrate, aoi, film_thickness, wavelength) print('vectorized done') else: for j in range(len(R)): n_list = [index_air, index_film[j], index_substrate[j]] R[j] = unpolarized_RT(n_list, d_list, aoi * degree, wavelength[j])['R'] else: raise Exception("polarization must be 's','p' or 'mixed'") return R
def calculate_rat(structure, wavelength, angle=0, pol='u', coherent=True, coherency_list=None, no_back_reflexion=True): """ Calculates the reflected, absorbed and transmitted intensity of the structure for the wavelengths and angles defined. :param structure: A solcore Structure object with layers and materials or a OptiStack object. :param wavelength: Wavelengths (in nm) in which calculate the data. :param angle: Angle (in degrees) of the incident light. Default: 0 (normal incidence). :param pol: Polarisation of the light: 's', 'p' or 'u'. Default: 'u' (unpolarised). :param coherent: If the light is coeherent or not. If not, a coherency list must be added. :param coherency_list: A list indicating in which layers light should be treated as coeherent ('c') and in which incoherent ('i'). It needs as many elements as layers in the structure. :param no_back_reflexion: If reflexion from the back must be supressed. Default=True. :return: A dictionary with the R, A and T at the specified wavelengths and angle. """ num_wl = len(wavelength) if 'OptiStack' in str(type(structure)): stack = structure stack.no_back_reflexion = no_back_reflexion else: stack = OptiStack(structure, no_back_reflexion=no_back_reflexion) if not coherent: if coherency_list is not None: assert len(coherency_list) == stack.num_layers, \ 'Error: The coherency list must have as many elements (now {}) as the ' \ 'number of layers (now {}).'.format(len(coherency_list), stack.num_layers) coherency_list = ['i'] + coherency_list + ['i'] else: raise Exception( 'Error: For incoherent or partly incoherent calculations you must supply the ' 'coherency_list parameter with as many elements as the number of layers in the ' 'structure') output = { 'R': np.zeros(num_wl), 'A': np.zeros(num_wl), 'T': np.zeros(num_wl), 'all_p': [], 'all_s': [] } if pol in 'sp': if coherent: for i, wl in enumerate(wavelength): out = tmm.coh_tmm(pol, stack.get_indices(wl), stack.get_widths(), angle * degree, wl) output['R'][i] = out['R'] output['A'][i] = 1 - out['R'] - out['T'] output['T'][i] = out['T'] else: for i, wl in enumerate(wavelength): out = tmm.inc_tmm(pol, stack.get_indices(wl), stack.get_widths(), coherency_list, angle * degree, wl) output['R'][i] = out['R'] output['A'][i] = 1 - out['R'] - out['T'] output['T'][i] = out['T'] else: if coherent: for i, wl in enumerate(wavelength): out = tmm.unpolarized_RT(stack.get_indices(wl), stack.get_widths(), angle * degree, wl) output['R'][i] = out['R'] output['A'][i] = 1 - out['R'] - out['T'] output['T'][i] = out['T'] else: for i, wl in enumerate(wavelength): out_p = tmm.inc_tmm('p', stack.get_indices(wl), stack.get_widths(), coherency_list, angle * degree, wl) out_s = tmm.inc_tmm('s', stack.get_indices(wl), stack.get_widths(), coherency_list, angle * degree, wl) output['R'][i] = 0.5 * (out_p['R'] + out_s['R']) output['T'][i] = 0.5 * (out_p['T'] + out_s['T']) output['A'][i] = 1 - output['R'][i] - output['T'][i] output['all_p'].append(out_p['power_entering_list']) output['all_s'].append(out_s['power_entering_list']) return output
def reflection_spectrum_from_nkt_list(wavelength_list, n_list, k_list, t_list): nk_list, t_list = complex_nk_t_list_from_n_k_t_list(n_list, k_list, t_list) result_array = [[i, unpolarized_RT(nk_list, t_list, 0, i)['R']] for i in wavelength_list] return sp.array(result_array)