本文整理汇总了Python中astropy.constants.G.to方法的典型用法代码示例。如果您正苦于以下问题:Python G.to方法的具体用法?Python G.to怎么用?Python G.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.constants.G
的用法示例。
在下文中一共展示了G.to方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def __init__(self,rc,Mtot,G='kpc km2 / (M_sun s2)'):
"""
Analytic Plummer model
:param rc: Plummer scale length
:param Mtot: Plummer total mass
:param G: Value of the gravitational constant G, it can be a number of a string.
If G=1, the physical value of the potential will be Phi/G.
If string it must follow the rule of the unity of the module.astropy constants.
E.g. to have G in unit of kpc3/Msun s2, the input string is 'kpc3 / (M_sun s2)'
See http://astrofrog-debug.readthedocs.org/en/latest/constants/
:return:
"""
self.rc=rc
self.Mmax=Mtot
if isinstance(G,float) or isinstance(G,int): self.G=G
else:
GG=conG.to(G)
self.G=GG.value
self._use_nparray=True
self._analytic_radius=True
self.use_c=False
self._densnorm=(3*Mtot)/(4*np.pi*rc*rc*rc)
self._sdensnorm=Mtot/(np.pi*rc*rc)
self._potnorm=self.G*Mtot
示例2: __init__
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def __init__(self,rc, G='kpc km2 / (M_sun s2)', Mmax=None, rmax=None, Vinf=None, d0=None):
"""
PseudoIsothermal Model:
d=d0/((1+r^2/rc^2)
Given that the Mass diverge at infinty it is possibile to initialize the
model in different ways:
Mmax (rmax): The model will have a mass of Mmax at radius rmax, if rmax is not supplied
it is equal to 10*rc
d0: Central density. The unity depends on the combinations of gthe value of G and rc. By default
is Msun/kpc^3.
Vinf: asymptotic circular velocity in km/s.
The routine gives priority firstly to Mmax, then to d0 and finally to Vinf.
:param rc:
:param G: Value of the gravitational constant G, it can be a number of a string.
If G=1, the physical value of the potential will be Phi/G.
If string it must follow the rule of the unity of the module.astropy constants.
E.g. to have G in unit of kpc3/Msun s2, the input string is 'kpc3 / (M_sun s2)'
See http://astrofrog-debug.readthedocs.org/en/latest/constants/
:param Mmax: Total Mass in Msun at radius rmax.
:param rmax: Radius to cut the density distribution, by default is equal to 10*rc.
:param d0: Central density. The unity depends on the combinations of gthe value of G and rc. By default
is Msun/kpc^3. Available only if Mmax is None.
:param Vinf: asymptotic circular velocity in km/s. Available only if Mmax and d0 are None.
:return:
"""
if rmax is None: self.rmax=10*rc
else: self.rmax=rmax
self.rc=rc
self.use_c=False
self._use_nparray=True
if isinstance(G,float) or isinstance(G,int): self.G=G
else:
GG=conG.to(G)
self.G=GG.value
self.Mc=1
self.dc=1
self.pc=1
if Mmax is not None:
totmass=self._evaluatemass(self.rmax)
self.Mc=Mmax/totmass
self.dc=self.Mc/(4*np.pi)
self.pc=self.G*self.Mc
elif d0 is not None:
self.dc=d0
self.Mc=(4*np.pi)*self.dc
self.pc=self.G*self.Mc
elif Vinf is not None:
self.pc=(Vinf*Vinf)/(self.rc*self.rc)
self.Mc=self.pc/self.G
self.dc=self.Mc/(4*np.pi)
示例3: __init__
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def __init__(self,dprof,sprof,mprof,amodel='isotropic',G='kpc km2 / (M_sun s2)'):
self.amodel=amodel
self.dprof=dprof
self.sprof=sprof
self.mprof=mprof
if isinstance(G,float) or isinstance(G,int): self.G=G
else:
GG=conG.to(G)
self.G=GG.value
if amodel=='isotropic':
self.kernel=self._kerneliso
self.cost=sqrt(2.*self.G)
示例4: tdyn
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def tdyn(self,mq=100,type=None,G='(kpc3)/(M_sun Gyr2)'):
"""
Calculate the dynamical time of a stystem as Tdyn=0.5*pi*Sqrt(Rh^3/(G*Mh)).
where Rh is the radius that contains the fraction Mh=h*M of the mass.
This is the time for a particle at distance r to reach r=0 in a homogeneus spherical system
with density rho. We do not have an homogenues sphere, but we use a medium value rho_mh
equals to Mh/(4/3 * pi * Rh^3).
:param mq: Fraction of the mass to use, it can ranges from 0 to 100
:param type: Type of particle to use, it need to be an array. If None use all
:param G: Value of the gravitational constant G, it can be a number of a string.
If G=1, the physical value of the potential will be Phi/G.
If string it must follow the rule of the unity of the module.astropy constants.
E.g. to have G in unit of kpc3/Msun s2, the input string is 'kpc3 / (M_sun s2)'
See http://astrofrog-debug.readthedocs.org/en/latest/constants/
:return: Dynamical tyme. The units wil depends on the units used in G, If used the
G in default the time will be in unit of Gyr.
"""
if type is None:
rad_array=self.p.Radius[:]
mas_array=self.p.Mass[:]
else:
type= nparray_check(type)
rad_array=self._make_array(self.p.Radius,type)
mas_array=self._make_array(self.p.Mass,type)
if isinstance(G,float) or isinstance(G,int): G=G
else:
GG=conG.to(G)
G=GG.value
rq,_=self.qradius_ext(rad_array,mas_array,mq)
mass_phy=G*(mq/100)*np.sum(mas_array)
tdyn=0.5*np.pi*rq*np.sqrt(rq/mass_phy)
return tdyn
示例5: __init__
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def __init__(self,m,rc,Mtot,G='kpc km2 / (M_sun s2)'):
"""
Analytic Sersic model:
Surface density: S(R)=S(0) * Exp(-(R/rc)^(1/m))
for the 3D deprojection we use the analytic approximation of Lima Neto, Gerbal and Marquez, 1999.
Density: d(r)=d(0) * Exp(-(r/rc)^(1/m)) * (r/rc)^(-p) where p=1 - 0.6097*(1/m) + 0.05463*(1/m^2)
:param m: Sersic exponent
:param rc: Sersic scale length
:param Mtot: Sersic total mass
:param G: Value of the gravitational constant G, it can be a number of a string.
If G=1, the physical value of the potential will be Phi/G.
If string it must follow the rule of the unity of the module.astropy constants.
E.g. to have G in unit of kpc3/Msun s2, the input string is 'kpc3 / (M_sun s2)'
See http://astrofrog-debug.readthedocs.org/en/latest/constants/
:return:
"""
self.rc=rc
self.Mmax=Mtot
self.m=m
self.nu=1/m
self.p=1-0.6097*self.nu+0.05463*self.nu*self.nu
self.use_c=False
self._use_nparray=True
self._analytic_radius=True
if isinstance(G,float) or isinstance(G,int): self.G=G
else:
GG=conG.to(G)
self.G=GG.value
dmgamma= self.m*gamma(self.m*(3-self.p)) #Mtot=4*pi*d0*rc^3 * m* *Gamma(m*(3-p))
self._densnorm=Mtot/(4*np.pi*rc*rc*rc*dmgamma)
sdmgamma= self.m*gamma(2*self.m) #Mtot=2*pi*S0*rc^2 * m * Gamma(2*m)
self._sdensnorm=Mtot/(2*np.pi*rc*rc*sdmgamma)
self._potnorm=(self.G*Mtot)
示例6: density_threshold
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
package developed by Benedikt Diemer, http://bdiemer.bitbucket.org.
Testing for this module is done in the
`~halotools.empirical_models.test_profile_helpers` module.
"""
from __future__ import division, print_function, absolute_import, unicode_literals
import numpy as np
from astropy import cosmology as astropy_cosmology_obj
from astropy import units as u
from astropy.constants import G
from ....custom_exceptions import HalotoolsError
newtonG = G.to(u.km*u.km*u.Mpc/(u.Msun*u.s*u.s))
__all__ = ('density_threshold', 'delta_vir', 'halo_mass_to_halo_radius',
'halo_radius_to_halo_mass', 'halo_mass_to_virial_velocity')
__author__ = ['Benedikt Diemer', 'Andrew Hearin']
def density_threshold(cosmology, redshift, mdef):
"""
The threshold density for a given spherical-overdensity mass definition.
:math:`\\rho_{\\rm thresh}(z) = \\Delta_{\\rm ref}(z)\\rho_{\\rm ref}(z)`.
See :ref:`halo_mass_definitions` for details.
示例7: __init__
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def __init__(self,R,dens,rc=1,Mmax=1, G='kpc km2 / (M_sun s2)', denorm=True, use_c=False):
"""
The purpose of the general model is to start from a density law R-dens to build a galaxy model.
Attenzione per come è creato il modello assume sempre che
per R>rmax la densita sia 0, la massa resti costante al suo valore massimo e il potenziale vada
come M/r. Per modelli che raggiungono la massa massima all infinito questo potrebbe essere un problema,
quindi si dovrebbero usare modelli con massa finita o troncarli e campionarli fino a quanto la massa non raggiunge
il suo valore max. Per modelli non troncati è meglio utilizzare modelli analitici se possibile.
Anche nel calcolo del potenziale Rinf è settato uguale all ultimo punto di R, poichè cmq per R>Rmax
dens=0 e l integrale int_Rmax^inf dens r dr=0 sempre.
:param R: list of radii, it needs to be in the form r/rc
:param dens: list of dens at radii R. It can be also a function or a lambda function that depends
only on the variable R=r/rc
:param rc: Scale length of the model, the R in input will be multiplyed by rc before start all the calculation
:param Mmax: Physical Value of the Mass at Rmax (the last point of the R grid). The physical unity of dens and pot and mass
will depends on the unity of Mmax
:param G: Value of the gravitational constant G, it can be a number of a string.
If G=1, the physical value of the potential will be Phi/G.
If string it must follow the rule of the unity of the module.astropy constants.
E.g. to have G in unit of kpc3/Msun s2, the input string is 'kpc3 / (M_sun s2)'
See http://astrofrog-debug.readthedocs.org/en/latest/constants/
:param denorm: If True, the output value of mass, dens and pot will be de normalized using Mmax and G.
:param use_c: To calculate pot and mass with a C-cyle, WARNING it creates more noisy results
"""
self.rc=rc
self.Mmax=Mmax
if isinstance(G,float) or isinstance(G,int): self.G=G
else:
GG=conG.to(G)
self.G=GG.value
if isinstance(dens,list) or isinstance(dens,tuple) or isinstance(dens,np.ndarray): self.dens_arr=np.array(dens,dtype=float,order='C')
else:
self.dens_arr=dens(R)
self.R=np.array(R,dtype=float,order='C')*self.rc
self.mass_arr=np.empty_like(self.dens_arr,dtype=float,order='C')
self.pot_arr=np.empty_like(self.dens_arr,dtype=float,order='C')
self.use_c=use_c
self._use_nparray=False
self._dens=UnivariateSpline(self.R,self.dens_arr, k=1, s=0, ext=1) #for R>rmax, dens=0
if self.use_c==True:
#add to path to use relative path
dll_name='model_c_ext/GeneralModel.so'
dllabspath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dll_name
lib = ct.CDLL(dllabspath)
#add to path to use relativ path
mass_func=lib.evalmass
mass_func.restype=None
mass_func.argtypes=[ndpointer(ct.c_double, flags="C_CONTIGUOUS"), ndpointer(ct.c_double, flags="C_CONTIGUOUS"),ct.c_int,ndpointer(ct.c_double, flags="C_CONTIGUOUS")]
mass_func(self.R,self.dens_arr,len(self.dens_arr),self.mass_arr)
self._mass_int=UnivariateSpline(self.R,self.mass_arr, k=1, s=0, ext=3) #ext=3, const for R>Rmax non ci osno piu particelle e la massa rimane uguale
pot_func=lib.evalpot
pot_func.restype=None
pot_func.argtypes=[ndpointer(ct.c_double, flags="C_CONTIGUOUS"),ndpointer(ct.c_double, flags="C_CONTIGUOUS"),ndpointer(ct.c_double, flags="C_CONTIGUOUS"),ct.c_int,ndpointer(ct.c_double, flags="C_CONTIGUOUS")]
pot_func(self.R,self.dens_arr,self.mass_arr,len(self.dens_arr),self.pot_arr)
self._pot_int=UnivariateSpline(self.R,self.pot_arr, k=1, s=0, ext=1)
else:
self._dm2=UnivariateSpline(self.R,self.R*self.R*self.dens_arr, k=2, s=0,ext=1)
self._dm=UnivariateSpline(self.R,self.R*self.dens_arr, k=1, s=0,ext=1)
#Evaluate mass and pot on the R grid in input
#mass
func=np.vectorize(self._dm2.integral)
self.mass_arr=func(0,self.R)
#pot
a=(1/self.R)*self.mass_arr
func=np.vectorize(self._dm.integral)
b=func(self.R,self.R[-1])
self.pot_arr=a+b
if denorm==True: self._set_denorm(self.Mmax)
else:
self.Mc=1
self.dc=1
self.pc=1
示例8: external_delta_sigma
# 需要导入模块: from astropy.constants import G [as 别名]
# 或者: from astropy.constants.G import to [as 别名]
def external_delta_sigma(galaxies, particles, rp_bins, period, projection_period,
cosmology=default_cosmology):
r"""
Parameters
----------
galaxies : array_like
Ngal x 2 numpy array containing 2-d positions of galaxies.
Length units are comoving and assumed to be in Mpc/h,
here and throughout Halotools.
particles : array_like
Npart x 2 numpy array containing 2-d positions of particles.
Length units are comoving and assumed to be in Mpc/h,
here and throughout Halotools. Assumes constant particle masses, but can
use weighted pair counts as scipy 0.19.0 is released.
scipy.spatial.cKDTree will acquire a weighted pair count functionality
rp_bins : array_like
array of projected radial boundaries defining the bins in which the result is
calculated. The minimum of rp_bins must be > 0.0.
Length units are comoving and assumed to be in Mpc/h,
here and throughout Halotools.
period : array_like
Length-2 sequence defining the periodic boundary conditions
in each dimension. If you instead provide a single scalar, Lbox,
period is assumed to be the same in all Cartesian directions.
Length units are comoving and assumed to be in Mpc/h,
here and throughout Halotools.
projection_period : float
The period along the direction of projection
cosmology : instance of `astropy.cosmology`, optional
Default value is set in `~halotools.sim_manager.default_cosmology` module.
Typically you should use the `cosmology` attribute of the halo catalog
you used to populate mock galaxies.
Returns
-------
rmids : np.array
The bins at which :math:`\Delta\Sigma` is calculated.
The units of `rmids` is :math:`hinv Mpc`, where distances are in comoving units.
You can convert to physical units using the input cosmology and redshift.
Note that little h = 1 here and throughout Halotools.
Delta_Sigma : np.array
:math:`\Delta\Sigma(r_p)` calculated at projected comoving radial distances ``rp_bins``.
The units of `ds` are :math:`h * M_{\odot} / Mpc^2`, where distances are in comoving units.
You can convert to physical units using the input cosmology and redshift.
Note that little h = 1 here and throughout Halotools.
Notes
-----
:math:`\Delta\Sigma` is calculated by first calculating the projected
surface density :math:`\Sigma` using the particles passed to the code
and then,
.. math::
\Delta\Sigma(r_p) = \bar{\Sigma}(<r_p) - \Sigma(r_p)
"""
from scipy.spatial import cKDTree
from astropy.constants import G
Ngal = float(galaxies.shape[0])
Npart = float(particles.shape[0])
if np.isscalar(period):
Area = period**2
else:
Area = period[0] * period[1]
tree = cKDTree(galaxies, boxsize=period)
ptree = cKDTree(particles, boxsize=period)
pairs_inside_rad = tree.count_neighbors(ptree, rp_bins)
pairs_in_annuli = np.diff(pairs_inside_rad)
# rhobar = 3H0^2/(8 pi G) Om0
rhobar = 3.e4/(8*np.pi*G.to('km^2 Mpc/(s^2 Msun)').value)*cosmology.Om0
sigmabar = rhobar*projection_period
# This initializes sigma(rmids)
rmids = rp_bins[1:]/2+rp_bins[:-1]/2
xi2d = pairs_in_annuli/(Ngal*Npart/Area*(np.pi*(rp_bins[1:]**2-rp_bins[:-1]**2))) - 1.0
sigma = sigmabar*xi2d
# Now initialize sigmainside(rp_bins)
xi2dinside = pairs_inside_rad/(Npart*Ngal/Area*(np.pi*rp_bins**2)) - 1.0
sigmainside = sigmabar*xi2dinside
from scipy.interpolate import interp1d
spl = interp1d(np.log(rp_bins), np.log(sigmainside), kind="cubic")
return rmids, np.exp(spl(np.log(rmids)))-sigma