Calculate DIRINT DNI from supplied DISC DNI and Kt'.

    Supports :py:func:`gti_dirint`
769304
def _dirint_from_dni_ktprime(dni, kt_prime, solar_zenith, use_delta_kt_prime,
                             temp_dew):
    
    times = dni.index
    delta_kt_prime = _delta_kt_prime_dirint(kt_prime, use_delta_kt_prime,
                                            times)
    w = _temp_dew_dirint(temp_dew, times)
    dirint_coeffs = _dirint_coeffs(times, kt_prime, solar_zenith, w,
                                   delta_kt_prime)
    dni_dirint = dni * dirint_coeffs
    return dni_dirint
370120
def _get_delta(self, stds, dists):
        
        delta = np.maximum((0.1-0.001*dists.repi), np.zeros_like(dists.repi))
        return delta
107311
def calc_drm(skydir, ltc, event_class, event_types,
             egy_bins, cth_bins, nbin=64):
    """"""
    npts = int(np.ceil(128. / bins_per_dec(egy_bins)))
    egy_bins = np.exp(utils.split_bin_edges(np.log(egy_bins), npts))

    etrue_bins = 10**np.linspace(1.0, 6.5, nbin * 5.5 + 1)
    egy = 10**utils.edge_to_center(np.log10(egy_bins))
    egy_width = utils.edge_to_width(egy_bins)
    etrue = 10**utils.edge_to_center(np.log10(etrue_bins))
    edisp = create_avg_edisp(skydir, ltc, event_class, event_types,
                             egy, etrue, cth_bins)
    edisp = edisp * egy_width[:, None, None]
    edisp = sum_bins(edisp, 0, npts)
    return edisp
96022
def dcm2nii(
        dcmpth,
        fimout = '',
        fprefix = 'converted-from-DICOM_',
        fcomment = '',
        outpath = '',
        timestamp = True,
        executable = '',
        force = False,
    ):
    ''' 
    '''

    # skip conversion if the output already exists and not force is selected
    if os.path.isfile(fimout) and not force:
        return fimout

    if executable=='':
        try:
            import resources
            executable = resources.DCM2NIIX
        except:
            raise NameError('e> could not import resources \
                    or find variable DCM2NIIX in resources.py')
    elif not os.path.isfile(executable):
        raise IOError('e> the executable is incorrect!')

    if not os.path.isdir(dcmpth):
        raise IOError('e> the provided DICOM path is not a folder!')

    #> output path
    if outpath=='' and fimout!='' and '/' in fimout:
        opth = os.path.dirname(fimout)
        if opth=='':
            opth = dcmpth
        fimout = os.path.basename(fimout)

    elif outpath=='':
        opth = dcmpth

    else:
        opth = outpath

    create_dir(opth)

    if fimout=='':
        fimout = fprefix
        if timestamp:
            fimout += time_stamp(simple_ascii=True)

    fimout = fimout.split('.nii')[0]


    # convert the DICOM mu-map images to nii
    call([executable, '-f', fimout, '-o', opth, dcmpth])

    fniiout = glob.glob( os.path.join(opth, '*'+fimout+'*.nii*') )

    if fniiout:
        return fniiout[0]
    else:
        raise ValueError('e> could not get the output file!')
774934
def dKdiag_dX(self, dL_dKdiag, X, target):
        """"""
        self._K_diag_computations(X)
        arg = self._K_diag_poly_arg
        target += 2.*self.weight_variance*self.degree*self.variance*X*dL_dKdiag[:, None]*(arg**(self.degree-1))[:, None]
881182
def mk_dx_dy_from_geotif_layer(geotif):
    
    ELLIPSOID_MAP = {'WGS84': 'WGS-84'}
    ellipsoid = ELLIPSOID_MAP[geotif.grid_coordinates.wkt]
    d = distance(ellipsoid=ellipsoid)
    dx = geotif.grid_coordinates.x_axis
    dy = geotif.grid_coordinates.y_axis
    dX = np.zeros((dy.shape[0]-1))
    for j in xrange(len(dX)):
        dX[j] = d.measure((dy[j+1], dx[1]), (dy[j+1], dx[0])) * 1000  # km2m
    dY = np.zeros((dy.shape[0]-1))
    for i in xrange(len(dY)):
        dY[i] = d.measure((dy[i], 0), (dy[i+1], 0)) * 1000  # km2m
    return dX, dY
1053662
def get_closest_dt_idx(dt, dt_list):
    
    from pygeotools.lib import malib
    dt_list = malib.checkma(dt_list, fix=False)
    dt_diff = np.abs(dt - dt_list)
    return dt_diff.argmin()
334831
function getSqDist(p1, p2) {

    var dx = p1[0] - p2[0],
        dy = p1[1] - p2[1];

    return dx * dx + dy * dy;
}
502133
def Kdiag(self, X):
        """"""
        vyt = self.variance_Yt
        vyx = self.variance_Yx

        lyt = 1./(2*self.lengthscale_Yt)
        lyx = 1./(2*self.lengthscale_Yx)

        a = self.a
        b = self.b
        c = self.c

        ## dk^2/dtdt'
        k1 = (2*lyt )*vyt*vyx
        ## dk^2/dx^2
        k2 = ( - 2*lyx )*vyt*vyx
        ## dk^4/dx^2dx'^2
        k3 = ( 4*3*lyx**2 )*vyt*vyx


        Kdiag = np.zeros(X.shape[0])
        slices = index_to_slices(X[:,-1])

        for i, ss1 in enumerate(slices):
            for s1 in ss1:
                if i==0:
                    Kdiag[s1]+= vyt*vyx
                elif i==1:
                    #i=1
                    Kdiag[s1]+= b**2*k1 - 2*a*c*k2 + a**2*k3 + c**2*vyt*vyx
                    #Kdiag[s1]+= Vu*Vy*(k1+k2+k3)
                else:
                    raise ValueError("invalid input/output index")

        return Kdiag
315820
def dK_dr_via_X(self, X, X2):
        
        #a convenience function, so we can cache dK_dr
        return self.dK_dr(self._scaled_dist(X, X2))
241128
def dovds(data):
    
    vds, X = 0, []
    for rec in data:
        X.append(dir2cart(rec))
    for k in range(len(X) - 1):
        xdif = X[k + 1][0] - X[k][0]
        ydif = X[k + 1][1] - X[k][1]
        zdif = X[k + 1][2] - X[k][2]
        vds += np.sqrt(xdif**2 + ydif**2 + zdif**2)
    vds += np.sqrt(X[-1][0]**2 + X[-1][1]**2 + X[-1][2]**2)
    return vds
510382
def total(self, xbin1=1, xbin2=-2):
        
        integral, stat_error = self.hist.integral(
            xbin1=xbin1, xbin2=xbin2, error=True)
        # sum systematics in quadrature
        ups = [0]
        dns = [0]
        for sys_name in self.sys_names():
            sys_low, sys_high = self.sys_hist(sys_name)
            up = sys_high.integral(xbin1=xbin1, xbin2=xbin2) - integral
            dn = sys_low.integral(xbin1=xbin1, xbin2=xbin2) - integral
            if up > 0:
                ups.append(up**2)
            else:
                dns.append(up**2)
            if dn > 0:
                ups.append(dn**2)
            else:
                dns.append(dn**2)
        syst_error = (sqrt(sum(ups)), sqrt(sum(dns)))
        return integral, stat_error, syst_error
18825
def Kdiag(self, X, target):
        """"""
        self._K_diag_computations(X)
        target+= self.variance*self._K_diag_dvar
937832
def _forceInt(x,y,z,dens,b2,c2,i,glx=None,glw=None):
    """"""
    def integrand(s):
        t= 1/s**2.-1.
        return dens(numpy.sqrt(x**2./(1.+t)+y**2./(b2+t)+z**2./(c2+t)))\
            *(x/(1.+t)*(i==0)+y/(b2+t)*(i==1)+z/(c2+t)*(i==2))\
            /numpy.sqrt((1.+(b2-1.)*s**2.)*(1.+(c2-1.)*s**2.))
    if glx is None:
        return integrate.quad(integrand,0.,1.)[0]                              
    else:
        return numpy.sum(glw*integrand(glx))
763014
def Kdiag(self, X):
        """"""
        ret = np.empty(X.shape[0])
        ret[:] = self.variance
        return ret
1162209
def dKdiag_dX(self, dL_dKdiag, X, target):
        """"""
        target += 2.*self.mapping.df_dX(dL_dKdiag[:, None], X)*self.mapping.f(X)
1327639
def position_d(self):
        
        self._position_d, value = self.get_attr_int(self._position_d, 'hold_pid/Kd')
        return value