当前位置: 首页>>代码示例>>Python>>正文


Python astropy.units方法代码示例

本文整理汇总了Python中astropy.units方法的典型用法代码示例。如果您正苦于以下问题:Python astropy.units方法的具体用法?Python astropy.units怎么用?Python astropy.units使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy的用法示例。


在下文中一共展示了astropy.units方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gen_radius

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def gen_radius(self,n):
        """Generate planetary radius values in Earth radius
        
        Samples the mass distribution and then converts to radius using the physical model.
        
        Args:
            n (integer):
                Number of samples to generate
                
        Returns:
            Rp (astropy Quantity array):
                Planet radius values in units of Earth radius
        
        """
        n = self.gen_input_check(n)
        Mp = self.gen_mass(n)
        Rp = self.PlanetPhysicalModel.calc_radius_from_mass(Mp).to('earthRad')
        
        return Rp 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:21,代码来源:KnownRVPlanets.py

示例2: gen_mass

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def gen_mass(self,n):
        """Generate planetary mass values in Earth mass
        
        The mass is determined by sampling the RV mass distribution from
        Cumming et al. 2010
        
        Args:
            n (integer):
                Number of samples to generate
                
        Returns:
            Mp (astropy Quantity array):
                Planet mass values in units of Earth mass
        
        """
        n = self.gen_input_check(n)
        # unitless mass range
        Mpr = self.Mprange.to('earthMass').value
        Mp = statsFun.simpSample(self.dist_mass, n, Mpr[0], Mpr[1])*u.earthMass
        
        return Mp 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:23,代码来源:KnownRVPlanets.py

示例3: __init__

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def __init__(self, frequency, power, nyquist=None, label=None,
                 targetid=None, default_view='frequency', meta={}):
        # Input validation
        if not isinstance(frequency, u.quantity.Quantity):
            raise ValueError('frequency must be an `astropy.units.Quantity` object.')
        if not isinstance(power, u.quantity.Quantity):
            raise ValueError('power must be an `astropy.units.Quantity` object.')
        # Frequency must have frequency units
        try:
            frequency.to(u.Hz)
        except u.UnitConversionError:
            raise ValueError('Frequency must be in units of 1/time.')
        # Frequency and power must have sensible shapes
        if frequency.shape[0] <= 1:
            raise ValueError('frequency and power must have a length greater than 1.')
        if frequency.shape != power.shape:
            raise ValueError('frequency and power must have the same length.')

        self.frequency = frequency
        self.power = power
        self.nyquist = nyquist
        self.label = label
        self.targetid = targetid
        self.default_view = self._validate_view(default_view)
        self.meta = meta 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:27,代码来源:periodogram.py

示例4: query

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def query(self, coords, component='mean'):
        """
        Returns the extinction density (in e-foldings / kpc, in Gaia G-band)
        at the given coordinates.

        Args:
            coords (:obj:`astropy.coordinates.SkyCoord`): Coordinates at which
                to query the extinction. Must be 3D (i.e., include distance
                information).
            component (str): Which component to return. Allowable values are
                'mean' (for the mean extinction density) and 'std' (for the
                standard deviation of extinction density). Defaults to 'mean'.

        Returns:
            The extinction density, in units of e-foldings / pc, as either a
            numpy array or float, with the same shape as the input
            :obj:`coords`.
        """
        idx,mask = self._coords2idx(coords)

        v = self._data[component][idx[0], idx[1], idx[2]]
        
        if np.any(mask):
            # Set extinction to NaN for out-of-bounds (x, y, z)
            v[mask] = np.nan

        return v 
开发者ID:gregreen,项目名称:dustmaps,代码行数:29,代码来源:leike_ensslin_2019.py

示例5: units

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def units(self):
        if self._units is None:
            try:
                from astropy import units

                self.log
            except ImportError:
                units = NotAModule(self._name)
            self._units = units
        return self._units 
开发者ID:yt-project,项目名称:unyt,代码行数:12,代码来源:_on_demand_imports.py

示例6: identify_unit_framework

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def identify_unit_framework(target_unit):
    """
    Identify whether the user is requesting unit validation against
    astropy.units, pint, or quantities.
    """

    if HAS_ASTROPY:

        from astropy.units import UnitBase

        if isinstance(target_unit, UnitBase):

            return ASTROPY

    if HAS_PINT:

        from pint.unit import UnitsContainer

        if hasattr(target_unit, 'dimensionality') and isinstance(target_unit.dimensionality, UnitsContainer):

            return PINT

    if HAS_QUANTITIES:

        from quantities.unitquantity import IrreducibleUnit
        from quantities import Quantity

        if isinstance(target_unit, IrreducibleUnit) or isinstance(target_unit, Quantity):

            return QUANTITIES

    raise TraitError("Could not identify unit framework for target unit of type {0}".format(type(target_unit).__name__)) 
开发者ID:astrofrog,项目名称:numtraits,代码行数:34,代码来源:numtraits.py

示例7: flatten

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def flatten(self, method='logmedian', filter_width=0.01, return_trend=False):
        """Estimates the Signal-To-Noise (SNR) spectrum by dividing out an
        estimate of the noise background.

        This method divides the power spectrum by a background estimated
        using a moving filter in log10 space by default. For details on the
        `method` and `filter_width` parameters, see `Periodogram.smooth()`

        Dividing the power through by the noise background produces a spectrum
        with no units of power. Since the signal is divided through by a measure
        of the noise, we refer to this as a `Signal-To-Noise` spectrum.

        Parameters
        ----------
        method : str, one of 'boxkernel' or 'logmedian'
            Background estimation method passed on to `Periodogram.smooth()`.
            Defaults to 'logmedian'.
        filter_width : float
            If `method` = 'boxkernel', this is the width of the smoothing filter
            in units of frequency.
            If method = `logmedian`, this is the width of the smoothing filter
            in log10(frequency) space.
        return_trend : bool
            If True, then the background estimate, alongside the SNR spectrum,
            will be returned.

        Returns
        -------
        snr_spectrum : `Periodogram` object
            Returns a periodogram object where the power is an estimate of the
            signal-to-noise of the spectrum, creating by dividing the powers
            with a simple estimate of the noise background using a smoothing filter.
        bkg : `Periodogram` object
            The estimated power spectrum of the background noise. This is only
            returned if `return_trend = True`.
        """
        bkg = self.smooth(method=method, filter_width=filter_width)
        snr_pg = self / bkg.power
        snr = SNRPeriodogram(snr_pg.frequency, snr_pg.power,
                             nyquist=self.nyquist, targetid=self.targetid,
                             label=self.label, meta=self.meta)
        if return_trend:
            return snr, bkg
        return snr 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:46,代码来源:periodogram.py

示例8: assert_unit_convertability

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def assert_unit_convertability(name, value, target_unit, unit_framework):
    """
    Check that a value has physical type consistent with user-specified units

    Note that this does not convert the value, only check that the units have
    the right physical dimensionality.

    Parameters
    ----------
    name : str
        The name of the value to check (used for error messages).
    value : `numpy.ndarray` or instance of `numpy.ndarray` subclass
        The value to check.
    target_unit : unit
        The unit that the value should be convertible to.
    unit_framework : str
        The unit framework to use
    """

    if unit_framework == ASTROPY:

        from astropy.units import Quantity

        if not isinstance(value, Quantity):
            raise TraitError("{0} should be given as an Astropy Quantity instance".format(name))

        if not target_unit.is_equivalent(value.unit):
            raise TraitError("{0} should be in units convertible to {1}".format(name, target_unit))

    elif unit_framework == PINT:

        from pint.unit import UnitsContainer

        if not (hasattr(value, 'dimensionality') and isinstance(value.dimensionality, UnitsContainer)):
            raise TraitError("{0} should be given as a Pint Quantity instance".format(name))

        if value.dimensionality != target_unit.dimensionality:
            raise TraitError("{0} should be in units convertible to {1}".format(name, target_unit))

    elif unit_framework == QUANTITIES:

        from quantities import Quantity

        if not isinstance(value, Quantity):
            raise TraitError("{0} should be given as a quantities Quantity instance".format(name))

        if value.dimensionality.simplified != target_unit.dimensionality.simplified:
            raise TraitError("{0} should be in units convertible to {1}".format(name, target_unit.dimensionality.string)) 
开发者ID:astrofrog,项目名称:numtraits,代码行数:50,代码来源:numtraits.py

示例9: _generate_unit_names

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import units [as 别名]
def _generate_unit_names():
        from astropy import units as u
        from astropy.units import required_by_vounit as uvo

        names = {}
        deprecated_names = set()

        bases = [
            'A', 'C', 'D', 'F', 'G', 'H', 'Hz', 'J', 'Jy', 'K', 'N',
            'Ohm', 'Pa', 'R', 'Ry', 'S', 'T', 'V', 'W', 'Wb', 'a',
            'adu', 'arcmin', 'arcsec', 'barn', 'beam', 'bin', 'cd',
            'chan', 'count', 'ct', 'd', 'deg', 'eV', 'erg', 'g', 'h',
            'lm', 'lx', 'lyr', 'm', 'mag', 'min', 'mol', 'pc', 'ph',
            'photon', 'pix', 'pixel', 'rad', 'rad', 's', 'solLum',
            'solMass', 'solRad', 'sr', 'u', 'voxel', 'yr'
        ]
        binary_bases = [
            'bit', 'byte', 'B'
        ]
        simple_units = [
            'Angstrom', 'angstrom', 'AU', 'au', 'Ba', 'dB', 'mas'
        ]
        si_prefixes = [
            'y', 'z', 'a', 'f', 'p', 'n', 'u', 'm', 'c', 'd',
            '', 'da', 'h', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
        ]
        binary_prefixes = [
            'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei'
        ]
        deprecated_units = set([
            'a', 'angstrom', 'Angstrom', 'au', 'Ba', 'barn', 'ct',
            'erg', 'G', 'ph', 'pix'
        ])

        def do_defines(bases, prefixes, skips=[]):
            for base in bases:
                for prefix in prefixes:
                    key = prefix + base
                    if key in skips:
                        continue
                    if keyword.iskeyword(key):
                        continue

                    names[key] = getattr(u if hasattr(u, key) else uvo, key)
                    if base in deprecated_units:
                        deprecated_names.add(key)

        do_defines(bases, si_prefixes, ['pct', 'pcount', 'yd'])
        do_defines(binary_bases, si_prefixes + binary_prefixes, ['dB', 'dbyte'])
        do_defines(simple_units, [''])

        return names, deprecated_names, [] 
开发者ID:holzschu,项目名称:Carnets,代码行数:54,代码来源:vounit.py


注:本文中的astropy.units方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。