def find_TOF(day, shot, start_time, end_time):
    ### LOAD SHOT ####
    print 'Loading Shot ', shot
    time, bdot, timeb, b, bmod, fulldata = mj.process_mjmag_data(day +
                                                                 str(shot))
    tindex1 = ssxuf.tindex_min(time, start_time)
    tindex2 = ssxuf.tindex_min(time, end_time)
    time = time[tindex1:tindex2]
    b = b[:, :, tindex1:tindex2]
    bx25 = b[0, 24, :]
    bx24 = b[0, 23, :]

    ### GENERTATE FILTERS ###
    #N  = 2    # Filter order
    #Wn = 0.009 # Cutoff frequency
    #B, A = sig.butter(N, Wn,btype='highpass', output='ba')
    low_cutoff = 1.0  #in MHZ
    high_cutoff = 6.0  #in MHZ
    b_high, a_high = sig.butter(4, high_cutoff / 50.0,
                                'high')  #, analog=True)  #HIGH PASS Filter
    b_low, a_low = sig.butter(4, low_cutoff / 50.0,
                              'low')  #, analog=True)      #LOW PASS Filter
    b_band, a_band = sig.butter(6, [low_cutoff / 50.0, high_cutoff / 50.0],
                                'band')  #, analog=True) #BAND PASS Filter

    ### APPLY FILTERS ###

    #BX#
    bx25_hp = sig.filtfilt(b_high, a_high, bx25)
    bx25_lp = sig.filtfilt(b_low, a_low, bx25)
    bx24_hp = sig.filtfilt(b_high, a_high, bx24)
    bx24_lp = sig.filtfilt(b_low, a_low, bx24)

    ### COMPUTE correlation function ###

    #BX#
    tau0, corr_bx_unfilt = gc.get_corr(
        time, bx25, bx24, normalized=True)  #unfiltered correlation
    tau2, corr_bx_lp = gc.get_corr(time, bx25_lp, bx24_lp,
                                   normalized=True)  #low passed correlation
    #Note on interpreting lead and lag--> If array1 leads array2 (that is, features in array1 appear before that of array2),
    #then, this will result in a NEGATIVE tau in the cross-correlation function

    ### Find Peak ###
    peakindex = np.argmax(corr_bx_lp)
    peaktau = np.abs(tau2[peakindex])
    velocity = sep_dist / (peaktau * 1e-6)  #in km/s
    print 'Peak Velocity is ', velocity, ' km/s'
    return velocity  #in km/s
Beispiel #2
0
    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']
#loop over shots to read in data and compute cross correlation function
for shot in np.arange(numshots):
    for direction in np.arange(3):
        d1 = data['pos3']['b'][direction_list[direction]][
            shot, start_time_index:end_time_index]
        d2 = data['pos1']['b'][direction_list[direction]][
            shot, start_time_index:end_time_index]
        t = timeB_s[start_time_index:end_time_index]
        tau, corr = gc.get_corr(t, d1, d2, normalized=False)
        index_at_zero_time = iff.tindex_min(0, tau)
        indexsize_of_timerange_limit = int(np.round(timerange_limit / dt))

        #find time (in seconds) of max in correlation function within timerange limit
        delayshifts[0, direction, shot] = np.argmax(
            np.abs(corr[index_at_zero_time -
                        indexsize_of_timerange_limit:index_at_zero_time +
                        indexsize_of_timerange_limit]))
        delay = tau[
            index_at_zero_time - indexsize_of_timerange_limit + np.argmax(
                np.abs(corr[index_at_zero_time -
                            indexsize_of_timerange_limit:index_at_zero_time +
                            indexsize_of_timerange_limit]))]
        #delay=tau[index_at_zero_time+np.argmax(np.abs(corr))]
Beispiel #3
0
    Bz9_dtr = sps.detrend(Bz9)
    B7tot = np.sqrt(Br7_dtr**2+Bt7_dtr**2+Bz7_dtr**2)
    B9tot = np.sqrt(Br9_dtr**2+Bt9_dtr**2+Bz9_dtr**2)
    
    nper=22250#16384
    timeB_ms=timeB_s*1e6
    tindex1 = ssxf.tindex_min(timeB_ms,20.0)#20.0
    tindex2 = ssxf.tindex_min(timeB_ms,198.0)#198.0
    tindex2 = tindex1+nper
    n=timeB_s[tindex1:tindex2].shape[0]
    

    
    rando=1000*np.random.rand(n)
    
    tau,corr = gc.get_corr(timeB_s[tindex1:tindex2],Br7_dtr[tindex1:tindex2],Br9_dtr[tindex1:tindex2],normalized=False)
    #tau,corr = gc.get_corr(np.arange(22250),Br7_dtr[tindex1:tindex2],Br7_dtr[tindex1:tindex2],normalized=False)
    f,f0,compr7,pwrbr7,mag1,phase1,cos_phase1,interval=spec.spectrum_wwind(Br7_dtr[tindex1:tindex2],timeB_s[tindex1:tindex2],window='None')
    f,f0,compr9,pwrbr9,mag1,phase1,cos_phase1,interval=spec.spectrum_wwind(Br9_dtr[tindex1:tindex2],timeB_s[tindex1:tindex2],window='None')
    #f,f0,compran,pwrran,mag1,phase1,cos_phase1,interval=spec.spectrum_wwind(rando,timeB_s[tindex1:tindex2],window='None')
    interval = timeB_s[1]-timeB_s[0]
    
    factor = 2.0/(n*interval)    
    cross_spec = np.conj(compr7)*compr9*factor

    crossf, cross_csd = sps.csd(Br7_dtr[tindex1:tindex2],Br9_dtr[tindex1:tindex2],fs=(1.0/interval),nperseg=nper)
    #crossf2, cross_csd2 = sps.csd(Br7_dtr[tindex1:tindex2],Br9_dtr[tindex1:tindex2],fs=(1.0/interval),nperseg=11125)
    
    crossf_auto, autobr7_csd = sps.csd(Br7_dtr[tindex1:tindex2],Br7_dtr[tindex1:tindex2],fs=(1.0/interval),nperseg=nper)#scaling='density')
    crossf_auto, autobr9_csd = sps.csd(Br9_dtr[tindex1:tindex2],Br9_dtr[tindex1:tindex2],fs=(1.0/interval),nperseg=nper)#scaling='spectrum')
    autobr7 = np.conj(compr7)*compr7*factor
Beispiel #4
0
galaxyname = r'M5'
dyntime = 1396

datafile = loadnpyfile(datadir + fileheader + npy)
num_orbits = int(datafile.shape[0])
timelength = int(datafile.shape[1])
print('Num orbits=', num_orbits)
print('Time length=', timelength)

peak_seps = []
numpeaks = np.zeros([num_orbits])
for orbit in np.arange(num_orbits):
    print('On Orbit ', orbit)
    tau, corr = gc.get_corr(np.arange(timelength),
                            datafile[orbit, :],
                            datafile[orbit, :],
                            normalized=False)
    #plt.plot(tau,corr)
    #plt.figure(2)
    #plt.plot(datafile[1,:])
    #tau_deriv=np.gradient(corr)
    #plt.figure(3)
    #plt.plot(tau,tau_deriv)
    peaks = find_peaks(np.abs(corr))
    numpeaks[orbit] = len(peaks[0])
    if len(peaks[0]) == 3:
        peak_seps.append(2 * (peaks[0][2] - peaks[0][1]))
    if len(peaks[0]) == 5:
        peak_seps.append(peaks[0][4] - peaks[0][2])
    if len(peaks[0]) == 7:
        peak_seps.append(peaks[0][5] - peaks[0][3])
Beispiel #5
0
bx24_lp = sig.filtfilt(b_low, a_low, bx24)

bx23_hp = sig.filtfilt(b_high, a_high, bx23)
bx23_lp = sig.filtfilt(b_low, a_low, bx23)

bx22_hp = sig.filtfilt(b_high, a_high, bx22)
bx22_lp = sig.filtfilt(b_low, a_low, bx22)

bx21_hp = sig.filtfilt(b_high, a_high, bx21)
bx21_lp = sig.filtfilt(b_low, a_low, bx21)

### COMPUTE correlation function ###
#bdotx25_roll = np.roll(bdotx25_lp,-100)

#BX#
tau0, corr_bx_unfilt = gc.get_corr(time, bx25, bx24,
                                   normalized=True)  #unfiltered correlation
tau2, corr_bx_lp = gc.get_corr(time, bx25_lp, bx24_lp,
                               normalized=True)  #low passed correlation
#Note on interpreting lead and lag--> If array1 leads array2 (that is, features in array1 appear before that of array2),
#then, this will result in a NEGATIVE tau in the cross-correlation function

### PLOT SHOT DATA ###

plt.figure(1)
plt.clf()
#plt.plot(time,bx25)
plt.plot(time, bx25_lp, label='Pos 25')
#plt.plot(time,-bx24)
plt.plot(time, bx24_lp, label='Pos 24')
#plt.plot(time,bx23_lp,label='Pos 23')
#plt.plot(time,bx22_lp,label='Pos 22')
Beispiel #6
0
1. Interest points
"""
pt_coord_0 = get_interest_points(img_0,
                                 block_size=10,
                                 kernel_size=5,
                                 suppression_window_size=15,
                                 threshold=0.005)
pt_coord_1 = get_interest_points(img_1,
                                 block_size=10,
                                 kernel_size=5,
                                 suppression_window_size=15,
                                 threshold=0.005)
"""
2. Putative correspondences
"""
p0, p1 = get_corr(img_0, img_1, pt_coord_0, pt_coord_1)  #[x,y]
"""
3. RANSAC
"""
F, pl, pr = ransac(p0, p1, N=4000, t=2)
"""
Visualize epipolar lines
"""
lab3.show_corresp(img_0, img_1, p0, p1)
lab3.show_corresp(img_0, img_1, pl, pr)

plt.figure('epipolar lines 0 - RANSAC')
plt.imshow(img_0)
lab3.plot_eplines(F, pr, img_0.shape)
plt.plot(pl[0], pl[1], 'o')
plt.figure('epipolar lines 1 - RANSAC')