예제 #1
0
def compare_interpolated_spectrum():
    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_subplot(111)

    out = fft(ifftshift(f_full))
    freqs = fftfreq(len(f_full), d=0.01) # spacing, Ang
    sfreqs = fftshift(freqs)
    taper = gauss_taper(freqs, sigma=0.0496) #Ang, corresponds to 2.89 km/s at 5150A.
    tout = out * taper

    ax.plot(sfreqs, fftshift(tout))

    wl_h, fl_h = np.abs(np.load("PH6.8kms_0.01ang.npy"))
    wl_l, fl_l = np.abs(np.load("PH2.5kms.npy"))

    #end edges
    wl_he = wl_h[200:-200]
    fl_he = fl_h[200:-200]
    interp = Sinc_w(wl_l, fl_l, a=5, window='kaiser')
    fl_hi = interp(wl_he)

    d = wl_he[1] - wl_he[0]
    out = fft(ifftshift(fl_hi))
    freqs = fftfreq(len(out), d=d)
    ax.plot(fftshift(freqs), fftshift(out))

    plt.show()
예제 #2
0
def plot_pixel_effect():
    fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(8, 8))
    #fig = plt.figure()
    #ax = fig.add_subplot(111)
    out = fft(ifftshift(f_full))
    freqs = fftfreq(len(f_full), d=0.01) # spacing, Ang
    sfreqs = fftshift(freqs)
    taper = gauss_taper(freqs, sigma=0.0496) #Ang, corresponds to 2.89 km/s at 5150A.
    tout = out * taper

    for ax in axs[:, 0]:
        ax.plot(sfreqs, fftshift(tout) / tout[0])
        ax.plot(sfreqs, fftshift(taper))
        ax.plot(sfreqs, 0.0395 * np.sinc(0.0395 * sfreqs))
        ax.plot(sfreqs, 0.0472 * np.sinc(0.0472 * sfreqs))

    for ax in axs[:, 1]:
        ax.plot(sfreqs, 10 * np.log10(np.abs(fftshift(tout) / tout[0])))
        ax.plot(sfreqs, 10 * np.log10(np.abs(fftshift(taper))))
        ax.plot(sfreqs, 10 * np.log10(np.abs(0.0395 * np.sinc(0.0395 * sfreqs))))
        ax.plot(sfreqs, 10 * np.log10(np.abs(0.0472 * np.sinc(0.0472 * sfreqs))))

    axs[0, 0].set_ylabel("Norm amp")
    axs[1, 0].set_ylabel("Norm amp")
    axs[0, 1].set_ylabel("dB")
    axs[1, 1].set_ylabel("dB")
    for ax in axs.flatten():
        ax.set_xlabel(r"cycles/$\lambda$")
    plt.show()
예제 #3
0
def plot_FFTs():
    fig, ax = plt.subplots(nrows=4, figsize=(15, 8))

    #n = 100000
    ##Take FFT of f_grid
    #w_full = w_full[:-1]
    #f_full = f_full[:-1]
    out = np.fft.fft(np.fft.fftshift(f_full))
    freqs = fftfreq(len(f_full), d=0.01) # spacing, Ang
    sfreqs = fftshift(freqs)
    taper = gauss_taper(freqs, sigma=0.0496) #Ang, corresponds to 2.89 km/s at 5150A.
    tout = out * taper

    ax[0].plot(sfreqs, np.fft.fftshift(out))
    ax[1].plot(tout)
    #ax[1].plot(sfreqs,np.fft.fftshift(taper)*tout[0])
    ax[1].set_xlabel(r"cycles/$\lambda$")

    n_wl = len(w_full)
    print(n_wl)
    #trucate at 3 Sigma = 3.21 cycles/Ang
    #ind = np.abs(freqs) < 3.21
    #Pad tout and window
    f_restored = ifftshift(ifft(tout))
    #ax[2].plot(w_full,f_full)
    ax[2].plot(w_full, f_restored, "bo")

    #where to pad zeros? In the middle near high frequencies, so it goes +, zeros, -
    zeros = np.zeros((n_wl,))
    nyq = np.ceil(n_wl / 2) #find where the nyquist frequency is stored in the array
    t_pack = np.concatenate((tout[:nyq], zeros, tout[nyq:]))
    wl0 = w_full[nyq]

    scale_factor = len(t_pack) / n_wl
    f_restored2 = scale_factor * ifftshift(ifft(t_pack))
    wls = ifftshift(fftfreq(len(t_pack), d=0.01)) + wl0
    #ax[2].plot(wls,f_restored2)

    #print(np.sum(f_restored),np.sum(f_restored2))
    #print(trapz(f_restored,w_full),trapz(f_restored2,wls))

    #sample at an offset in phase
    half_shift = tout * np.exp(-2j * np.pi * freqs * 0.0248)
    f_restored_shift = ifftshift(ifft(half_shift))
    ax[2].plot(w_full - 0.0248, f_restored_shift, "go")

    plt.show()
예제 #4
0
def plot_truncation():
    n_wl = len(w_full)
    if n_wl % 2 == 0:
        print("Full Even")
    else:
        print("Full Odd")

    out = fft(ifftshift(f_full))
    w0 = ifftshift(w_full)[0]
    freqs = fftfreq(len(f_full), d=0.01) # spacing, Ang
    #sfreqs = fftshift(freqs)
    taper = gauss_taper(freqs, sigma=0.0496) #Ang, corresponds to 2.89 km/s at 5150A.
    tout = out * taper
    #ignore all samples higher than 5.0 km/s = 0.5/0.0429 cycles/Ang
    sc = 0.5 / 0.0429
    ind = np.abs(freqs) <= sc
    ttrim = tout[ind]
    if len(ttrim) % 2 == 0:
        print("Trim Even")
    else:
        print("Trim Odd")

    f_restored = fftshift(ifft(tout))
    np.save("PH6.8kms_0.01ang.npy", np.array([w_full, np.abs(f_restored)]))
    scale_factor = len(ttrim) / n_wl
    f_restored2 = scale_factor * fftshift(ifft(ttrim))
    d = freqs[1]
    print(d)
    # must keep track of which index!! AND which ifftshift vs fftshift
    raw_wl = fftshift(fftfreq(len(ttrim), d=d))
    wl_restored = raw_wl + w0
    np.save("PH2.5kms.npy", np.array([wl_restored, np.abs(f_restored2)]))

    plt.plot(w_full, f_restored)
    plt.plot(wl_restored, f_restored2, "go")
    plt.show()
    return wl_restored