def calculate_color(self): ''' Generate a color tuple of (r, g, b) normalized to 255 for transmittance and reflectance. ''' if not self._TR_calculated: self.calculate_TR() os.chdir("plot support files") rgbdata = np.loadtxt("rgbdata.txt", skiprows=1) os.chdir("..") rgbwl = rgbdata[:,0] struct_wl = self.wl * 1e3 if self.unit == 'micron' else self.wl if struct_wl[0] > rgbwl[0] or struct_wl[-1] < rgbwl[-1]: raise Exception("The entire visible spectrum must be available in the structure simulation.") rgb_sens = rgbdata[:,1:] rgb_sens /= np.sum(rgb_sens, 0) # Normalize sum to 1 T_interp = calc.interpolate(struct_wl, self.T, rgbwl) R_interp = calc.interpolate(struct_wl, self.R, rgbwl) T_rgb = np.sum(T_interp[:,np.newaxis] * rgb_sens, 0) * 255 R_rgb = np.sum(R_interp[:,np.newaxis] * rgb_sens, 0) * 255 self.T_color = tuple(T_rgb.astype(int)) self.R_color = tuple(R_rgb.astype(int))
def calculate_color(self): ''' Generate a color tuple of (r, g, b) normalized to 255 for transmittance and reflectance. ''' if not self._TR_calculated: self.calculate_TR() os.chdir("plot support files") rgbdata = np.loadtxt("rgbdata.txt", skiprows=1) os.chdir("..") rgbwl = rgbdata[:,0] struct_wl = self.wl * 1e3 if self.unit == 'micron' else self.wl if struct_wl[0] > rgbwl[0] or struct_wl[-1] < rgbwl[-1]: raise Exception("The entire visible spectrum must be available in the structure simulation.") rgb_sens = rgbdata[:,1:] rgb_sens /= np.sum(rgb_sens, 0) # Normalize sum to 1 T_interp = calc.interpolate(struct_wl, self.T, rgbwl) R_interp = calc.interpolate(struct_wl, self.R, rgbwl) T_rgb = np.sum(T_interp[:,np.newaxis] * rgb_sens, 0) * 255 R_rgb = np.sum(R_interp[:,np.newaxis] * rgb_sens, 0) * 255 #T_rgb = np.sum(T_interp[:,np.newaxis] * rgb_sens, 0) #R_rgb = np.sum(R_interp[:,np.newaxis] * rgb_sens, 0) self.T_color = tuple(T_rgb.astype(int)) self.R_color = tuple(R_rgb.astype(int))
def latvtimesage(datao, variable, ncdf): plt.figure(figsize=figsize) #construct strings label = labels[variable] if variable in names: title = names[variable] else: title = variable subtitle = ncdf.filetitle filename = variable + '_' + filenames[ncdf.filename] + '_lvt' + '.eps' #calculate params time = ncdf.getvar('rtime', None, None) data = calc.interpolate(datao, time) time = calc.interpolatetime(datao, time) z = data.transpose() datamax, datamin = calc.getmax(z), calc.getmin(z) v = np.linspace(datamin, datamax, 5) #colormap cmap = LinearSegmentedColormap('red', colors2) cmap = plt.getcmap('inferno') #create plot norm = Normalize(vmin=datamin, vmax=datamax, clip=False) cp = plt.contourf(z, v, norm=norm, extend='max', cmap=cmap) cp.cmap.set_over('white') cp.cmap.set_bad('.5') #create colorbar cbar = plt.colorbar(cp, orientation='horizontal', aspect=15, format='%.2g', pad=0.2) cbar.ax.set_xlabel(label) #label & title plt.xlabel('Years after eruption') plt.ylabel('Latitude') newlabels=[] for label in cbar.ax.xaxis.get_ticklabels()[::2]: newlabels.append(label.get_text()) cbar.ax.xaxis.set_ticklabels(newlabels) newticks=[] for tick in cbar.ax.get_xticks()[::2]: newticks.append(tick) cbar.ax.set_xticks(newticks) #additional formating ax = plt.gca() plt.yticks(np.linspace(0, 23, 7, endpoint=True), [-90,-60,-30,0,30,60,90]) xlabels = time[::4] xlabels = [int(i) for i in xlabels] plt.xticks(np.linspace(0, 14, 15, endpoint=True)[::4], xlabels) plt.ylim(0,23.) plt.rc('font', **font) plt.title(title) #show/save plot plt.savefig(filename, bbox_inches='tight') #print str(max(z.flat)) + " + " + str(min(z.flat)) plt.close()
def calculate_TR(self): if not self._layers_list: raise EmptyStructureException("Structure is empty.") num_layers = len(self._layers_list) num_wl = len(self.wl) # n a 2d array of layers (row) and wavelength (column) n = np.empty([num_layers, num_wl], complex) for i, L in enumerate(self._layers_list): L_wl = L.wl * 1e3 if self.unit == 'nm' and L.unit == 'micron' else\ L.wl / 1e3 if self.unit == 'micron' and L.unit == 'nm' else\ L.wl layer_n = calc.interpolate(L_wl, L.n, self.wl) n[num_layers - 1 - i] = layer_n wl = self.wl / 1e9 if self.unit == 'nm' else self.wl / 1e6 k0 = 2 * np.pi / wl d = np.array([layer.d / 1e9 if self.unit == 'nm' else layer.d / 1e6 \ for layer in self._layers_list[::-1]]) self.T = calc.transmittance(k0, n, d, n0=self.n0, ns=self.ns) self.R = calc.reflectance(k0, n, d, n0=self.n0, ns=self.ns) self.A = 1 - self.T - self.R self._TR_calculated = True
_AlN_nkdata = np.loadtxt("aln_ellipsometry_sai_nk.txt", skiprows=1) _AlN_wl = _AlN_nkdata[:,0] * 1000 _AlN_nk = _AlN_nkdata[:,1] - 1j * _AlN_nkdata[:,2] _AlNH_nkdata = np.loadtxt("alN-H-nk.txt") _AlNH_wl = _AlNH_nkdata[:,0] * 1000 _AlNH_nk = _AlNH_nkdata[:,1] - 1j * _AlNH_nkdata[:,2] _BK7_ndata = np.loadtxt("BK7_n.txt", skiprows=1) _BK7_kdata = np.loadtxt("BK7_k.txt", skiprows=1) _BK7_wl = _BK7_ndata[:,0] * 1000 # BK7 doesn't have the same number of data points for n and k _wl_temp = _BK7_kdata[:,0] * 1000 _k_temp = _BK7_kdata[:,1] _BK7_k = calc.interpolate(_wl_temp, _k_temp, _BK7_wl) _BK7_nk = _BK7_ndata[:,1] - 1j * _BK7_k _DLC_nkdata = [np.loadtxt("DLC{}W_nk.txt".format(n), skiprows=1) for \ n in [3, 5, 10, 15, 20, 40, 60]] _DLC_wl = [_DLC_nkdata[i][:,0] for i in range(7)] _DLC_nk = [_DLC_nkdata[i][:,1] - 1j * _DLC_nkdata[i][:,2] for i in range(7)] _DLC3W_wl, _DLC5W_wl, _DLC10W_wl, _DLC15W_wl, _DLC20W_wl, _DLC40W_wl, _DLC60W_wl = _DLC_wl _DLC3W_nk, _DLC5W_nk, _DLC10W_nk, _DLC15W_nk, _DLC20W_nk, _DLC40W_nk, _DLC60W_nk = _DLC_nk _DLC_ext_nkdata = [np.loadtxt("DLC{}W_extended_nk.txt".format(n), skiprows=1) \ for n in [3, 5, 10, 15, 20, 40, 60]] _DLC_ext_wl = [_DLC_ext_nkdata[i][:,0] for i in range(7)] _DLC_ext_nk = [_DLC_ext_nkdata[i][:,1] - 1j * _DLC_ext_nkdata[i][:,2] \ for i in range(7)] _DLC3W_ext_wl, _DLC5W_ext_wl, _DLC10W_ext_wl, _DLC15W_ext_wl, _DLC20W_ext_wl, _DLC40W_ext_wl, _DLC60W_ext_wl = _DLC_ext_wl
_Al_ndata = np.loadtxt("Al_n_Rakic1998.txt", skiprows=1) _Al_kdata = np.loadtxt("Al_k_Rakic1998.txt", skiprows=1) _Al_wl = _Al_ndata[:, 0] * 1000 _Al_nk = _Al_ndata[:, 1] - 1j * _Al_kdata[:, 1] _AlN_nkdata = np.loadtxt("AlN_nk.txt", skiprows=1) _AlN_wl = _AlN_nkdata[:, 0] _AlN_nk = _AlN_nkdata[:, 1] - 1j * _AlN_nkdata[:, 2] _BK7_ndata = np.loadtxt("BK7_n.txt", skiprows=1) _BK7_kdata = np.loadtxt("BK7_k.txt", skiprows=1) _BK7_wl = _BK7_ndata[:, 0] * 1000 # BK7 doesn't have the same number of data points for n and k _wl_temp = _BK7_kdata[:, 0] * 1000 _k_temp = _BK7_kdata[:, 1] _BK7_k = calc.interpolate(_wl_temp, _k_temp, _BK7_wl) _BK7_nk = _BK7_ndata[:, 1] - 1j * _BK7_k _DLC_nkdata = [np.loadtxt("DLC{}W_nk.txt".format(n), skiprows=1) for \ n in [3, 5, 10, 15, 20, 40, 60]] _DLC_wl = [_DLC_nkdata[i][:, 0] for i in range(7)] _DLC_nk = [_DLC_nkdata[i][:, 1] - 1j * _DLC_nkdata[i][:, 2] for i in range(7)] _DLC3W_wl, _DLC5W_wl, _DLC10W_wl, _DLC15W_wl, _DLC20W_wl, _DLC40W_wl, _DLC60W_wl = _DLC_wl _DLC3W_nk, _DLC5W_nk, _DLC10W_nk, _DLC15W_nk, _DLC20W_nk, _DLC40W_nk, _DLC60W_nk = _DLC_nk _DLC_ext_nkdata = [np.loadtxt("DLC{}W_extended_nk.txt".format(n), skiprows=1) \ for n in [3, 5, 10, 15, 20, 40, 60]] _DLC_ext_wl = [_DLC_ext_nkdata[i][:, 0] for i in range(7)] _DLC_ext_nk = [_DLC_ext_nkdata[i][:,1] - 1j * _DLC_ext_nkdata[i][:,2] \ for i in range(7)] _DLC3W_ext_wl, _DLC5W_ext_wl, _DLC10W_ext_wl, _DLC15W_ext_wl, _DLC20W_ext_wl, _DLC40W_ext_wl, _DLC60W_ext_wl = _DLC_ext_wl