@_log<EOL><INDENT>def calibrate(self, analytes=None, drift_correct=True,<EOL>srms_used=['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'],<EOL>zero_intercept=True, n_min=<NUM_LIT:10>, reload_srm_database=False):<DEDENT>
if analytes is None:<EOL><INDENT>analytes = self.analytes[self.analytes != self.internal_standard]<EOL><DEDENT>elif isinstance(analytes, str):<EOL><INDENT>analytes = [analytes]<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.srm_id_auto(srms_used=srms_used, n_min=n_min, reload_srm_database=reload_srm_database)<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>gTime = self.stdtab.gTime.unique()<EOL>self.calib_params = pd.DataFrame(columns=pd.MultiIndex.from_product([analytes, ['<STR_LIT:m>']]),<EOL>index=gTime)<EOL><DEDENT>calib_analytes = self.srmtabs.index.get_level_values(<NUM_LIT:0>).unique()<EOL>if zero_intercept:<EOL><INDENT>fn  = lambda x, m: x * m<EOL><DEDENT>else:<EOL><INDENT>fn = lambda x, m, c: x * m + c<EOL><DEDENT>for a in calib_analytes:<EOL><INDENT>if zero_intercept:<EOL><INDENT>if (a, '<STR_LIT:c>') in self.calib_params:<EOL><INDENT>self.calib_params.drop((a, '<STR_LIT:c>'), <NUM_LIT:1>, inplace=True)<EOL><DEDENT><DEDENT>if drift_correct:<EOL><INDENT>for g in self.stdtab.gTime.unique():<EOL><INDENT>ind = idx[a, :, :, g]<EOL>if self.srmtabs.loc[ind].size == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>meas = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>srm = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>merr = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>serr = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>sigma = np.sqrt(merr**<NUM_LIT:2> + serr**<NUM_LIT:2>)<EOL>if len(meas) > <NUM_LIT:1>:<EOL><INDENT>p, cov = curve_fit(fn, meas, srm, sigma=sigma)<EOL>pe = unc.correlated_values(p, cov)                <EOL>self.calib_params.loc[g, (a, '<STR_LIT:m>')] = pe[<NUM_LIT:0>]<EOL>if not zero_intercept:<EOL><INDENT>self.calib_params.loc[g, (a, '<STR_LIT:c>')] = pe[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.calib_params.loc[g, (a, '<STR_LIT:m>')] = (un.uarray(srm, serr) / <EOL>un.uarray(meas, merr))[<NUM_LIT:0>]<EOL>if not zero_intercept:<EOL><INDENT>self.calib_params.loc[g, (a, '<STR_LIT:c>')] = <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>ind = idx[a, :, :, :]<EOL>meas = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>srm = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>merr = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>serr = self.srmtabs.loc[ind, '<STR_LIT>']<EOL>sigma = np.sqrt(merr**<NUM_LIT:2> + serr**<NUM_LIT:2>)<EOL>if len(meas) > <NUM_LIT:1>:<EOL><INDENT>p, cov = curve_fit(fn, meas, srm, sigma=sigma)<EOL>pe = unc.correlated_values(p, cov)                <EOL>self.calib_params.loc[:, (a, '<STR_LIT:m>')] = pe[<NUM_LIT:0>]<EOL>if not zero_intercept:<EOL><INDENT>self.calib_params.loc[:, (a, '<STR_LIT:c>')] = pe[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.calib_params.loc[:, (a, '<STR_LIT:m>')] = (un.uarray(srm, serr) / <EOL>un.uarray(meas, merr))[<NUM_LIT:0>]<EOL>if not zero_intercept:<EOL><INDENT>self.calib_params.loc[:, (a, '<STR_LIT:c>')] = <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT><DEDENT>if self.calib_params.index.min() == <NUM_LIT:0>:<EOL><INDENT>self.calib_params.drop(<NUM_LIT:0>, inplace=True)<EOL>self.calib_params.drop(self.calib_params.index.max(), inplace=True)<EOL><DEDENT>self.calib_params.loc[<NUM_LIT:0>, :] = self.calib_params.loc[self.calib_params.index.min(), :]<EOL>maxuT = np.max([d.uTime.max() for d in self.data.values()])  <EOL>self.calib_params.loc[maxuT, :] = self.calib_params.loc[self.calib_params.index.max(), :]<EOL>self.calib_params.sort_index(<NUM_LIT:1>, inplace=True)<EOL>self.calib_params.sort_index(<NUM_LIT:0>, inplace=True)<EOL>self.calib_ps = Bunch()<EOL>for a in analytes:<EOL><INDENT>self.calib_ps[a] = {'<STR_LIT:m>': un_interp1d(self.calib_params.index.values,<EOL>self.calib_params.loc[:, (a, '<STR_LIT:m>')].values)}<EOL>if not zero_intercept:<EOL><INDENT>self.calib_ps[a]['<STR_LIT:c>'] = un_interp1d(self.calib_params.index.values,<EOL>self.calib_params.loc[:, (a, '<STR_LIT:c>')].values)<EOL><DEDENT><DEDENT>with self.pbar.set(total=len(self.data), desc='<STR_LIT>') as prog:<EOL><INDENT>for d in self.data.values():<EOL><INDENT>d.calibrate(self.calib_ps, analytes)<EOL>prog.update()<EOL><DEDENT><DEDENT>markers = '<STR_LIT>'  <EOL>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.srms_used = set(srms_used)<EOL><DEDENT>else:<EOL><INDENT>self.srms_used.update(srms_used)<EOL><DEDENT>self.srm_mdict = {k: markers[i] for i, k in enumerate(self.srms_used)}<EOL>self.stages_complete.update(['<STR_LIT>'])<EOL>self.focus_stage = '<STR_LIT>'<EOL>return<EOL>
Calibrates the data to measured SRM values.

Assumes that y intercept is zero.

Parameters
----------  
analytes : str or iterable
    Which analytes you'd like to calibrate. Defaults to all.
drift_correct : bool
    Whether to pool all SRM measurements into a single calibration,
    or vary the calibration through the run, interpolating
    coefficients between measured SRMs.
srms_used : str or iterable
    Which SRMs have been measured. Must match names given in
    SRM data file *exactly*.
n_min : int
    The minimum number of data points an SRM measurement
    must have to be included.

Returns
-------
None