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


Python units.Quantity方法代码示例

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


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

示例1: query_gal

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def query_gal(self, l, b, d=None, **kwargs):
        """
        A web API version of :obj:`DustMap.query_gal()`. See the documentation for
        the corresponding local query object. Queries using Galactic
        coordinates.

        Args:
            l (:obj:`float`, scalar or array-like): Galactic longitude, in degrees,
                or as an :obj:`astropy.unit.Quantity`.
            b (:obj:`float`, scalar or array-like): Galactic latitude, in degrees,
                or as an :obj:`astropy.unit.Quantity`.
            d (Optional[:obj:`float`, scalar or array-like]): Distance from the Solar
                System, in kpc, or as an :obj:`astropy.unit.Quantity`. Defaults to
                ``None``, meaning no distance is specified.
            **kwargs: Any additional keyword arguments accepted by derived
                classes.

        Returns:
            The results of the query.
        """
        pass 
开发者ID:gregreen,项目名称:dustmaps,代码行数:23,代码来源:map_base.py

示例2: query_equ

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def query_equ(self, ra, dec, d=None, frame='icrs', **kwargs):
        """
        A web API version of :obj:`DustMap.query_equ()`. See the documentation for
        the corresponding local query object. Queries using Equatorial
        coordinates. By default, the ICRS frame is used, although other frames
        implemented by :obj:`astropy.coordinates` may also be specified.

        Args:
            ra (:obj:`float`, scalar or array-like): Galactic longitude, in degrees,
                or as an :obj:`astropy.unit.Quantity`.
            dec (:obj:`float`, scalar or array-like): Galactic latitude, in degrees,
                or as an :obj:`astropy.unit.Quantity`.
            d (Optional[:obj:`float`, scalar or array-like]): Distance from the Solar
                System, in kpc, or as an :obj:`astropy.unit.Quantity`. Defaults to
                ``None``, meaning no distance is specified.
            frame (Optional[icrs]): The coordinate system. Can be 'icrs' (the
                default), 'fk5', 'fk4' or 'fk4noeterms'.
            **kwargs: Any additional keyword arguments accepted by derived
                classes.

        Returns:
            The results of the query.
        """
        pass 
开发者ID:gregreen,项目名称:dustmaps,代码行数:26,代码来源:map_base.py

示例3: stellarTeff

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def stellarTeff(self, sInds):
        """Calculate the effective stellar temperature based on B-V color.
        
        This method uses the empirical fit from Ballesteros (2012) doi:10.1209/0295-5075/97/34008
        
        Args:
            sInds (integer ndarray):
                Indices of the stars of interest
        
        Returns:
            Quantity array:
                Stellar effective temperatures in degrees K
        
        """
        
        # cast sInds to array
        sInds = np.array(sInds, ndmin=1, copy=False)
        
        Teff = 4600.0*u.K * (1.0/(0.92*self.BV[sInds] + 1.7) + 1.0/(0.92*self.BV[sInds] + 0.62))
        
        return Teff 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:23,代码来源:TargetList.py

示例4: eclip2equat

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def eclip2equat(self, r_eclip, currentTime):
        """Rotates heliocentric coordinates from ecliptic to equatorial frame.
        
        Args:
            r_eclip (astropy Quantity nx3 array):
                Positions vector in heliocentric ecliptic frame in units of AU
            currentTime (astropy Time array):
                Current absolute mission time in MJD
        
        Returns:
            r_equat (astropy Quantity nx3 array):
                Positions vector in heliocentric equatorial frame in units of AU
        
        """
        
        r_equat = self.equat2eclip(r_eclip, currentTime, rotsign=-1)
        
        return r_equat 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:20,代码来源:Observatory.py

示例5: get_time

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def get_time(self, frame_rate=None):
        """Converts ref_epoch, seconds, and frame_nr to Time object.

        Uses 'ref_epoch', which stores the number of half-years from 2000,
        and 'seconds'.  By default, it also calculates the offset using
        the current frame number.  For non-zero 'frame_nr', this requires the
        frame rate, which is calculated from the sample rate in the header.
        The latter can also be explicitly passed on.

        Parameters
        ----------
        frame_rate : `~astropy.units.Quantity`, optional
            For non-zero 'frame_nr', this is used to calculate the
            corresponding offset. If not given, the frame rate from the
            header is used (if it is non-zero).

        Returns
        -------
        time : `~astropy.time.Time`
        """
        if frame_rate is None and self['sampling_rate'] != 0:
            frame_rate = self.frame_rate
        return super().get_time(frame_rate=frame_rate) 
开发者ID:mhvk,项目名称:baseband,代码行数:25,代码来源:header.py

示例6: get_frame_rate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def get_frame_rate(self):
        """Determine the number of frames per second.

        The frame rate is calculated from the time elapsed between the
        first two frames, as inferred from their time stamps.

        Returns
        -------
        frame_rate : `~astropy.units.Quantity`
            Frames per second.
        """
        with self.temporary_offset(0):
            header0 = self.find_header()
            self.seek(header0.frame_nbytes, 1)
            header1 = self.read_header()

        # Mark 4 specification states frames-lengths range from 1.25 ms
        # to 160 ms.
        tdelta = (header1.fraction[0] - header0.fraction[0]) % 1.
        return u.Quantity(1 / tdelta, u.Hz).round() 
开发者ID:mhvk,项目名称:baseband,代码行数:22,代码来源:base.py

示例7: mape_core

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def mape_core(x, y, axis=None, mode=None):
    if isinstance(x, list):
        x = np.array(x)
    if isinstance(y, list):
        y = np.array(y)
    if isinstance(x, u.Quantity) and isinstance(y, u.Quantity):
        percentage = ((x - y) / y).value
        # still need to take the value for creating mask
        x = x.value
        y = y.value
    elif (isinstance(x, u.Quantity) and not isinstance(y, u.Quantity)) or \
            (not isinstance(x, u.Quantity) and isinstance(y, u.Quantity)):
        raise TypeError("Only one of your data provided has astropy units \n"
                        "Either both x and y are ndarray or both x and y are astropy.Quatity, "
                        "return without astropy units in all case")
    else:
        percentage = (x - y) / y
    if mode == 'mean':
        return np.ma.mean(np.ma.array(np.abs(percentage) * 100., mask=((x == MAGIC_NUMBER) | (y == MAGIC_NUMBER))),
                          axis=axis)
    elif mode == 'median':
        return np.ma.median(np.ma.array(np.abs(percentage) * 100., mask=[(x == MAGIC_NUMBER) | (y == MAGIC_NUMBER)]),
                            axis=axis) 
开发者ID:henrysky,项目名称:astroNN,代码行数:25,代码来源:numpy.py

示例8: mean_absolute_percentage_error

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def mean_absolute_percentage_error(x, y, axis=None):
    """
    | NumPy implementation of tf.keras.metrics.mean_absolute_percentage_error with capability to deal with ``magicnumber``
      and astropy Quantity
    | Either both x and y are ndarray or both x and y are astropy.Quatity, return has no astropy units in all case

    :param x: prediction
    :type x: Union[ndarray, float, astropy.Quatity]
    :param y: ground truth
    :type y: Union[ndarray, float, astropy.Quatity]
    :param axis: NumPy axis
    :type axis: Union[NoneType, int]
    :raise: TypeError when only either x or y contains astropy units. Both x, y should carry/not carry astropy units at the same time
    :return: Mean Absolute Percentage Error
    :rtype: Union[ndarray, float]
    :History: 2018-Apr-11 - Written - Henry Leung (University of Toronto)
    """
    return mape_core(x, y, axis=axis, mode='mean') 
开发者ID:henrysky,项目名称:astroNN,代码行数:20,代码来源:numpy.py

示例9: median_absolute_percentage_error

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def median_absolute_percentage_error(x, y, axis=None):
    """
    | NumPy implementation of a median version of tf.keras.metrics.mean_absolute_percentage_error with capability to
    | deal with ``magicnumber`` and astropy Quantity
    | Either both x and y are ndarray or both x and y are astropy.Quatity, return has no astropy units in all case

    :param x: prediction
    :type x: Union[ndarray, float, astropy.Quatity]
    :param y: ground truth
    :type y: Union[ndarray, float, astropy.Quatity]
    :param axis: NumPy axis
    :type axis: Union[NoneType, int]
    :raise: TypeError when only either x or y contains astropy units. Both x, y should carry/not carry astropy units at the same time
    :return: Median Absolute Percentage Error
    :rtype: Union[ndarray, float]
    :History: 2018-May-13 - Written - Henry Leung (University of Toronto)
    """
    return mape_core(x, y, axis=axis, mode='median') 
开发者ID:henrysky,项目名称:astroNN,代码行数:20,代码来源:numpy.py

示例10: mae_core

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def mae_core(x, y, axis=None, mode=None):
    if isinstance(x, list):
        x = np.array(x)
    if isinstance(y, list):
        y = np.array(y)
    if isinstance(x, u.Quantity) and isinstance(y, u.Quantity):
        diff = (x - y).value
        # still need to take the value for creating mask
        x = x.value
        y = y.value
    elif (isinstance(x, u.Quantity) and not isinstance(y, u.Quantity)) or \
            (not isinstance(x, u.Quantity) and isinstance(y, u.Quantity)):
        raise TypeError("Only one of your data provided has astropy units \n"
                        "Either both x and y are ndarray or both x and y are astropy.Quatity, "
                        "return without astropy units in all case")
    else:
        diff = (x - y)
    if mode == 'mean':
        return np.ma.mean(np.ma.array(np.abs(diff), mask=((x == MAGIC_NUMBER) | (y == MAGIC_NUMBER))), axis=axis)
    elif mode == 'median':
        return np.ma.median(np.ma.array(np.abs(diff), mask=[(x == MAGIC_NUMBER) | (y == MAGIC_NUMBER)]), axis=axis) 
开发者ID:henrysky,项目名称:astroNN,代码行数:23,代码来源:numpy.py

示例11: mean_absolute_error

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def mean_absolute_error(x, y, axis=None):
    """
    NumPy implementation of tf.keras.metrics.mean_absolute_error  with capability to deal with ``magicnumber``
    and astropy Quantity

    Either both x and y are ndarray or both x and y are astropy.Quatity, return without astropy units in all case

    :param x: prediction
    :type x: Union[ndarray, float, astropy.Quatity]
    :param y: ground truth
    :type y: Union[ndarray, float, astropy.Quatity]
    :param axis: NumPy axis
    :type axis: Union[NoneType, int]
    :raise: TypeError when only either x or y contains astropy units. Both x, y should carry/not carry astropy units at the same time
    :return: Mean Absolute Error
    :rtype: Union[ndarray, float]
    :History: 2018-Apr-11 - Written - Henry Leung (University of Toronto)
    """
    return mae_core(x, y, axis=axis, mode='mean') 
开发者ID:henrysky,项目名称:astroNN,代码行数:21,代码来源:numpy.py

示例12: absmag_to_pc

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def absmag_to_pc(absmag, mag):
    """
    To convert absolute magnitude to parsec, Magic Number will be preserved

    :param absmag: absolute magnitude
    :type absmag: Union[float, ndarray]
    :param mag: apparent magnitude
    :type mag: Union[float, ndarray]
    :return: parsec
    :rtype: astropy Quantity
    :History: 2017-Nov-16 - Written - Henry Leung (University of Toronto)
    """
    absmag = np.array(absmag)
    mag = np.array(mag)
    magic_idx = ((absmag == MAGIC_NUMBER) | (mag == MAGIC_NUMBER))  # check for magic number

    with warnings.catch_warnings():  # suppress numpy Runtime warning caused by MAGIC_NUMBER
        warnings.simplefilter("ignore")
        pc = (10. ** (((mag - absmag) / 5.) + 1.))

    if absmag.shape != ():  # check if its only 1 element
        pc[magic_idx] = MAGIC_NUMBER
        return pc * u.parsec
    else:
        return (MAGIC_NUMBER if magic_idx == [1] else pc) * u.parsec 
开发者ID:henrysky,项目名称:astroNN,代码行数:27,代码来源:gaia_shared.py

示例13: prepare_quantity

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def prepare_quantity(value, units=None, name_val=None):
    """ The function verifys that a
    """
    if value is None:
        return None

    if isinstance(value, u.Quantity):
        if units in [u.K, u.deg_C, u.Kelvin, u.Celsius, u.imperial.deg_F]:
            return value.to(units, equivalencies=u.temperature()).value
        else:
            return value.to(units).value

    elif isinstance(value, numbers.Number) and units is not None:
        return value
    elif isinstance(value, np.ndarray) and units is not None:
        return value
    elif isinstance(value, list) and units is not None:
        return np.array([prepare_quantity(v, units, name_val) for v in value])
    elif isinstance(value, tuple) and units is not None:
        return np.array([prepare_quantity(v, units, name_val) for v in value])
    else:
        raise ValueError('%s has not the correct format. It must be a value,'
                         'sequence, array, or a Quantity with %s units' %
                         (name_val, str(units))) 
开发者ID:iportillo,项目名称:ITU-Rpy,代码行数:26,代码来源:utils.py

示例14: test_find_neighbor_pixels

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def test_find_neighbor_pixels():
    """ test basic neighbor functionality """
    n_pixels = 5
    x, y = u.Quantity(
        np.meshgrid(np.linspace(-5, 5, n_pixels), np.linspace(-5, 5, n_pixels)), u.cm
    )

    geom = CameraGeometry(
        "test",
        pix_id=np.arange(n_pixels),
        pix_area=u.Quantity(4, u.cm ** 2),
        pix_x=x.ravel(),
        pix_y=y.ravel(),
        pix_type="rectangular",
    )

    neigh = geom.neighbors
    assert set(neigh[11]) == {16, 6, 10, 12} 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:20,代码来源:test_geometry.py

示例15: test_calc_pixel_neighbors_square_diagonal

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Quantity [as 别名]
def test_calc_pixel_neighbors_square_diagonal():
    """
    check that neighbors for square-pixel cameras are what we expect,
    namely that the diagonals are included if requested.
    """
    x, y = np.meshgrid(np.arange(20), np.arange(20))

    cam = CameraGeometry(
        camera_name="test",
        pix_id=np.arange(400),
        pix_type="rectangular",
        pix_x=u.Quantity(x.ravel(), u.cm),
        pix_y=u.Quantity(y.ravel(), u.cm),
        pix_area=u.Quantity(np.ones(400), u.cm ** 2),
    )

    cam._neighbors = cam.calc_pixel_neighbors(diagonal=True)
    assert set(cam.neighbors[21]) == {0, 1, 2, 20, 22, 40, 41, 42} 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:20,代码来源:test_geometry.py


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