def mass_3(self):
"""
*astropy.Quantity*
The mass of the tertiary. Defined as total_mass * epsilon[2].
An *astropy.Quantity* with mass units. If set as a *float*,
units are assumed to be solMass.
Note that if total_mass is defined before mass_3, and there is
no epsilon corresponding to mass_3, mass_3 is added to the total_mass.
"""
return self.total_mass * self._epsilon[2]
python类Quantity()的实例源码
def distance(self):
"""
*astropy.Quantity*
The distance to the lens.
May be set as a *float*. If no unit is given, the value is
assumed to be kpc.
"""
return self._distance
def distance(self, new_distance):
if not isinstance(new_distance, u.Quantity):
self._distance = new_distance * 1000. * u.pc
else:
if new_distance.unit.physical_type != 'distance':
TypeError('Wrong type of new_distance!')
if (new_distance.unit == "pc") or (new_distance.unit == "kpc"):
self._distance = new_distance
else:
raise u.UnitsError(
'Allowed units for Lens distance are "pc" or "kpc"')
def pi_L(self):
"""
*astropy.Quantity*
The parallax to the lens in milliarcseconds. May be set as a
*float*, in which case units are assumed to be
milliarcseconds.
"""
return self._distance.to(u.mas, equivalencies=u.parallax())
def a_proj(self):
"""
*astropy.Quantity*
Projected separation between the components of the lens in
AU. An *astropy.Quantity* with distance units. If set as *float*
(without units), AU is assumed.
"""
raise NotImplementedError('a_proj is not used, e.g. to set s')
return self._a_proj
def a_proj(self, new_a_proj):
raise NotImplementedError('a_proj is not used, e.g. to set s')
if not isinstance(new_distance, u.Quantity):
new_a_proj = new_a_proj * u.au
self._a_proj = new_a_proj
def mu_rel(self):
"""
*astropy.Quantity*
Relative proper motion between the source and lens
stars. If set as a *float*, units are assumed to be mas/yr.
"""
return self._mu_rel
def mu_rel(self, value):
if isinstance(value, u.Quantity):
self._mu_rel = value
else:
self._mu_rel = value * u.mas / u.yr
def t_E(self):
"""
*astropy.Quantity*
The Einstein crossing time (in days). If set as a *float*,
assumes units are in days.
"""
try:
t_E = self.theta_E/self.mu_rel
return t_E.to(u.day)
except Exception:
return None
def pi_rel(self):
"""
*astropy.Quantity*, read-only
The source-lens relative parallax in milliarcseconds.
"""
return self.lens.pi_L.to(u.mas) - self.source.pi_S.to(u.mas)
def theta_E(self):
"""
*astropy.Quantity*, read-only
The angular Einstein Radius in milliarcseconds.
"""
kappa = (4. * G / (c**2 * au)).to(
u.mas/u.Msun, equivalencies=u.dimensionless_angles())
return np.sqrt(
kappa * self.lens.total_mass.to(u.solMass) *
self.pi_rel.to(u.mas))
def r_E(self):
"""
*astropy.Quantity*, read-only
The physical size of the Einstein Radius in the Lens plane (in AU).
"""
return (self.lens.distance * self.theta_E.to(
'', equivalencies=u.dimensionless_angles())).to(u.au)
def r_E_tilde(self):
"""
*astropy.Quantity*, read-only
The physical size of the Einstein Radius projected onto the
Observer plane (in AU).
"""
return self.r_E * self.source.distance / (
self.source.distance - self.lens.distance)
def distance(self, new_distance):
if new_distance is None:
self._distance = new_distance
else:
if not isinstance(new_distance, u.Quantity):
self._distance = new_distance * 1000. * u.pc
else:
if (new_distance.unit == "pc") or (new_distance.unit == "kpc"):
self._distance = new_distance
else:
raise u.UnitsError(
'Allowed units for Source distance are "pc" or "kpc"')
def pi_S(self):
"""
*astropy.Quantity*
The parallax to the source in millarcseconds. May be set as a
*float*. If no units are specified, assumes milliarcseconds (*u.mas*).
"""
return self._distance.to(u.mas, equivalencies=u.parallax())
def pi_S(self, new_value):
if new_value is None:
pass
else:
if not isinstance(new_value, u.Quantity):
new_value = new_value * u.mas
self._distance = new_value.to(u.pc, equivalencies=u.parallax())
def angular_radius(self):
"""
*astropy.Quantity*
Angular radius of the source. May be set as a *float*. If
units are not specified, assumed to be microarcseconds (*u.mas*).
"""
return self._angular_radius
def angular_radius(self, new_value):
if not isinstance(new_value, u.Quantity) and new_value is not None:
new_value = new_value * u.uas
self._angular_radius = new_value
def coord_to_ID(self, coord, tol=0.5*u.arcsec, closest=True, **kwargs):
""" Convert an input coord to an ID if matched within a
given tolerance. If multiple sources are identified, return
the closest unless closest=False
Parameters
----------
coord : str or tuple or SkyCoord
See linetools.utils.radec_to_coord
Single coordinate
tol : Quantity
Angle
closest : bool, optional
If False, raise an error if multiple sources are within tol
Returns
-------
ID : int
ID of the closest source to the input coord
within the given tolerance
"""
# Catalog
ids = self.radial_search(coord, tol, **kwargs)
if len(ids) == 0:
warnings.warn("No sources found at your coordinate within tol={:g}. Returning None".format(tol))
return None, None
elif len(ids) > 1:
if closest:
warnings.warn("Found multiple sources in the catalog. Taking the closest one")
else:
raise IOError("Multiple sources within tol={:g}. Refine".format(tol))
# Finish
ID = ids[0]
return ID
def pairs(self, sep, dv):
""" Generate a pair catalog
Parameters
----------
sep : Angle or Quantity
dv : Quantity
Offset in velocity. Positive for projected pairs (i.e. dz > input value)
Returns
-------
"""
# Checks
if not isinstance(sep, (Angle, Quantity)):
raise IOError("Input radius must be an Angle type, e.g. 10.*u.arcsec")
if not isinstance(dv, (Quantity)):
raise IOError("Input velocity must be a quantity, e.g. u.km/u.s")
# Match
idx, d2d, d3d = match_coordinates_sky(self.coords, self.coords, nthneighbor=2)
close = d2d < sep
# Cut on redshift
if dv > 0.: # Desire projected pairs
zem1 = self.cat['zem'][close]
zem2 = self.cat['zem'][idx[close]]
dv12 = ltu.dv_from_z(zem1,zem2)
gdz = np.abs(dv12) > dv
# f/g and b/g
izfg = dv12[gdz] < 0*u.km/u.s
ID_fg = self.cat[self.idkey][close][gdz][izfg]
ID_bg = self.cat[self.idkey][idx[close]][gdz][izfg]
else:
pdb.set_trace()
# Reload
return ID_fg, ID_bg