Table of Contents

    Noise Analysis TestΒΆ

    Imports

    from qetpy import Noise
    from qetpy.sim import TESnoise
    from qetpy.plotting import compare_noise, plot_noise_sim
    import numpy as np
    import matplotlib.pyplot as plt
    

    Load test data

    pathToTraces = ''
    traces_PT_on = np.load(pathToTraces+'traces.npy')
    

    Create noise object

    Noise?
    
    #savePath = 'example_Figs/' #used for test, user should define new path for test so they don't save over these figs
    savePath = '' #user needs to define new path
    
    fs = 625e3 #define sample rate
    channels = [ 'PCS1' , 'PES1' , 'PFS1' , 'PAS2' , 'PBS2' , 'PES2' , 'PDS2' ] #define the channel names
    g124_noise = Noise(traces=traces_PT_on,
                       fs=fs,
                       channames=channels,
                       name= 'G124 SLAC Run 37 Pulse Tube On') #initialize a noise object
    

    Calculate the PSD and corrCoeff

    g124_noise.calculate_psd()
    g124_noise.calculate_corrcoeff()
    g124_noise.calculate_csd()
    

    Calculate unCorrelated noise

    g124_noise.calculate_uncorr_noise()
    

    Test saving.

    Uncomment to save and re-load

    #saveName = pathToTraces + g124_noise.name.replace(" ", "_") + '.pkl'
    #g124_noise.save(pathToTraces)
    
    #del g124_noise
    
    # with open(pathToTraces,'rb') as savefile:
    #     g124_noise = pickle.load(savefile)
    

    Test plotting of PSD and corrCoeff

    g124_noise.plot_psd(lgcoverlay=True)
    
    ../_images/noise_example_18_0.png
    g124_noise.plot_psd(lgcoverlay=False)
    
    ../_images/noise_example_19_0.png
    g124_noise.plot_corrcoeff(lgcsave=False, lgcsmooth=True, nwindow=13 )
    
    ../_images/noise_example_20_0.png

    Plot a few CSDs

    g124_noise.plot_csd(whichcsd=['66','26'])
    
    ../_images/noise_example_22_0.png ../_images/noise_example_22_1.png

    Try to plot a CSD for a non existant channel

    g124_noise.plot_csd(whichcsd=['68'])
    
    index out of range
    

    Try to save a figure with a bad path

    g124_noise.plot_csd(whichcsd=['11'], lgcsave=True, savepath = 'yay/python/is/great')
    
    Invalid save path. Figure not saved
    
    ../_images/noise_example_26_1.png

    Plot Real vs Imaginary PSDs

    g124_noise.plot_reim_psd()
    
    ../_images/noise_example_28_0.png

    Plot unCorrelated part of the noise PSD

    g124_noise.calculate_uncorr_noise()
    
    g124_noise.plot_decorrelatednoise(lgccorrelated=True,lgcsum = True, lgcsave=False)
    
    ../_images/noise_example_31_0.png
    g124_noise.plot_decorrelatednoise(lgcoverlay = True)
    
    ../_images/noise_example_32_0.png

    Create noise simulation object

    noise_sim = TESnoise(freqs = g124_noise.freqs[1:])
    

    Note, these default noise parameters are completely made up, just for demostration

    plot_noise_sim(g124_noise.freqs, g124_noise.psd[0,:], noise_sim, istype='power', qetbias=0)
    
    ../_images/noise_example_36_1.png