Get maximum difference between spline and energy trend.
3838
def max_spline_jump(self):
        
        sp = self.spline()
        return max(self.energies - sp(range(len(self.energies))))
557740
def farthest(self, dt1, dt2, *dts):
        from functools import reduce

        
        dt1 = pendulum.instance(dt1)
        dt2 = pendulum.instance(dt2)

        dts = [dt1, dt2] + [pendulum.instance(x) for x in dts]
        dts = [(abs(self - dt), dt) for dt in dts]

        return max(dts)[1]
973571
def energy(data):
    """"""
    data = np.mean(data, axis=1)
    return np.sum(data ** 2) / np.float64(len(data))
1173888
def get_band_gap(self):
        ''''''
        dosdata = self.get_dos()
        if type(dosdata) == type(None):
            return None # cannot find DOS
        else:
            energy = dosdata.conditions.scalars
            dos = dosdata.scalars
            step_size = energy[1].value - energy[0].value
            not_found = True ; l = 0 ; bot = 10**3 ; top = -10**3
            while not_found and l < len(dos):
                # iterate through the data
                e = float(energy[l].value)
                dens = float(dos[l].value)
                # note: dos already shifted by efermi
                if e < 0 and dens > 1e-3:
                    bot = e
                elif e > 0 and dens > 1e-3:
                    top = e
                    not_found = False
                l += 1
            if top < bot:
                raise Exception('Algorithm failed to find the band gap')
            elif top - bot < step_size*2:
                return Property(scalars=[Scalar(value=0)], units='eV')
            else:
                bandgap = float(top-bot)
                return Property(scalars=[Scalar(value=round(bandgap,3))], units='eV')
695038
def transition(value, maximum, start, end):
    
    return round(start + (end - start) * value / maximum, 2)
596969
def get_cutoff_energy(self):
        ''''''
        return Value(
            scalars=[Scalar(value=self.settings["kinetic-energy cutoff"])],
            units=self.settings['kinetic-energy cutoff units']
        )
158063
def fn_max(self, a, axis=None):
        

        return numpy.nanmax(self._to_ndarray(a), axis=axis)
871990
def most_energetic(df):
    """"""
    idx = df.groupby(['event_id'])['energy'].transform(max) == df['energy']
    return df[idx].reindex()
1106459
def maximum_variation(arr):
  '''
  
  '''
  return np.max(arr, axis=0) - np.min(arr, axis=0)
1207715
def max_pool(x, dim):
        """"""
        return tf.nn.max_pool(
            x, ksize=[1, dim, dim, 1], strides=[1, dim, dim, 1],
            padding='SAME')
39917
def _basis_spline_factory(coef, degree, knots, der, ext):
        """"""
        return functools.partial(interpolate.splev, tck=(knots, coef, degree), der=der, ext=ext)
174649
def _diff(self, x, th, eps):
        
        foo = lambda y: self.igen(numpy.sum(self.gen(y, th), 0), th)

        out1 = out2 = 0.
        sign = 1 - 2*(x > .5).T
        for I in numpy.ndindex(*((2,)*(len(x)-1)+(1,))):

            eps_ = numpy.array(I)*eps
            x_ = (x.T + sign*eps_).T
            out1 += (-1)**sum(I)*foo(x_)

            x_[-1] = 1
            out2 += (-1)**sum(I)*foo(x_)

        out = out1/out2
        return out
951874
def xAxisIsMajor(self):
        '''
        
        '''
        return max(self.radius.x, self.radius.y) == self.radius.x
1334287
def get_maximum(self, other):
        """"""
        return Point(max(self.x, other.x), max(self.y, other.y))
1198636
def _get_energy(self, x):
        
        return self.pd.get_hull_energy(self.comp1 * x + self.comp2 * (1-x)) - \
            self.e1 * x - self.e2 * (1-x)
29677
def energy_value(h: List[Union[int, float]],
                 J: Dict[Tuple[int, int], Union[int, float]],
                 sol: List[int]) -> Union[int, float]:
    
    ener_ising = 0
    for elm in J.keys():
        if elm[0] == elm[1]:
            raise TypeError("""Interaction term must connect two different variables""")
        else:
            ener_ising += J[elm] * int(sol[elm[0]]) * int(sol[elm[1]])
    for i in range(len(h)):
        ener_ising += h[i] * int(sol[i])
    return ener_ising
430082
def detrend(arr, x=None, deg=5, tol=1e-3, maxloop=10):
    """"""

    xx = numpy.arange(len(arr)) if x is None else x
    base = arr.copy()
    trend = base
    pol = numpy.ones((deg + 1,))
    for _ in range(maxloop):
        pol_new = numpy.polyfit(xx, base, deg)
        pol_norm = numpy.linalg.norm(pol)
        diff_pol_norm = numpy.linalg.norm(pol - pol_new)
        if diff_pol_norm / pol_norm < tol:
            break
        pol = pol_new
        trend = numpy.polyval(pol, xx)
        base = numpy.minimum(base, trend)
    return trend