Best Python code snippet using prospector_python
thar_update.py
Source:thar_update.py
1import scipy2import pyfits3import numpy as np4import os5import matplotlib.pyplot as plt6from astropy.io import fits7from scipy.signal import find_peaks_cwt8from scipy.optimize import curve_fit9from sklearn.metrics.pairwise import euclidean_distances#pairwise_distances10from astroML.stats import sigmaG11import sys12from astropy import constants as C13from astropy.table import Table, Column14from astropy.io import ascii15import sys16import matplotlib.gridspec as gridspec # GRIDSPEC !17cc = C.c.value*1.e-3 # [km/s]18# Gaussian function19def gauss_function(x, a, x0, sigma, zero):20 return a*np.exp(-(x-x0)**2/(2*sigma**2)) + zero21# Two Gaussian function22def twoGauss_function(x, a, x0, sigma, zero, a2, x02, sigma2):23 return a*np.exp(-(x-x0)**2/(2*sigma**2)) + zero + a2*np.exp(-(x-x02)**2/(2*sigma2**2))24# ===== Master Arc ffor Reference25# cafe2_00126# tpath = '/Users/lillo_box/00_Instrumentation/CAFE/CAFExtractor/cafextractor/test_data/11_REDUCED/120705/reduced'27# order0 = 6028# norders = 8029# cafe2_00230# tpath = '/Volumes/willyfog/gang5/jlillo/22_RUNS/2018_07_CAHA_2.2_CAFE_CHRONOS/11_REDUCED/181217/reduced'31# order0 = 6032# norders = 8033# cafe2_00334# tpath = '/Volumes/willyfog/gang5/jlillo/22_RUNS/2019_01_CAHA_2.2_CAFE_Recommisioning_Run2/11_REDUCED/190306/reduced'35# order0 = 6336# norders = 8037# cafe2_00438tpath = '/Volumes/willyfog/gang5/jlillo/22_RUNS/2019_01_CAHA_2.2_CAFE_Recommisioning_Run2/11_REDUCED/190425_digest/reduced'39order0 = 6240norders = 7941t = fits.open(tpath+'/MasterArc_0_red.fits') #42# ===== ThAr lines from Lovis+200743lovis_file = '/Users/lillo_box/00_Instrumentation/CAFE/CAFExtractor/cafextractor/ReferenceFrames/ThAr_ReferenceLines/ThAr_Lovis07.txt'44file = np.genfromtxt(lovis_file,dtype=None)45lovis_lines = file['f0']46lovis_int = file['f2']*1.47lovis_Species = file['f3']48s = 1.e4/lovis_lines49n = 1 + 0.0000834254 + 0.02406147 / (130 - s**2) + 0.00015998 / (38.9 - s**2)50lovis_lines = lovis_lines/n51# ===== ThAr lines from CERES52file2 = np.genfromtxt('/Users/lillo_box/00_Instrumentation/CAFE/CAFExtractor/cafextractor/ReferenceFrames/ThAr_ReferenceLines/all_ThAr_lines.lis',dtype=None)53ceres_lines = file2['f2']54Xpix = np.arange(2048)*1.55# ===== LOOP for each order (starting at the first order with Lovis+ information)56for oo in np.arange(norders-23)+23:57 wave = t["WAVELENGTH"].data[oo,:]58 flux = t["FLUX"].data[oo,:]59 plt.plot(wave, flux,c='k',zorder=0)60 resolution0 = 2.3 * np.mean(wave[1:-1]-wave[0:-2])61 62 ceres_inorder = np.where((ceres_lines > np.min(wave)) & (ceres_lines < np.max(wave)) )[0]63 for i in range(len(ceres_inorder)): plt.axvline(ceres_lines[ceres_inorder[i]],ls='--',c='red',alpha=0.5,zorder=5)64 lovis_inorder = np.where((lovis_lines > np.min(wave)) & (lovis_lines < np.max(wave)) )[0]65 for i in range(len(lovis_inorder)): 66 plt.axvline(lovis_lines[lovis_inorder[i]],ls=':',c='k',alpha=0.5,zorder=10)67 plt.text(lovis_lines[lovis_inorder[i]], 0.0, i)68 69 ok_line = []70 yes_results = []71 no_results = []72 no_reasons = []73 74 for i,line in enumerate(lovis_lines[lovis_inorder]):75 76 # ===== Subrange77 subspec = np.where((wave > line-3.*resolution0) & (wave < line+3.*resolution0))[0]78 x0, y0, xpix0 = wave[subspec], flux[subspec], Xpix[subspec]79 x, y, xpix = x0[~np.isnan(y0)], y0[~np.isnan(y0)], xpix0[~np.isnan(y0)]80 81 resolution = 2.3 * np.mean(x[1:-1]-x[0:-2])82 if len(y) == 0: continue83 84 # ===== Look for the closest line and decide if fitting 1 or 2 Gaussians85 twoGauss = None86 diff = line-lovis_lines[lovis_inorder]87 sorting = np.argsort(np.abs(diff))88 intensity = lovis_int[lovis_inorder]89 int_ratio = intensity[sorting[1]]/intensity[sorting[0]]90 blend_line = lovis_lines[lovis_inorder[sorting[1]]]91 if (np.abs(diff[sorting[1]]) > 3.0*resolution): 92 twoGauss = False93 elif (np.abs(diff[sorting[1]]) > 1.5*resolution):94 if (int_ratio > 0.1) : twoGauss = True95 if (int_ratio < 0.1) : twoGauss = False96 elif ( (np.abs(diff[sorting[1]]) < 1.5*resolution) & (int_ratio < 0.1) ):97 twoGauss = False98 # ===== Try fitting 1-Gaussian99 if twoGauss == False:100 try:101 popt, pcov = curve_fit(gauss_function, x, y, 102 p0 = [np.max(y), line, resolution, 0.0],103 bounds=([0.0,line-resolution,0.0,-np.inf],104 [np.inf,line+resolution,3*resolution,np.inf]))105 perr = np.sqrt(np.diag(pcov))106 except:107 popt = np.zeros(4)108 109 ymodel = gauss_function(x,popt[0],popt[1],popt[2],popt[3])110 try:111 xpix0 = np.interp(line,x,xpix)112 poptX, pcovX = curve_fit(gauss_function, xpix, y, 113 p0 = [np.max(y), xpix0, 2.3, 0.0],114 bounds=([0.0,xpix0-2.3,0.0,-np.inf],115 [np.inf,xpix0+2.3,3*2.3,np.inf]))116 perrX = np.sqrt(np.diag(pcovX))117 except:118 poptX = np.zeros(4)119 120 # ===== Try fitting 2-Gaussians121 if twoGauss == True:122 try:123 popt, pcov = curve_fit(twoGauss_function, x, y, 124 p0 = [np.max(y), line, resolution, 0.0, np.max(y)*int_ratio, blend_line, resolution],125 bounds=([0.0,line-resolution,0.0,-np.inf,0.0,blend_line-resolution,0.0],126 [np.inf,line+resolution,3*resolution,np.inf,np.inf,blend_line+resolution,3*resolution]))127 perr = np.sqrt(np.diag(pcov))128 except:129 popt = np.zeros(7)130 ymodel = twoGauss_function(x,popt[0],popt[1],popt[2],popt[3],popt[4],popt[5],popt[6]) 131 132 try:133 xpix0 = np.interp(line,x,xpix)134 xpix0_blend = np.interp(blend_line,x,xpix)135 poptX, pcovX = curve_fit(twoGauss_function, xpix, y, 136 p0 = [np.max(y), xpix0, 2.3, 0.0, np.max(y)*int_ratio, xpix0_blend, 2.3],137 bounds=([0.0,xpix0-2.3,0.0,-np.inf,0.0,xpix0_blend-2.3,0.0],138 [np.inf,xpix0+2.3,3*2.3,np.inf,np.inf,xpix0_blend+2.3,3*2.3]))139 perrX = np.sqrt(np.diag(pcovX))140 except:141 poptX = np.zeros(7)142 143 if twoGauss == None:144 popt = np.zeros(4)145 ymodel = x*0.0146 poptX = np.zeros(4)147 #| Region around the maximum to check fitting: +/- 2 pix ~ 1xFWHM148 elem_check = np.where( (x > line-1.*resolution) & (x < line+1.*resolution) )[0] 149 ground_noise = np.nanmedian(flux[400:-400])/10.150 snr = popt[0]/ground_noise151 resid = np.nanstd(y[elem_check]-ymodel[elem_check])/ground_noise152 chi2 = np.nansum((y[elem_check]-ymodel[elem_check])**2/(9.*np.abs(y[elem_check]))) / (1.*len(x[elem_check]))153 154 if i == 20000:155 plt.close()156 plt.errorbar(x,y,yerr=3.*np.sqrt(y))157 #plt.plot(x,y)158 plt.plot(x[elem_check],y[elem_check])159 plt.plot(x,ymodel,c='red')160 print twoGauss, int_ratio, np.abs(diff[sorting[1]])/resolution, resolution161 plt.show()162 plt.close()163 164 #diff = np.sort(np.abs(line-lovis_lines[lovis_inorder]))165 166 if ((np.abs(popt[1]-line)*1.e3 < 10.) & (chi2 < 10.) & (snr > 5) ): 167 168 if (np.abs(diff[1]) > 2.0*resolution): 169 ok = 'yes'170 elif (np.abs(diff[1]) > 1.5*resolution):171 ok = 'yes' if ((int_ratio < 0.05) | (int_ratio > 0.3)) else ' no'172 elif (np.abs(diff[1]) < 1.5*resolution):173 ok = 'yes' if (int_ratio < 0.05) else ' no'174 else:175 ok = ' no' 176 else:177 ok = ' no'178 179 if ok == 'yes': ok_line.append(line)180 #print i, ok, np.abs(popt[1]-line)/resolution, chi2, snr, np.abs(diff[sorting[1]])/resolution,int_ratio, intensity[sorting[0]], intensity[sorting[1]], twoGauss181 if ok == 'yes':182 #print i, ok, round(poptX[1],2), line, intensity[sorting[0]], twoGauss183 yes_results.append([i, ok, round(poptX[1],2), line, intensity[sorting[0]], lovis_Species[lovis_inorder[sorting[0]]], twoGauss])184 else:185 no_results.append([i, ok, round(poptX[1],2), line, intensity[sorting[0]], lovis_Species[lovis_inorder[sorting[0]]], twoGauss])186 no_reasons.append([i, ok, np.abs(popt[1]-line)*1.e3, chi2, snr, np.abs(diff[1])/resolution, int_ratio, intensity[sorting[0]], intensity[sorting[1]], twoGauss])187 188 ok_line = np.array(ok_line)189 print oo,len(ok_line), len(ceres_inorder)190 for i in ok_line: plt.axvline(i,ls=':',c='blue',zorder=15)191 192 if 1:193 fyes = open('auxiliar/yes_cafeX_order_'+str(order0+oo).zfill(3)+'.dat','w')194 fno = open('auxiliar/no_cafeX_order_'+str(order0+oo).zfill(3)+'.dat','w')195 f = open('auxiliar/cafeX_order_'+str(order0+oo).zfill(3)+'.dat','w')196 fyes.write("%5s %10s %20s %15s %10s \n" % ("# ID","Xpix","Wavelength","Intens","Line"))197 f.write( "%5s %10s %20s %15s %10s \n" % ("# ID","Xpix","Wavelength","Intens","Line"))198 fno.write( "%5s %10s %20s %15s %10s \n" % ("# ID","Xpix","Wavelength","Intens","Line"))199 for hh in yes_results:200 fyes.write("%5i %10.1f %20.8f %15.1f %10s \n" % (hh[0],hh[2],hh[3],hh[4],hh[5]))201 f.write( "%5i %10.1f %20.8f %15.1f %10s \n" % (hh[0],hh[2],hh[3],hh[4],hh[5]))202 for hh in no_results:203 fno.write("%5i %10.1f %20.8f %15.1f %10s \n" % (hh[0],hh[2],hh[3],hh[4],hh[5]))204 fyes.close()205 fno.close()206 f.close()207 208 fnoreasons = open('auxiliar/noreasons_cafeX_order_'+str(order0+oo).zfill(3)+'.dat','w')209 fnoreasons.write("%5s %5s %10s %10s %10s %10s %10s %10s %10s \n" % ("ID","ok","Diff(mA)","chi2","SNR","Diff/R","I1/I0","I0","I1"))210 for hh in no_reasons: 211 fnoreasons.write("%5s %5s %10.1f %10.1f %10.1f %10.1f %10.3f %10.1f %10.1f \n" % (hh[0],hh[1],hh[2],hh[3],hh[4],hh[5],hh[6],hh[7],hh[8]))212 fnoreasons.close()213 214 plt.ylim(-500,3000)215 #plt.show()216 #sys.exit()...
thar_update_ceres.py
Source:thar_update_ceres.py
1import scipy2import pyfits3import numpy as np4import os5import matplotlib.pyplot as plt6from astropy.io import fits7from scipy.signal import find_peaks_cwt8from scipy.optimize import curve_fit9from sklearn.metrics.pairwise import euclidean_distances#pairwise_distances10from astroML.stats import sigmaG11import sys12from astropy import constants as C13from astropy.table import Table, Column14from astropy.io import ascii15import sys16import matplotlib.gridspec as gridspec # GRIDSPEC !17cc = C.c.value*1.e-3 # [km/s]18# Gaussian function19def gauss_function(x, a, x0, sigma, zero):20 return a*np.exp(-(x-x0)**2/(2*sigma**2)) + zero21# Two Gaussian function22def twoGauss_function(x, a, x0, sigma, zero, a2, x02, sigma2):23 return a*np.exp(-(x-x0)**2/(2*sigma**2)) + zero + a2*np.exp(-(x-x02)**2/(2*sigma2**2))24# ===== Master Arc ffor Reference25# tpath = '/Users/lillo_box/00_Instrumentation/CAFE/CAFExtractor/test_data/12_REDUCED/180725_digest/reduced'26# cafe2_00327# tpath = '/Volumes/willyfog/gang5/jlillo/22_RUNS/2019_01_CAHA_2.2_CAFE_Recommisioning_Run2/11_REDUCED/190306/reduced'28# order0 = 6329# norders = 8130# cafe2_00431tpath = '/Volumes/willyfog/gang5/jlillo/22_RUNS/2019_01_CAHA_2.2_CAFE_Recommisioning_Run2/11_REDUCED/190425_digest/reduced'32order0 = 6233norders = 7934t = fits.open(tpath+'/MasterArc_0_red.fits') #35# ===== ThAr lines from Lovis+200736lovis_file = '/Users/lillo_box/00_Instrumentation/CAFE/CAFExtractor/cafextractor/ReferenceFrames/ThAr_ReferenceLines/ThAr_Lovis07.txt'37file = np.genfromtxt(lovis_file,dtype=None)38lovis_lines = file['f0']39lovis_int = file['f2']*1.40lovis_Species = file['f3']41s = 1.e4/lovis_lines42n = 1 + 0.0000834254 + 0.02406147 / (130 - s**2) + 0.00015998 / (38.9 - s**2)43lovis_lines = lovis_lines/n44# ===== ThAr lines from CERES45file2 = np.genfromtxt('/Users/lillo_box/00_Instrumentation/CAFE/CAFExtractor/cafextractor/ReferenceFrames/ThAr_ReferenceLines/all_ThAr_lines.lis',dtype=None)46ceres_lines = file2['f2']47ceres_pix = file2['f1']48ceres_Species = file2['f3']49ceres_int = ceres_pix*0.0+1.050Xpix = np.arange(2048)*1.51# ===== LOOP for each order (starting at the first order with CERES information)52for oo in np.arange(norders):53 wave = t["WAVELENGTH"].data[oo,:]54 flux = t["FLUX"].data[oo,:]55 plt.plot(wave, flux,c='k',zorder=0)56 resolution0 = 2.3 * np.mean(wave[1:-1]-wave[0:-2])57 58 ceres_inorder = np.where((ceres_lines > np.min(wave)) & (ceres_lines < np.max(wave)) )[0]59 for i in range(len(ceres_inorder)): plt.axvline(ceres_lines[ceres_inorder[i]],ls='--',c='red',alpha=0.5,zorder=5)60 lovis_inorder = np.where((lovis_lines > np.min(wave)) & (lovis_lines < np.max(wave)) )[0]61 for i in range(len(lovis_inorder)): 62 plt.axvline(lovis_lines[lovis_inorder[i]],ls=':',c='k',alpha=0.5,zorder=10)63 plt.text(lovis_lines[lovis_inorder[i]], 0.0, i)64 65 ok_line = []66 yes_results = []67 no_results = []68 no_reasons = []69 70 for i,line in enumerate(ceres_lines[ceres_inorder]):71 72 # ===== Subrange73 subspec = np.where((wave > line-3.*resolution0) & (wave < line+3.*resolution0))[0]74 x0, y0, xpix0 = wave[subspec], flux[subspec], Xpix[subspec]75 x, y, xpix = x0[~np.isnan(y0)], y0[~np.isnan(y0)], xpix0[~np.isnan(y0)]76 77 resolution = 2.3 * np.mean(x[1:-1]-x[0:-2])78 if len(y) == 0: continue79 80 # ===== Look for the closest line and decide if fitting 1 or 2 Gaussians81 twoGauss = None82 diff = line-ceres_lines[ceres_inorder]83 sorting = np.argsort(np.abs(diff))84 intensity = ceres_int[ceres_inorder]85 int_ratio = intensity[sorting[1]]/intensity[sorting[0]]86 blend_line = ceres_lines[ceres_inorder[sorting[1]]]87 if (np.abs(diff[sorting[1]]) > 3.0*resolution): 88 twoGauss = False89 elif (np.abs(diff[sorting[1]]) > 1.5*resolution):90 if (int_ratio > 0.1) : twoGauss = True91 if (int_ratio < 0.1) : twoGauss = False92 elif ( (np.abs(diff[sorting[1]]) < 1.5*resolution) & (int_ratio < 0.1) ):93 twoGauss = False94 # ===== Try fitting 1-Gaussian95 if twoGauss == False:96 try:97 popt, pcov = curve_fit(gauss_function, x, y, 98 p0 = [np.max(y), line, resolution, 0.0],99 bounds=([0.0,line-resolution,0.0,-np.inf],100 [np.inf,line+resolution,3*resolution,np.inf]))101 perr = np.sqrt(np.diag(pcov))102 except:103 popt = np.zeros(4)104 105 ymodel = gauss_function(x,popt[0],popt[1],popt[2],popt[3])106 try:107 xpix0 = np.interp(line,x,xpix)108 poptX, pcovX = curve_fit(gauss_function, xpix, y, 109 p0 = [np.max(y), xpix0, 2.3, 0.0],110 bounds=([0.0,xpix0-2.3,0.0,-np.inf],111 [np.inf,xpix0+2.3,3*2.3,np.inf]))112 perrX = np.sqrt(np.diag(pcovX))113 except:114 poptX = np.zeros(4)115 116 # ===== Try fitting 2-Gaussians117 if twoGauss == True:118 try:119 popt, pcov = curve_fit(twoGauss_function, x, y, 120 p0 = [np.max(y), line, resolution, 0.0, np.max(y)*int_ratio, blend_line, resolution],121 bounds=([0.0,line-resolution,0.0,-np.inf,0.0,blend_line-resolution,0.0],122 [np.inf,line+resolution,3*resolution,np.inf,np.inf,blend_line+resolution,3*resolution]))123 perr = np.sqrt(np.diag(pcov))124 except:125 popt = np.zeros(7)126 ymodel = twoGauss_function(x,popt[0],popt[1],popt[2],popt[3],popt[4],popt[5],popt[6]) 127 128 try:129 xpix0 = np.interp(line,x,xpix)130 xpix0_blend = np.interp(blend_line,x,xpix)131 poptX, pcovX = curve_fit(twoGauss_function, xpix, y, 132 p0 = [np.max(y), xpix0, 2.3, 0.0, np.max(y)*int_ratio, xpix0_blend, 2.3],133 bounds=([0.0,xpix0-2.3,0.0,-np.inf,0.0,xpix0_blend-2.3,0.0],134 [np.inf,xpix0+2.3,3*2.3,np.inf,np.inf,xpix0_blend+2.3,3*2.3]))135 perrX = np.sqrt(np.diag(pcovX))136 except:137 poptX = np.zeros(7)138 139 if twoGauss == None:140 popt = np.zeros(4)141 ymodel = x*0.0142 poptX = np.zeros(4)143 #| Region around the maximum to check fitting: +/- 2 pix ~ 1xFWHM144 elem_check = np.where( (x > line-1.*resolution) & (x < line+1.*resolution) )[0] 145 ground_noise = np.nanmedian(flux[400:-400])/10.146 snr = popt[0]/ground_noise147 resid = np.nanstd(y[elem_check]-ymodel[elem_check])/ground_noise148 chi2 = np.nansum((y[elem_check]-ymodel[elem_check])**2/(9.*np.abs(y[elem_check]))) / (1.*len(x[elem_check]))149 150 if i == 20000:151 plt.close()152 plt.errorbar(x,y,yerr=3.*np.sqrt(y))153 #plt.plot(x,y)154 plt.plot(x[elem_check],y[elem_check])155 plt.plot(x,ymodel,c='red')156 print twoGauss, int_ratio, np.abs(diff[sorting[1]])/resolution, resolution157 plt.show()158 plt.close()159 160 #diff = np.sort(np.abs(line-ceres_lines[ceres_inorder]))161 162 if ((np.abs(popt[1]-line)*1.e3 < 10.) & (chi2 < 10.) & (snr > 5) ): 163 164 if (np.abs(diff[1]) > 2.0*resolution): 165 ok = 'yes'166 elif (np.abs(diff[1]) > 1.5*resolution):167 ok = 'yes' if ((int_ratio < 0.05) | (int_ratio > 0.3)) else ' no'168 elif (np.abs(diff[1]) < 1.5*resolution):169 ok = 'yes' if (int_ratio < 0.05) else ' no'170 else:171 ok = ' no' 172 else:173 ok = ' no'174 175 if ok == 'yes': ok_line.append(line)176 #print i, ok, np.abs(popt[1]-line)/resolution, chi2, snr, np.abs(diff[sorting[1]])/resolution,int_ratio, intensity[sorting[0]], intensity[sorting[1]], twoGauss177 if ok == 'yes':178 #print i, ok, round(poptX[1],2), line, intensity[sorting[0]], twoGauss179 yes_results.append([i, ok, round(poptX[1],2), line, intensity[sorting[0]], ceres_Species[ceres_inorder[sorting[0]]], twoGauss])180 else:181 no_results.append([i, ok, round(poptX[1],2), line, intensity[sorting[0]], ceres_Species[ceres_inorder[sorting[0]]], twoGauss])182 no_reasons.append([i, ok, np.abs(popt[1]-line)*1.e3, chi2, snr, np.abs(diff[1])/resolution, int_ratio, intensity[sorting[0]], intensity[sorting[1]], twoGauss])183 184 ok_line = np.array(ok_line)185 print oo,len(ok_line), len(ceres_inorder)186 for i in ok_line: plt.axvline(i,ls=':',c='blue',zorder=15)187 188 if 1:189 fyes = open('auxiliar/yes_ceres_order_'+str(order0+oo).zfill(3)+'.dat','w')190 fno = open('auxiliar/no_ceres_order_'+str(order0+oo).zfill(3)+'.dat','w')191 f = open('auxiliar/ceres_order_'+str(order0+oo).zfill(3)+'.dat','w')192 fyes.write("%5s %10s %20s %15s %10s \n" % ("# ID","Xpix","Wavelength","Intens","Line"))193 f.write( "%5s %10s %20s %15s %10s \n" % ("# ID","Xpix","Wavelength","Intens","Line"))194 fno.write( "%5s %10s %20s %15s %10s \n" % ("# ID","Xpix","Wavelength","Intens","Line"))195 for hh in yes_results:196 fyes.write("%5i %10.1f %20.8f %15.1f %10s \n" % (hh[0],hh[2],hh[3],hh[4],hh[5]))197 f.write( "%5i %10.1f %20.8f %15.1f %10s \n" % (1,hh[2],hh[3],hh[4],hh[5]))198 for hh in no_results:199 fno.write("%5i %10.1f %20.8f %15.1f %10s \n" % (hh[0],hh[2],hh[3],hh[4],hh[5]))200 fyes.close()201 fno.close()202 f.close()203 204 fnoreasons = open('auxiliar/noreasons_ceres_order_'+str(order0+oo).zfill(3)+'.dat','w')205 fnoreasons.write("%5s %5s %10s %10s %10s %10s %10s %10s %10s \n" % ("ID","ok","Diff(mA)","chi2","SNR","Diff/R","I1/I0","I0","I1"))206 for hh in no_reasons: 207 fnoreasons.write("%5s %5s %10.1f %10.1f %10.1f %10.1f %10.3f %10.1f %10.1f \n" % (hh[0],hh[1],hh[2],hh[3],hh[4],hh[5],hh[6],hh[7],hh[8]))208 fnoreasons.close()209 210 plt.ylim(-500,3000)211 #plt.show()212 #sys.exit()...
curve.py
Source:curve.py
...77 x = (1 - t) * x1 + t * x278 y = (1 - t) * y1 + t * y279 draw_point((x,y))80 draw_point(p2)81def blend_line(p1,p2,p3,p4):82 x1, y1 = p183 x2, y2 = p284 x3, y3 = p385 x4, y4 = p486 draw_big_point(p1)87 draw_big_point(p2)88 draw_big_point(p3)89 draw_big_point(p4)90 for i in range(0,100,2):91 t= i/10092 lx = (1 - t)* x2 + t*x393 ly = (1 - t)*y2 + t*y394 rx = (1 - t) * x4 + t * x195 ry = (1 - t) * y4 + t * y196 draw_point((lx, ly))97 draw_point((rx, ry))98 x = (1 - t) * lx + t * rx99 y = (1 - t) * ly + t * ry100 draw_point((x,y))101def draw_curve_3_points(p1, p2, p3):102 draw_big_point(p1)103 draw_big_point(p2)104 draw_big_point(p3)105 x1, y1 = p1; x2, y2 = p2; x3, y3 = p3106 for i in range(0, 100, 2):107 t = i / 100108 x = (2 * t ** 2 - 3 * t + 1) * x1 + (-4 * t ** 2 + 4 * t) * x2 + (2 * t ** 2 - t) * x3109 y = (2 * t ** 2 - 3 * t + 1) * y1 + (-4 * t ** 2 + 4 * t) * y2 + (2 * t ** 2 - t) * y3110 draw_point((x, y))111 draw_point(p3)112prepare_turtle_canvas()113p1 = x1, y1 = random.randint(100, 300), random.randint(100, 300)114p2 = x2, y2 = random.randint(-300, -200), random.randint(100, 300)115p3 = x3, y3 = random.randint(-300, -200), random.randint(-300, -100)116p4 = x4, y4 = random.randint(200, 300), random.randint(-300, -100)117#draw_curve_3_points(p1, p2, p3)118#blend_line(p1, p2, p3, p4)119draw_curve_4_points(p1, p2, p3, p4)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!