def ddelmsync(shotnr, diag, signal, experiment='AUGD', edition=0, tBegin=0.0, tEnd=10.0, preft=0.001, suft=0.004, felm_min=0, felm_max=1000, elm_exper="AUGD", elm_edition=0): """Gets a selected 1-D signal and syncs it to the ELMs in the desired time interval Parameters ------------ shotnr: int Number of the shot to analyse. diag: str Name of the shotfile containing the data. signal: str Name of the signal in 'diag' to analyse. experiment: str Naame of the experiment (username) containing the shotfile. edition: int Edition of the shotfile. tBegin: float Initial time of analysis. tEnd: float Final time for analysis. preft: float 'Prefix time' to consider before ELM onset. suft: float 'Suffix time' to consider after ELM ends. felm_min: float Minimum ELM frequency to include in analysis. Default value 0Hz considers all ELMs. felm_max : float Maximum ELM frequency to include in analysis. Default value 1000Hz considers all ELMs. elm_exper: str User of the experiment. Default is public shotfile 'AUGD'. elm_edition: int Edition of the ELM shotfile. Default is latest edition, 0. Returns ------------ synctime: np.array(float) Array of times resetted to the closest ELM. syncsig: np.array(float) 1D or 2D array of data ordered according to the sychronized times. """ ################################# ##Flag to check if data came from a signal group sgrp = False ###### Gets ELM data ############ ELM = dd.shotfile("ELM", shotnr, experiment=elm_exper, edition=elm_edition) elmd = ELM("t_endELM", tBegin=tBegin, tEnd=tEnd) freq_ELM = ELM("f_ELM", tBegin=tBegin, tEnd=tEnd) t_endELM = elmd.data t_begELM = elmd.time ELM.close() ################################ ################################ ###### Get the signal in cause signal = getsig(shotnr, diag, signal, tBegin=tBegin, tEnd=tEnd, edition=edition) #################### Syncs the timebase to the ELM timebase ########################### ###### Signal group ########################### syncsig = []#np.zeros_like(signal.data) synctime = []#np.zeros_like(signal.time) for elm in range(t_begELM.size): #Only accept ELMs at the chosen frequency window if (freq_ELM.data[elm]>=felm_min)&(freq_ELM.data[elm]<=felm_max): t1, t2 =t_begELM[elm]-preft, t_endELM[elm]+suft #Re-adjust ELM times so no overlap between consecutive ELMs occurs if (elm >=1 ) : tendprev = t_endELM[elm-1] t1 = np.max([t1,tendprev]) if (elm<t_begELM.size-1): tstartnext = t_begELM[elm+1] t2 = np.min([t2,tstartnext]) elmind = np.where((signal.time >= t1) & (signal.time <=t2)) synctime.append(signal.time[elmind]-t_begELM[elm]) #Distinguish between 1D (signal) and 2D array (Signal group) if len(signal.data.shape)==1: syncsig.append(signal.data[elmind]) elif len(signal.data.shape)==2: syncsig.append(signal.data[elmind,:]) else: raise Exception('Array format not supported!') else:#Space left open for possible analysis a=0 #Finally, return is again dependent on array dimensions if len(signal.data.shape)==1: synctime_return = np.concatenate(synctime) syncsig_return = np.concatenate(syncsig) if len(signal.data.shape)==2: synctime_return = np.concatenate(synctime) syncsig_return = np.concatenate(syncsig, axis=1)[0,:,:] return synctime_return, syncsig_return
def overview_plot(shotnr, intervals=[[0,1.8],[1.8,2.0],[2.0,3.0],[3.0,5.0],[5.0,7.0]], print_fig=False, titlestr='', lwid=2): """Plots a simple overview plot for the AR seeding experiments""" tBegin = np.min(np.array(intervals)) tEnd = np.max(np.array(intervals)) prnt = False ip = getsig(shotnr, "MAG", "Ipa", tBegin=tBegin, tEnd=tEnd) wmhd = getsig(shotnr, "FPG", "Wmhd", tBegin=tBegin, tEnd=tEnd) q95 = getsig(shotnr, "FPG", "q95", tBegin=tBegin, tEnd=tEnd) h1 = getsig(shotnr, "DCN", "H-1", tBegin=tBegin, tEnd=tEnd) h5 = getsig(shotnr, "DCN", "H-5", tBegin=tBegin, tEnd=tEnd) ecrh = getsig(shotnr, "ECS", "PECRH", tBegin=tBegin, tEnd=tEnd) nbi = getsig(shotnr, "NIS", "PNI", tBegin=tBegin, tEnd=tEnd) prad= getsig(shotnr, "BPD", "Pradtot", tBegin=tBegin, tEnd=tEnd) dtot = getsig(shotnr, "UVS", "D_tot", tBegin=tBegin, tEnd=tEnd) ntot = getsig(shotnr, "UVS", "N_tot", tBegin=tBegin, tEnd=tEnd) artot = getsig(shotnr, "UVS", "CFA03A", tBegin=tBegin, tEnd=tEnd) #############First plot f, ax = plt.subplots( nrows=4, ncols=1, sharex=True, sharey=False, gridspec_kw={'height_ratios':[1,1,1,1]},figsize=(6, 5.5),dpi=200) hdl_len = 0.7 alphaval = 0.45 plt.setp(ax[0].get_xticklabels(), visible=False) ax[0].set_title(titlestr, loc='left') ax[0].set_ylim([0,1.1]) ax[0].plot(ip.time, ip.data*1e-6, label=r"$\mathrm{Ip\,[MA]}$", lw=lwid) ax[0].plot(wmhd.time, wmhd.data*1e-6, label="Wmhd [MJ]", lw=lwid) ax[0].plot(q95.time, -q95.data/10.0, label="q95", lw=lwid) ax[0].legend(loc='best', handlelength=hdl_len) #############Second plot plt.setp(ax[1].get_xticklabels(), visible=False) ax[1].set_ylim([0,9.5]) ax[1].plot(h1.time, h1.data*1e-19, label=r"$\mathrm{H-1\,[10^{19}m^{-3}]}$", lw=lwid) ax[1].plot(h5.time, h5.data*1e-19, label=r"$\mathrm{H-5\,[10^{19}m^{-3}]}$", lw=lwid) ax[1].legend(loc='best', handlelength=hdl_len) #############Third plot ax[2].plot(ecrh.time, ecrh.data*1e-6, label=r"$\mathrm{ECRH\,[MW]}$", lw=lwid) ax[2].plot(nbi.time, nbi.data*1e-6, label=r"$\mathrm{NBI\,[MW]}$", lw=lwid) ax[2].plot(prad.time, prad.data*1e-6, label=r"$\mathrm{NBI\,[MW]}$", lw=lwid) ax[2].legend(loc='best', handlelength=hdl_len) ax[2].set_ylim([0,9.8]) ax[3].plot(dtot.time, dtot.data*1e-22, label=r"$\mathrm{D\,[10^{22}e/s]}$", lw=lwid) ax[3].plot(ntot.time, ntot.data*1e-22, label=r"$\mathrm{N\,[10^{22}e/s]}$", lw=lwid) ax[3].plot(artot.time, artot.data*1e-21, label=r"$\mathrm{Ar\,[10^{21}e/s]}$", lw=lwid) ax[3].legend(loc='best', handlelength=hdl_len) ax[3].set_ylim(0,3.3) ax[3].set_xlabel("time [s]") ####################### ax[3].set_xlim([tBegin,tEnd]) clrs = ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7'] for interv, i in zip(intervals, range(len(intervals))): for axa in ax: axa.axvspan(interv[0], interv[1], facecolor=clrs[i], alpha=alphaval) plt.subplots_adjust(left=0.1, bottom=0.12, right=0.95, top=0.94, wspace=0.26, hspace=0.05) #plt.tight_layout() #if print_fig == True: #fname = "./Images/overview_"+str(shotnr)+'.png' #plt.savefig(fname, dpi=150) plt.show()
def neAugped(shotnr=30554, exper='guimas', edition=3, nr_diags=4, elm_exper='AUGD', magdiag='FPP'): """Reads the density information of a PED shotfile and returns an object with electron density data Parameters ----------- shotnr: int Number of the shot exper: str AUGPED only saves private shotfiles, so you must explicit the name of the author of the private shotfile edition: int Edition of the private shotfile nr_diags: int How many diagnostics are stored in the private shotfile: still under automation. elm_exper: str Where to get the ELM data. This is still needed to set Returns ----------- The return is a single object with the following entries: t1: float Initial time for the analysis t2: float Final time for the analysis rhos: np.array(float) rad: np.array(float) dens: np.array(float) indi: np.array(int) indf: np.array(int) neRshift: np.array(float) fpgavg: float """ ped = dd.shotfile('PED', shotnr, experiment='guimas', edition=edition) t1 = ped('t1') t2 = ped('t2') nedata = ped('neData') mskz = nedata.data != 0.0 rhos = nedata.area.data[0, mskz] dens = nedata.data[mskz] diagind = ped('DiagIndx') nedpts = ped('neDPts') indexesr = nedpts.data[nedpts.data != 0] tstart = ped('tstart') tstop = ped('tstop') neRshift = ped('neRshift') ped.close() #Check the intervals indi = np.zeros(nr_diags).astype(int) indf = np.zeros(nr_diags).astype(int) #Initialize arrays indf[0] = np.array(indexesr[0] - 1).astype(int) for i in range(1, nr_diags): indi[i] = np.sum(indexesr[0:i]).astype(int) indf[i] = np.sum(indexesr[0:i + 1]).astype(int) - 1 #Gets the average separatrix position if magdiag == 'FPP': sep_shotfile = 'FPG' elif magdiag == 'EQH': sep_shotfile = 'GQH' elif magdiag == 'EQI': sep_shotfile = 'GQI' elif magdiag == 'IDE': sep_shotfile == 'IDG' else: #Use FPP by default sep_shotfile = 'FPG' magdiag = 'FPP' print('Unknown magnectic reconstruction shotfile, reverting to FPP!') fpg = getsig(shotnr, sep_shotfile, 'Raus') fpgmsk = ddremoveELMData(shotnr, fpg.time, preft=0.002, suft=0.004, elm_exper=elm_exper) fpgind = (fpg.time >= t1.data) & (fpg.time <= t2.data) & fpgmsk fpgavg = np.mean(fpg.data[fpgind]) eq = kk_abock.kk() eq.Open(shotnr, diag=magdiag) radius = eq.rhopol_to_Rz((np.float(t1.data) + np.float(t2.data)) / 2.0, rhos, 0.0) rad = radius['R'] eq.Close() return objview({ 't1': np.array(t1.data), 't2': np.array(t2.data), 'rhos': np.array(rhos), 'rad': np.array(rad), 'dens': np.array(dens), 'indi': np.array(indi), 'indf': np.array(indf), 'neRshift': np.array(neRshift.data), 'fpgavg': np.array(fpgavg) })
def pedshtf(shotnr=30554, exper='guimas', edition=3, nr_diags=4, elm_exper='AUGD'): """Reads the density information of a PED shotfile and returns an object with electron density data """ ped = dd.shotfile('PED', shotnr, experiment='guimas', edition=edition) t1 = ped('t1') t2 = ped('t2') nedata = ped('neData') mskz = nedata.data != 0.0 rhos = nedata.area.data[0, mskz] dens = nedata.data[mskz] diagind = ped('DiagIndx') nedpts = ped('neDPts') indexesr = nedpts.data[nedpts.data != 0] tstart = ped('tstart') tstop = ped('tstop') neRshift = ped('neRshift') ped.close() #Check the intervals indi = np.zeros(nr_diags).astype(int) indf = np.zeros(nr_diags).astype(int) #Initialize arrays indf[0] = np.array(indexesr[0] - 1).astype(int) for i in range(1, nr_diags): indi[i] = np.sum(indexesr[0:i]).astype(int) indf[i] = np.sum(indexesr[0:i + 1]).astype(int) - 1 #Gets the average separatrix position fpg = getsig(shotnr, 'FPG', 'Raus') fpgmsk = ddremoveELMData(shotnr, fpg.time, preft=0.002, suft=0.004, elm_exper=elm_exper) fpgind = (fpg.time >= t1.data) & (fpg.time <= t2.data) & fpgmsk fpgavg = np.mean(fpg.data[fpgind]) import kk_abock eq = kk_abock.kk() eq.Open(shotnr, diag='FPP') radius = eq.rhopol_to_Rz((np.float(t1.data) + np.float(t2.data)) / 2.0, rhos, 0.0) rad = radius['R'] eq.Close() return objview({ 'shotnr': shotnr, 't1': np.array(t1.data), 't2': np.array(t2.data), 'rhos': np.array(rhos), 'rad': np.array(rad), 'dens': np.array(dens), 'indi': np.array(indi), 'indf': np.array(indf), 'neRshift': np.array(neRshift.data), 'fpgavg': np.array(fpgavg) })
def ddelmsync_old(shotnr, diag, signal, edition=0, ti=0.0, tf=10.0, preft=0.001, suft=0.004, elm_exper="AUGD", elm_edition=0): """Gets a selected 1-D signal and syncs it to the ELMs in the desired time interval Parameters ------------ shotnr: int diag: str signal: str edition: int ti: float tf: float preft: float suft: float elm_exper: str elm_edition: int Returns ------------ synctime: np.array(float) Array of times resetted to the closest ELM. syncsig: np.array(float) 1D or 2D array of data ordered according to the sychronized times. """ ################################# ##Flag to check if data came from a signal group sgrp = False ###### Gets ELM data ############ ELM = dd.shotfile("ELM", shotnr, experiment=elm_exper, edition=elm_edition) elmd = ELM("t_endELM", tBegin=ti, tEnd=tf) t_endELM = elmd.data t_begELM = elmd.time ELM.close() ################################ ################################ ###### Get the signal in cause signal = getsig(shotnr, diag, signal, tBegin=ti, tEnd=tf, edition=edition) #################### Syncs the timebase to the ELM timebase ########################### ###### Signal group ########################### syncsig = []#np.zeros_like(signal.data) synctime = []#np.zeros_like(signal.time) for elm in range(t_begELM.size): t1, t2 =t_begELM[elm]-preft, t_endELM[elm]+suft #Re-adjust ELM times so no overlap between consecutive ELMs occurs if (elm >=1 ) : tendprev = t_endELM[elm-1] t1 = np.max([t1,tendprev]) if (elm<t_begELM.size-1): tstartnext = t_begELM[elm+1] t2 = np.min([t2,tstartnext]) elmind = np.where((signal.time >= t1) & (signal.time <=t2)) synctime.append(signal.time[elmind]-t_begELM[elm]) #Distinguish between 1D (signal) and 2D array (Signal group) if len(signal.data.shape)==1: syncsig.append(signal.data[elmind]) elif len(signal.data.shape)==2: syncsig.append(signal.data[elmind,:]) else: raise Exception('Array format not supported!') #Finally, return is again dependent on array dimensions if len(signal.data.shape)==1: synctime_return = np.concatenate(synctime) syncsig_return = np.concatenate(syncsig) if len(signal.data.shape)==2: synctime_return = np.concatenate(synctime) syncsig_return = np.concatenate(syncsig, axis=1)[0,:,:] return synctime_return, syncsig_return
def create_dd_df(shotnr=30554, tBegin=1.0, tEnd=6.5, dt=0.1, dne_data=['DNE', 'neDdel_2', 17, 'sfp', 21], ouput_file=None): """Returns a pandas dataframe""" times = np.arange(tBegin, tEnd + dt, dt) beta = getsig(shotnr, 'TOT', 'beta_N') wmhd = getsig(shotnr, 'TOT', 'Wmhd') taue = getsig(shotnr, 'TOT', 'tau_tot') h98 = getsig(shotnr, 'TTH', 'H/L-facs') h98y2_index = 7 nev_shotfile = 'DNE' nev_signal = 'neDdel_2' nev_channel = 17 nev_experiment = 'sfp' medfilt_pts = 21 #Divertor Spectroscpy data nev_shotfile = dne_data[0] nev_signal = dne_data[1] nev_channel = int(dne_data[2]) nev_experiment = dne_data[3] medfilt_pts = int(dne_data[4]) dne = getsig(shotnr, nev_shotfile, nev_signal, exper=nev_experiment) #Interpolations try: interp_beta = interp1d(beta.time, beta.data) beta_df_entry = interp_beta(times) except: beta_df_entry = np.zeros_like(times) try: interp_wmhd = interp1d(wmhd.time, wmhd.data) wmhd_df_entry = interp_wmhd(times) except: wmhd_df_entry = np.zeros_like(times) try: interp_taue = interp1d(taue.time, taue.data) taue_df_entry = interp_taue(times) except: taue_df_entry = np.zeros_like(times) try: interp_h98 = interp1d(h98.time, h98.data[:, h98y2_index]) h98_df_entry = interp_h98(times) except: h98_df_entry = np.zeros_like(times) interp_nev = interp1d(dne.time, medfilt(dne.data[:, nev_channel], medfilt_pts)) nev_df_entry = interp_nev(times) dict_df = { 'time': times, 'nev': nev_df_entry, 'h98y2': h98_df_entry, 'taue': taue_df_entry, 'beta': beta_df_entry, 'wmhd': wmhd_df_entry } ddf = pd.DataFrame(data=dict_df) df = ddf[['time', 'nev', 'beta', 'taue', 'h98y2', 'wmhd']] #if output_file is not None: # writer = pd.ExcelWriter(output_file) # df.to_excel(writer,'Sheet1') return df