Exemple #1
0
 def disvecinf(self, x, y, aq=None):
     if aq is None:
         aq = self.model.aq.find_aquifer_data(x, y)
     rv = np.zeros((2, self.nparam, aq.naq))
     if aq == self.aq:
         qx = np.zeros(aq.naq)
         qy = np.zeros(aq.naq)
         rsq = (x - self.xw) ** 2 + (y - self.yw) ** 2
         r = np.sqrt(rsq)
         xminxw = x - self.xw
         yminyw = y - self.yw
         if r < self.rw:
             r = self.rw
             rsq = r ** 2
             xminxw = self.rw
             yminyw = 0.0
         if aq.ilap:
             qx[0] = -1 / (2 * np.pi) * xminxw / rsq
             qy[0] = -1 / (2 * np.pi) * yminyw / rsq
             kone = k1(r / aq.lab[1:])
             qx[1:] = -kone * xminxw / (r * aq.lab[1:]) / (2 * np.pi)
             qy[1:] = -kone * yminyw / (r * aq.lab[1:]) / (2 * np.pi)
         else:
             kone = k1(r / aq.lab)
             qx[:] = -kone * xminxw / (r * aq.lab) / (2 * np.pi)
             qy[:] = -kone * yminyw / (r * aq.lab) / (2 * np.pi)
         rv[0] = self.aq.coef[self.layers] * qx
         rv[1] = self.aq.coef[self.layers] * qy
     return rv
Exemple #2
0
 def disvecinf(self, x, y, aq=None):
     if aq is None: aq = self.model.aq.find_aquifer_data(x, y)
     rv = np.zeros((2, self.nparam, aq.naq))
     if aq == self.aq:
         qx = np.zeros(aq.naq)
         qy = np.zeros(aq.naq)
         rsq = (x - self.xw) ** 2 + (y - self.yw) ** 2
         r = np.sqrt(rsq)
         xminxw = x - self.xw
         yminyw = y - self.yw
         if r < self.rw:
             r = self.rw
             rsq = r ** 2
             xminxw = self.rw
             yminyw = 0.0
         if aq.ilap:
             qx[0] = -1 / (2 * np.pi) * xminxw / rsq
             qy[0] = -1 / (2 * np.pi) * yminyw / rsq
             kone = k1(r / aq.lab[1:])
             qx[1:] = -kone * xminxw / (r * aq.lab[1:]) / (2 * np.pi)
             qy[1:] = -kone * yminyw / (r * aq.lab[1:]) / (2 * np.pi)
         else:
             kone = k1(r / aq.lab)
             qx[:] = -kone * xminxw / (r * aq.lab) / (2 * np.pi)
             qy[:] = -kone * yminyw / (r * aq.lab) / (2 * np.pi)
         rv[0] = self.aq.coef[self.layers] * qx
         rv[1] = self.aq.coef[self.layers] * qy
     return rv
Exemple #3
0
def T6fun(i, x):
    betah = (locs['a'])[i] * (locs['k'])[i] * locs['alpha'][i]
    betam = par['am'] * par['km'] * par['alpha_m']
    a = numpy.zeros([2, 2])
    a[0, 0] = i0(locs['alpha'][i] * locs['rad'][i])
    a[1, 0] = betah * i1(locs['alpha'][i] * locs['rad'][i])
    a[0, 1] = -k0(par['alpha_m'] * locs['rad'][i])
    a[1, 1] = betam * k1(par['alpha_m'] * locs['rad'][i])
    ## b is markedly different in zheng2009 and confirm.nb
    ## this is now the confirm.nb version
    b = numpy.zeros([2, 1])
    b[0] = (1.0 / par['cm']) - (locs['rad'][i] *
                                k0(locs['alpha'][i] * locs['rad'][i]) *
                                i1(locs['alpha'][i] * locs['rad'][i]) /
                                ((locs['a'])[i] * locs['alpha'][i]))
    b[1] = ((locs['k'])[i] * locs['rad'][i] *
            k1(locs['alpha'][i] * locs['rad'][i]) *
            i1(locs['alpha'][i] * locs['rad'][i]))
    const = (inv(a)).dot(b)
    qh = ((1.0 / (locs['c'])[i]) *
          (1.0 - locs['alpha'][i] * locs['rad'][i] * i0(locs['alpha'][i] * x) *
           k1(locs['alpha'][i] * locs['rad'][i])))
    if (x < locs['rad'][i]):
        return const[0] * i0(locs['alpha'][i] * x) + qh
    else:
        return const[1] * k0(par['alpha_m'] * x) + (1.0 / par['cm'])
Exemple #4
0
def B4B1(s, H_g, kappa, r_Db):
    numerator = kappa * math.sqrt(H_g * s / kappa) * sp.i1(r_Db * math.sqrt(H_g * s / kappa)) * sp.k0(
        r_Db * math.sqrt(H_g * s / kappa)) + kappa * math.sqrt(H_g * s / kappa) * sp.i0(
        r_Db * math.sqrt(H_g * s / kappa)) * sp.k1(r_Db * math.sqrt(H_g * s / kappa))
    denominator = kappa * math.sqrt(H_g * s / kappa) * sp.k1(r_Db * math.sqrt(H_g * s / kappa)) * sp.k0(
        r_Db * math.sqrt(s)) - math.sqrt(s) * sp.k0(r_Db * math.sqrt(H_g * s / kappa)) * sp.k1(r_Db * math.sqrt(s))
    rt = numerator / denominator
    return rt
Exemple #5
0
def Gamma(nw_rad, lay_ox, L_d, L_tf, eps_1, eps_2, eps_3): 
    fact1 = (nw_rad + lay_ox)/L_d
    fact2 = nw_rad/L_tf
    fact3 = fact1**(-1)
    fact4 = (nw_rad + lay_ox)/nw_rad 
    num    = eps_1*k0(fact1)*(L_d/L_tf)*i1(fact2)
    denom1 = k0(fact1)*fact3 
    denom2 = log(fact4)*k1(fact1)*(eps_3/eps_2)
    denom3 = (denom1 + denom2)*eps_1*fact2*i1(fact2) 
    denom  = denom3 + eps_3*k1(fact1)*i0(fact2) 
    gamma = num/denom 
    return gamma
Exemple #6
0
def Gamma(nw_rad, lay_ox, L_d, L_tf, eps_1, eps_2, eps_3):
    fact1 = (nw_rad + lay_ox) / L_d
    fact2 = nw_rad / L_tf
    fact3 = fact1**(-1)
    fact4 = (nw_rad + lay_ox) / nw_rad
    num = eps_1 * k0(fact1) * (L_d / L_tf) * i1(fact2)
    denom1 = k0(fact1) * fact3
    denom2 = log(fact4) * k1(fact1) * (eps_3 / eps_2)
    denom3 = (denom1 + denom2) * eps_1 * fact2 * i1(fact2)
    denom = denom3 + eps_3 * k1(fact1) * i0(fact2)
    gamma = num / denom
    return gamma
Exemple #7
0
 def test_besselk1(self):
     xs = [0.1, 1.0, 10.0]
     for x in xs:
         sp = k1(x)
         hal = besselk1(x)
         relerr = abs((sp - hal) / sp)
         self.assertLessEqual(relerr, 0.05)
Exemple #8
0
def exponential_velocity(r, rd, vmax):
    """
    Velocity function for an exponential profile
	r and rd must be in the same units

	Parameters
	----------
	r : array
		radial positions where the model is to be computed
    rd : float
		radius at which the maximum velocity is reached
    vmax : float
		Maximum velocity of the model

	Returns
	-------
	Array with the same shape of r, containing the model velocity curve/map

    """

    # disk scale length
    rd2 = rd / 2.15
    vr = np.zeros(np.shape(r))
    # to prevent any problem in the center
    q = np.where(r != 0)
    vr[q] = r[q] / rd2 * vmax / 0.88 * np.sqrt(
        i0(0.5 * r[q] / rd2) * k0(0.5 * r[q] / rd2) -
        i1(0.5 * r[q] / rd2) * k1(0.5 * r[q] / rd2))
    return vr
Exemple #9
0
    def tetmConstants(self, ri, ro, neff, wl, EH, c, idx):
        a = numpy.empty((2, 2))
        n = self.maxIndex(wl)
        u = self.u(ro, neff, wl)
        urp = self.u(ri, neff, wl)

        if neff < n:
            B1 = j0(u)
            B2 = y0(u)
            F1 = j0(urp) / B1
            F2 = y0(urp) / B2
            F3 = -j1(urp) / B1
            F4 = -y1(urp) / B2
            c1 = wl.k0 * ro / u
        else:
            B1 = i0(u)
            B2 = k0(u)
            F1 = i0(urp) / B1
            F2 = k0(urp) / B2
            F3 = i1(urp) / B1
            F4 = -k1(urp) / B2
            c1 = -wl.k0 * ro / u
        c3 = c * c1

        a[0, 0] = F1
        a[0, 1] = F2
        a[1, 0] = F3 * c3
        a[1, 1] = F4 * c3

        return numpy.linalg.solve(a, EH.take(idx))
Exemple #10
0
def PotDisk(n,r):
  "n: order of differentiation"
  rratio  =0.5*r/r0
  if n==1:
    dPhidr_disk  =(G*Md*r/(2.*r0*r0*r0)) * (i0(rratio)*k0(rratio)-i1(rratio)*k1(rratio))
    return dPhidr_disk
  elif n==2:
    d2Phidr2_disk=(G*Md  /(4.*r0*r0*r0)) * (-rratio*iv(2,rratio)*k1(rratio) + i0(rratio)*(2*k0(rratio)-3.*rratio*k1(rratio)) + i1(rratio)*(3.*rratio*k0(rratio)-2.*k1(rratio)+rratio*kn(2,rratio)) )
    return d2Phidr2_disk
  elif n=='v':
    dPhidr_disk  =(G*Md*r/(2.*r0*r0*r0)) * (i0(rratio)*k0(rratio)-i1(rratio)*k1(rratio))
    Vc  =  np.sqrt(r*dPhidr_disk)
    return Vc
  else:
    Phi_disk     =(-G*Md*r/(2.*r0*r0)) * (i0(rratio)*k1(rratio)-i1(rratio)*k0(rratio))
    return Phi_disk
Exemple #11
0
    def tetmConstants(self, ri, ro, neff, wl, EH, c, idx):
        a = numpy.empty((2, 2))
        n = self.maxIndex(wl)
        u = self.u(ro, neff, wl)
        urp = self.u(ri, neff, wl)

        if neff < n:
            B1 = j0(u)
            B2 = y0(u)
            F1 = j0(urp) / B1
            F2 = y0(urp) / B2
            F3 = -j1(urp) / B1
            F4 = -y1(urp) / B2
            c1 = wl.k0 * ro / u
        else:
            B1 = i0(u)
            B2 = k0(u)
            F1 = i0(urp) / B1
            F2 = k0(urp) / B2
            F3 = i1(urp) / B1
            F4 = -k1(urp) / B2
            c1 = -wl.k0 * ro / u
        c3 = c * c1

        a[0, 0] = F1
        a[0, 1] = F2
        a[1, 0] = F3 * c3
        a[1, 1] = F4 * c3

        return numpy.linalg.solve(a, EH.take(idx))
Exemple #12
0
def calculate_1D_truncated_coulomb(pd, q_v=None, N_c=None):
    """ Simple 1D truncation of Coulomb kernel PRB 73, 205119.
    The periodic direction is determined from k-point grid.
    """

    from scipy.special import j1, k0, j0, k1

    qG_Gv = pd.get_reciprocal_vectors(add_q=True)
    if pd.kd.gamma:
        if q_v is not None:
            qG_Gv += q_v
        else:
            raise ValueError('Presently, calculations only work with a small q in the normal direction')

    # The periodic direction is determined from k-point grid
    Nn_c = np.where(N_c == 1)[0]
    Np_c = np.where(N_c != 1)[0]
    if len(Nn_c) != 2:
        # The k-point grid does not fit with boundary conditions
        Nn_c = [0, 1]    # Choose reduced cell vectors 0, 1
        Np_c = [2]       # Choose reduced cell vector 2
    # The radius is determined from area of non-periodic part of cell
    Acell_cv = pd.gd.cell_cv[Nn_c, :][:, Nn_c]
    R = (np.linalg.det(Acell_cv) / np.pi)**0.5

    qGnR_G = (qG_Gv[:, Nn_c[0]]**2 + qG_Gv[:, Nn_c[1]]**2)**0.5 * R
    qGpR_G = abs(qG_Gv[:, Np_c[0]]) * R
    v_G = 4 * np.pi / (qG_Gv**2).sum(axis=1)
    v_G *= (1.0 + qGnR_G * j1(qGnR_G) * k0(qGpR_G)
            - qGpR_G * j0(qGnR_G) * k1(qGpR_G))

    return v_G.astype(complex)
Exemple #13
0
def Vd(R, Rd, sigma_0):

    y = R / (2 * Rd)

    return np.sqrt(
        4 * np.pi * G * sigma_0 * Rd * y**2 *
        [special.i0(y) * special.k0(y) - special.i1(y) * special.k1(y)][0])
 def _evaluate(self, R, z, phi=0., t=0.):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the potential at (R,z)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        potential at (R,z)
     HISTORY:
        2012-12-26 - Written - Bovy (IAS)
     """
     if self._new:
         #if R > 6.: return self._kp(R,z)
         if nu.fabs(z) < 10.**-6.:
             y = 0.5 * self._alpha * R
             return -nu.pi * R * (special.i0(y) * special.k1(y) -
                                  special.i1(y) * special.k0(y))
         kalphamax = 10.
         ks = kalphamax * 0.5 * (self._glx + 1.)
         weights = kalphamax * self._glw
         sqrtp = nu.sqrt(z**2. + (ks + R)**2.)
         sqrtm = nu.sqrt(z**2. + (ks - R)**2.)
         evalInt = nu.arcsin(2. * ks / (sqrtp + sqrtm)) * ks * special.k0(
             self._alpha * ks)
         return -2. * self._alpha * nu.sum(weights * evalInt)
     raise NotImplementedError(
         "Not new=True not implemented for RazorThinExponentialDiskPotential"
     )
 def _evaluate(self,R,z,phi=0.,t=0.):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the potential at (R,z)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        potential at (R,z)
     HISTORY:
        2012-12-26 - Written - Bovy (IAS)
     """
     if self._new:
         #if R > 6.: return self._kp(R,z)
         if nu.fabs(z) < 10.**-6.:
             y= 0.5*self._alpha*R
             return -nu.pi*R*(special.i0(y)*special.k1(y)-special.i1(y)*special.k0(y))
         kalphamax= 10.
         ks= kalphamax*0.5*(self._glx+1.)
         weights= kalphamax*self._glw
         sqrtp= nu.sqrt(z**2.+(ks+R)**2.)
         sqrtm= nu.sqrt(z**2.+(ks-R)**2.)
         evalInt= nu.arcsin(2.*ks/(sqrtp+sqrtm))*ks*special.k0(self._alpha*ks)
         return -2.*self._alpha*nu.sum(weights*evalInt)
     raise NotImplementedError("Not new=True not implemented for RazorThinExponentialDiskPotential")
Exemple #16
0
    def w_minus(self, r):

        if self.r0 == 1:

            return r * 0

        return (special.i1(np.sqrt(self.Pi) * r) * self.nu_1(r) / r +
                special.k1(np.sqrt(self.Pi) * r) * self.nu_2(r) / r)
Exemple #17
0
    def _tefield(self, wl, nu, neff, r):
        rho = self.fiber.outerRadius(0)
        k = wl.k0
        nco2 = self.fiber.maxIndex(0, wl)**2
        ncl2 = self.fiber.minIndex(1, wl)**2
        u = rho * k * sqrt(nco2 - neff**2)
        w = rho * k * sqrt(neff**2 - ncl2)

        if r < rho:
            hz = -Y0 * u / (k * rho) * j0(u * r / rho) / j1(u)
            ephi = -j1(u * r / rho) / j1(u)
        else:
            hz = Y0 * w / (k * rho) * k0(w * r / rho) / k1(w)
            ephi = -k1(w * r / rho) / k1(w)
        hr = -neff * Y0 * ephi

        return numpy.array((0, ephi, 0)), numpy.array((hr, 0, hz))
Exemple #18
0
    def _tefield(self, wl, nu, neff, r):
        rho = self.fiber.outerRadius(0)
        k = wl.k0
        nco2 = self.fiber.maxIndex(0, wl)**2
        ncl2 = self.fiber.minIndex(1, wl)**2
        u = rho * k * sqrt(nco2 - neff**2)
        w = rho * k * sqrt(neff**2 - ncl2)

        if r < rho:
            hz = -Y0 * u / (k * rho) * j0(u * r / rho) / j1(u)
            ephi = -j1(u * r / rho) / j1(u)
        else:
            hz = Y0 * w / (k * rho) * k0(w * r / rho) / k1(w)
            ephi = -k1(w * r / rho) / k1(w)
        hr = -neff * Y0 * ephi

        return numpy.array((0, ephi, 0)), numpy.array((hr, 0, hz))
Exemple #19
0
def rotation_velocity(pos):
  rho = (pos[0]**2 + pos[1]**2)**0.5
  phi = np.arctan2(pos[1], pos[0])
  y = rho/(2*Rd)
  sigma0 = M_dm / (2*pi*Rd**2)
  speed = (4*pi*G*sigma0*y**2*(i0(y)*k0(y) - i1(y)*k1(y)) +
           (G*M_dm*rho)/(rho+a_dm)**2 + (G*M_bulge*rho)/(rho+a_bulge)**2)**0.5
  return (-speed*sin(phi), speed*cos(phi), 0)
def C0(s, N_s, N_w, H_g, kappa, r_Db):
    rt = 1.0 - 1.0 / (
        1.0 - kappa * N_s / 2 / N_w * math.sqrt(H_g * s / kappa) *
        (sp.i1(math.sqrt(H_g * s / kappa)) -
         B2B1(s, H_g, kappa, r_Db) * sp.k1(math.sqrt(H_g * s / kappa))) /
        (sp.i0(math.sqrt(H_g * s / kappa)) +
         B2B1(s, H_g, kappa, r_Db) * sp.k0(math.sqrt(H_g * s / kappa))))
    return rt
Exemple #21
0
def gendata(X):
    l = '%5s%23s%23s%23s%23s%23s%23s%23s%23s\n' % ('x', 'I0', 'I1', 'I2', 'I3',
                                                   'K0', 'K1', 'K2', 'K3')
    for i, x in enumerate(X):
        l += '%5.2f%23.15e%23.15e%23.15e%23.15e%23.15e%23.15e%23.15e%23.15e\n' % (
            x, sp.i0(x), sp.i1(x), sp.iv(2, x), sp.iv(
                3, x), sp.k0(x), sp.k1(x), sp.kn(2, x), sp.kn(3, x))
    return l
Exemple #22
0
    def backward(ctx, grad_output):
        input, = ctx.saved_tensors
        dev = grad_output.device
        with torch.no_grad():
            grad_input = grad_output*(-special.k1(input.detach().cpu())).to(dev)
            input.to(dev)

        return grad_input
Exemple #23
0
    def _tmfield(self, wl, nu, neff, r):
        rho = self.fiber.outerRadius(0)
        k = wl.k0
        nco2 = self.fiber.maxIndex(0, wl)**2
        ncl2 = self.fiber.minIndex(1, wl)**2
        u = rho * k * sqrt(nco2 - neff**2)
        w = rho * k * sqrt(neff**2 - ncl2)

        if r < rho:
            ez = -u / (k * neff * rho) * j0(u * r / rho) / j1(u)
            er = j1(u * r / rho) / j1(u)
            hphi = Y0 * nco2 / neff * er
        else:
            ez = nco2 / ncl2 * w / (k * neff * rho) * k0(w * r / rho) / k1(w)
            er = nco2 / ncl2 * k1(w * r / rho) / k1(w)
            hphi = Y0 * nco2 / ncl2 * k1(w * r / rho) / k1(w)

        return numpy.array((er, 0, ez)), numpy.array((0, hphi, 0))
Exemple #24
0
def get_vcirc_expo(R, Mgas=3e10, Rd=4.0):
    sigma0 = Mgas / (2.0 * np.pi * Rd**2)
    sigma = sigma0 * np.exp(-R / Rd)
    y = R / (2.0 * Rd)
    I0 = special.i0(y)
    K0 = special.k0(y)
    I1 = special.i1(y)
    K1 = special.k1(y)
    return np.sqrt(4.0 * np.pi * G * sigma0 * Rd * y**2 * (I0 * K0 - I1 * K1))
Exemple #25
0
def rotation_velocity(pos):
    rho = (pos[0]**2 + pos[1]**2)**0.5
    phi = np.arctan2(pos[1], pos[0])
    y = rho / (2 * Rd)
    sigma0 = M_dm / (2 * pi * Rd**2)
    speed = (4 * pi * G * sigma0 * y**2 * (i0(y) * k0(y) - i1(y) * k1(y)) +
             (G * M_dm * rho) / (rho + a_dm)**2 + (G * M_bulge * rho) /
             (rho + a_bulge)**2)**0.5
    return (-speed * sin(phi), speed * cos(phi), 0)
Exemple #26
0
    def _tmfield(self, wl, nu, neff, r):
        rho = self.fiber.outerRadius(0)
        k = wl.k0
        nco2 = self.fiber.maxIndex(0, wl)**2
        ncl2 = self.fiber.minIndex(1, wl)**2
        u = rho * k * sqrt(nco2 - neff**2)
        w = rho * k * sqrt(neff**2 - ncl2)

        if r < rho:
            ez = -u / (k * neff * rho) * j0(u * r / rho) / j1(u)
            er = j1(u * r / rho) / j1(u)
            hphi = Y0 * nco2 / neff * er
        else:
            ez = nco2 / ncl2 * w / (k * neff * rho) * k0(w * r / rho) / k1(w)
            er = nco2 / ncl2 * k1(w * r / rho) / k1(w)
            hphi = Y0 * nco2 / ncl2 * k1(w * r / rho) / k1(w)

        return numpy.array((er, 0, ez)), numpy.array((0, hphi, 0))
Exemple #27
0
def get_integrated_kernel(pd, N_c, truncation=None, N=100, reduced=False):
    from scipy.special import j1, k0, j0, k1

    B_cv = 2 * np.pi * pd.gd.icell_cv
    Nf_c = np.array([N, N, N])
    if reduced:
        # Only integrate periodic directions if truncation is used
        Nf_c[np.where(N_c == 1)[0]] = 1
    q_qc = monkhorst_pack(Nf_c) / N_c
    q_qc += pd.kd.ibzk_kc[0]
    q_qv = np.dot(q_qc, B_cv)

    if truncation is None:
        V_q = 4 * np.pi / np.sum(q_qv**2, axis=1)
    elif truncation == '2D':
        # The non-periodic direction is determined from k-point grid
        Nn_c = np.where(N_c == 1)[0]
        Np_c = np.where(N_c != 1)[0]
        if len(Nn_c) != 1:
            # The k-point grid does not fit with boundary conditions
            Nn_c = [2]  # Choose reduced cell vectors 0, 1
            Np_c = [0, 1]  # Choose reduced cell vector 2
        # Truncation length is half of cell vector in non-periodic direction
        R = pd.gd.cell_cv[Nn_c[0], Nn_c[0]] / 2.

        qp_q = ((q_qv[:, Np_c[0]])**2 + (q_qv[:, Np_c[1]]**2))**0.5
        qn_q = q_qv[:, Nn_c[0]]

        V_q = 4 * np.pi / (q_qv**2).sum(axis=1)
        a_q = qn_q / qp_q * np.sin(qn_q * R) - np.cos(qn_q * R)
        V_q *= 1. + np.exp(-qp_q * R) * a_q
    elif truncation == '1D':
        # The non-periodic direction is determined from k-point grid
        Nn_c = np.where(N_c == 1)[0]
        Np_c = np.where(N_c != 1)[0]

        if len(Nn_c) != 2:
            # The k-point grid does not fit with boundary conditions
            Nn_c = [0, 1]  # Choose reduced cell vectors 0, 1
            Np_c = [2]  # Choose reduced cell vector 2
        # The radius is determined from area of non-periodic part of cell
        Acell_cv = pd.gd.cell_cv[Nn_c, :][:, Nn_c]
        R = (np.linalg.det(Acell_cv) / np.pi)**0.5

        qnR_q = (q_qv[:, Nn_c[0]]**2 + q_qv[:, Nn_c[1]]**2)**0.5 * R
        qpR_q = abs(q_qv[:, Np_c[0]]) * R
        V_q = 4 * np.pi / (q_qv**2).sum(axis=1)
        V_q *= (1.0 + qnR_q * j1(qnR_q) * k0(qpR_q) -
                qpR_q * j0(qnR_q) * k1(qpR_q))
    elif truncation == '0D' or 'wigner-seitz':
        R = (3 * np.linalg.det(pd.gd.cell_cv) / (4 * np.pi))**(1. / 3.)
        q2_q = (q_qv**2).sum(axis=1)
        V_q = 4 * np.pi / q2_q
        V_q *= 1.0 - np.cos(q2_q**0.5 * R)

    return np.sum(V_q) / len(V_q), np.sum(V_q**0.5) / len(V_q)
def tRelax_e_rel(E, r):
    n_e = eDens(r)
    theta = boltzmann * electronTemp(r) / electronRestEnergy
    k1 = sp.k1(1.0 / theta)
    k2 = sp.kn(2, 1.0 / theta)
    g = E / electronRestEnergy
    factor = np.power(np.abs(k1 / k2 - 1.0 / g), -1)
    return 2.0 / 3.0 * g / (
        n_e * thomson * cLight *
        (20.0 + 9.0 / 16.0 - np.log(np.sqrt(2.0)))) * factor
Exemple #29
0
def pdf(x,Θ):
    """
    x.shape = () : value in nig support (-∞,∞)
    Θ.shape = (4,) : nig params
    """
    μ,δ,β,γ = Θ
    α = np.sqrt(β**2 + γ**2)
    ϕ = np.sqrt(δ**2 + (x - μ)**2)
    ρ = α*δ*k1(α*ϕ)/np.pi/ϕ*np.exp(δ*γ + β*(x - μ))
    return ρ
Exemple #30
0
    def get_two_parts(self):

        # get rid of x1 and x2 as they're not needed
        x1 = -1.
        x2 = -1.

        if self.physics.D == 3:

            if self.physics.coupling == 'linear' and self.high_density:

                # coefficient for two-part solution
                A = (1. + np.sqrt(2.) * self.x0) * (1. - self.phi_c) / (
                    np.cos(self.x0) + np.sqrt(2.) * np.sin(self.x0))
                # test for validity of two-part solution
                two_parts = (self.phi_c + A * np.sin(self.x0) / self.x0 >
                             5. / 6.)

            else:
                A = (1. + np.sqrt(2.)*self.x0 ) * (1.-self.phi_c)/(self.nu_eff*np.cosh(self.nu_eff*self.x0)+ \
                                                                   np.sqrt(2.)*np.sinh(self.nu_eff*self.x0))

                two_parts = (
                    self.phi_c + A * np.sinh(self.nu_eff * self.x0) / self.x0 >
                    5. / 6.)

        elif self.physics.D == 2:

            if self.physics.coupling == 'linear' and self.high_density:
                A = np.sqrt(2.)*(1.-self.phi_c)*k1(np.sqrt(2.)*self.x0)/ \
                    (-j1(self.x0)*k0(np.sqrt(2.)*self.x0)+np.sqrt(2.)*j0(self.x0)*k1(np.sqrt(2.)*self.x0))
                two_parts = (self.phi_c + A * j0(self.x0) > 5. / 6.)

            else:

                A = np.sqrt(2.)*(1.-self.phi_c)*k1(np.sqrt(2.)*self.x0)/ \
                    (self.nu_eff*i1(self.nu_eff*self.x0)*k0(np.sqrt(2.)*self.x0)+\
                     np.sqrt(2.)*i0(self.nu_eff*self.x0)*k1(np.sqrt(2.)*self.x0))
                # test for validity of two-part solution
                two_parts = (self.phi_c + A * i0(self.nu_eff * self.x0) >
                             5. / 6.)

        return x1, x2, two_parts
Exemple #31
0
 def get_vcirc_disk(self, r):
     sigma0 = (self.Mgal *
               (1.0 - self.f_mbulge)) / (2.0 * np.pi * self.Rd**2)
     sigma = sigma0 * np.exp(-r / self.Rd)
     y = r / (2.0 * self.Rd)
     I0 = special.i0(y)
     K0 = special.k0(y)
     I1 = special.i1(y)
     K1 = special.k1(y)
     return np.sqrt(4.0 * np.pi * self.G * sigma0 * self.Rd * y**2 *
                    (I0 * K0 - I1 * K1))
Exemple #32
0
    def mu_incl_exp_func(r, mu_0z, z0, case):
        s = np.array([0.0] * len(r))
        for i in range(0, len(r)):
            if case == 'r0':
                s[i] = -1.0 * (mu_0z - 5.0 * np.log10(1.0 / cosh(r[i] / z0)))
            if case == 'z0':
                s[i] = -1.0 * (mu_0z - 2.5 * np.log10(r[i] / z0 * k1(r[i] / z0)))

        if r[0] == 0.0:
            s[0] = -1.0 * mu_0z
        return s*-1.0
def tRelax_e_rel_exact(E, r):
    n_e = eDens(r)
    theta = boltzmann * electronTemp(r) / electronRestEnergy
    k1 = sp.k1(1.0 / theta)
    k2 = sp.kn(2, 1.0 / theta)
    g = E / electronRestEnergy
    factor = np.power(
        np.abs(np.vectorize(integ.quad)(integrand2, 0.0, 20.0, args=(g))[0]),
        -1)
    return 4.0 / 3.0 * k2 * g * g * g / (
        n_e * thomson * cLight *
        (20.0 + 9.0 / 16.0 - np.log(np.sqrt(2.0)))) * factor
Exemple #34
0
 def ZTransISC(self):
     if self.beam.gammarel == float('inf'):
         ZTrans_ISC = np.zeros(len(self.f)) + 1.j * np.zeros(len(self.f))
         return ZTrans_ISC
     kbess = 2 * const.pi * self.f / (self.beam.betarel * const.c)
     argbess0 = kbess * self.beam.test_beam_shift / self.beam.gammarel
     argbess1 = kbess * self.chamber.pipe_rad_m / self.beam.gammarel
     BessBeamTISC = -k1(argbess1) / i1(argbess1)
     # transverse indirect space charge
     if (self.beam.test_beam_shift == 0.):
         BessA = kbess**2 / (2 * self.beam.gammarel * self.beam.gammarel) \
                 * k1(argbess1) / i1(argbess1)
         ZTrans_ISC = (
             1.j * Z0 * self.chamber.pipe_len_m * BessA /
             (2 * const.pi * self.beam.gammarel**2 * self.beam.betarel))
     else:
         BessBeamT = (i1(argbess0) / self.beam.test_beam_shift)**2
         ZTrans_ISC = -(
             1.j * Z0 * self.chamber.pipe_len_m * BessBeamT * BessBeamTISC /
             (const.pi * self.beam.gammarel**2 * self.beam.betarel))
     return ZTrans_ISC
Exemple #35
0
    def w_minus_prime(self, r):

        if self.r0 == 1:

            return r * 0

        sPi = np.sqrt(self.Pi)

        return (sPi * special.ivp(1, sPi * r, 1) * self.nu_1(r) / r +
                special.i1(sPi * r) * self.nu_1_prime(r) / r +
                sPi * special.kvp(1, sPi * r, 1) * self.nu_2(r) / r +
                special.k1(sPi * r) * self.nu_2_prime(r) / r -
                self.w_minus(r) / r)
Exemple #36
0
def _Dsk_integral_fixed_quad(k, y, Nquad):

    # Get numerical quadrature nodes and weight
    nodes, weights = p_roots(Nquad)

    # Rescale for integration interval from [-1,1] to [-pi,pi]
    nodes = nodes * np.pi
    weights = weights * 0.5
    arg1 = 2 * k * (1 + y * np.cos(nodes)) / 3
    arg2 = k * nodes + 4 * k * y * np.sin(nodes) / 3
    integrand = -2 * k * k1(arg1) * np.cos(nodes) * np.cos(
        arg2) / 3 - 4 * k * k0(arg1) * np.sin(nodes) * np.sin(arg2) / 3
    return (2 / np.pi) * integrand @ weights
Exemple #37
0
def calculatefx(fov=1000.0, plam=7.7e4, dlam=0.0):
    # fov: diameter of field-of-view [km]
    # plam: Molecular lifetime of parent [km], if molecule is parent use plam = 0
    # dlam: Molecular lifetime of daughter [km]
    if fov == 0 or plam == 0.0: return 0.0
    x = 0.5 * fov / plam
    if dlam == 0.0:
        # Parent molecule
        gx = 1.0 / x
        gx += -special.k1(x)
        gx += np.pi / 2.0 - special.iti0k0(x)[1]
        fx = x * gx
    else:
        # Daughter molecule
        u2 = plam / dlam
        if u2 == 1.0: u2 = 1.001
        gx = 1.0 / (u2 * x) - 1.0 / x
        gx += -special.k1(u2 * x) + special.k1(x)
        gx += -special.iti0k0(u2 * x)[1] + special.iti0k0(x)[1]
        fx = (u2 * x / (1.0 - u2)) * gx
    #Endelse
    return fx
Exemple #38
0
 def I1RK1r(self, rin):
     rv = np.zeros(len(self.lab))
     if self.islarge.any():
         index = (rin - self.R) / self.labbig < 10
         if index.any():
             r = rin / self.labbig[index]
             R = self.R / self.labbig[index]
             rv[self.islarge * index] = np.sqrt(1 / (4 * r * R)) * np.exp(R - r) * \
                                (1 - 3 / (8 * R) - 15 / (128 * R ** 2) - 315 / (3072 * R ** 3)) * \
                                (1 + 3 / (8 * r) - 15 / (128 * r ** 2) + 315 / (3072 * r ** 3))
     if ~self.islarge.any():
         index = (self.R - rin) / self.labsmall < 10
         if index.any():
             r = rin / self.labsmall[index]
             rv[~self.islarge * index] = self.i1Roverlab[index] * k1(r)
     return rv
Exemple #39
0
    def _teceq(self, neff, wl, nu):
        N = len(self.fiber)
        EH = numpy.empty(4)
        ri = 0

        for i in range(N-1):
            ro = self.fiber.outerRadius(i)
            self.fiber.layers[i].EH_fields(ri, ro, nu, neff, wl, EH, False)
            ri = ro

        # Last layer
        _, Hz, Ep, _ = EH
        u = self.fiber.layers[-1].u(ri, neff, wl)

        F4 = k1(u) / k0(u)
        return Ep + wl.k0 * ri / u * constants.eta0 * Hz * F4
Exemple #40
0
 def _tmcoeq(self, v0, nu):
     u1r1, u2r1, u2r2, s1, s2, n1sq, n2sq, n3sq = self.__params(v0)
     if s1 == 0:  # e
         f11a, f11b = 2, 1
     elif s1 > 0:  # a, b, d
         f11a, f11b = j0(u1r1) * u1r1, j1(u1r1)
     else:  # c
         f11a, f11b = i0(u1r1) * u1r1, i1(u1r1)
     if s2 > 0:
         f22a, f22b = j0(u2r2), y0(u2r2)
         f2a = j1(u2r1) * f22b - y1(u2r1) * f22a
         f2b = j0(u2r1) * f22b - y0(u2r1) * f22a
     else:  # a
         f22a, f22b = i0(u2r2), k0(u2r2)
         f2a = i1(u2r1) * f22b + k1(u2r1) * f22a
         f2b = i0(u2r1) * f22b - k0(u2r1) * f22a
     return f11a * n2sq * f2a - f11b * n1sq * f2b * u2r1
Exemple #41
0
    def _tmceq(self, neff, wl, nu):
        N = len(self.fiber)
        EH = numpy.empty(4)
        ri = 0

        for i in range(N-1):
            ro = self.fiber.outerRadius(i)
            self.fiber.layers[i].EH_fields(ri, ro, nu, neff, wl, EH, True)
            ri = ro

        # Last layer
        Ez, _, _, Hp = EH
        u = self.fiber.layers[-1].u(ri, neff, wl)
        n = self.fiber.maxIndex(-1, wl)

        F4 = k1(u) / k0(u)
        return Hp - wl.k0 * ri / u * constants.Y0 * n * n * Ez * F4
Exemple #42
0
 def initialize(self):
     self.aq = self.model.aq.find_aquifer_data(self.xc, self.yc)
     self.aq.add_element(self)
     self.parameters = np.array([[self.N]])
     self.Rlarge = 500.0  # If R/lab > Rlarge, then we use asymptotic approximation to compute potential
     if self.aq.ilap:
         self.lab = self.aq.lab[1:]
         self.A = -self.aq.coef[self.pylayers, 1:] * self.R * self.lab
         self.B = self.aq.coef[self.pylayers, 1:] * self.R * self.lab
         self.C = self.aq.coef[self.pylayers, 1:] * self.lab ** 2
     else:
         self.lab = self.aq.lab
         self.A = -self.aq.coef[self.pylayers] * self.R * self.lab
         self.B = self.aq.coef[self.pylayers] * self.R * self.lab
         self.C = self.aq.coef[self.pylayers] * self.lab ** 2
     self.islarge = self.R / self.lab > self.Rlarge
     self.labsmall = self.lab[~self.islarge]
     self.labbig = self.lab[self.islarge]
     self.k1Roverlab = k1(self.R / self.labsmall)
     self.i1Roverlab = i1(self.R / self.labsmall)
Exemple #43
0
def v1D_Coulomb(qG, N_p, N_np, R):
    """Coulomb Potential in the 1D Periodic Case.
    
    Nanotube/Nanowire/Atomic Chain calculation.
    Cutoff in non-periodic N_np directions.
    No cutoff in periodic N_p direction.

    ::
    
      v1D = 4 pi/|q+G|^2 * [1 + |G_n|R J_1(|G_n|R) K_0(G_p R)
                              - G_p R J_0(|G_n| R) K_1(G_p R)]
    """

    from scipy.special import j1, k0, j0, k1

    G_nR = (qG[:, N_np[0]]**2 + qG[:, N_np[1]]**2)**0.5 * R
    G_pR = abs(qG[:, N_p[0]]) * R
    v_q = 1. / (qG**2).sum(axis=1)
    v_q *= (1. + G_nR * j1(G_nR) * k0(G_pR)
            - G_pR * j0(G_nR) * k1(G_pR))
    return v_q
 def _R2deriv(self,R,z,phi=0.,t=0.):
     """
     NAME:
        R2deriv
     PURPOSE:
        evaluate R2 derivative
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        -d K_R (R,z) d R
     HISTORY:
        2012-12-27 - Written - Bovy (IAS)
     """
     if self._new:
         if nu.fabs(z) < 10.**-6.:
             y= 0.5*self._alpha*R
             return nu.pi*self._alpha*(special.i0(y)*special.k0(y)-special.i1(y)*special.k1(y)) \
                 +nu.pi/4.*self._alpha**2.*R*(special.i1(y)*(3.*special.k0(y)+special.kn(2,y))-special.k1(y)*(3.*special.i0(y)+special.iv(2,y)))
         raise AttributeError("'R2deriv' for RazorThinExponentialDisk not implemented for z =/= 0")
 def _Rforce(self,R,z,phi=0.,t=0.):
     """
     NAME:
        Rforce
     PURPOSE:
        evaluate radial force K_R  (R,z)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        K_R (R,z)
     HISTORY:
        2012-12-27 - Written - Bovy (IAS)
     """
     if self._new:
         #if R > 6.: return self._kp(R,z)
         if nu.fabs(z) < 10.**-6.:
             y= 0.5*self._alpha*R
             return -2.*nu.pi*y*(special.i0(y)*special.k0(y)-special.i1(y)*special.k1(y))
         kalphamax1= R
         ks1= kalphamax1*0.5*(self._glx+1.)
         weights1= kalphamax1*self._glw
         sqrtp= nu.sqrt(z**2.+(ks1+R)**2.)
         sqrtm= nu.sqrt(z**2.+(ks1-R)**2.)
         evalInt1= ks1**2.*special.k0(ks1*self._alpha)*((ks1+R)/sqrtp-(ks1-R)/sqrtm)/nu.sqrt(R**2.+z**2.-ks1**2.+sqrtp*sqrtm)/(sqrtp+sqrtm)
         if R < 10.:
             kalphamax2= 10.
             ks2= (kalphamax2-kalphamax1)*0.5*(self._glx+1.)+kalphamax1
             weights2= (kalphamax2-kalphamax1)*self._glw
             sqrtp= nu.sqrt(z**2.+(ks2+R)**2.)
             sqrtm= nu.sqrt(z**2.+(ks2-R)**2.)
             evalInt2= ks2**2.*special.k0(ks2*self._alpha)*((ks2+R)/sqrtp-(ks2-R)/sqrtm)/nu.sqrt(R**2.+z**2.-ks2**2.+sqrtp*sqrtm)/(sqrtp+sqrtm)
             return -2.*nu.sqrt(2.)*self._alpha*nu.sum(weights1*evalInt1
                                                       +weights2*evalInt2)
         else:
             return -2.*nu.sqrt(2.)*self._alpha*nu.sum(weights1*evalInt1)
     raise NotImplementedError("Not new=True not implemented for RazorThinExponentialDiskPotential")
Exemple #46
0
def func_seaton(b1, c1):
    '''Implicit equation to solve for Seaton IPM method
    '''
    return ss.k0(b1)**2 + ss.k1(b1)**2 - c1
import scipy.special as scsp


# In[137]:

R = np.arange(0,14*10**3)
R_d = 4.*10**3 #in pc
M_star = 3.*10**10*2*10**30
M_dm = 10.**11.8*2*10**30
c_mod = 10.
r_s = 250.*10**3/10 #in pc
sigma_0 = M_star/(2*np.pi*R_d**2)
arg = R/(2*R_d)
G = 4.302*10**(-3)/(2*10**30)

v_d = np.sqrt(np.pi*G*sigma_0*((R**2)/R_d)*(scsp.i0(arg)*scsp.k0(arg)-scsp.i1(arg)*scsp.k1(arg)))

v_dm = np.sqrt((G*M_dm)*(np.log((r_s+R)/r_s)-R/(r_s+R))/(R*(np.log(1+c_mod)-c_mod/(1+c_mod))))

v_comb = np.sqrt(v_d**2+v_dm**2)


# In[240]:

plt.clf()
plt.errorbar(np.array(radii)*1000,vrts,yerr=verr,marker='*',color='g')
plt.errorbar(np.array(radii)*1000,vrts,xerr=np.array(rerr)*1000,marker='*',color='k')
plt.plot(R,v_d, label='Disk profile')
plt.plot(R,v_dm, label='DM profile')
plt.plot(R,v_comb, label='Disk + DM profile')
plt.title('Rotation Curves')
guess = [x /10 for x in range (1, 2, 1)] #The guess needs to be a small value to ensure correct answer, since we Know the value of x1 then it is safe to assume a an 
#initial guess near that value, the important thing to note is the answer for x0 must be larger than x1. when the guess range is changed it alteres the value of t and X0
x0 = sy.symbols('x0')
i = (S*x0)*(1-tb**3)*besselk(0, x0) /  3*(log(x0/x1)+B) * besselk(0, S*x0)
t = - i*( (log(x0/x1)*B)**2 - (log(x0/x1)+B)**2 )
X0 = nsolve(t, guess)
print 'value of x0 is:' +' '+ str(X0)
#Once the value of x0 is known the first calculations look into the normal region of the Weak link the region that is x1<= x < x0
#First a few variables are declared a few variables and list
x=x1
Temp=[]
X=[]
while x<X0:
    x +=0.0001
    print 'value of x is:' +' '+ str(x)
    E = ((S*float(X0))*(1-tb**3) *sp.k1(float(X0)*S)) / ( 3*(np.log(float(X0)/x1)+B) * sp.k0(S*float(X0)))
    print 'value of i is:' +' '+ str(E)
    t = math.sqrt(1 - E * ( ((np.log(x/x1)+B)**2) - ((np.log(float(X0)/x1)+B)**2) ))
    print t
    T = t*Tc
    Temp.append(T)
    X.append(x)
    print t
    print 'The Temperature at x='+' '+str(x)+' is '+str(T)
    if x==X0:
        break
# The same process is repeated for the superconducting region thats everywhere beyond x0 where the temperature goes to the bath temperature 
x2=X0
XX = 40*X0
Temp1=[]
x00=[]
 def char(um):
     wm = sqrt(V**2-um**2)
     return um*j1(um)/j0(um) - wm*k1(wm)/k0(wm)
Exemple #50
0
def gzw(theta, x):
    sqr0 = sqrt(delta ** 2 + (x - mu) ** 2)
    sqr1 = sqrt(delta ** 2 + (x - theta - mu) ** 2)
    return (exp(x) - K) ** 2 * alpha * delta / pi * special.k1(alpha * sqr0) ** 2 / sqr0 ** 2 * sqr1 / special.k1(alpha * sqr1) * exp(delta * sqrt(alpha ** 2 - beta ** 2) + beta * (x + theta - mu))
Exemple #51
0
def stationary_box(axes):
    """
    A single boost-invariant volume element with zero flow velocity.
    This is a rudimentary test case with easily-calculated observables.

    """
    volume = 1500.
    tau = 1.
    T = .15
    ymax = np.random.uniform(.5, .8)

    info = [frzout.species_dict[i] for (i, _) in id_parts]
    m = np.array([i['mass'] for i in info])
    g = np.array([i['degen'] for i in info])
    sign = np.array([-1 if i['boson'] else 1 for i in info])

    n = np.arange(1, 10)
    densities = g * m*m*T / (2*np.pi**2*hbarc**3) * (
        np.power.outer(-sign, n-1)/n *
        special.kn(2, np.outer(m, n)/T)
    ).sum(axis=1)
    yields = 2*ymax * volume * densities

    x = np.array([[tau, 0, 0]])
    sigma = np.array([[volume/tau, 0, 0]])
    v = np.zeros((1, 2))

    sampler = frzout.Sampler(x, sigma, v, T, ymax=ymax)

    nsamples = 10000
    samples = list(sampler.iter_samples(nsamples))
    parts = np.concatenate(samples).view(np.recarray)

    abs_ID = np.abs(parts.ID)
    E, px, py, pz = parts.p.T

    with axes(
            'Multiplicity distributions',
            'These are histograms of particle counts from many oversamples. '
            'Production of each species should be Poissonian:'
    ) as ax:
        for (i, label), N in zip(id_parts, yields):
            dist = stats.poisson(N)
            x = np.arange(*dist.ppf([.0001, .9999]).astype(int))
            ax.plot(x, dist.pmf(x), color=default_color)
            N = np.array([np.count_nonzero(s.ID == i) for s in samples])
            ax.hist(
                N, bins=(np.arange(N.min(), N.max() + 2) - .5),
                normed=True, histtype='step',
                label=label.replace(r'\pm', '+').replace(r' \bar p', '')
            )

        ax.set_xlim(xmin=0)
        ax.set_xlabel('Number of particles')
        ax.set_ylabel('Probability')
        ax.set_yticklabels([])
        ax.legend()

    with axes(caption=(
            'Overall particle production (all species) '
            'should also be Poissonian:'
    )) as ax:
        N = np.array([s.size for s in samples])
        dist = stats.poisson(sampler.navg)
        x = np.arange(*dist.ppf([.0001, .9999]).astype(int))
        ax.plot(x, dist.pmf(x), color=default_color)
        ax.hist(
            N, bins=(np.arange(N.min(), N.max() + 3, 2) - .5),
            normed=True, histtype='step', color=color_cycle[-1]
        )
        ax.set_xlabel('Number of particles')
        ax.set_ylabel('Probability')
        ax.set_yticklabels([])

    with axes('Transverse momentum', 'Spectra are perfectly thermal:') as ax:
        pT = np.sqrt(px*px + py*py)
        pT_plot = np.linspace(0, 3, 1000)
        for k, (i, label) in enumerate(id_parts):
            mT = np.sqrt(frzout.species_dict[i]['mass']**2 + pT_plot**2)
            dN_dpT = 2*(
                volume * frzout.species_dict[i]['degen'] * (
                    np.outer(
                        2*mT,
                        (1 if frzout.species_dict[i]['boson'] else -1)**(n-1)
                    ) * special.k1(np.outer(mT, n)/T)
                ).sum(axis=1) / (2*np.pi*hbarc)**3
            )
            scale = 10**(-2*k)
            ax.plot(pT_plot, dN_dpT*scale, color=default_color)
            pT_ = pT[abs_ID == i]
            bins = np.linspace(0, pT_.max(), 50)
            ax.hist(
                pT_, bins=bins,
                weights=bins.size/bins.ptp()*scale/(
                    2*np.pi*pT_*2*ymax*nsamples),
                histtype='step', log=True,
                label=r'{} $({{\times}}10^{{{:d}}})$'.format(label, -2*k)
            )

        ax.set_xlabel('$p_T\ [\mathrm{GeV}]$')
        ax.set_ylabel('$1/2\pi p_T \: dN/dp_T\,dy\ [\mathrm{GeV}^{-2}]$')
        ax.yaxis.get_major_locator().base(100)
        ax.legend()

    nbins = 100

    with axes('Rapidity', '`dN/dy` should be flat:') as ax:
        y = .5*np.log((E + pz)/(E - pz))
        for (i, label), N in zip(id_parts, yields):
            ax.plot([-ymax, ymax], [2*N]*2, color=default_color)
            y_ = y[abs_ID == i]
            ax.hist(y_, bins=nbins, weights=np.full_like(y_, nbins/nsamples),
                    histtype='step', log=True, label=label)

        ax.set_xlabel('$y$')
        ax.set_ylabel('$dN/dy$')
        ax.legend(loc='lower center', ncol=len(id_parts))

    with axes('Azimuthal angle', '`dN/d\phi` should be flat:') as ax:
        phi = np.arctan2(py, px)
        for (i, label), N in zip(id_parts, yields):
            ax.plot([-np.pi, np.pi], [2*N]*2, color=default_color)
            phi_ = phi[abs_ID == i]
            ax.hist(phi_, bins=nbins,
                    weights=np.full_like(phi_, nbins/nsamples),
                    histtype='step', log=True, label=label)

        ax.set_xlim(-np.pi, np.pi)
        ax.set_xlabel('$\phi$')
        ax.set_ylabel('$dN/d\phi$')
        ax.legend(loc='lower center', ncol=len(id_parts))
Exemple #52
0
 def gradPDF(self, x):
     sq = self.delta ** 2 + (x - self.mu) ** 2
     sqr = sqrt(sq)
     return self.alpha * self.delta / pi * exp(self.delta * sqrt(self.alpha ** 2 - self.beta ** 2) + self.beta * (x - self.mu)) * (self.beta * special.k1(self.alpha * sqr) / sqr - special.kv(2, self.alpha * sqr) * self.alpha * (x - self.mu) / sq)
Exemple #53
0
def zeta(x):
    ''' Function for the IPM (Seaton, 1962)
    '''
    return x**2 * (ss.k0(x)**2 + ss.k1(x)**2)
Exemple #54
0
 def _tmceq(self, neff, wl, nu):
     u, w = self._uw(wl, neff)
     nco = self.fiber.maxIndex(0, wl)
     ncl = self.fiber.minIndex(1, wl)
     return (u * j0(u) * k1(w) * ncl**2 +
             w * j1(u) * k0(w) * nco**2)
Exemple #55
0
def gdisk(r):
    y = r / (2 * RD)
    return 4 * pi * G * Sigma0 * (RD / r) * (y ** 2) * (sp.i0(y) * sp.k0(y) - sp.i1(y) * sp.k1(y))
Exemple #56
0
 def _teceq(self, neff, wl, nu):
     u, w = self._uw(wl, neff)
     return u * j0(u) * k1(w) + w * j1(u) * k0(w)
Exemple #57
0
def phi(x):
    ''' Function for the IPM (Seaton, 1962)
    '''
    return x * ss.k0(x) * ss.k1(x)