def init_gd(self, init_type="quad", steps=6): """Group delay initialization: init_type: 'line': linear initialization 'quad': second order initialization. Default steps: number of points to extrapolate between 0 and first probed frequency. Default to 6. """ if not hasattr(self, 'nfreqs'): self.freq_ini = np.linspace(0, self.freqs[0], num=steps) self.nfreqs = np.concatenate((self.freq_ini, self.freqs[1:])) self.freqs = self.nfreqs.copy() self.ne = rf.freq2den(self.nfreqs * 1e9) if init_type == 'line': self.ini_t = np.linspace(0, self.gd[0], num=steps) elif init_type == 'quad': mean_pos = steps / 2 mean_t = self.gd[0] * 0.5 * 0.8 polynomial = np.polyfit((0, self.freq_ini[mean_pos], self.freq_ini[-1]), (0, mean_t, self.gd[0]), 2) pol = np.poly1d(polynomial) self.ini_t = pol(self.freq_ini) # frequency and group delay now starts from zero self.gd = np.concatenate((self.ini_t[:-1], self.gd))
def eval_freq_overlap(self): if not hasattr(self, 'freqs'): # index position of overlap in K and Ka bands self.cmin = None self.cmax = None # check the number of points of overlaped frquency self.freq_k_max = self.X['K'][-1] self.freq_ka_min = self.X['Ka'][0] delta_freq_gap = self.freq_ka_min - self.freq_k_max if delta_freq_gap < 0: # index position of overlap in K band self.cmax = np.where((self.X['K'] - min(self.X['Ka'])) > 0)[0][0] # frequency in K band that starts to overlap self.freq_k_max = self.X['K'][self.cmax] # index position of overlap in Ka band self.cmin = np.where( (self.X['Ka'] - max(self.X['K'])) < 0)[0][-1] + 1 # frequency in Ka band that finishs the overlap print(self.cmin,self.cmax) self.freq_ka_min = self.X['Ka'][self.cmin] # creates an array with all the overlapping frequencies self.freqs_over = np.sort(np.concatenate( (self.X['K'][self.cmax:], self.X['Ka'][:self.cmin]))) else: self.freqs_over = np.array([]) # delta_freq_ka = self.X['Ka'][1] - self.X['Ka'][0] # self.freqs_over = np.empty() # # if gap is larger than a frequency step in Ka band, add points # if delta_freq_gap > (delta_freq_ka): # self.freqs_over = np.arange( # self.freq_k_max + delta_freq_ka, self.freq_ka_min, delta_freq_ka) # else: # self.freqs_over = np.array([]) # creates a frequency array for all bands self.freqs = np.concatenate( (self.X['K'][:self.cmax], self.freqs_over, self.X['Ka'][self.cmin:])) self.ne = rf.freq2den(self.freqs * 1e9)
shot.eval_phase() fig, ax = plt.subplots() plt.subplots_adjust(bottom=0.25) lines = {} for f in factors.keys(): pos[f] = ppb.find_pos(shot.freqs[1:], shot.phi, factor=eval(f)) lines[f], = plt.plot(pos[f] * 1e2, shot.ne[1:], label=factors[f]) ax.legend(loc='upper left', title='Factor:') ax.set_xlabel('r (cm)') ax.set_ylabel('density (10^19 m^-3)') plt.title("# %s - time: %s ms" % (shot_number, shot.sweep2time(shot.sweep_cur))) plt.axis([0, 20, shot.ne[1], shot.ne[-1] * 1.1]) plt.axhline(rf.freq2den(shot.freq_ini[-1] * 1e9), color='g', linestyle='-.') if len(shot.freqs_over) != 0: plt.axhline(rf.freq2den(shot.freqs_over[0] * 1e9), color='k', linestyle='-.') plt.axhline(rf.freq2den(shot.freqs_over[-1] * 1e9), color='k', linestyle='-.') else: plt.axhline(rf.freq2den(shot.X['K'][-1] * 1e9), color='r', linestyle='-.') plt.axhline(rf.freq2den(shot.X['Ka'][0] * 1e9), color='r', linestyle='-.') axcolor = 'lightgoldenrodyellow' axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor) sweep = Slider(axfreq,
shot = pp.ProcProfile(33708) shot.reference_gd(all_shot=1, sw_clustersize=1) cluster = 50 shot.plasma_gd(7000, cluster, 1) shot.find_ne_max2() ne = shot.ne_full*1e-19 r = np.nan*np.ones(len(ne)) if not shot.no_plasma: r_inver = shot.abel_transform(shot.gd2*1e-9, shot.freqs2*1e9, order=2, init=2) r[:len(r_inver)] = r_inver tau0 = np.polyval(np.polyfit(shot.freqs2, shot.gd2, 2), shot.freqs2[0]) f_init = np.linspace(1, shot.freqs2[0], 10) tau_init = f_init * tau0 / (f_init[-1]**2) ne_init = rf.freq2den(f_init*1e9)*1e-19 r_init = shot.abel_transform(tau_init*1e-9, f_init*1e9, order=2, init=2) l, = plt.plot(r, ne) m, = plt.plot(r_init, ne_init, 'r--') plt.xlabel("r [m]") plt.ylabel("ne [$10^{19}$ m$^-3$]") plt.title("# %s - time: %s ms" % (shot.shot, shot.sweep2time(shot.sweep_cur))) plt.ylim(0, 2) plt.xlim(-0.05, 0.2) axcolor = 'lightgoldenrodyellow' axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor) sweep = Slider(axfreq, 'Sweep', 1, len(shot.points) - 1 - cluster, valinit=1, valfmt='%1.f')
shot.reference_gd(all_shot=1, sw_clustersize=cluster) shot.eval_freq_overlap() shot.prepare_gd(sweep_ini, cluster, all_shot=1) shot.profile() pos_abel = ppa.find_pos(shot.freqs, shot.gd) fig = plt.figure() ax1 = fig.add_subplot(212) plt.subplots_adjust(bottom=0.25) lineb, = ax1.plot(shot.pos * 1e2, shot.ne[1:], label="Bottollier") linea, = ax1.plot(pos_abel * 1e2, shot.ne, label="Abel Inversion") ax1.legend(loc='upper left') ax1.set_xlabel('r (cm)') ax1.set_ylabel('density (10^19 m^-3)') plt.axis([0, 20, shot.ne[1], shot.ne[-1] * 1.1]) ax1.axhline(rf.freq2den(shot.freq_ini[-1] * 1e9), color='g', linestyle='-.') if len(shot.freqs_over) != 0: ax1.axhline(rf.freq2den(shot.freqs_over[ 0] * 1e9), color='k', linestyle='-.') ax1.axhline(rf.freq2den( shot.freqs_over[-1] * 1e9), color='k', linestyle='-.') else: ax1.axhline(rf.freq2den(shot.X['K'][-1] * 1e9), color='r', linestyle='-.') ax1.axhline(rf.freq2den(shot.X['Ka'][0] * 1e9), color='r', linestyle='-.') ax2 = fig.add_subplot(211) lined, = ax2.plot(abs(pos_abel[:-1] - shot.pos) * 1e2, 'k') ax2.set_ylabel("abs diff (cm)") ax2.set_title("# %s - time: %s ms - #sweeps average: %s " % (shot_number, shot.sweep2time(shot.sweep_cur), cluster))
cluster = 50 shot.plasma_gd(7000, cluster, 1) shot.find_ne_max2() ne = shot.ne_full * 1e-19 r = np.nan * np.ones(len(ne)) if not shot.no_plasma: r_inver = shot.abel_transform(shot.gd2 * 1e-9, shot.freqs2 * 1e9, order=2, init=2) r[:len(r_inver)] = r_inver tau0 = np.polyval(np.polyfit(shot.freqs2, shot.gd2, 2), shot.freqs2[0]) f_init = np.linspace(1, shot.freqs2[0], 10) tau_init = f_init * tau0 / (f_init[-1]**2) ne_init = rf.freq2den(f_init * 1e9) * 1e-19 r_init = shot.abel_transform(tau_init * 1e-9, f_init * 1e9, order=2, init=2) l, = plt.plot(r, ne) m, = plt.plot(r_init, ne_init, 'r--') plt.xlabel("r [m]") plt.ylabel("ne [$10^{19}$ m$^-3$]") plt.title("# %s - time: %s ms" % (shot.shot, shot.sweep2time(shot.sweep_cur))) plt.ylim(0, 2) plt.xlim(-0.05, 0.2) axcolor = 'lightgoldenrodyellow' axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)