def calc(self, data=None, slope=1.0):

        if data is None:
            data = self.data

        width    = self.width
        exponent = self.exponent
        tangent  = self.tangent
        compress = self.compress

        nchans   = len(data)
        self.bgr = np.zeros(nchans, dtype=np.int)
        scratch  = data[:]

        # Compress scratch spectrum
        if compress > 1:
            tmp = compress_array(scratch, compress)
            if tmp is None:
                compress = 1
            else:
                scratch = tmp
                slope = slope * compress
                nchans = nchans / compress

        # Copy scratch spectrum to background spectrum
        bckgnd = scratch[:]

        # Find maximum counts in input spectrum. This information is used to
        # limit the size of the function lookup table
        max_counts = max(scratch)

        # Fit functions which come up from below
        bckgnd = np.arange(nchans, dtype=np.float) - HUGE

        denom = max(TINY, (width / (2. * slope)**exponent))

        indices     = np.arange(nchans*2+1, dtype=np.float) - nchans
        power_funct = indices**exponent  * (REFERENCE_AMPL / denom)
        power_funct = np.compress((power_funct <= max_counts), power_funct)
        max_index   = len(power_funct)/2 - 1
        # print( "NCHANS: ", nchans, denom, min(indices), max(indices), max_index)
        for chan in range(nchans-1):
            tan_slope = 0.
            if tangent:
                # Find slope of tangent to spectrum at this channel
                chan0  = max((chan - MAX_TANGENT), 0)
                chan1  = min((chan + MAX_TANGENT), (nchans-1))
                denom  = chan - np.arange(chan1 - chan0 + 1, dtype=np.float)
                # is this correct?
                denom   = max(max(denom), 1)
                tan_slope = (scratch[chan] - scratch[chan0:chan1+1]) / denom
                tan_slope = np.sum(tan_slope) / (chan1 - chan0)

            chan0 = max((chan - max_index), 0)
            chan1 = min((chan + max_index), (nchans-1))
            chan1 = max(chan1, chan0)
            nc    = chan1 - chan0 + 1
            lin_offset = scratch[chan] + (np.arange(float(nc)) - nc/2) * tan_slope

            # Find the maximum height of a function centered on this channel
            # such that it is never higher than the counts in any channel
            f      = chan0 - chan + max_index
            l      = chan1 - chan + max_index
            test   = scratch[chan0:chan1+1] - lin_offset + power_funct[f:l+1]
            height = min(test)

            # We now have the function height. Set the background to the
            # height of the maximum function amplitude at each channel

            test = height + lin_offset - power_funct[f:l+1]
            sub  = bckgnd[chan0:chan1+1]
            bckgnd[chan0:chan1+1] = np.maximum(sub, test)

        # Expand spectrum
        if compress > 1:
            bckgnd = expand_array(bckgnd, compress)

        # Bgr should be positive integers??
        bgr = bckgnd.astype(int)
        idx = np.where(bgr <= 0)
        bgr[idx] = 0
        self.bgr = bgr
Given an expression assumed to be in the form
dataset/ETHPy150Open xraypy/xraylarch/plugins/xrf/xrf_bgr.py/XRFBackground.calc--crossover with--dataset/ETHPy150Open sympy/sympy/sympy/solvers/bivariate.py/_lambert