Beispiel #1
0
def transition_trace(dats: List[DatHDF], x_func: Callable,
                     from_square_entropy: bool = True, fit_name: str = 'default',
                     param: str = 'amp', label: str = '',
                     **kwargs) -> go.Scatter:
    divide_const, divide_acc_divider = False, False
    if param == 'amp/const':
        divide_const = True
        param = 'amp'
    elif param == 'theta real':
        divide_acc_divider = True
        param = 'theta'

    plotter = OneD(dats=dats)
    if from_square_entropy:
        vals = [dat.SquareEntropy.get_fit(which_fit='transition', fit_name=fit_name, check_exists=True).best_values.get(
            param) for dat in dats]
    else:
        vals = [dat.Transition.get_fit(name=fit_name).best_values.get(param) for dat in dats]
        if divide_const:
            vals = [amp / dat.Transition.get_fit(name=fit_name).best_values.const for amp, dat in zip(vals, dats)]
        elif divide_acc_divider:
            divider_vals = [int(re.search(r'\d+', dat.Logs.xlabel)[0]) for dat in dats]  # e.g. get the 1000 part of ACC*1000 /mV
            vals = [val/divider for val, divider in zip(vals, divider_vals)]
    x = [x_func(dat) for dat in dats]
    trace = plotter.trace(x=x, data=vals, name=label, text=[dat.datnum for dat in dats], **kwargs)
    return trace
def plot_linear_theta_comparison(
        e_dats,
        t_dats,
        a_dats,
        fit_name='gamma_small') -> Tuple[List[FitInfo], go.Figure]:
    csq_mapped = True if 'csq' in fit_name else False
    efit = plot_linear_theta_nrg_fit(e_dats,
                                     show_plots=False,
                                     csq_mapped=csq_mapped)
    tfit = plot_linear_theta_nrg_fit(t_dats,
                                     show_plots=False,
                                     csq_mapped=csq_mapped)
    fit = plot_linear_theta_nrg_fit(a_dats,
                                    show_plots=False,
                                    csq_mapped=csq_mapped)

    plotter = OneD(dats=all_dats)
    fig = plotter.figure(
        xlabel='ESC /mV',
        ylabel='Theta /mV (real)',
        title=f'Dats{all_dats[0].datnum}-{all_dats[-1].datnum}: Theta vs ESC')
    for dats, name in zip((e_dats, t_dats), ['entropy', 'transition']):
        xs = [dat.Logs.dacs['ESC'] for dat in dats]
        thetas = [
            dat.NrgOcc.get_fit(name=fit_name).best_values.theta for dat in dats
        ]
        datnums = [dat.datnum for dat in dats]
        fig.add_trace(
            plotter.trace(data=thetas,
                          x=xs,
                          name=name,
                          mode='markers',
                          text=datnums))

    xs = [dat.Logs.dacs['ESC'] for dat in t_dats]
    for f, name in zip((efit, tfit, fit),
                       ['entropy fit', 'transition fit', 'all fit']):
        fig.add_trace(
            plotter.trace(x=xs,
                          data=f.eval_fit(np.array(xs)),
                          name=name,
                          mode='lines'))
    return [efit, tfit, fit], fig
Beispiel #3
0
def dcbias_multi_dat(dats: List[DatHDF]):
    plotter = OneD(dats=dats)

    fig = plotter.figure(
        xlabel='Heater Current Bias /nA',
        ylabel='Theta /mV',
        title=f'Dats{dats[0].datnum}-{dats[-1].datnum}: DCbias')

    thetas = []
    biases = []
    for dat in dats:
        fit = dat.Transition.get_fit(which='avg',
                                     name='default',
                                     check_exists=False)
        theta = fit.best_values.theta
        thetas.append(theta)
        biases.append(dat.Logs.fds['HO1/10M'] / 10)

    hover_infos = common_dat_hover_infos(datnum=True)
    hover_infos.append(
        HoverInfo(name='Bias',
                  func=lambda dat: dat.Logs.dacs['HO1/10M'] / 10,
                  precision='.2f',
                  units='nA'))
    hover_infos.append(
        HoverInfo(name='Theta',
                  func=lambda dat: dat.Transition.get_fit().best_values.theta,
                  precision='.2f',
                  units='mV'))
    hover_group = HoverInfoGroup(hover_infos=hover_infos)

    fig.add_trace(
        plotter.trace(x=biases,
                      data=thetas,
                      mode='markers+lines',
                      hover_template=hover_group.template,
                      hover_data=hover_group.customdata(dats)))
    return fig
Beispiel #4
0
def entropy_vs_time_trace(dats: List[DatHDF],
                          trace_name=None,
                          integrated=False,
                          fit_name: str = 'SPS.005',
                          integrated_name: str = 'first'):
    plotter = OneD(dats=dats)
    if integrated is False:
        entropies = [
            dat.Entropy.get_fit(which='avg', name=fit_name).best_values.dS
            for dat in dats
        ]
        entropies_err = [
            np.nanstd([
                fit.best_values.dS
                if fit.best_values.dS is not None else np.nan
                for fit in dat.Entropy.get_row_fits(name=fit_name)
            ]) / np.sqrt(len(dats)) for dat in dats
        ]
    else:
        entropies = [
            np.nanmean(
                dat.Entropy.get_integrated_entropy(
                    name=integrated_name,
                    data=dat.SquareEntropy.get_Outputs(
                        name=fit_name).average_entropy_signal)[-10:])
            for dat in dats
        ]
        entropies_err = [0.0] * len(dats)

    times = [str(dat.Logs.time_completed) for dat in dats]

    trace = plotter.trace(data=entropies,
                          data_err=entropies_err,
                          x=times,
                          text=[dat.datnum for dat in dats],
                          mode='lines',
                          name=trace_name)
    return trace
Beispiel #5
0
def single_transition_trace(dat: DatHDF, label: Optional[str] = None, subtract_fit=False,
                            fit_only=False, fit_name: str = 'narrow', transition_only=True,
                            se_output_name: str = 'SPS.005',
                            csq_mapped=False) -> go.Scatter():
    plotter = OneD(dat=dat)
    if transition_only:
        if csq_mapped:
            x = dat.Data.get_data('csq_x_avg')
        else:
            x = dat.Transition.avg_x
    else:
        if csq_mapped:
            raise NotImplementedError
        x = dat.SquareEntropy.avg_x

    if not fit_only:
        if transition_only:
            if csq_mapped:
                data = dat.Data.get_data('csq_mapped_avg')
            else:
                data = dat.Transition.avg_data
        else:
            data = dat.SquareEntropy.get_transition_part(name=se_output_name, part='cold')
    else:
        data = None  # Set below

    if fit_only or subtract_fit:
        if transition_only:
            fit = dat.Transition.get_fit(name=fit_name)
        else:
            fit = dat.SquareEntropy.get_fit(which_fit='transition', fit_name=fit_name)
        if fit_only:
            data = fit.eval_fit(x=x)
        elif subtract_fit:
            data = data - fit.eval_fit(x=x)

    trace = plotter.trace(x=x, data=data, name=label, mode='lines')
    return trace
Beispiel #6
0
def trace_stdev_of_avg_data(dat: DatHDF,
                            data_type: str = 'transition',
                            data_name: str = 'default') -> go.Scatter:
    """Trace for stdev of averaged 2D data"""
    if data_type.lower() == 'transition':
        _, stdev, x = dat.Transition.get_avg_data(name=data_name,
                                                  return_x=True,
                                                  return_std=True,
                                                  check_exists=True)
    elif data_type.lower() == 'entropy':
        _, stdev, x = dat.Entropy.get_avg_data(name=data_name,
                                               return_x=True,
                                               return_std=True,
                                               check_exists=True)
    else:
        raise NotImplementedError(f'{data_type} not implemented')

    plotter = OneD(dat=dat)
    trace = plotter.trace(data=stdev,
                          x=x,
                          name=f'Dat{dat.datnum}',
                          mode='lines')
    return trace
Beispiel #7
0
def get_integrated_trace(
        dats: List[DatHDF],
        x_func: Callable,
        x_label: str,
        trace_name: str,
        save_name: str,
        int_info_name: Optional[str] = None,
        SE_output_name: Optional[str] = None,
        sub_linear: bool = False,
        signal_width: Optional[Union[float, Callable]] = None) -> go.Scatter:
    """
    Returns a trace Integrated Entropy vs x_func
    Args:
        dats ():
        x_func ():
        x_label ():
        trace_name ():
        save_name ():
        int_info_name ():
        SE_output_name ():
        sub_linear (): Whether to subtract linear entropy term from both integrated trace (note: requires signal_width)
        signal_width (): How wide the actual entropy signal is so that a slope can be fit to the sides around it,
            Can be a callable which takes 'dat' as the argument

    Returns:
        go.Scatter: The trace
    """
    if int_info_name is None:
        int_info_name = save_name
    if SE_output_name is None:
        SE_output_name = save_name

    plotter = OneD(dats=dats)
    dats = U.order_list(dats, [x_func(dat) for dat in dats])

    standard_hover_infos = common_dat_hover_infos(
        datnum=True,
        heater_bias=True,
        fit_entropy_name=save_name,
        fit_entropy=True,
        int_info_name=int_info_name,
        output_name=SE_output_name,
        integrated_entropy=True,
        sub_lin=sub_linear,
        sub_lin_width=signal_width,
        int_info=True,
    )
    standard_hover_infos.append(
        HoverInfo(name=x_label,
                  func=lambda dat: x_func(dat),
                  precision='.1f',
                  units='mV',
                  position=1))
    hover_infos = HoverInfoGroup(standard_hover_infos)

    x = [x_func(dat) for dat in dats]
    if not sub_linear:
        integrated_entropies = [
            np.nanmean(
                dat.Entropy.get_integrated_entropy(
                    name=int_info_name,
                    data=dat.SquareEntropy.get_Outputs(
                        name=SE_output_name,
                        check_exists=True).average_entropy_signal)[-10:])
            for dat in dats
        ]
    else:
        integrated_entropies = [
            np.nanmean(
                dat_integrated_sub_lin(dat,
                                       signal_width=signal_width(dat),
                                       int_info_name=int_info_name,
                                       output_name=SE_output_name)[-10:])
            for dat in dats
        ]
    trace = plotter.trace(data=integrated_entropies,
                          x=x,
                          name=trace_name,
                          mode='markers+lines',
                          trace_kwargs=dict(
                              customdata=hover_infos.customdata(dats),
                              hovertemplate=hover_infos.template))
    return trace
Beispiel #8
0
def plot_fit_integrated_comparison(dats: List[DatHDF],
                                   x_func: Callable,
                                   x_label: str,
                                   title_append: Optional[str] = '',
                                   int_info_name: Optional[str] = None,
                                   fit_name: str = 'SPS.0045',
                                   plot=True) -> go.Figure():
    if int_info_name is None:
        int_info_name = 'default'
    plotter = OneD(dats=dats)
    fig = plotter.figure(
        title=
        f'Dats{dats[0].datnum}-{dats[-1].datnum}: Fit and Integrated (\'{int_info_name}\') Entropy{title_append}',
        xlabel=x_label,
        ylabel='Entropy /kB')

    hover_infos = [
        HoverInfo(name='Dat',
                  func=lambda dat: dat.datnum,
                  precision='.d',
                  units=''),
        HoverInfo(name='Temperature',
                  func=lambda dat: dat.Logs.temps.mc * 1000,
                  precision='.1f',
                  units='mK'),
        HoverInfo(name='Bias',
                  func=lambda dat: dat.AWG.max(0) / 10,
                  precision='.1f',
                  units='nA'),
        # HoverInfo(name='Fit Entropy', func=lambda dat: dat.SquareEntropy.get_fit(which_fit='entropy', fit_name=fit_name).best_values.dS,
        #           precision='.2f', units='kB'),
        HoverInfo(
            name='Integrated Entropy',
            func=lambda dat: np.nanmean(
                dat.Entropy.get_integrated_entropy(
                    name=int_info_name,
                    data=dat.SquareEntropy.get_Outputs(
                        name=fit_name).average_entropy_signal)[-10:]),
            # TODO: Change to using proper output (with setpoints)
            precision='.2f',
            units='kB'),
    ]

    funcs, template = _additional_data_dict_converter(hover_infos)
    x = [x_func(dat) for dat in dats]
    hover_data = [[func(dat) for func in funcs] for dat in dats]

    entropies = [
        dat.Entropy.get_fit(name=fit_name).best_values.dS for dat in dats
    ]
    # entropy_errs = [np.nanstd([
    #     f.best_values.dS if f.best_values.dS is not None else np.nan
    #     for f in dat.Entropy.get_row_fits(name=fit_name) for dat in dats
    # ]) / np.sqrt(dat.Data.y_array.shape[0]) for dat in dats]
    entropy_errs = None
    fig.add_trace(
        plotter.trace(data=entropies,
                      data_err=entropy_errs,
                      x=x,
                      name=f'Fit Entropy',
                      mode='markers',
                      trace_kwargs={
                          'customdata': hover_data,
                          'hovertemplate': template
                      }))
    integrated_entropies = [
        np.nanmean(
            dat.Entropy.get_integrated_entropy(
                name=int_info_name,
                data=dat.SquareEntropy.get_Outputs(
                    name=fit_name).average_entropy_signal)[-10:])
        for dat in dats
    ]

    ### For plotting the impurity dot scans (i.e. isolate only the integrated entropy due to the main dot transition)
    # integrated_entropies = []
    # for dat in dats:
    #     out = dat.SquareEntropy.get_Outputs(name=fit_name)
    #     x1, x2 = U.get_data_index(out.x, [-40, 40], is_sorted=True)
    #     integrated = dat.Entropy.get_integrated_entropy(name=int_info_name,
    #                                                     data=out.average_entropy_signal)
    #     integrated_entropies.append(integrated[x2]-integrated[x1])

    fig.add_trace(
        plotter.trace(data=integrated_entropies,
                      x=x,
                      name=f'Integrated',
                      mode='markers+lines',
                      trace_kwargs={
                          'customdata': hover_data,
                          'hovertemplate': template
                      }))

    if plot:
        fig.show(renderer='browser')
    return fig