@_log<EOL><INDENT>def filter_gradient_threshold_percentile(self, analyte, percentiles, level='<STR_LIT>', win=<NUM_LIT:15>, filt=False,<EOL>samples=None, subset=None):<DEDENT>
params = locals()<EOL>del(params['<STR_LIT>'])<EOL>if samples is not None:<EOL><INDENT>subset = self.make_subset(samples)<EOL><DEDENT>samples = self._get_samples(subset)<EOL>self.minimal_analytes.update([analyte])<EOL>self.get_gradients(analytes=[analyte], win=win, filt=filt, subset=subset)<EOL>grad = self.gradients[analyte][~np.isnan(self.gradients[analyte])]<EOL>if isinstance(percentiles, (int, float)):<EOL><INDENT>percentiles = [percentiles]<EOL><DEDENT>if level == '<STR_LIT>':<EOL><INDENT>lims = np.percentile(grad, percentiles)<EOL><DEDENT>with self.pbar.set(total=len(samples), desc='<STR_LIT>') as prog:<EOL><INDENT>for s in samples:<EOL><INDENT>d = self.data[s]<EOL>setn = d.filt.maxset + <NUM_LIT:1><EOL>g = calc_grads(d.Time, d.focus, [analyte], win)[analyte]<EOL>if level == '<STR_LIT>':<EOL><INDENT>gt = nominal_values(g)<EOL>lims = np.percentile(gt[~np.isnan(gt)], percentiles)<EOL><DEDENT>if len(lims) == <NUM_LIT:1>:<EOL><INDENT>above = g >= lims[<NUM_LIT:0>]<EOL>below = g < lims[<NUM_LIT:0>]<EOL>d.filt.add(analyte + '<STR_LIT>'.format(percentiles[<NUM_LIT:0>]),<EOL>below,<EOL>'<STR_LIT>'.format(percentiles[<NUM_LIT:0>], analyte, lims[<NUM_LIT:0>]),<EOL>params, setn=setn)<EOL>d.filt.add(analyte + '<STR_LIT>'.format(percentiles[<NUM_LIT:0>]),<EOL>above,<EOL>'<STR_LIT>'.format(percentiles[<NUM_LIT:0>], analyte, lims[<NUM_LIT:0>]),<EOL>params, setn=setn)<EOL><DEDENT>elif len(lims) == <NUM_LIT:2>:<EOL><INDENT>inside = (g >= min(lims)) & (g <= max(lims))<EOL>outside = (g < min(lims)) | (g > max(lims))<EOL>lpc = '<STR_LIT:->'.join(['<STR_LIT>'.format(p) for p in percentiles])<EOL>d.filt.add(analyte + '<STR_LIT:_>' + lpc + '<STR_LIT>',<EOL>inside,<EOL>'<STR_LIT>' + lpc + '<STR_LIT:U+0020>' + analyte + '<STR_LIT>',<EOL>params, setn=setn)<EOL>d.filt.add(analyte + '<STR_LIT:_>' + lpc + '<STR_LIT>',<EOL>outside,<EOL>'<STR_LIT>' + lpc + '<STR_LIT:U+0020>' + analyte + '<STR_LIT>',<EOL>params, setn=setn)<EOL><DEDENT>prog.update()<EOL><DEDENT><DEDENT>return<EOL>
Calculate a gradient threshold filter to the data.

Generates two filters above and below the threshold value for a
given analyte.

Parameters
----------
analyte : str
    The analyte that the filter applies to.
win : int
    The window over which to calculate the moving gradient
percentiles : float or iterable of len=2
    The percentile values.
filt : bool
    Whether or not to apply existing filters to the data before
    calculating this filter.
samples : array_like or None
    Which samples to apply this filter to. If None, applies to all
    samples.
subset : str or number
    The subset of samples (defined by make_subset) you want to apply
    the filter to.

Returns
-------
None