def entropy_vs_time_fig(title: Optional[str] = None): plotter = OneD() if title is None: title = 'Entropy vs Time' fig = plotter.figure(xlabel='Time', ylabel='Entropy /kB', title=title) fig.update_xaxes(tickformat="%H:%M\n%a") return fig
def dcbias_single_dat(dat: DatHDF, fig_x_func: Callable, x_label: str): plotter = OneD(dat=dat) x = dat.Transition.x data = dat.Transition.data func, params = _get_transition_fit_func_params(x, data[0], 'i_sense', theta=None, gamma=0) fits = dat.Transition.get_row_fits(name='i_sense', fit_func=func, initial_params=None, check_exists=False, overwrite=False) thetas = [fit.best_values.theta for fit in fits] fig_x = fig_x_func(dat) fig = plotter.plot( data=thetas, x=fig_x, xlabel=x_label, ylabel='Theta /mV', mode='markers+lines', title= f'Dat{dat.datnum}: MC temp={dat.Logs.temps.mc * 1000:.1f}mK DCBias thetas' ) return fig
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 get_integrated_fig(dats=None, title_append: str = '') -> go.Figure: plotter = OneD() if dats: title_prepend = f'Dats{dats[0].datnum}-{dats[-1].datnum}: ' else: title_prepend = '' fig = plotter.figure( xlabel='ESC /mV', ylabel='Entropy /kB', title=f'{title_prepend}Integrated Entropy {title_append}') return fig
def plot_stdev_of_avg_data(dat: DatHDF, data_type: str = 'transition', data_name: str = 'default') -> go.Figure: """Plot the stdev of averaging the 2D data (i.e. looking for whether more uncertainty near transition)""" plotter = OneD(dat=dat) fig = plotter.figure( ylabel=f'{dat_analysis.dat_analysis.characters.SIG}I_sense /nA', title= f'Dat{dat.datnum}: Standard deviation of averaged I_sense data after centering', ) fig.add_trace(trace_stdev_of_avg_data(dat, data_type, data_name)) return fig
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
def transition_fig(dats: Optional[List[DatHDF]] = None, xlabel: str = '/mV', title_append: str = '', param: str = 'amp') -> go.Figure: plotter = OneD(dats=dats) titles = { 'amp': 'Amplitude', 'theta': 'Theta', 'theta real': 'Theta', 'g': 'Gamma', 'amp/const': 'Amplitude/Const (sensitivity)', } ylabels = { 'amp': 'Amplitude /nA', 'theta': 'Theta /mV', 'theta real': 'Theta /mV (real)', 'g': 'Gamma /mV', 'amp/const': 'Amplitude/Const' } fig = plotter.figure(xlabel=xlabel, ylabel=ylabels[param], title=f'Dats{dats[0].datnum}-{dats[-1].datnum}: {titles[param]}{title_append}') return fig
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
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
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
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
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
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
import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.pylab as pylab import numpy as np from typing import Optional from dataclasses import dataclass import dat_analysis.useful_functions as U from dat_analysis.plotting.mpl.PlotUtil import set_default_rcParams from dat_analysis.plotting.plotly import OneD from FinalFigures.Gamma.plots import getting_amplitude_and_dt, dndt_signal from dat_analysis.analysis_tools.nrg import NRG_func_generator, NrgUtil, NRGParams from temp import get_avg_entropy_data, _center_func, get_avg_i_sense_data p1d = OneD(dat=None) # @dataclass # class NRGParams: # gamma: float # theta: float # center: float # amp: float # lin: float # const: float # lin_occ: float # vary_theta: bool = False # vary_gamma: bool = False # datnum: Optional[int] = None if __name__ == '__main__': set_default_rcParams()
""" title = f'Dat{dat.datnum}: {TransitionGraphText.get_full_name_from_param(param_name)} for each row' ylabel = TransitionGraphText.get_ylabel_from_param(par_name=param_name) x = dat.Data.y xlabel = dat.Logs.ylabel if param_name not in (keys := dat.Transition.get_fit(which='row', name=fit_name, row=0).best_values.keys): raise KeyError(f'{param_name} not in {keys}') params = [fit.params.get(param_name) for fit in dat.Transition.get_row_fits(name=fit_name)] fit_values = [param.value for param in params] fit_errs = [param.stderr for param in params] plotter = OneD(dat=dat) fig = plotter.plot(data=fit_values, data_err=fit_errs, x=x, xlabel=xlabel, ylabel=ylabel, title=title, mode='markers') return fig def plot_multiple_transition_row_fit_with_stdev(dats: Iterable[DatHDF], param_name: str, fit_name: str = 'default', x: U.ARRAY_LIKE = None, xlabel: str = 'Datnum', stdev_only=False) -> go.Figure: """ Display avg of row fit values with stdev or just stdev for Transition fits of multiple dats (i.e. for looking
def __init__(self, dat: dat_hdf): self.dat: dat_hdf = dat self.one_plotter: OneD = OneD(dat) self.two_plotter: TwoD = TwoD(dat)