def get_stats_err(shots, day, show=True, save=True, ylim=35): """ A function to get the statistics for a series of shots - INCLUDES ERROR BARS. Pass in the shots and the day, and it will plot the averaged density and temperature trace, as well as printing the density and temperature stats. Code gets messy becuase Ti data is not masked, bad elements are removed so I had to re-fill in None values There are some numbers hard-coded in, guesses of where the code should look for density and temperature peaks. You can also run run_nBT then look at all the outputs and updated these params if needed (block comments below) -- KG 06/28/19 """ num = len(shots) #stats I want: all_ne = [i for i in range(num)] all_Ti = [i for i in range(num)] ne_t = np.zeros(num) # Time of ne peak ne_peak = np.zeros(num) # value of ne peak ne_pre = np.zeros(num) # value of ne before peak ne_post = np.zeros(num) # value of ne after peak (20 us average) t_dens = [] den = [] # Ti_stats = [np.zeros(num) for i in range(4)] Ti_t = np.zeros(num) # Time of Ti p Ti_peak = np.zeros(num) # value of Ti p Ti_pre = np.zeros(num) # value of Ti before p Ti_post = np.zeros(num) # value of Ti after peak (20 us average) t_Ti = np.arange(-2, 125) Ti = np.zeros(len(t_Ti)) ave_over = np.zeros(len(t_Ti)) scope_used = '1' env, offset, phasediff = ds.dens_calib(dcs.calshot(day), scope=scope_used) a = env[0] / 2 b = env[1] / 2 for i, shot in enumerate(shots): #get density data: dens = ssxd.interferometer(day + 'r' + str(shot), [a, b], scope=scope_used, showPlot=False) density = dens.density sm_density = ism.iter_smooth(density, loops=30, window_len=29) n = sm_density / (1e15) timeN = dens.time if i == 0: t_dens = timeN den = n else: den = [d + n[k] for k, d in enumerate(den, 0)] all_ne[i] = [x for x in n] # now get the peak between 20 and 30 us """ Edit density peak here """ peak = np.array((20, 30)) t_index, peakt, peakne = my.fix_array(peak, timeN, n) max_index = np.argmax(peakne) ne_t[i] = peakt[max_index] ne_peak[i] = peakne[max_index] #min in the 5mu before peak t_index, minT, minNe = my.fix_array(np.array((peak[0] - 5, peak[0])), timeN, n) ne_pre[i] = np.min(minNe) #and the average value of the 20 mu after t_index, peakt, peakne = my.fix_array( np.array((peak[1], peak[1] + 20)), timeN, n) ne_post[i] = np.average(peakne) # print(ne_t, ne_peak ,ne_pre , ne_post) ########################################################## #get temperature data d = idsd.ids(day + 'r' + str(shot)) d.processIDS(times=[-2, 125]) timeT = d.time indices = np.where( d.kTFit.mask == False)[0] #Get indices of unmasked values Temp = d.kTFit.compressed() #Get unmasked values timeT = timeT[indices] #Adjust length of time array Terr = d.kTErr[indices] j = 0 # index for the Ti data of the shot all_Ti[i] = [0 for x in t_Ti] for k, t in enumerate(t_Ti): # jumping timesteps with missing values if (j >= len(timeT)): break if (np.absolute(timeT[j] - t) < .01): Ti[k] += Temp[j] ave_over[k] += 1 all_Ti[i][k] = Temp[j] j += 1 # now get the peak: """ Edit temperature peak here """ t_index, peakt, peakTi = my.fix_array(np.array((35, 50)), timeT, Temp) max_index = np.argmax(peakTi) Ti_t[i] = peakt[max_index] Ti_peak[i] = peakTi[max_index] #the min in the 5mu before the peak minTi = my.local_min_before(Ti_t[i] - 5, timeT, Temp) Ti_pre[i] = np.min(minTi) #and the average value after the peak t_index, peakt, peakti = my.fix_array( np.array((Ti_t[i] + 5, Ti_t[i] + 25)), timeT, Temp) Ti_post[i] = np.average(peakti) print("Shot", shot) #average den = [d / num for d in den] for i in range(len(Ti)): if ave_over[i] > 0: Ti[i] = Ti[i] / ave_over[i] else: Ti[i] = 0 ave_over[i] = 1 t_dens = t_dens[:len(den)] t_Ti = t_Ti[:len(Ti)] lens = np.sqrt(num) d_err = [] t_err = [] all_ne = [list(i) for i in zip(*all_ne)] all_Ti = list(it.zip_longest(*all_Ti, fillvalue=None)) for i, t in enumerate(t_dens): x = np.std(all_ne[i][:]) / lens d_err = np.append(d_err, x) for i in range(len(t_Ti)): x = np.nanstd(all_Ti[i][:]) / lens t_err = np.append(t_err, x) def stats(arr): return (np.mean(arr), np.std(arr, dtype=np.float64) / lens) if show: title = day + ' - averaged' plot_nTave(title, t_dens, den, t_Ti, Ti, ylim, d_err, t_err, save) print("Density Stats:") print("\tAverage time of peak:\n\t %.1f +/- %2.1f us" % (stats(ne_t))) print("\tAverage Value of peak:\n\t %.1f +/- %2.1f e15" % (stats(ne_peak))) print("\tAverage value before peak:\n\t %.2f +/- %2.2f e15" % (stats(ne_pre))) print("\tAverage value after peak:\n\t %.1f +/- %2.1f e15" % (stats(ne_post))) print("Temp Stats:") print("\tAverage time of peak:\n\t %.1f +/- %2.1f us" % (stats(Ti_t))) print("\tAverage value of peak:\n\t %.1f +/- %2.1f eV" % (stats(Ti_peak))) print("\tAverage value before peak:\n\t %.1f +/- %2.1f eV" % (stats(Ti_pre))) print("\tAverage value after peak:\n\t %.1f +/- %2.1f eV" % (stats(Ti_post))) if save: df = pd.DataFrame() df['Average time of peak density'] = stats(ne_t) df['Average peak density:'] = stats(ne_peak) df['Average before peak density:'] = stats(ne_pre) df['Average after peak density:'] = stats(ne_post) df[' '] = [" ", " "] df['Average time of peak temp'] = stats(Ti_t) ti_peak, std_peak = stats(Ti_peak) ti_pre, std_pre = stats(Ti_pre) heat = ti_peak - ti_pre std = np.amax([std_pre, std_peak]) df['Average peak temp:'] = [ti_peak, std_peak] df['Average before peak temp:'] = [ti_pre, std_pre] df['Average heating:'] = [heat, std] df['Average after peak temp:'] = stats(Ti_post) df = df.round(2) file = os.getcwd() + '\\data\\20' + day[ 4:6] + '\\' + day + '\\Analyzed\\' + day + '-stats.csv' # print(file) df.to_csv(str(file))
def main(): minorLocator = AutoMinorLocator(10) # leads to a single minor tick #ml = MultipleLocator(5) #minorLocator = MultipleLocator(10) gs = gridspec.GridSpec(4, 1) # plt.rc('text', usetex=True) plt.rcParams['text.latex.preamble'] = [r'\boldmath'] # where day day = '061219' shot_range = [6, 15] ## 87 code broke # Looks like the scope that is used for inferometer? scope_used = '1' t0 = 40 tf = 70 path = 'data\\2019\\' + day + '\\' + day + '-Analysed\\' BEGIN = 35 END = 100 setting1 = '_wind-tunnel' setting2 = '_beta_Alfvenspeed' #'_WLH_GasDelay_550mus' setting3 = '_eos_windtunnel' title1 = r': WLH, 1 mW, 600 $\mu s$, Merging Configuration' #title1 = ': WLH, 1 mW, 600 $\mu s$, coil scan at 25 kV' title2 = ': WLH, 1 mW, 600 $\mu s$, Merging Configuration' title3 = ': WLH, 1 mW, 600 $\mu s$, Merging Configuration' env, offset, phasediff = ds.dens_calib(dcs.calshot(day), scope=scope_used) a = env[0] / 2 b = env[1] / 2 # a = 1.312/2 for day = '013017' # b = 1.234/2 # a = 0.928/2 # b = 0.978/2 def f(time, A, B): # this is your 'straight line' y=f(x) return A * time + B for shot in range(shot_range[0], shot_range[1] + 1): print('On Shot', shot) # if shot==11 or 12: continue ######################################### plt.close('all') fig = plt.figure(num=1, figsize=(8.5, 10), facecolor='w', edgecolor='k') #, dpi=600) #plt.clf() fig.subplots_adjust(top=0.95, bottom=0.11, left=0.14, right=0.96, hspace=0.2) ax1 = plt.subplot(3, 1, 1) plt.text( 0.07, 0.92, '(a)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax1.transAxes, ) density = np.zeros([20002]) dens = ssxd.interferometer(day + 'r' + str(shot), [a, b], scope=scope_used, showPlot=False) density = dens.density sm_density = ism.iter_smooth(density, loops=30, window_len=29) n = sm_density / (1e15) #popt, pcov = curve_fit(f, dens.time[0:2000], n[0:2000]) #n = n + f(dens.time, *popt*1.3) timeN = dens.time plt.plot(timeN, n, color='k', lw=2) plt.ylabel(r'n $(10^{15}\ cm^{-3})$', fontsize=20, weight='bold') plt.title(day + 'r' + str(shot) + title1, fontsize=20, weight='bold') ax1.get_yaxis().set_label_coords( -0.11, 0.6) # for aligning the y-labels in one line plt.setp(ax1.spines.values(), linewidth=2) #changing the axis linewidth ax1.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax1.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax1.xaxis.set_minor_locator(minorLocator) #ax1.set_xticklabels([]) #ax1.set_yticks([0.5,1.0,1.5,2.0]) plt.xlim(20, 100) # plt.ylim(0, 2) ######################################### ax2 = plt.subplot(3, 1, 2) plt.text(0.07, 0.92, '(b)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax2.transAxes) d = idsd.ids(day + 'r' + str(shot)) d.processIDS(times=[-2, 125]) timeT = d.time indices = np.where( d.kTFit.mask == False)[0] #Get indices of unmasked values Temp = d.kTFit.compressed() #Get unmasked values timeT = timeT[indices] #Adjust length of time array Terr = d.kTErr[indices] plt.errorbar(timeT, Temp, Terr, fmt='None', ecolor='k', elinewidth=2, markeredgewidth=2, capsize=4) plt.plot(timeT, Temp, 'kx', color='k', ms=8, mew=2) plt.plot(timeT, Temp, color='k', linewidth=1) plt.ylabel(r'T$_i\ (eV)$', fontsize=20, weight='bold') #ax2.set_xticklabels([]) ax2.get_yaxis().set_label_coords(-0.11, 0.6) plt.setp(ax2.spines.values(), linewidth=2) ax2.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax2.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax2.xaxis.set_minor_locator(minorLocator) #ax2.tick_params(axis='y', direction='in', length=7, width =2) plt.xlim(20, 100) plt.ylim(0, 35) ######################################### ax3 = plt.subplot(3, 1, 3) plt.text(0.07, 0.92, '(c)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax3.transAxes) data = hdr.getquikData( day + 'r' + str(shot)) #x, y and z components of the 5th probe ##### changing from 15x, 15y and 15z to 6x, 6y and 6z # Bx=cumtrapz(data.unCalibData[0,14,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[0,14,:], 15), data.time)/7.63e-4 # By=cumtrapz(data.unCalibData[1,14,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[1,14,:], 15), data.time)/8.06e-4 # Bz=cumtrapz(data.unCalibData[2,2,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[2,2,:], 15), data.time)/6.76e-4 # I think the get moving average is accounting for some ofset... # Bx=cumtrapz(data.unCalibData[0,5,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[0,5,:], 15), data.time)/7.63e-4 # By=cumtrapz(data.unCalibData[1,5,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[1,5,:], 15), data.time)/8.06e-4 # Bz=cumtrapz(data.unCalibData[2,1,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[2,1,:], 15), data.time)/6.76e-4 Bx = cumtrapz( data.unCalibData[0, 5, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[0, 5, :], 15), data.time) * -1.088718234303543795e+03 By = cumtrapz( data.unCalibData[1, 5, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[1, 5, :], 15), data.time) * -1.119343007186590285e+03 Bz = cumtrapz( data.unCalibData[2, 1, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[2, 1, :], 15), data.time) * -1.422749719357707363e+03 timeB = data.time - data.time[0] - 2 timeB = timeB[:-1] # Bx=cumtrapz(data.unCalibData[0,14,1500:] - np.mean(data.unCalibData[0,14,4700:6500]), data.time[1500:])/7.63e-4 # By=cumtrapz(data.unCalibData[1,14,1500:] - np.mean(data.unCalibData[1,14,4700:6500]), data.time[1500:])/8.06e-4 # Bz=cumtrapz(data.unCalibData[2,2,1500:] - np.mean(data.unCalibData[2,2,4700:6500]), data.time[1500:])/6.76e-4 # timeB=data.time-data.time[0]-2 # timeB= timeB[1500:-1] ########## detrending the Bx, By, Bz signals ################ # poptx, pcovx = curve_fit(f, timeB, Bx) # Bx = Bx - f(timeB, *poptx) # popty, pcovy = curve_fit(f, timeB, By) # By = By - f(timeB, *popty) # poptz, pcovz = curve_fit(f, timeB, Bz) # Bz = Bz - f(timeB, *poptz) # plt.plot(timeB, Bx,color='r', lw =2) # plt.plot(timeB, By,color='b', lw =2) # plt.plot(timeB, Bz,color='g', lw =2) modB = np.sqrt((Bx**2) + (By**2) + (Bz**2)) #poptz, pcovz = curve_fit(f, timeB, modB) #plt.plot(timeB, modB, linewidth=2) # plt.plot(timeB, f(timeB, *poptz),color='g', lw =2) # modB_diff = np.mean(data.unCalibData[0,14,4700:4700]) # modB = modB-modB_diff plt.plot(timeB, Bx, color='r', lw=1, label='B$_{x,6}$') plt.plot(timeB, By, color='g', lw=1, label='B$_{y,6}$') plt.plot(timeB, Bz, color='b', lw=1, label='B$_{z,6}$') plt.plot(timeB, modB, color='k', lw=2, label='$|B|$') plt.legend().draggable() plt.ylabel(r'$|B|\ (T)$', fontsize=20, weight='bold') #ax.set_xticklabels([]) #ax.xaxis.set_tick_params(labeltop='on',labelsize=20) plt.setp(ax3.spines.values(), linewidth=2) ax3.get_yaxis().set_label_coords(-0.11, 0.6) ax3.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax3.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax3.xaxis.set_minor_locator(minorLocator) plt.xlim(20, 100) plt.xlabel(r'$Time\ (\mu s)$', fontsize=20, weight='bold') ########## Saving Figure 1 ################## plt.show() fName = path + day + 'r' + str(shot) + setting1 + '_plot.png' # fig.savefig(fName,dpi=600,facecolor='w',edgecolor='k') '''
def plot_ids(shot, day): d = idsd.ids(day + 'r' + str(shot)) # d.plotRawIDS() # d.im() d.plotIDS() plt.show()
def get_stats(shots, day, show=True, save=True, ylim=35): """ A function to get the statistics for a series of shots Pass in the shots and the day, and it will plot the averaged density and temperature trace, as well as printing the density and temperature stats. There are some numbers hard-coded in, guesses of where the code should look for density and temperature peaks. You can also run run_nBT then look at all the outputs and updated these params if needed (block comments below) -- KG 06/28/19 """ num = len(shots) #stats I want: ne_t = np.zeros(num) # Time of ne peak ne_peak = np.zeros(num) # value of ne peak ne_pre = np.zeros(num) # value of ne before peak ne_post = np.zeros(num) # value of ne after peak (20 us average) t_dens = [] den = [] Ti_t = np.zeros(num) # Time of Ti p Ti_peak = np.zeros(num) # value of Ti p Ti_pre = np.zeros(num) # value of Ti before p Ti_post = np.zeros(num) # value of Ti after peak (20 us average) t_Ti = np.arange(-2, 125) Ti = np.zeros(len(t_Ti)) ave_over = np.zeros(len(t_Ti)) scope_used = '1' env, offset, phasediff = ds.dens_calib(dcs.calshot(day), scope=scope_used) a = env[0] / 2 b = env[1] / 2 for i, shot in enumerate(shots): #get density data: dens = ssxd.interferometer(day + 'r' + str(shot), [a, b], scope=scope_used, showPlot=False) density = dens.density sm_density = ism.iter_smooth(density, loops=30, window_len=29) n = sm_density / (1e15) timeN = dens.time if i == 0: t_dens = timeN den = n else: den = [d + n[i] for i, d in enumerate(den, 0)] # now get the peak between 20 and 30 us """ Edit density peak here """ peak = np.array((20, 30)) t_index, peakt, peakne = my.fix_array(peak, timeN, n) max_index = np.argmax(peakne) ne_t[i] = peakt[max_index] ne_peak[i] = peakne[max_index] #min in the 5mu before peak t_index, minT, minNe = my.fix_array(np.array((peak[0] - 5, peak[0])), timeN, n) ne_pre[i] = np.min(minNe) #and the average value of the 20 mu after t_index, peakt, peakne = my.fix_array( np.array((peak[1], peak[1] + 20)), timeN, n) ne_post[i] = np.average(peakne) # print(ne_t, ne_peak ,ne_pre , ne_post) ########################################################## #get temperature data d = idsd.ids(day + 'r' + str(shot)) d.processIDS(times=[-2, 125]) timeT = d.time indices = np.where( d.kTFit.mask == False)[0] #Get indices of unmasked values Temp = d.kTFit.compressed() #Get unmasked values timeT = timeT[indices] #Adjust length of time array Terr = d.kTErr[indices] # if i == 0: # t_Ti = timeT # Ti = Temp # print(timeT, t_Ti) j = 0 # index for the Ti data of the shot for k, t in enumerate(t_Ti): # jumping timesteps with missing values if (j >= len(timeT)): break if (np.absolute(timeT[j] - t) < .01): Ti[k] += Temp[j] ave_over[k] += 1 # print(t, timeT[j]) j += 1 # Ti = [ti + Temp[i] for i,ti in enumerate(Ti) if i < len(Temp)] # now get the peak: """ Edit temperature peak here """ t_index, peakt, peakTi = my.fix_array(np.array((35, 50)), timeT, Temp) max_index = np.argmax(peakTi) Ti_t[i] = peakt[max_index] Ti_peak[i] = peakTi[max_index] #the min in the 5mu before the peak minTi = my.local_min_before(Ti_t[i] - 5, timeT, Temp) Ti_pre[i] = np.min(minTi) #and the average value after the peak t_index, peakt, peakti = my.fix_array( np.array((Ti_t[i] + 5, Ti_t[i] + 25)), timeT, Temp) Ti_post[i] = np.average(peakti) print("Shot", shot) #average den = [d / num for d in den] for i in range(len(Ti)): if ave_over[i] > 0: Ti[i] = Ti[i] / ave_over[i] print(ave_over[i]) else: Ti[i] = 0 t_dens = t_dens[:len(den)] t_Ti = t_Ti[:len(Ti)] lens = np.sqrt(num) def stats(arr): return (np.mean(arr), np.std(arr, dtype=np.float64) / lens) if show: title = day + ' - averaged' plot_nTave(title, t_dens, den, t_Ti, Ti, ylim) print("Density Stats:") print("\tAverage time of peak:\n\t %.1f +/- %2.1f us" % (stats(ne_t))) print("\tAverage Value of peak:\n\t %.1f +/- %2.1f e15" % (stats(ne_peak))) print("\tAverage value before peak:\n\t %.2f +/- %2.2f e15" % (stats(ne_pre))) print("\tAverage value after peak:\n\t %.1f +/- %2.1f e15" % (stats(ne_post))) print("Temp Stats:") print("\tAverage time of peak:\n\t %.1f +/- %2.1f us" % (stats(Ti_t))) print("\tAverage value of peak:\n\t %.1f +/- %2.1f eV" % (stats(Ti_peak))) # print(Ti_pre) print("\tAverage value before peak:\n\t %.1f +/- %2.1f eV" % (stats(Ti_pre))) print("\tAverage value after peak:\n\t %.1f +/- %2.1f eV" % (stats(Ti_post))) if save: #haven't wrote yet but you could add a function to save the data here pass
def plot_nT(shots, day, t_min=15, t_max=100, show=True, save=False, ylim=35, mask=False, mark=-1): """ same as run NbT but ommits the magnetic field -- KG 06/28/19 """ minorLocator = AutoMinorLocator(10) # leads to a single minor tick gs = gridspec.GridSpec(4, 1) plt.rcParams['text.latex.preamble'] = [r'\boldmath'] # Looks like the scope that is used for inferometer? scope_used = '1' path = 'data\\2019\\' + day + '\\Analyzed\\' setting1 = '_merging' setting2 = '_beta_Alfvenspeed' #'_WLH_GasDelay_550mus' setting3 = '_eos_windtunnel' title1 = r': WLH, 1 mW, 600 $\mu s$, Merging Configuration' #title1 = ': WLH, 1 mW, 600 $\mu s$, coil scan at 25 kV' title2 = ': WLH, 1 mW, 600 $\mu s$, Merging Configuration' title3 = ': WLH, 1 mW, 600 $\mu s$, Merging Configuration' env, offset, phasediff = ds.dens_calib(dcs.calshot(day), scope=scope_used) a = env[0] / 2 b = env[1] / 2 # a = 1.312/2 for day = '013017' # b = 1.234/2 # a = 0.928/2 # b = 0.978/2 def f(time, A, B): # this is your 'straight line' y=f(x) return A * time + B for shot in shots: print('On Shot', shot) plt.close('all') # Adjust the spacing: fig = plt.figure(num=1, figsize=(8.5, 10), facecolor='w', edgecolor='k') #, dpi=600) fig.subplots_adjust(top=0.95, bottom=0.11, left=0.14, right=0.96, hspace=0.2) ax1 = plt.subplot(2, 1, 1) plt.text( 0.07, 0.92, '(a)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax1.transAxes, ) dens = ssxd.interferometer(day + 'r' + str(shot), [a, b], scope=scope_used, showPlot=False) density = dens.density sm_density = ism.iter_smooth(density, loops=30, window_len=29) n = sm_density / (1e15) #popt, pcov = curve_fit(f, dens.time[0:2000], n[0:2000]) #n = n + f(dens.time, *popt*1.3) timeN = dens.time plt.plot(timeN, n, color='k', lw=2) if (mark > 0): interp_den = interp1d(timeN, n, kind='linear') plt.scatter(mark, interp_den(mark), color='red', linewidth=5) plt.ylabel(r'n $(10^{15}\ cm^{-3})$', fontsize=20, weight='bold') # plt.title(day+'r'+str(shot)+title1, fontsize=20, weight='bold') plt.title(day + 'r' + str(shot), fontsize=20, weight='bold') # if mark: # plt.title(day+'r'+str(shot) + '- ' + str(mark), fontsize=20, weight='bold') ax1.get_yaxis().set_label_coords( -0.11, 0.6) # for aligning the y-labels in one line plt.setp(ax1.spines.values(), linewidth=2) #changing the axis linewidth ax1.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax1.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax1.xaxis.set_minor_locator(minorLocator) plt.xlim(t_min, t_max) ######################################### ax2 = plt.subplot(2, 1, 2) plt.text(0.07, 0.92, '(b)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax2.transAxes) d = idsd.ids(day + 'r' + str(shot)) d.processIDS(times=[-2, 125]) timeT = d.time # This is where the errors happen? indices = np.where( d.kTFit.mask == False)[0] #Get indices of unmasked values Temp = d.kTFit.compressed() #Get unmasked values timeT = timeT[indices] #Adjust length of time array Terr = d.kTErr[indices] if mask: timeT = ma.masked_less(timeT, 26) mask = ma.getmask(timeT) Temp = ma.masked_where(mask, Temp) Terr = ma.masked_where(mask, Terr) plt.errorbar(timeT, Temp, Terr, fmt='None', ecolor='k', elinewidth=2, markeredgewidth=2, capsize=4) plt.plot(timeT, Temp, 'kx', color='k', ms=8, mew=2) plt.plot(timeT, Temp, color='k', linewidth=1) if (mark > 0): interp_Temp = interp1d(timeT, Temp, kind='linear') plt.scatter(mark, interp_Temp(mark), color='red', linewidth=5) plt.ylabel(r'T$_i\ (eV)$', fontsize=20, weight='bold') #ax2.set_xticklabels([]) ax2.get_yaxis().set_label_coords(-0.11, 0.6) plt.setp(ax2.spines.values(), linewidth=2) ax2.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax2.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax2.xaxis.set_minor_locator(minorLocator) #ax2.tick_params(axis='y', direction='in', length=7, width =2) plt.xlim(t_min, t_max) plt.ylim(0, ylim) plt.xlim(t_min, t_max) plt.xlabel(r'$Time\ (\mu s)$', fontsize=20, weight='bold') ########## Saving Figure 1 ################## fName = path + day + 'r' + str(shot) + setting1 + '_plot.png' if save: fig.savefig(fName, dpi=600, facecolor='w', edgecolor='k') print("Saved as", fName) if show: plt.show()
def get_nT(shot, t, ax1, ax2): """little plotter code to get the n and T, used for the mangetic animations -- KG 07/12/19 """ # minorLocator = AutoMinorLocator(10) # leads to a single minor tick # Looks like the scope that is used for inferometer? scope_used = '1' setting1 = '_wind-tunnel' setting2 = '_beta_Alfvenspeed' #'_WLH_GasDelay_550mus' setting3 = '_eos_windtunnel' title1 = r': WLH, 1 mW, 600 $\mu s$, Merging Configuration' env, offset, phasediff = ds.dens_calib(dcs.calshot(shot[:6]), scope=scope_used) a = env[0] / 2 b = env[1] / 2 def f(time, A, B): # this is your 'straight line' y=f(x) return A * time + B # plt.text(0.07,0.92,'(a)',fontsize=26, weight='bold',horizontalalignment='center',verticalalignment='center',transform=ax1.transAxes,) dens = ssxd.interferometer(shot, [a, b], scope=scope_used, showPlot=False) density = dens.density sm_density = ism.iter_smooth(density, loops=30, window_len=29) n = sm_density / (1e15) #popt, pcov = curve_fit(f, dens.time[0:2000], n[0:2000]) #n = n + f(dens.time, *popt*1.3) timeN = dens.time ax1.plot(timeN, n, color='k', lw=2) # plt.title(shot, fontsize=20, weight='bold') ax1.set_ylabel(r'n $(10^{15}\ cm^{-3})$', fontsize=20, weight='bold') # ax1.get_yaxis().set_label_coords(-0.11,0.6) # for aligning the y-labels in one line # plt.setp(ax1.spines.values(), linewidth=2)#changing the axis linewidth # ax1.tick_params(axis='both', direction='in', length=7, width =2, labelsize = 20) # ax1.tick_params(axis='x', which='minor', direction='in', length=5, width =1) ax1.set_xlim(t[0], t[-1]) ######################################### # ax2=plt.subplot(3,1,2) # ax2.text(0.07,0.92,'(b)',fontsize=26, weight='bold',horizontalalignment='center',verticalalignment='center',transform=ax2.transAxes) d = idsd.ids(shot) d.processIDS(times=[-2, 125]) timeT = d.time # This is where the errors happen? indices = np.where( d.kTFit.mask == False)[0] #Get indices of unmasked values Temp = d.kTFit.compressed() #Get unmasked values timeT = timeT[indices] #Adjust length of time array Terr = d.kTErr[indices] ax2.errorbar(timeT, Temp, Terr, fmt='None', ecolor='k', elinewidth=2, markeredgewidth=2, capsize=4) # ax2.plot(timeT, Temp, 'kx', color='k',ms = 8, mew=2) ax2.plot(timeT, Temp, color='k', linewidth=1) ax2.set_ylabel(r'T$_i\ (eV)$', fontsize=20, weight='bold') ax2.get_yaxis().set_label_coords(-0.11, 0.6) plt.setp(ax2.spines.values(), linewidth=2) ax2.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax2.tick_params(axis='x', which='minor', direction='in', length=5, width=1) #ax2.tick_params(axis='y', direction='in', length=7, width =2) plt.xlim(t[0], t[-1]) # print(t[0], t[-1]) #find the closest time t (regardless of repeats!) #and chuck the value at that time in # n_shifted = [n[my.tindex_center(timeN, time)] for time in t] # Temp_shifted = [interp_Temp[my.tindex_center(timeT, time)] for time in t ] interp_den = interp1d(timeN, n, kind='linear') interp_Temp = interp1d(timeT, Temp, kind='linear') # print("density") # interp_den(t) # print("temp") # interp_den(t) plt.ylim(0, 1.5 * np.amax(interp_Temp(t))) return ax1, ax2, interp_den(t), interp_Temp(t)
def run_nBT(shots, day, t_min=15, t_max=100, show=True, save=False, ylim=35): """All of this based on Manjit's code, with a minimal amount of modifications. This is the main code to prodcue graphs of the temperature, density and magnetic feidl strength -- KG 06/28/19 """ minorLocator = AutoMinorLocator(10) # leads to a single minor tick gs = gridspec.GridSpec(4, 1) plt.rcParams['text.latex.preamble'] = [r'\boldmath'] # Looks like the scope that is used for inferometer? scope_used = '1' path = 'data\\2019\\' + day + '\\Analyzed\\' setting1 = '_wind-tunnel' setting2 = '_beta_Alfvenspeed' #'_WLH_GasDelay_550mus' setting3 = '_eos_windtunnel' title1 = r': WLH, 1 mW, 600 $\mu s$, Merging Configuration' #title1 = ': WLH, 1 mW, 600 $\mu s$, coil scan at 25 kV' title2 = ': WLH, 1 mW, 600 $\mu s$, Merging Configuration' title3 = ': WLH, 1 mW, 600 $\mu s$, Merging Configuration' env, offset, phasediff = ds.dens_calib(dcs.calshot(day), scope=scope_used) a = env[0] / 2 b = env[1] / 2 # a = 1.312/2 for day = '013017' # b = 1.234/2 # a = 0.928/2 # b = 0.978/2 def f(time, A, B): # this is your 'straight line' y=f(x) return A * time + B for shot in shots: print('On Shot', shot) plt.close('all') # Adjust the spacing: fig = plt.figure(num=1, figsize=(8.5, 10), facecolor='w', edgecolor='k') #, dpi=600) fig.subplots_adjust(top=0.95, bottom=0.11, left=0.14, right=0.96, hspace=0.2) ax1 = plt.subplot(3, 1, 1) plt.text( 0.07, 0.92, '(a)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax1.transAxes, ) dens = ssxd.interferometer(day + 'r' + str(shot), [a, b], scope=scope_used, showPlot=False) density = dens.density sm_density = ism.iter_smooth(density, loops=30, window_len=29) n = sm_density / (1e15) #popt, pcov = curve_fit(f, dens.time[0:2000], n[0:2000]) #n = n + f(dens.time, *popt*1.3) timeN = dens.time plt.plot(timeN, n, color='k', lw=2) plt.ylabel(r'n $(10^{15}\ cm^{-3})$', fontsize=20, weight='bold') # plt.title(day+'r'+str(shot)+title1, fontsize=20, weight='bold') plt.title(day + 'r' + str(shot), fontsize=20, weight='bold') ax1.get_yaxis().set_label_coords( -0.11, 0.6) # for aligning the y-labels in one line plt.setp(ax1.spines.values(), linewidth=2) #changing the axis linewidth ax1.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax1.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax1.xaxis.set_minor_locator(minorLocator) plt.xlim(t_min, t_max) ######################################### ax2 = plt.subplot(3, 1, 2) plt.text(0.07, 0.92, '(b)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax2.transAxes) d = idsd.ids(day + 'r' + str(shot)) d.processIDS(times=[-2, 125]) timeT = d.time # This is where the errors happen? indices = np.where( d.kTFit.mask == False)[0] #Get indices of unmasked values Temp = d.kTFit.compressed() #Get unmasked values timeT = timeT[indices] #Adjust length of time array Terr = d.kTErr[indices] plt.errorbar(timeT, Temp, Terr, fmt='None', ecolor='k', elinewidth=2, markeredgewidth=2, capsize=4) plt.plot(timeT, Temp, 'kx', color='k', ms=8, mew=2) plt.plot(timeT, Temp, color='k', linewidth=1) plt.ylabel(r'T$_i\ (eV)$', fontsize=20, weight='bold') #ax2.set_xticklabels([]) ax2.get_yaxis().set_label_coords(-0.11, 0.6) plt.setp(ax2.spines.values(), linewidth=2) ax2.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax2.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax2.xaxis.set_minor_locator(minorLocator) #ax2.tick_params(axis='y', direction='in', length=7, width =2) plt.xlim(t_min, t_max) plt.ylim(0, ylim) ######################################### ax3 = plt.subplot(3, 1, 3) plt.text(0.07, 0.92, '(c)', fontsize=26, weight='bold', horizontalalignment='center', verticalalignment='center', transform=ax3.transAxes) data = hdr.getquikData( day + 'r' + str(shot)) #x, y and z components of the 5th probe #calibration factors from lookup_4 calib = [ 9.834933502238857272e+02, -1.263620982013806497e+03, -1.679900552773548725e+03 ] Bx = cumtrapz( data.unCalibData[0, 4, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[0, 4, :], 15), data.time) * calib[0] By = cumtrapz( data.unCalibData[1, 4, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[1, 4, :], 15), data.time) * calib[1] Bz = cumtrapz( data.unCalibData[2, 4, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[2, 4, :], 15), data.time) * calib[2] timeB = data.time - data.time[0] - 2 # timeB= data.time # make sure that the dimesntions match timeB = timeB[:len(Bx)] modB = np.sqrt((Bx**2) + (By**2) + (Bz**2)) plt.plot(timeB, Bx, color='r', lw=1, label='B$_{x,6}$') plt.plot(timeB, By, color='g', lw=1, label='B$_{y,6}$') plt.plot(timeB, Bz, color='b', lw=1, label='B$_{z,6}$') plt.plot(timeB, modB, color='k', lw=2, label='$|B|$') plt.legend().draggable() plt.ylabel(r'$|B|\ (G)$', fontsize=20, weight='bold') plt.setp(ax3.spines.values(), linewidth=2) ax3.get_yaxis().set_label_coords(-0.11, 0.6) ax3.tick_params(axis='both', direction='in', length=7, width=2, labelsize=20) ax3.tick_params(axis='x', which='minor', direction='in', length=5, width=1) ax3.xaxis.set_minor_locator(minorLocator) plt.xlim(t_min, t_max) plt.xlabel(r'$Time\ (\mu s)$', fontsize=20, weight='bold') ########## Saving Figure 1 ################## if show: plt.show() fName = path + day + 'r' + str(shot) + setting1 + '_plot.png' if save: fig.savefig(fName, dpi=600, facecolor='w', edgecolor='k')