def get_Bxy_vecRendering_format_lookup(shot, fix=False, num_probes=16): """Basically get_data() but returns data in a form that is compatible with the b-field animations found in anim_bfield_merging files Returns data, the calibrated, integrated magentic field data using lookup calibration. --KG 07/25/19 """ data = [[0] * 3 for i in range(num_probes)] # B25 = [[0] *num_probes for i in range(3)] magdata = hdr.getquikData(shot) timeB = magdata.time calibFile = 'calib-050119-4x4_lookup_final.txt' calibFile = os.path.join(os.getcwd() + "\\magcalib\\", calibFile) #change where caliv file is here calibFactor = np.loadtxt(calibFile) B25 = np.zeros([3, num_probes, len(timeB) - 1]) for probe in range(num_probes): Bx_all = cumtrapz( magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg( timeB, magdata.unCalibData[0, probe, :], num_probes - 1), timeB) Bx = Bx_all * calibFactor[probe][0] By_all = cumtrapz( magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg( timeB, magdata.unCalibData[1, probe, :], num_probes - 1), timeB) By = By_all * calibFactor[probe][1] Bz_all = cumtrapz( magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( timeB, magdata.unCalibData[2, probe, :], num_probes - 1), timeB) Bz = Bz_all * calibFactor[probe][2] B25[0, probe, :] = Bx B25[1, probe, :] = By B25[2, probe, :] = Bz if fix: B25[2, 9, :] = B25[2, 9, :] * 100 B25[2, 11, :] = B25[2, 11, :] * 100 B25[1, 12, :] = B25[1, 12, :] * 100 Bmod25 = np.zeros([num_probes, len(timeB) - 1]) for j in range(num_probes): Bmod25[j, :] = np.sqrt(B25[0, j, :]**2 + B25[1, j, :]**2 + B25[2, j, :]**2) return (timeB, B25)
def integrated_B(shot, num_probes=16, probe=3): """ There are different way that I've seen the data integrated: this will plot the different ones, along with a variety of different moving averages --KG 06/13/19 """ # data = [[0] *3 for i in range(num_probes)] fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True) data = hdr.getquikData(shot) btime = data.time Bz_nBT_15 = cumtrapz( data.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[2, probe, :], 15), data.time) * -1.103810335732411829e+02 Bz_nBT_100 = cumtrapz( data.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[2, probe, :], 100), data.time) * -1.103810335732411829e+02 Bz_nBT_500 = cumtrapz( data.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( data.time, data.unCalibData[2, probe, :], 500), data.time) * -1.103810335732411829e+02 # num_probes = 1 #only plot the first probe # probe_locs = get_probeLocs_calib_setup(shot) # Bz=sp.signal.detrend(magdata.fullData[2,probe_num,:]) # Bx=sp.signal.detrend(magdata.fullData[0,probe_num,:]) # By=sp.signal.detrend(magdata.fullData[1,probe_num,:]) # Bz=cumtrapz(data.unCalibData[2,1,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[2,1,:], 1), data.time) Bz = sp.signal.detrend(cumtrapz(data.unCalibData[2, probe, :], data.time)) btime = btime[:len(Bz)] ax1.plot(btime, Bz, label='Detrend, integrated') ax1.plot(btime, Bz_nBT_15, label='-moving avg, win = 15') ax1.plot(btime, Bz_nBT_100, label='-moving avg, win = 100') ax1.plot(btime, Bz_nBT_500, label='-moving avg, win = 500') ax1.legend() Bdot25 = np.zeros([3, 25, 8192]) timeB = data.time[801:] Bdot25[0, 3, :] = data.Bdot[0, 3, :] Bdot25[1, 3, :] = data.Bdot[1, 3, :] Bdot25[2, 3, :] = data.Bdot[2, 3, :] bzero = pyl.detrend_linear(Bdot25[2, 3, 800:]) bint = sp.integrate.cumtrapz(bzero, data.time[800:]) ax2.plot(btime, Bz_nBT_15, label='-moving avg, win = 15') ax2.plot(btime, Bz_nBT_500, label='-moving avg, win = 500') ax2.plot(timeB, bint, label="detrend LINEAR and integrated time shifted") # ax2.set_title("Current") plt.legend() plt.show()
def get_data_slice(shot, t, num_probes=16): """Gets the data from the 4x4 probe setup AT A SPECIFIC SLICE OF TIME Returns data, the calibrated, integrated magentic field data Data has the dimensions of [probes][direction][time] - probes is the number of probes, from 0 to 15 typically - direction is the direction of the magnetic field - 0 is x-dir - 1 is y-dir - 2 is z-dir ie Bx of probe 5 (index starting from 0) can be found: Bx = data[5][0] Very time inefficent, so don't plan to use this often --KG 07/25/19 """ data = [[0] * 3 for i in range(num_probes)] magdata = hdr.getMagData(shot) calibFile = 'calib-050119-4x4_lookup_final.txt' calibFile = os.path.join(os.getcwd() + '\\magcalib\\', calibFile) #change where caliv file is here calibFactor = np.loadtxt(calibFile) for probe in range(num_probes): Bx_all = cumtrapz( magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[0, probe, :], num_probes - 1), magdata.time) Bx = Bx_all[int(t)] * calibFactor[probe][0] By_all = cumtrapz( magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[1, probe, :], num_probes - 1), magdata.time) By = By_all[int(t)] * calibFactor[probe][1] Bz_all = cumtrapz( magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[2, probe, :], num_probes - 1), magdata.time) Bz = Bz_all[int(t)] * calibFactor[probe][2] data[probe] = [Bx, By, Bz] return data
def get_data(shot, num_probes=16): """Gets the data from the 4x4 probe setup at ALL TIMES Returns data, the calibrated, integrated magentic field data using lookup calibration. Data has the dimensions of [probes][direction] - probes is the number of probes, from 0 to 15 typically - direction is the direction of the magnetic field - 0 is x-dir - 1 is y-dir - 2 is z-dir ie Bx of probe 5 (index starting from 0) can be found: Bx = data[5][0] ASSUMES THE CALIBRATION FILE IS IN magcalib (feel free to change that tho)""" data = [[0] * 3 for i in range(num_probes)] magdata = hdr.getMagData(shot) calibFile = 'calib-050119-4x4_lookup_final.txt' calibFile = os.path.join(os.getcwd() + '\\magcalib\\', calibFile) #change where caliv file is here calibFactor = np.loadtxt(calibFile) for probe in range(num_probes): Bx_all = cumtrapz( magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[0, probe, :], num_probes - 1), magdata.time) Bx = Bx_all * calibFactor[probe][0] By_all = cumtrapz( magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[1, probe, :], num_probes - 1), magdata.time) By = By_all * calibFactor[probe][1] Bz_all = cumtrapz( magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[2, probe, :], num_probes - 1), magdata.time) Bz = Bz_all * calibFactor[probe][2] data[probe] = [Bx, By, Bz] return magdata.time, data
def get_v(magdata, probe, time): # from itertools import izip as zip, count # izip for maximum efficiency # print("here") i = mt.find_closest(magdata.time, time, False) # i = [i for i, j in enumerate(magdata.time) if j == time] # print(i) win_size = 25 Vx = cumtrapz(magdata.unCalibData[0,probe,:]-mj.get_gaussian_moving_avg(magdata.time, magdata.unCalibData[0,probe,:], win_size), magdata.time) Vy = cumtrapz(magdata.unCalibData[1,probe,:]-mj.get_gaussian_moving_avg(magdata.time, magdata.unCalibData[1,probe,:], win_size), magdata.time) Vz = cumtrapz(magdata.unCalibData[2,probe,:]-mj.get_gaussian_moving_avg(magdata.time, magdata.unCalibData[2,probe,:], win_size), magdata.time) return Vx[i], Vy[i], Vz[i]
def getMagData(shot, t0=-1, tf=-1, num_probes=16): """The main function that should be used Gets the data from the 4x4 probe setup at ALL TIMES Returns Bx,By and Bz, the calibrated, integrated magentic field data using a matrix calibration Data has the dimensions of [probes][time] - probes is the number of probes, from 0 to 15 typically assumes the calibration file is stored in magcalib folder --KG 07/10/19""" magdata = hdr.getquikData(shot) timeB = magdata.time if t0 != -1 and tf != -1: #trim to desired time t_index, t = my.fix_bounds(np.array((t0, tf)), timeB) magdata = magdata[:, :, t0:tf] calibFile = 'calib-050119-4x4_matrix.txt' calibFile = os.path.join(os.getcwd() + '\\magcalib\\', calibFile) #change where caliv file is here calibFactor = np.loadtxt(calibFile) B = np.zeros([3, num_probes, len(timeB) - 1]) win_size = 25 for probe in range(num_probes): for i in range(3): B_vec[i, probe, :] = cumtrapz( magdata.unCalibData[i, probe, :] - mj.get_gaussian_moving_avg( timeB, magdata.unCalibData[i, probe, :], win_size), timeB) for t in range(len(timeB) - 1): for probe in range(num_probes): C = np.reshape(calibFactor[probe], (3, 3)) #put into 3 x1 matric V = [[B_vec[0, probe, t]], [B_vec[1, probe, t]], [B_vec[2, probe, t]]] B_data = np.dot(C, V) B[0, probe, t], B[1, probe, t], B[2, probe, t] = B_data return B
def plot_every_single_calib_chan(shot, dir, lim, save=False, show=True, num_probes=16): """This function will plot a 4x4 (though there is some funcitonality built in for a different number of probes) grid of the CALIBRATED, INTEGRATED signals. Unless the calibration value was zero (when I built this some of the probes were dead during calibration) In which case it will plot the UNCALIBRATED (INTEGRATED) DATA IN RED for un-dead probes. Give it the shot (date + r + shot number) and the direction - 0 for x 1 for y 2 for z and it will plot all the signals. If you want to mess around with the number of probes, try passing it in as the parameter, though you may need to adjust cols or rows or both, and also maybe the figure size, (make is smaller if you have more probes) --KG 06/13/19 """ if (dir == 0): direction = 'X' elif (dir == 1): direction = 'Y' else: direction = 'Z' figsize = (9, 5) cols = 4 rows = (num_probes) // cols # define the data for cartesian plots def trim_axs(axs, N): """helper function to make sure the axs list to have correct length""" axs = axs.flat for ax in axs[N:]: ax.remove() return axs[:N] calibFile = 'calib-050119-4x4_lookup_1.txt' calibFile = os.path.join(os.getcwd(), calibFile) calibFactor = np.loadtxt(calibFile) fig1, axs = plt.subplots(rows, cols, figsize=figsize) axs = trim_axs(axs, num_probes) # for ax, case in zip(axs, cases) magdata = hdr.getquikData(shot) # Bx,By, Bz = pmd.getMagData(shot) for i in range(len(axs)): y = cumtrapz( magdata.unCalibData[dir, i, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[dir, i, :], 15), magdata.time) # print(calibFactor[i][dir]) x = magdata.time x = x[:len(y)] ax = axs[i] ax.set_title('Probe (%s,%s %s)' % (str(i // 4 + 1), str(i % 4 + 1), direction), fontsize=10) if (calibFactor[i][dir] == 0): # If the probe was dead during calibration ax.plot(x, y, color='r', linestyle='dashed') else: y = y * calibFactor[i][dir] ax.plot(x, y) ax.set_ylim(-lim, lim) # if np.average(np.abs(y)) < lim*1e-2: # ax.plot(x, y, color = 'r') # ax.set_ylim(-lim*1e-5, lim*1e-5) # print(i, np.max(y), np.min(y)) ax.tick_params(axis='both', which='major', labelsize=7) ax.tick_params(axis='both', which='minor', labelsize=7) if (i % cols == 0): #lable all the left cols with y label ax.set_ylabel("Gauss", fontsize=8) if (i // rows == rows - 1): #lable all the left cols with y label ax.set_xlabel("Time $\\mu$s", fontsize=8) # plt.title("Shot %s" %(shot)) if show: plt.show() if save: try: figname = os.getcwd() + '\\generated_images\\' + str( shot) + "-" + direction + "-chans.png" # print("Saved fig: %s" %(figname)) plt.savefig(figname) except: figname = os.getcwd() + str(shot) + "-" + direction + "-chans.png" plt.savefig(figname) print("No generated_images folder. \nSaved fig: %s" % (figname))
def generate_color_frame(shot, t, count, num_probes=16): plt.close("all") """ saves a frame instead of returning it ! """ data = [[0] * 3 for i in range(num_probes)] magdata = hdr.getMagData(shot) # print(len(magdata.time)) calibFile = 'calib-050119-4x4_lookup_1.txt' calibFile = os.path.join(os.getcwd(), calibFile) calibFactor = np.loadtxt(calibFile) for probe in range(num_probes): Bx_all = cumtrapz( magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[0, probe, :], num_probes - 1), magdata.time) Bx = Bx_all[int(t)] * calibFactor[probe][0] By_all = cumtrapz( magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[1, probe, :], num_probes - 1), magdata.time) By = By_all[int(t)] * calibFactor[probe][1] Bz_all = cumtrapz( magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[2, probe, :], num_probes - 1), magdata.time) Bz = Bz_all[int(t)] * calibFactor[probe][2] data[probe] = [Bx, By, Bz] # Get position vectors in meters position_vectors = get_probeLocs_SSX_setup() u = [data[i][0] for i in range(len(data))] v = [data[i][1] for i in range(len(data))] w = [data[i][2] for i in range(len(data))] # too big, so I just zero it out # v[6] = 0 x = [position_vectors[i][0] for i in range(len(position_vectors))] y = [position_vectors[i][1] for i in range(len(position_vectors))] z = [position_vectors[i][2] for i in range(len(position_vectors))] # qq = plt.quiver(y,z, v,w, u) # plt.plot() qq = plt.quiver(y, z, v, w, u, cmap=plt.cm.jet) scale_arrow = plt.quiver(.9, .9, .1, 0, label=".1 Tesla") cbar = plt.colorbar(qq, cmap=plt.cm.jet) cbar.set_label("Magnetic Field Strength (T)") # cbar.set_norm((-.085,.085)) cbar.set_clim(-.085, .085) plt.xlabel("Y direction") plt.ylabel("Z direction") plt.xlim(-.085, .085) plt.ylim(-.085, .085) plt.title("Magnetic Data - Shot %s. Time: %s" % (shot, str(t))) path = os.getcwd() path = path + '/mag_images/' path = path + 'mag-' + str(count) + '.png' plt.savefig(path)
def generate_3d_frame(shot, t, count, num_probes=16): """ saves a frame instead of returning it """ plt.close("all") data = [[0] * 3 for i in range(num_probes)] magdata = hdr.getMagData(shot) # print(len(magdata.time)) calibFile = 'calib-050119-4x4_lookup_1.txt' calibFile = os.path.join(os.getcwd(), calibFile) calibFactor = np.loadtxt(calibFile) for probe in range(num_probes): Bx_all = cumtrapz( magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[0, probe, :], num_probes - 1), magdata.time) Bx = Bx_all[int(t)] * calibFactor[probe][0] By_all = cumtrapz( magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[1, probe, :], num_probes - 1), magdata.time) By = By_all[int(t)] * calibFactor[probe][1] Bz_all = cumtrapz( magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg( magdata.time, magdata.unCalibData[2, probe, :], num_probes - 1), magdata.time) Bz = Bz_all[int(t)] * calibFactor[probe][2] data[probe] = [Bx, By, Bz] # Get position vectors in meters position_vectors = get_probeLocs_SSX_setup_cm() u = [data[i][0] for i in range(len(data))] v = [data[i][1] for i in range(len(data))] w = [data[i][2] for i in range(len(data))] # too big, so I just zero it out # v[6] = 0 """ In SSX setup: x -> -z y -> theta z -> -r """ x = [position_vectors[i][0] * -1 for i in range(len(position_vectors))] y = [position_vectors[i][1] for i in range(len(position_vectors))] z = [position_vectors[i][2] * -1 for i in range(len(position_vectors))] # qq = plt.quiver(y,z, v,w, u) # plt.plot() iffy_chans = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0] good_u = np.ma.masked_array(u, iffy_chans) good_v = np.ma.masked_array(v, iffy_chans) good_w = np.ma.masked_array(w, iffy_chans) dead_chans = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] dead_u = np.ma.masked_array(u, np.logical_not(dead_chans)) dead_v = np.ma.masked_array(v, np.logical_not(dead_chans)) dead_w = np.ma.masked_array(w, np.logical_not(dead_chans)) fixed_chans = np.logical_xor(iffy_chans, dead_chans) fixed_u = np.ma.masked_array(u, np.logical_not(fixed_chans)) fixed_v = np.ma.masked_array(v, np.logical_not(fixed_chans)) fixed_w = np.ma.masked_array(w, np.logical_not(fixed_chans)) fig = plt.figure() ax = fig.gca(projection='3d') col_map = plt.get_cmap('Blues') # ax.quiver(x,y,z,good_u,good_v,good_w, length=0.01, normalize=False,cmap = col_map, label = "Calibrated probes" ) # ax.quiver(x,y,z,dead_u,dead_v,dead_w, length=0.01, normalize=False, color = 'r', label = "Broken components") # ax.quiver(x,y,z,fixed_u,fixed_v,fixed_w, length=0.01, normalize=False,color = 'g', label = "interpolated components") # Q = ax.quiver(x,y,z,good_u,good_v,good_w, length=0.05, normalize=False, pivot = 'middle', cmap = col_map) # ax.quiver(x,y,z,dead_u,dead_v,dead_w, length=0.05, normalize=False, pivot = 'mid', color = 'r') # ax.quiver(x,y,z,fixed_u,fixed_v,fixed_w, length=0.05, normalize=False, pivot = 'mid', color = 'g') ax.quiver3D(x, y, z, good_u, good_v, good_w, length=0.02, arrow_length_ratio=.4, pivot='middle', normalize=False, cmap=col_map) ax.quiver3D(x, y, z, dead_u, dead_v, dead_w, length=0.02, arrow_length_ratio=.4, pivot='middle', normalize=False, color='r') ax.quiver3D(x, y, z, fixed_u, fixed_v, fixed_w, length=0.02, arrow_length_ratio=.4, pivot='middle', normalize=False, color='g') # qk = Q.quiverkey(Q, .92,.92, .1, label = ".1 Tesla") # ax.plot(np.zeros(100),np.zeros(100),'cyan--', alpha = .3) #set up the pivot = 'mid',midline N = 100 lim = 8.5 #workaround quiverkey: ax.quiver(0, 0, 0, 100, 0, 0, length=0.02, arrow_length_ratio=.4, pivot='middle', color='c', label='100 Gauss') # ax.plot(np.linspace(-lim, lim, N), np.zeros(N), 'k--', alpha = 0.6, label = "midline") ax.plot(np.linspace(-lim, lim, N), np.zeros(N), 'k--', alpha=0.6) plt.legend() # add the sca;le # plt.legend(loc= 'upper right') #add cylinder: # Xc,Yc,Zc = generate_cyl_dat() # Xc[Xc>lim]= np.nan # Xc[Xc<-lim]= np.nan # Yc[Yc>lim]= np.nan # Yc[Yc<-lim]= np.nan # Zc[Zc>lim]= np.nan # Zc[Zc<-lim]= np.nan # ax.plot_surface(Xc, Yc, Zc, color = 'tan', alpha=0.3) #add edge of SSX # z = np.empty(N) # z.fill(0.08025) # x = np.linspace(-lim, lim, N) # X, Z = np.meshgrid(x,z) # Y = # ax.plot(np.linspace(-lim, lim, N), z, 'y--', alpha = 0.6, label = "midline") # ax.plot_surface(, z, 'y--', alpha = 0.6, label = "edge of SSX") #add title/labels ax.set_xlabel("$\\hat{Z}$, cm") ax.set_ylabel("$\\hat{\\theta}, cm$") ax.set_zlabel("$\\hat{R}, cm$") ax.set_zlim3d(-lim, lim) ax.set_xlim3d(-lim, lim) ax.set_ylim3d(-lim, lim) # plt.zlim(-lim, lim) # plt.xlim(-lim, lim) # plt.ylim(-lim, lim) plt.axis('equal') # plt.title("Magnetic Data - Shot %s. \n $\\bf{Time}$: %.2f $\\it{\mu s}$ " %(shot[7:], t)) plt.title("Magnetic Data - Shot %s. \n $\\bf{Time}$: %.2f $\\it{\mu s}$ " % (shot, t)) path = os.getcwd() path = path + '/mag_images/' #quick fix to make sure the ordering makes sense: str_count = str(count) if count < 10: str_count = '0' + str_count if count < 100: str_count = '0' + str_count if count < 1000: str_count = '0' + str_count path = path + str_count + '-mag' + '.png' plt.savefig(path)
def get_Bxy_vecRendering_format(shot, fix=False, num_probes=16): """ Returns data, the calibrated, integrated magentic field data using matrix calibration. UNFINISHED becuase of the matrix thing. But this function would return getMagData() data but in a version compatible with the animations in anim_bfield_merging.py --KG 07/25/19 """ data = [[0] * 3 for i in range(num_probes)] # B25 = [[0] *num_probes for i in range(3)] magdata = hdr.getquikData(shot) timeB = magdata.time calibFile = 'calib-050119-4x4_matrix.txt' calibFile = os.path.join(os.getcwd() + '\\magcalib\\', calibFile) #change where caliv file is here print("\n\nHERE") calibFactor = np.loadtxt(calibFile) # calibFactor[14] = [0,0,0] # calibFactor[6] = [0,0,0] # calibFactor[7] = [0,0,0] B25 = np.zeros([3, num_probes, len(timeB) - 1]) B_vec = np.zeros([3, num_probes, len(timeB) - 1]) win_size = 25 for probe in range(num_probes): for i in range(3): B_vec[i, probe, :] = cumtrapz( magdata.unCalibData[i, probe, :] - mj.get_gaussian_moving_avg( timeB, magdata.unCalibData[i, probe, :], win_size), timeB) for t in range(len(timeB) - 1): for probe in range(num_probes): C = np.reshape(calibFactor[probe], (3, 3)) #put into 3 x1 matric V = [[B_vec[0, probe, t]], [B_vec[1, probe, t]], [B_vec[2, probe, t]]] B = np.dot(C, V) Bx, By, Bz = B B25[0, probe, t] = Bx B25[1, probe, t] = By B25[2, probe, t] = Bz Bmod25 = np.zeros([num_probes, len(timeB) - 1]) for j in range(num_probes): Bmod25[j, :] = np.sqrt(B25[0, j, :]**2 + B25[1, j, :]**2 + B25[2, j, :]**2) return (timeB, B25)
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 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')