Ejemplo n.º 1
0
def tesc(
    Chipnum,
    KIDnum,
    SCvol=None,
    usePread="max",
    minTemp=200,
    maxTemp=400,
    taunonkaplan=2e2,
    taures=1e1,
    relerrthrs=0.2,
    pltfit=False,
    pltkaplan=False,
    reterr=False,
    defaulttesc=0,
):
    """Calculates the phonon escape time from the GR noise lifetimes and Kaplan.
    Uses data at Pread (default max), and temperatures between minTemp,maxTemp
    (default (200,400)). Only lifetimes between taunonkaplan and taures, and with
    a relative error threshold of relerrthrs are considered.
    The remaining lifetimes, tesc is calculated and averaged. The error (optional return) 
    is the variance of the remaining lifetimes. If this fails, defaulttesc is returned."""

    TDparam = io.get_grTDparam(Chipnum)
    Pread = _selectPread(usePread, io.get_grPread(TDparam, KIDnum))[0]
    if SCvol is None:
        S21data = io.get_S21data(Chipnum, KIDnum)
        SCvol = SuperCond.Volume(SuperCond.Al(Tc=S21data[0, 21]),
                                 V=S21data[0, 14],
                                 d=S21data[0, 25])

    Temp = io.get_grTemp(TDparam, KIDnum, Pread)
    Temp = Temp[np.logical_and(Temp < maxTemp, Temp > minTemp)]
    tescar, tescarerr, tqpstar, tqpstarerr = np.zeros((4, len(Temp)))
    for i in range(len(Temp)):
        if pltfit:
            print("{} KID{} -{} dBm T={} mK".format(Chipnum, KIDnum, Pread,
                                                    Temp[i]))
        freq, SPR = io.get_grdata(TDparam, KIDnum, Pread, Temp[i])
        tqpstar[i], tqpstarerr[i] = tau(freq, SPR, plot=pltfit)

        if tqpstarerr[i] / tqpstar[i] > relerrthrs or (
                tqpstar[i] > taunonkaplan or tqpstar[i] < taures):
            tescar[i] = np.nan
        else:
            tescar[i] = kidcalc.tesc(
                const.Boltzmann / const.e * 1e6 * Temp[i] * 1e-3, tqpstar[i],
                SCvol.SC)
            tescarerr[i] = np.abs(
                kidcalc.tesc(const.Boltzmann / const.e * 1e6 * Temp[i] *
                             1e-3, tqpstarerr[i], SCvol.SC) + SCvol.SC.tpb)

    if tescar[~np.isnan(tescar)].size > 0:
        tesc1 = np.mean(tescar[~np.isnan(tescar)])
        tescerr = np.sqrt(
            np.std(tescar[~np.isnan(tescar)])**2 +
            ((tescarerr[~np.isnan(tescar)] /
              (~np.isnan(tescar)).sum())**2).sum())
    else:
        tesc1 = np.nan

    if tesc1 < 0 or np.isnan(tesc1) or tesc1 > 1e-2:
        warnings.warn(
            "tesc ({}) is not valid and set to {} µs. {}, KID{}".format(
                tesc1, defaulttesc, Chipnum, KIDnum))
        tesc1 = defaulttesc
        tescerr = 0
    SCvol.tesc = tesc1
    if pltkaplan:
        plt.figure()
        plt.errorbar(Temp, tqpstar, yerr=tqpstarerr, capsize=5.0, fmt="o")
        mask = ~np.isnan(tescar)
        plt.errorbar(Temp[mask], tqpstar[mask], fmt="o")
        try:
            T = np.linspace(Temp[~np.isnan(tqpstar)].min(),
                            Temp[~np.isnan(tqpstar)].max(), 100)
        except ValueError:
            T = np.linspace(minTemp, maxTemp, 100)
        taukaplan = kidcalc.tau_kaplan(T * 1e-3, SCvol)
        plt.plot(T, taukaplan)
        plt.yscale("log")
        plt.ylim(None, 1e4)
        plt.xlabel("T (mK)")
        plt.ylabel(r"$\tau_{qp}^*$ (µs)")
        plt.legend(["Kaplan", "GR Noise Data", "Selected Data"])
        plt.show()
        plt.close()
    if reterr:
        return tesc1, tescerr
    else:
        return tesc1
Ejemplo n.º 2
0
def NLcomp(Chipnum, KIDnum, Pread, SCvol=None, method="", var="cross"):
    """Returns a spline representation of a Noise Level (non-dB) vs Temperature (K), 
    with which the measured noise level can be compensated. For example,
    the method \'Resp\' gives the responsivity squared. If the measured 
    noise level is divided by the responsivity squared, one is left with 
    the quasiparticle fluctuation level.
    Arguments:
    Chipnum, KIDnum, Pread -- define which data is to be used (S21data and/or pulse data)
    SCvol -- a Volume object (see SC module), which defines superconductor properties
    method -- defines which level is to be returned. See if statements in the function for the options.
            (future: multiply every individual method stated in the method string)
    var -- gives the type of PSD to be compensated - cross, amp or phase - and is used 
            if \'Reps\' is in the method """

    if SCvol is None and method != "":
        S21data = io.get_S21data(Chipnum, KIDnum, Pread)
        SCvol = SuperCond.Volume(SuperCond.Al(Tc=S21data[0, 21]),
                                 V=S21data[0, 14],
                                 d=S21data[0, 25])

    if method != "":
        S21data = io.get_S21data(Chipnum, KIDnum, Pread)
        if "ak" in method:
            akin = ak(S21data)

        if method == "QakV":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1], (S21data[:, 2] * akin)**2 / SCvol.V**2, s=0)

        elif method == "QaksqrtV":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1], (S21data[:, 2] * akin)**2 / (SCvol.V), s=0)

        elif method == "QaksqrtVtesc":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                (S21data[:, 2] * akin)**2 / (SCvol.V *
                                             (1 + SCvol.tesc / SCvol.SC.tpb)),
                s=0,
            )

        elif method == "QaksqrtVtescTc":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                (S21data[:, 2] * akin)**2 /
                (SCvol.V * (1 + SCvol.tesc / SCvol.SC.tpb) *
                 (const.Boltzmann / const.e * 1e6 * S21data[0, 21])**3 /
                 (SCvol.SC.D0 / const.e * 1e6)**2),
                s=0,
            )

        elif method == "Resp":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                interpolate.splev(S21data[:, 1],
                                  Respspl(Chipnum, KIDnum, Pread, var=var))**2,
            )

        elif method == "RespPulse":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                interpolate.splev(
                    S21data[:, 1],
                    Respspl(Chipnum, KIDnum, Pread, ampmethod="pulse",
                            var=var),
                )**2,
            )

        elif method == "RespPint":
            Pint = 10**(-Pread / 10) * S21data[:,
                                               2]**2 / (S21data[:, 3] * np.pi)
            Pint /= Pint[0]
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                interpolate.splev(S21data[:, 1],
                                  Respspl(Chipnum, KIDnum, Pread, var=var)) /
                Pint**(1 / 2),
                s=0,
            )

        elif method == "RespV":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                interpolate.splev(S21data[:, 1],
                                  Respspl(Chipnum, KIDnum, Pread, var=var)) *
                SCvol.V,
                s=0,
            )

        elif method == "RespVtescTc":
            kbTc = const.Boltzmann / const.e * 1e6 * S21data[0, 21]
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                interpolate.splev(S21data[:, 1],
                                  Respspl(Chipnum, KIDnum, Pread, var=var)) *
                SCvol.V * (1 + SCvol.tesc / SCvol.tpb) * (kbTc)**3 /
                (kidcalc.D(const.Boltzmann / const.e * 1e6 * S21data[:, 1],
                           SCvol.SC))**2,
                s=0,
            )

        elif method == "RespLowT":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                np.ones(len(S21data[:, 1])) * interpolate.splev(
                    S21data[0, 1], Respspl(Chipnum, KIDnum, Pread, var=var)),
            )

        elif method == "Resptres":
            lvlcompspl = interpolate.splrep(
                S21data[:, 1],
                interpolate.splev(S21data[:, 1],
                                  Respspl(Chipnum, KIDnum, Pread, var=var))**2
                * (1 + (S21data[:, 1] * 2 * S21data[:, 2] / S21data[:, 5])**2),
            )
        else:
            raise ValueError(
                "{} is an invalid compensation method".format(method))
        Pint = 10 * np.log10(
            10**(-1 * Pread / 10) * S21data[0, 2]**2 / S21data[0, 3] / np.pi)
    else:
        lvlcompspl = interpolate.splrep(np.linspace(0.01, 10, 10), np.ones(10))
    return lvlcompspl