input: b, b_star (actual and corrected slope)
    output: delta_pal
344322
def get_delta_pal(b, b_star):
    
    delta_pal = numpy.abs(old_div((b - b_star), b)) * 100
    return delta_pal
512530
def get_delta_plus_epsilon(nat, i_now, dr_now, dr_old):
    
    XIJ = get_XIJ(nat, i_now, dr_now, dr_old)
    YIJ = get_YIJ(nat, i_now, dr_old)

    YIJ_invert = array_inverse(YIJ)

    # Perform sum_k X_ik Y_jk^-1
    epsilon = np.sum(XIJ.reshape(-1,3,1,3)*YIJ_invert.reshape(-1,1,3,3), axis=3)

    return epsilon
656195
def prox_yline(y, step):
    """"""
    if not np.isscalar(y):
        y= y[0]
    if y > -0.75:
        return np.array([-0.75])
    else:
        return np.array([y])
1171091
def ddtohms(xsky,ysky,verbose=False,precision=6):
    
    xskyh = xsky /15.
    xskym = (xskyh - np.floor(xskyh)) * 60.
    xskys = (xskym - np.floor(xskym)) * 60.
    yskym = (np.abs(ysky) - np.floor(np.abs(ysky))) * 60.
    yskys = (yskym - np.floor(yskym)) * 60.

    fmt = "%."+repr(precision)+"f"
    if isinstance(xskyh,np.ndarray):
        rah,dech = [],[]
        for i in range(len(xskyh)):
            rastr = repr(int(xskyh[i]))+':'+repr(int(xskym[i]))+':'+fmt%(xskys[i])
            decstr = repr(int(ysky[i]))+':'+repr(int(yskym[i]))+':'+fmt%(yskys[i])
            rah.append(rastr)
            dech.append(decstr)
            if verbose:
                print('RA = ',rastr,', Dec = ',decstr)
    else:
        rastr = repr(int(xskyh))+':'+repr(int(xskym))+':'+fmt%(xskys)
        decstr = repr(int(ysky))+':'+repr(int(yskym))+':'+fmt%(yskys)
        rah = rastr
        dech = decstr
        if verbose:
            print('RA = ',rastr,', Dec = ',decstr)

    return rah,dech
1161169
def y0astep():
    
    """

    global mp_b
    mp_b[:] = mp_inv_off_diag * np.sum((mp_S + mp_rho*(mp_DX+mp_U0)),
                                       axis=mp_axisM, keepdims=True)
44716
def deltas(errors, epsilon, mean, std):
    
    below = errors[errors <= epsilon]
    if not len(below):
        return 0, 0

    return mean - below.mean(), std - below.std()
1129129
def par_y0bstep(i):
    
    """

    global mp_Y0
    mp_Y0[i] = 1/mp_rho*mp_S + mp_DX[i] + mp_U0[i] + mp_b
853153
function deltaTransformPoint(matrix, x, y) {
  return {
    x: x * matrix.a + y * matrix.c + 0
  , y: x * matrix.b + y * matrix.d + 0
  }
}
944544
def lnlike(x, star):
    """"""
    ll = lnprior(x)
    if np.isinf(ll):
        return ll, (np.nan, np.nan)
    per, t0, b = x
    model = TransitModel('b', per=per, t0=t0, b=b, rhos=10.)(star.time)
    like, d, vard = star.lnlike(model, full_output=True)
    ll += like
    return ll, (d,)
556358
public void orizzonte5( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
            WritableRaster curvatureImage, int[][] shadow ) {
        int rows = curvatureImage.getHeight();
        int cols = curvatureImage.getWidth();
        /*=====================*/

        int y, I, J;
        double zenith;

        /*======================*/

        for( int j = quadrata; j >= 0; j-- ) {
            I = -1;
            J = -1;
            y = 0;
            for( int jj = j; jj < quadrata; jj++ ) {
                for( int i = rows - (int) floor(1 / tan(beta) * (jj - j)) - 1; i >= rows
                        - (int) floor(1 / tan(beta) * (jj - j + 1)) - 1
                        && i >= 0; i-- ) {
                    if (jj >= quadrata - cols && !isNovalue(elevImageIterator.getSampleDouble(jj - (quadrata - cols), i, 0))) {
                        /*shadow.element[i][jj-(quadrata-Z0.nch)]=j;}}}}*/
                        if (curvatureImage.getSampleDouble(jj - (quadrata - cols), i, 0) == 1 && I == -1) {
                            I = i;
                            J = jj - (quadrata - cols);
                            y = 1;
                        } else if (curvatureImage.getSampleDouble(jj - (quadrata - cols), i, 0) == 1 && I != -1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(jj
                                    - (quadrata - cols), i, 0))
                                    / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                            + pow((double) (J - (jj - (quadrata - cols))) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[i][jj - (quadrata - cols)] = 0;
                                I = i;
                                J = jj - (quadrata - cols);
                            } else {
                                shadow[i][jj - (quadrata - cols)] = 1;
                            }
                        } else if (curvatureImage.getSampleDouble(jj - (quadrata - cols), i, 0) == 0 && y == 1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(jj
                                    - (quadrata - cols), i, 0))
                                    / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                            + pow((double) (J - (jj - (quadrata - cols))) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[i][jj - (quadrata - cols)] = 0;
                                y = 0;
                            } else {
                                shadow[i][jj - (quadrata - cols)] = 1;
                            }
                        }
                    }
                }
            }
        }

    }
156632
def _get_msge_with_gradient(data, delta, xvschema, skipstep, p):
    
    t, m, l = data.shape

    n = (l - p) * t
    underdetermined = n < m * p

    if underdetermined:
        return _msge_with_gradient_underdetermined(data, delta, xvschema,
                                                   skipstep, p)
    else:
        return _msge_with_gradient_overdetermined(data, delta, xvschema,
                                                  skipstep, p)
324174
def delta(a, b):
    
    diff = a - b
    return numpy.einsum("i...,i...->...", diff, diff)
1320503
def dz_fltr_ma(dem, refdem, perc=None, rangelim=(0,30), smooth=False):
    
    if smooth:
        refdem = gauss_fltr_astropy(refdem)
        dem = gauss_fltr_astropy(dem)

    dz = refdem - dem

    #This is True for invalid values in DEM, and should be masked
    demmask = np.ma.getmaskarray(dem)

    if perc:
        dz_perc = malib.calcperc(dz, perc)
        print("Applying dz percentile filter (%s%%, %s%%): (%0.1f, %0.1f)" % (perc[0], perc[1], dz_perc[0], dz_perc[1]))
        #This is True for invalid values
        perc_mask = ((dz < dz_perc[0]) | (dz > dz_perc[1])).filled(False)
        demmask = (demmask | perc_mask)

    if rangelim:
        #This is True for invalid values
        range_mask = ((np.abs(dz) < rangelim[0]) | (np.abs(dz) > rangelim[1])).filled(False)
        if False:
            cutoff = 150
            rangelim = (0, 80)
            low = (refdem < cutoff).data
            range_mask[low] = ((np.abs(dz) < rangelim[0]) | (np.abs(dz) > rangelim[1])).filled(False)[low]
        demmask = (demmask | range_mask)

    out = np.ma.array(dem, mask=demmask, fill_value=dem.fill_value)
    return out
1294194
def wye_to_delta(z1,z2,z3):
    """"""
    summand = z1*z2 + z2*z3 + z3*z1
    return (summand/z2,summand/z1,summand/z3)
382077
def S_star(u, dfs_data):
    """"""
    s_u = S(u, dfs_data)
    if u not in s_u:
        s_u.append(u)
    return s_u
678862
def render_delta(d):
    """"""
    s = '' if d >= 0 else '-'
    d = abs(d)

    for unit in _SORTED_UNITS:
        span = __timedelta_millis(unit[1])
        if d >= span:
            count = int(d // span)
            s += '{0}{1}'.format(count, unit[0])
            d -= count * span

    if d or not s:
        s += str(d)

    return s
23497
def _smooth(aprob, bprob, Ndiff):
    
    gamma, epsilon = _smoothing_parameters(aprob, bprob, Ndiff)

    # Remove zeros.
    in_a = [i for i,v in enumerate(aprob) if abs(v) > 0.0]
    aprob = list([list(aprob)[i] for i in in_a])
    bprob = list([list(bprob)[i]*gamma for i in in_a])

    # Replace zero values with epsilon.
    bprob = list(map(lambda v: v if v != 0. else epsilon, bprob))

    return aprob, bprob