@_log<EOL><INDENT>def bkg_subtract(self, analytes=None, errtype='<STR_LIT>', focus_stage='<STR_LIT>'):<DEDENT>
if analytes is None:<EOL><INDENT>analytes = self.analytes<EOL><DEDENT>elif isinstance(analytes, str):<EOL><INDENT>analytes = [analytes]<EOL><DEDENT>if focus_stage == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' not in self.stages_complete:<EOL><INDENT>focus_stage = '<STR_LIT>'<EOL><DEDENT><DEDENT>bkg_interps = {}<EOL>for a in analytes:<EOL><INDENT>bkg_interps[a] = un_interp1d(x=self.bkg['<STR_LIT>']['<STR_LIT>'],<EOL>y=un.uarray(self.bkg['<STR_LIT>'][a]['<STR_LIT>'],<EOL>self.bkg['<STR_LIT>'][a][errtype]))<EOL><DEDENT>self.bkg_interps = bkg_interps<EOL>with self.pbar.set(total=len(self.data), desc='<STR_LIT>') as prog:<EOL><INDENT>for d in self.data.values():<EOL><INDENT>[d.bkg_subtract(a, bkg_interps[a].new(d.uTime), ~d.sig, focus_stage=focus_stage) for a in analytes]<EOL>d.setfocus('<STR_LIT>')<EOL>prog.update()<EOL><DEDENT><DEDENT>self.stages_complete.update(['<STR_LIT>'])<EOL>self.focus_stage = '<STR_LIT>'<EOL>return<EOL>
Subtract calculated background from data.

Must run bkg_calc first!

Parameters
----------
analytes : str or iterable
    Which analyte(s) to subtract.
errtype : str
    Which type of error to propagate. default is 'stderr'.
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.