#place the following file in the directory indicated above datafilename = 'sample_2kV_oddpos1to13_2ms_stuffdelay_17shots_04232019.h5' datafilename = '2kV_0p5ms_1msGas_20shots_bdot_10142019.h5' #datafilename='2kV_0p5ms_10msGas_20shots_bdot_10142019.h5' datafilename = '2kV_oddpos9to21zr_2ms_stuffdelay_40_07022019.h5' #load hdf5 file data = load_hdf5(data_directory_location + datafilename, verbose=True) timeB_us = data['time']['timeB_us'][:] timeB_s = timeB_us / 1e6 #select time range for FFT (in us) start_time = 40 end_time = 90 time_range = [start_time, end_time] #compute indices from time range start_time_index = iff.tindex_min(start_time, timeB_us) end_time_index = iff.tindex_min(end_time, timeB_us) #select shots to analyze first_shot = 1 last_shot = 16 numshots = 40 shot_range = [first_shot, last_shot] delaytimes = np.zeros([ 3, 3, numshots ]) #storage for number of delay times from cross correlation function delayshifts = np.zeros([3, 3, numshots]) timerange_limit = 5e-6 #limits the range for finding the peak to +/- 2 microseconds dt = timeB_s[1] - timeB_s[0] port_sep = 0.0254 #m direction_list = ['r', 'theta', 'z']
# Sample rate and desired cutoff frequencies (in Hz). fs = 125e6 lowcut = 50e3 highcut = 2e6 directory = 'C:\\Users\\dschaffner\\Dropbox\\Data\\BMPL\\BMX\\2022\\01122022\\' datafilename = 'Dataset_01122022.h5' data = load_hdf5(directory + datafilename, verbose=True) time_s = data['time']['time_s'] timeB_s = time_s[1:] time_us = data['time']['time_us'] timeB_us = time_us[1:] analysis_start_time = 60 analysis_end_time = 160 start_time_index = iff.tindex_min(analysis_start_time, timeB_us) end_time_index = iff.tindex_min(analysis_end_time, timeB_us) timerange_limit = 3e-6 #s port_sep = 0.0254 #m numshots = 94 direction_list = ['r', 't', 'z'] probelist = ['probe5', 'probe7', 'probe19', 'probe21', 'probe33', 'probe35'] directions = len(direction_list) numprobes = len(probelist) #determine Wavelet size arr = data['mag_probe']['positions']['probe5']['r']['bdot'][0, :] Bpwr_r, Bscalespec, wvfreq, Bfft, fftfreq = cw.compute_wavelet( arr, np.array(time_us)) #Bpwrslice = Bpwr_r[:,start_time_index:end_time_index]
fs = 125e6 lowcut = 50e3 highcut = 2e6 directory='C:\\Users\\dschaffner\\Dropbox\\Data\\BMPL\\BMX\\2022\\01122022\\' datafilename='Dataset_01122022.h5' data=load_hdf5(directory+datafilename,verbose=True) time_s = data['time']['time_s'] timeB_s = time_s[1:] time_us = data['time']['time_us'] timeB_us = time_us[1:] analysis_start_time = 20 analysis_end_time = 40 start_time_index = iff.tindex_min(analysis_start_time,timeB_us) end_time_index = iff.tindex_min(analysis_end_time,timeB_us) timerange_limit = 3e-6#s port_sep = 0.0254#m numshots=94 direction_list=['r','t','z'] num_pairs = 3 directions = 3 tde_pairs=[['probe5','probe7'],['probe19','probe21'],['probe33','probe35']] delaytimes = np.zeros([num_pairs, directions, numshots]) delayindex = np.zeros([num_pairs, directions, numshots]) plotshots=1 plt.rc('axes',linewidth=0.75)
# Calling time from our data time_us = data['time']['time_us'][:] time_s = data['time']['time_s'][:] # Calling the discharge current and discharge voltages: dis_current = data['discharge']['dis_I'][:] dis_current = dis_current*1e-3 raw_dis_current = data['discharge']['dis_I_raw'][:] dis_voltage = data['discharge']['dis_V'][:]/1e3 raw_dis_voltage = data['discharge']['dis_V_raw'][:] start_time = 50 end_time = 150 time_range = [start_time, end_time] start_time_index = iff.tindex_min(start_time, time_us) end_time_index = iff.tindex_min(end_time, time_us) # Shot 4 was a dud, so its excluded from the data calculation. avg_dis_current = np.zeros(25004) for s in range (0, 21): if s == 3: continue avg_dis_current = avg_dis_current + np.array((dis_current[s,:])/20) avg_dis_voltage = np.zeros(25004) for s in range(0, 21): if s == 3: continue avg_dis_voltage = avg_dis_voltage + np.array((dis_voltage[s,:])/20)
def bispec(timearray, array1, array2, array3, maxfreq, auto=True): freq, freq2, comp1, pwr, mag, phase2, cos_phase, dt = sw.spectrum_wwind( array1, timearray) if auto == False: freq, freq2, comp2, pwr, mag, phase2, cos_phase, dt = sw.spectrum_wwind( array2, timearray) freq, freq2, comp3, pwr, mag, phase2, cos_phase, dt = sw.spectrum_wwind( array3, timearray) if auto == True: comp2 = comp1 comp3 = comp1 # create list of positive and negative frequencies maxfreq_index = iff.tindex_min(freq2, maxfreq) print('For ', maxfreq, ' Hz, index is ', maxfreq_index) # pos freqs start at element 0, take first x chunk posfreqs = freq2[0:maxfreq_index] # neg freqs count up from min at halfway point, thus take last x chunk negfreqs = freq2[-maxfreq_index:] # print(posfreqs.shape) # print(negfreqs.shape) frequencies = np.append(negfreqs, posfreqs) # print(frequencies.shape) # create bispectral storage arrays based on frequency array size bisp = np.zeros([frequencies.shape[0] // 2, 376], dtype=complex) norm1 = np.zeros([frequencies.shape[0] // 2, 376], dtype=complex) norm2 = np.zeros([frequencies.shape[0] // 2, 376], dtype=complex) # halfindex=(frequencies.shape[0]//2)+1 # determine scaling amount so that frequencies are intergers power = np.log10(freq2[1]) if power < 0.0: powerceil = np.ceil(np.abs(power)) decimalpower = 10.0**(powerceil) else: decimalpower = 1.0 print('decimalpower ', decimalpower) scaled_frequencies = frequencies * decimalpower rounded_frequencies = np.around(scaled_frequencies) rounded_posfrequencies = np.around(posfreqs * decimalpower) for s in np.arange(1, posfreqs.shape[0]): #print('On frequency',s,' ',rounded_frequencies[s]) for t in np.arange(1, 376): f1 = rounded_posfrequencies[s] f2 = rounded_frequencies[t] if f1 == f2: print(s, ' and ', t) print(f1, ' and ', f2) continue f3 = f1 + f2 # find sum of rounded frequncies # f3arg=np.nonzero(rounded_frequencies==f3)#find index of frequncies array that matches the summed freq, f3 # find index of frequncies array that matches the summed freq, f3 f3arg = np.where(rounded_frequencies[251:] == f3) # if len(f3arg[0])==0: #print('f3arg is zero for s=',s,' and t=',t) # only compute bispectrum if there is a frequency in the frequencies array that matches f3 if len(f3arg[0]) != 0: # print(f3arg[0][0]) # print('###################') # print(f1,'+',f2,'=',f3) # print(frequencies[s],'+',frequencies[t],'=',frequencies[f3arg[0][0]]) # print(f3arg[0]) # if f3>500: # if s==10 and t==10: # print(f3) # break bisp[s, t] = comp1[s] * comp2[t] * np.conj(comp3[f3arg[0][0]]) norm1[s, t] = comp1[s] * comp2[t] norm2[s, t] = comp3[f3arg[0][0]] # print(freq2) return frequencies, posfreqs, bisp, norm1, norm2
plt.loglog(wavenum, mean_power_interp_60t160_trace[4, :], color='red', label='Probe 33') plt.xlabel(r'$\left(\frac{k_{v}}{2\pi}\right)$ [m$^{-1}$]', fontsize=labelfontsize) plt.ylabel(r'$Arb. Power$', fontsize=labelfontsize) plt.legend(loc='lower left', fontsize=legendfontsize, frameon=False, handlelength=5) #range 1 import MLE as mle wavenum_range = [2.7e0, 7e0] wvtindex1 = iff.tindex_min(wavenum, wavenum_range[0]) wvtindex2 = iff.tindex_min(wavenum, wavenum_range[1]) #position 5 max_alpha, alpha, L_vals, cdf_dat, cdf_mod, KS, sigma = mle.mle_werr( mean_power_interp_60t160_trace[0, :], wavenum, wvtindex1, wvtindex2) func = (wavenum**(-max_alpha)) scale_dat = mean_power_interp_60t160_trace[0, wvtindex1] scale_fit = func[wvtindex1] ratio = scale_dat / scale_fit plt.loglog(wavenum[wvtindex1:wvtindex2], 2.0 * ratio * func[wvtindex1:wvtindex2], linestyle='dotted', color='blue', linewidth=0.5) #,label='Fixed Range Fit: -'+str(max_alpha) ) sigma = np.round(sigma, decimals=2) plt.text(7e0,
### Mac Style ### #data_director_location = '/user/dschaffner/data/' ####################################################################### # place the following file in the directory indicated above datafilename = 'sample_2kV_oddpos1to13_2ms_stuffdelay_17shots_04232019.h5' # load hdf5 file data = load_hdf5(data_directory_location + datafilename, verbose=True) timeB_us = data['time']['timeB_us'][:] timeB_s = timeB_us / 1e6 # select time range for FFT (in us) start_time = 50 end_time = 150 time_range = [start_time, end_time] # compute indices from time range start_time_index = iff.tindex_min(start_time, timeB_us) end_time_index = iff.tindex_min(end_time, timeB_us) # select shot to analyze shot = 10 bt5 = data['pos5']['b']['theta'][5, :] bz5 = data['pos5']['b']['z'][5, :] mag5 = np.sqrt(bt5**2 + bz5**2) #Plot Details############################### plt.rc('axes', linewidth=1.0) plt.rc('xtick.major', width=1.0) plt.rc('ytick.major', width=1.0) plt.rc('xtick.minor', width=1.0) plt.rc('ytick.minor', width=1.0) plt.rc('lines', markersize=2.0, markeredgewidth=0.0, linewidth=1.0)
#load hdf5 file data = load_hdf5(data_directory_location + datafilename, verbose=True) timeB_us = data['time']['timeB_us'][:] timeB_s = timeB_us / 1e6 time_s = data['time']['time_s'][:] #poslist = ['pos9','pos11','pos13','pos15','pos17','pos19','pos21'] poslist = ['pos1', 'pos3', 'pos5', 'pos7'] #select time range for FFT (in us) start_time = 50 end_time = 150 time_range = [start_time, end_time] #compute indices from time range start_time_index = iff.tindex_min(start_time, timeB_us) end_time_index = iff.tindex_min(end_time, timeB_us) #select shots to analyze first_shot = 6 last_shot = 13 numshots = (last_shot - first_shot) + 1 numshots = 8 shot_range = [first_shot, last_shot] Bmag = np.zeros([4, numshots, len(data['pos1']['b']['z'][0, :])]) for pos in np.arange(len(poslist)): xx = data[poslist[pos]]['b']['r'][:] yy = data[poslist[pos]]['b']['z'][:] zz = data[poslist[pos]]['b']['z'][:] Bmag[pos, :] = np.sqrt(xx**2 + yy**2 + zz**2)
print('Arrays loaded: ') for arr in file.files: print(arr) return file directory = 'C:\\Users\\dschaffner\\Dropbox\\Data\\BMPL\\BMX\\2022\\01122022\\' datafilename = 'Dataset_01122022.h5' data = load_hdf5(directory + datafilename, verbose=True) time_s = data['time']['time_s'] timeB_s = time_s[1:] time_us = data['time']['time_us'] timeB_us = time_us[1:] analysis_start_time = 60 analysis_end_time = 160 start_time_index = iff.tindex_min(analysis_start_time, timeB_us) end_time_index = iff.tindex_min(analysis_end_time, timeB_us) timerange_limit = 3e-6 #s port_sep = 0.0254 #m #load velocities sheetdirectory = 'C:\\Users\\dschaffner\\Dropbox\\Data\\BMPL\\BMX\\2022\\01122022\\' spreadsheetfile = 'Separation Times by Shot.xlsx' sheet = pd.read_excel(sheetdirectory + spreadsheetfile, header=1) vels57 = np.array(sheet['57v']) * 1000.0 #m/s vels1921 = np.array(sheet['1921v']) * 1000.0 #m/s vels3335 = np.array(sheet['3335v']) * 1000.0 #m/s velsflags = np.array(sheet['flag']) mean_vels57 = np.mean(vels57) mean_vels1921 = np.mean(vels1921) mean_vels3335 = np.mean(vels3335)