def _get_params_from_dat(self, datnum, fit_which: str = 'i_sense', hot_or_cold: str = 'cold') -> NRGParams: dat = get_dat(datnum) orig_fit = dat.NrgOcc.get_fit(name=NRG_OCC_FIT_NAME) if fit_which == 'i_sense': data = get_avg_i_sense_data(dat, CSQ_DATNUM, center_func=_center_func, hot_or_cold=hot_or_cold) if hot_or_cold == 'hot': # Then allow theta to vary, but hold gamma const params = U.edit_params(orig_fit.params, ['g', 'theta'], [None, None], vary=[False, True]) else: params = orig_fit.params new_fit = dat.NrgOcc.get_fit(calculate_only=True, x=data.x, data=data.data, initial_params=params) elif fit_which == 'entropy': data = get_avg_entropy_data(dat, center_func=_center_func, csq_datnum=CSQ_DATNUM) new_fit = NrgUtil(inital_params=orig_fit).get_fit( data.x, data.data, which_data='dndt') else: raise NotImplementedError params = NRGParams.from_lm_params(new_fit.params) return params
def _get_datas(self) -> Tuple[List[Data1D], List[float], List[float]]: datas = [] if self.which_plot == 'data': gammas = [] thetas = [] for k in PARAM_DATNUM_DICT: dat = get_dat(k) data = get_avg_entropy_data(dat, center_func=_center_func, csq_datnum=CSQ_DATNUM) occ_data = get_avg_i_sense_data(dat, CSQ_DATNUM, center_func=_center_func) data.x = occ_data.x data.x -= dat.NrgOcc.get_x_of_half_occ( fit_name=NRG_OCC_FIT_NAME) fit = dat.NrgOcc.get_fit(name=NRG_OCC_FIT_NAME) # data.x = data.x/fit.best_values.theta*kb*0.1 # So that difference in lever arm is taken into account gammas.append(fit.best_values.g) thetas.append(fit.best_values.theta) rescale = max(fit.best_values.g, fit.best_values.theta) datas.append( Data1D(x=data.x / rescale, data=data.data * rescale)) elif self.which_plot == 'nrg': gts = [0.1, 1, 5, 10, 25] theta = 1 thetas = [theta] * len(gts) gammas = list(np.array(gts) * theta) for gamma in gammas: x_width = max([gamma, theta]) * 15 pars = NRGParams(gamma=gamma, theta=theta) data = NrgUtil().data_from_params(params=pars, x=np.linspace( -x_width, x_width, 501), which_data='dndt', which_x='sweepgate') data.x -= get_x_of_half_occ(params=pars.to_lm_params()) data.x *= 0.0001 # Convert back to NRG units data.data = data.data / np.sum(data.data) / np.mean( np.diff(data.x)) * np.log(2) # Convert to real entropy rescale = max(gamma, theta) data.x = data.x / rescale data.data = data.data * rescale datas.append(data) else: raise NotImplementedError return datas, gammas, thetas
def plot_occupation_fit(dat: DatHDF) -> go.Figure: data = get_avg_i_sense_data(dat, None, lambda _: False, overwrite=False, hot_or_cold='cold') fit = dat.NrgOcc.get_fit(name='forced_theta') fig = p1d.figure(xlabel='Sweepgate', ylabel='Delta I', title=f'Dat{dat.datnum}: Checking NRG Transition Fit') fig.add_trace( p1d.trace(x=data.x, data=data.data, mode='lines', name='Data')) fig.add_trace( p1d.trace(x=data.x, data=fit.eval_fit(data.x), mode='lines', name='Fit')) return fig
def get_real_data(self, occupation=False) -> Data1D: if self.which_plot == 'weak': dat = get_dat(2164) elif self.which_plot == 'strong': dat = get_dat(2170) # dat = get_dat(2213) else: raise NotImplementedError if occupation: data = get_avg_i_sense_data(dat, CSQ_DATNUM, center_func=_center_func, hot_or_cold='cold') else: data = get_avg_entropy_data(dat, center_func=_center_func, csq_datnum=CSQ_DATNUM) return Data1D(x=data.x, data=data.data)
def run_dat_init(dat: DatHDF, overwrite: bool = False) -> FitInfo: def lin_theta_slope_name() -> str: if 5000 < dat.datnum < 6000: return 'dats5000+' elif dat.datnum > 7000: return 'dats7000+' elif 1500 < dat.datnum < 2500: return 'normal' else: raise NotImplementedError lin_name = lin_theta_slope_name() avg_data = get_avg_i_sense_data(dat, None, center_func=lambda _: False) pars = get_initial_params(avg_data, which='nrg') theta = get_linear_theta(dat, which_params=lin_name) if 45 < dat.Logs.temps.mc * 1000 < 55: theta = theta / 2 pars['theta'].value = theta pars['theta'].vary = False pars['g'].value = 5 pars['g'].max = theta * 50 # limit of NRG data pars['g'].min = theta / 10000 # limit of NRG data # if abs((x := avg_data.x)[-1] - x[0]) > 1500: # If it's a wider scan, only fit over middle 1500 # cond = np.where(np.logical_and(x > -750, x < 750)) # avg_data.x, avg_data.data = x[cond], avg_data.data[cond] fit = dat.NrgOcc.get_fit(which='avg', name='forced_theta', initial_params=pars, data=avg_data.data, x=avg_data.x, calculate_only=False, check_exists=False, overwrite=overwrite) return fit
ax.plot(x_, nrg_fits[1].eval_fit(x=x_ * 100), label='NRG Fit') for ax in strong_fig.axes: ax.set_ylabel(ax.get_ylabel(), labelpad=5) plt.tight_layout() strong_fig.show() # Data for single hot/cold plot dat = get_dat(2164) # dat = get_dat(7334) _, avg_x = dat.NrgOcc.get_avg_data(check_exists=True, return_x=True) sweep_x = avg_x / 100 # Convert to real mV cold_data = get_avg_i_sense_data(dat, None, _center_func, False, hot_or_cold='cold') hot_data = get_avg_i_sense_data(dat, None, _center_func, False, hot_or_cold='hot') U.save_to_igor_itx(file_path=f'fig1_hot_cold.itx', xs=[sweep_x] * 2, datas=[cold_data.data, hot_data.data], names=['cold', 'hot'], x_labels=['Sweep Gate (mV)'] * 2, y_labels=['Current (nA)'] * 2)
################################################################ # Data for occupation data from temp import get_avg_i_sense_data, get_centered_x_at_half_occ from dat_analysis.analysis_tools.nrg import NrgUtil, NRGParams nrg_fit_name = nrg_fit_name # Use same as above entropy_dats = entropy_dats # Use same as above nrg = NrgUtil() # which = 'occupation' # i_sense or occupation which = 'i_sense' # i_sense or occupation datas = [] nrg_datas = [] fits = [] for dat in entropy_dats: data = get_avg_i_sense_data(dat, csq_datnum, None, hot_or_cold='hot') data.x = get_centered_x_at_half_occ(dat, csq_datnum=csq_datnum, fit_name=nrg_fit_name) data.data = U.decimate(data.data, measure_freq=dat.Logs.measure_freq, numpnts=200) data.x = U.get_matching_x(data.x, data.data) start_fit = dat.NrgOcc.get_fit(name=nrg_fit_name) fit = dat.NrgOcc.get_fit(initial_params=start_fit.params, data=data.data, x=data.x, calculate_only=True) expected_data = nrg.data_from_params(NRGParams.from_lm_params( fit.params),