def get_background(self, n_min=<NUM_LIT:10>, n_max=None, focus_stage='<STR_LIT>', bkg_filter=False, f_win=<NUM_LIT:5>, f_n_lim=<NUM_LIT:3>):
allbkgs = {'<STR_LIT>': [],<EOL>'<STR_LIT>': []}<EOL>if focus_stage == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' not in self.stages_complete:<EOL><INDENT>focus_stage = '<STR_LIT>'<EOL><DEDENT><DEDENT>for a in self.analytes:<EOL><INDENT>allbkgs[a] = []<EOL><DEDENT>n0 = <NUM_LIT:0><EOL>for s in self.data.values():<EOL><INDENT>if sum(s.bkg) > <NUM_LIT:0>:<EOL><INDENT>allbkgs['<STR_LIT>'].append(s.uTime[s.bkg])<EOL>allbkgs['<STR_LIT>'].append(enumerate_bool(s.bkg, n0)[s.bkg])<EOL>n0 = allbkgs['<STR_LIT>'][-<NUM_LIT:1>][-<NUM_LIT:1>]<EOL>for a in self.analytes:<EOL><INDENT>allbkgs[a].append(s.data[focus_stage][a][s.bkg])<EOL><DEDENT><DEDENT><DEDENT>allbkgs.update((k, np.concatenate(v)) for k, v in allbkgs.items())<EOL>bkgs = pd.DataFrame(allbkgs)  <EOL>self.bkg = Bunch()<EOL>if n_max is None:<EOL><INDENT>self.bkg['<STR_LIT>'] = bkgs.groupby('<STR_LIT>').filter(lambda x: len(x) > n_min)<EOL><DEDENT>else:<EOL><INDENT>self.bkg['<STR_LIT>'] = bkgs.groupby('<STR_LIT>').filter(lambda x: (len(x) > n_min) & (len(x) < n_max))<EOL><DEDENT>self.bkg['<STR_LIT>'] = self.bkg['<STR_LIT>'].groupby('<STR_LIT>').aggregate([np.mean, np.std, stderr])<EOL>self.bkg['<STR_LIT>'].sort_values(('<STR_LIT>', '<STR_LIT>'), inplace=True)<EOL>if bkg_filter:<EOL><INDENT>t = self.bkg['<STR_LIT>'].loc[:, idx[:, '<STR_LIT>']]<EOL>r = t.rolling(f_win).aggregate([np.nanmean, np.nanstd])<EOL>upper = r.loc[:, idx[:, :, '<STR_LIT>']] + f_n_lim * r.loc[:, idx[:, :, '<STR_LIT>']].values<EOL>over = r.loc[:, idx[:, :, '<STR_LIT>']] > np.roll(upper.values, <NUM_LIT:1>, <NUM_LIT:0>)<EOL>ns_drop = over.loc[over.apply(any, <NUM_LIT:1>), :].index.values<EOL>self.bkg['<STR_LIT>'].drop(ns_drop, inplace=True)<EOL>ind = np.ones(self.bkg['<STR_LIT>'].shape[<NUM_LIT:0>], dtype=bool)<EOL>for ns in ns_drop:<EOL><INDENT>ind = ind & (self.bkg['<STR_LIT>'].loc[:, '<STR_LIT>'] != ns)<EOL><DEDENT>self.bkg['<STR_LIT>'] = self.bkg['<STR_LIT>'].loc[ind, :]<EOL><DEDENT>return<EOL>
Extract all background data from all samples on universal time scale.
Used by both 'polynomial' and 'weightedmean' methods.

Parameters
----------
n_min : int
    The minimum number of points a background region must
    have to be included in calculation.
n_max : int
    The maximum number of points a background region must
    have to be included in calculation.
filter : bool
    If true, apply a rolling filter to the isolated background regions
    to exclude regions with anomalously high values. If True, two parameters
    alter the filter's behaviour:
f_win : int
    The size of the rolling window
f_n_lim : float
    The number of standard deviations above the rolling mean
    to set the threshold.
focus_stage : str
    Which stage of analysis to apply processing to. 
    Defaults to 'despiked' if present, or 'rawdata' if not. 
    Can be one of:
    * 'rawdata': raw data, loaded from csv file.
    * 'despiked': despiked data.
    * 'signal'/'background': isolated signal and background data.
      Created by self.separate, after signal and background
      regions have been identified by self.autorange.
    * 'bkgsub': background subtracted data, created by 
      self.bkg_correct
    * 'ratios': element ratio data, created by self.ratio.
    * 'calibrated': ratio data calibrated to standards, created by self.calibrate.

Returns
-------
pandas.DataFrame object containing background data.