python类Quantity()的实例源码

lens.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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]
lens.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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
lens.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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"')
lens.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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())
lens.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
lens.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def mu_rel(self, value):
        if isinstance(value, u.Quantity):
            self._mu_rel = value
        else:
            self._mu_rel = value * u.mas / u.yr
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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))
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
mulenssystem.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
source.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
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"')
source.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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())
source.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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())
source.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
source.py 文件源码 项目:MulensModel 作者: rpoleski 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
query_catalog.py 文件源码 项目:specdb 作者: specdb 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
query_catalog.py 文件源码 项目:specdb 作者: specdb 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号