コード例 #1
0
def create_example_pulseplusmuontail(lgcbaseline=False):
    """
    Function written for creating an example pulse with random time offset
    on top of a muon tail

    Parameters
    ----------
    lgcbaseline : bool, optional
        Flag for whether or not the trace should be shifted vertically from
        zero.

    Returns
    -------
    signal : ndarray
        An array of values containing the specified signal in time domain,
        including some noise.
    template : ndarray
        The template for a pulse (normalized to a maximum height of 1).
    psd_sim : ndarray
        The two-sided power spectral density used to generate the noise for
        `signal`.

    """

    # specify the random seed for consistent testing
    np.random.seed(1)

    fs = 625e3
    baseline_shift = 0.2e-6

    f = np.fft.fftfreq(32500, d=1 / fs)
    noisesim = qp.sim.TESnoise(r0=0.03)

    psd_sim = noisesim.s_iload(freqs=f) + noisesim.s_ites(
        freqs=f) + noisesim.s_itfn(freqs=f)

    t = np.arange(len(psd_sim)) / fs

    pulse = np.exp(-t / TAU_FALL) - np.exp(-t / TAU_RISE)

    # randomize the delay
    delayRand = np.random.uniform(size=1)
    pulse_shifted = np.roll(pulse, int(len(t) * delayRand))
    template = pulse_shifted / pulse_shifted.max()

    muon_fall = 200e-3
    muon_amp = -0.5e-6

    muon_pulse = np.exp(-t / muon_fall)
    muon_template = muon_pulse / muon_pulse.max()

    noise = qp.gen_noise(psd_sim, fs=fs, ntraces=1)[0]
    signal = noise + template * PULSE_AMP + muon_template * muon_amp

    if lgcbaseline:
        signal += baseline_shift

    return signal, template, psd_sim
コード例 #2
0
def create_example_data(lgcpileup=False, lgcbaseline=False):
    """
    Function written for creating example data when testing different
    optimum filters.
    
    Parameters
    ----------
    lgcpileup : bool, optional
        Flag for whether or not a second pulse should be added to the trace.
    lgcbaseline : bool, optional
        Flag for whether or not the trace should be shifted from zero.
        
    Returns
    -------
    signal : ndarray
        An array of values containing the specified signal in time domain, including
        some noise.
    template : ndarray
        The template for a pulse (normalized to a maximum height of 1).
    psd_sim : ndarray
        The two-sided power spectral density used to generate the noise for `signal`.
    
    """

    np.random.seed(1)  # need to specify the random seed for testing

    fs = 625e3
    pulse_amp = 4e-6
    baseline_shift = 0.02e-6
    tau_rise = 20e-6
    tau_fall = 66e-6

    f = np.fft.fftfreq(32500, d=1 / fs)
    noisesim = qp.sim.TESnoise(r0=0.03)

    psd_sim = noisesim.s_iload(freqs=f) + noisesim.s_ites(
        freqs=f) + noisesim.s_itfn(freqs=f)

    t = np.arange(len(psd_sim)) / fs

    pulse = np.exp(-t / tau_fall) - np.exp(-t / tau_rise)
    pulse_shifted = np.roll(pulse, len(t) // 2)
    template = pulse_shifted / pulse_shifted.max()

    noise = qp.gen_noise(psd_sim, fs=fs, ntraces=1)[0]
    signal = noise + np.roll(template, 100) * (pulse_amp)

    if lgcpileup:
        signal += pulse_amp * np.roll(template, 1000)

    if lgcbaseline:
        signal += baseline_shift

    return signal, template, psd_sim
コード例 #3
0
def create_example_muontail():
    """
    Function written for creating an example muon tail for 
    testing `qetpy.MuonTailFit`.
    
    Parameters
    ----------
    None
        
    Returns
    -------
    signal : ndarray
        An array of values containing the specified signal in time domain, including
        some noise.
    psd_sim : ndarray
        The two-sided power spectral density used to generate the noise for `signal`.
    
    """

    np.random.seed(1)  # need to specify the random seed for testing

    fs = 625e3
    tau_fall = 20e-3
    pulse_amp = 0.5e-6

    f = np.fft.fftfreq(32500, d=1 / fs)
    noisesim = qp.sim.TESnoise(r0=0.03)

    psd_sim = noisesim.s_iload(freqs=f) + noisesim.s_ites(
        freqs=f) + noisesim.s_itfn(freqs=f)

    t = np.arange(len(psd_sim)) / fs

    pulse = np.exp(-t / tau_fall)
    template = pulse / pulse.max()

    noise = qp.gen_noise(psd_sim, fs=fs, ntraces=1)[0]
    signal = noise + template * pulse_amp

    return signal, psd_sim
コード例 #4
0
def _initialize_didv(poles, priors, sgfreq=100, autoresample=False):
    """Function for initializing dIdV data"""
    np.random.seed(0)

    rsh = 5e-3
    rbias_sg = 20000
    fs = 625e3
    sgamp = 0.009381 / rbias_sg

    rfb = 5000
    loopgain = 2.4
    drivergain = 4
    adcpervolt = 65536 / 2
    tracegain = rfb * loopgain * drivergain * adcpervolt

    true_params = {
        'rsh': rsh,
        'rp': 0.006,
        'r0': 0.0756 if poles in [2, 3] else 0,
        'beta': 2 if poles in [2, 3] else 0,
        'l': 10 if poles in [2, 3] else 0,
        'L': 1e-7,
        'tau0': 500e-6 if poles in [2, 3] else 0,
        'gratio': 0.5 if poles in [3] else 0,
        'tau3': 1e-3 if poles in [3] else 0,
    }

    psd_test = np.ones(int(4 * fs / sgfreq)) / tracegain**2 / 1e4
    rawnoise = qp.gen_noise(psd_test, fs=fs, ntraces=300)

    t = np.arange(rawnoise.shape[-1]) / fs
    didv_response = qp.squarewaveresponse(
        t,
        sgamp,
        sgfreq,
        **true_params,
    )
    rawtraces = didv_response + rawnoise

    if priors:
        if poles == 1:
            dim = 4
        elif poles == 2:
            dim = 8
        elif poles == 3:
            dim = 10
        priors = np.zeros(dim)
        priorscov = np.zeros((dim, dim))

        priors[0] = true_params['rsh']
        priorscov[0, 0] = (0.1 * priors[0])**2
        priors[1] = true_params['rp']
        priorscov[1, 1] = (0.1 * priors[1])**2

        if poles != 1:
            priors[2] = true_params['r0']
            priorscov[2, 2] = (0.1 * priors[2])**2

        didvfit = qp.DIDVPriors(
            rawtraces,
            fs,
            sgfreq,
            sgamp,
            rsh,
            tracegain=1.0,
            dt0=-1e-6,
            autoresample=autoresample,
        )
        if poles == 1:
            didvfit.processtraces()
            didvfit.plot_full_trace()
        assert didvfit.fitresult(poles) == dict()
        didvfit.dofit(poles, priors, priorscov)
    else:
        didvfit = qp.DIDV(
            rawtraces,
            fs,
            sgfreq,
            sgamp,
            rsh,
            tracegain=1.0,
            r0=true_params['r0'],
            rp=true_params['rp'],
            dt0=-1e-6 - 1 / (2 * sgfreq),
            add180phase=True,
            autoresample=autoresample,
        )
        assert didvfit.fitresult(poles) == dict()
        didvfit.dofit(poles)

    _run_plotting_suite(didvfit, poles)

    return didvfit, true_params
コード例 #5
0
def create_example_ttl_leakage_pulses(
    fs=625e3,
    ttlrate=2e3,
    lgcbaseline=False,
):
    """
    Function written for creating example TTL pulses with certain frequency
    with a charge leakage pulse.

    Parameters
    ----------
    fs : float
        The sample rate of the data being taken (in Hz).
    ttlrate : float
        The rate of the ttl pulses
    lgcbaseline : bool, optional
        Flag for whether or not the trace should be shifted vertically from
        zero.

    Returns
    -------
    signal : ndarray
        An array of values containing the specified signal in time domain,
        including some noise.
    template : ndarray
        The template for a pulse (normalized to a maximum height of 1).
    psd_sim : ndarray
        The two-sided power spectral density used to generate the noise for
        `signal`.

    """

    # specify the random seed for consistent testing
    np.random.seed(1)

    bkgampscale = -4e-8
    baseline_shift = 0.2e-6
    nbin = 6250

    f = np.fft.fftfreq(nbin, d=1 / fs)
    noisesim = qp.sim.TESnoise(r0=0.03)

    psd_sim = noisesim.s_iload(freqs=f) + \
        noisesim.s_ites(freqs=f) + \
        noisesim.s_itfn(freqs=f)

    t = np.arange(len(psd_sim)) / fs

    template = np.exp(-t / TAU_FALL) - np.exp(-t / TAU_RISE)
    # move template to the middle of the trace
    template = np.roll(template, nbin // 2)
    template = template / template.max()

    # randomize the delay for the charge leakage
    delayrand = np.random.uniform(size=1)
    leakagetemplate = np.roll(template, int(len(t) * delayrand))
    leakagetemplate = leakagetemplate / leakagetemplate.max()
    leakagepulse = leakagetemplate * PULSE_AMP

    # space the TTL pulses evenly at 2 kHz = 500 us = 312.5 bins

    (
        backgroundtemplates,
        backgroundtemplateshifts,
        backgroundpolarityconstraint,
        indwindow_nsmb,
    ) = qp.maketemplate_ttlfit_nsmb(
        template,
        fs,
        ttlrate,
        lgcconstrainpolarity=True,
        lgcpositivepolarity=False,
    )

    nbkgtemp = np.shape(backgroundtemplates)[1]

    # generate random numbers for the background templates
    bkgamps = np.random.uniform(size=nbkgtemp)
    # set the slope component to 0
    bkgamps[-2] = 0
    backgroundpulses = backgroundtemplates @ bkgamps
    backgroundpulses = backgroundpulses * bkgampscale

    noise = qp.gen_noise(psd_sim, fs=fs, ntraces=1)[0]
    signal = noise + backgroundpulses + leakagepulse

    if lgcbaseline:
        signal += baseline_shift

    return signal, template, psd_sim