Python astropy.units 模块,hourangle() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用astropy.units.hourangle()

项目:atoolbox    作者:liweitianux    | 项目源码 | 文件源码
def main():
    parser = argparse.ArgumentParser(
        description="Convert among multiple coordinate formats")
    parser.add_argument("coord", nargs="+")
    args = parser.parse_args()

    ra, dec = parse_coord(args.coord)
    info = (
        "%-14s  %-14s\n" % ("R.A.", "Dec.") +
        "%s--%s\n" % ("-"*14, "-"*14) +
        "%-14.3f  %-+14.3f\n" % (ra.deg, dec.deg) +
        "%-14s  %-14s\n" % (
            ra.to_string(unit=au.hourangle, precision=4),
            dec.to_string(unit=au.deg, alwayssign=True, precision=3)) +
        "%-14s  %-14s\n" % (
            ra.to_string(unit=au.hourangle, sep=":", precision=4),
            dec.to_string(unit=au.deg, alwayssign=True,
                          sep=":", precision=3)) +
        "%-14s  %-14s\n" % (
            ra.to_string(unit=au.hourangle, sep=" ", precision=4),
            dec.to_string(unit=au.deg, alwayssign=True,
                          sep=" ", precision=3))
    )
    print(info)
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def test_model_coords():
    coords = SkyCoord('18:00:00 -30:00:00', unit=(u.hourangle, u.deg))
    model_1 = Model({'t_0':2450000, 'u_0':0.1, 't_E':100}, coords='18:00:00 -30:00:00')
    assert isinstance(model_1.coords, SkyCoord)
    assert model_1.coords.ra == coords.ra
    assert model_1.coords.dec == coords.dec
    assert  model_1.coords.dec.deg == -30.00

    model_3 = Model({'t_0':2450000, 'u_0':0.1, 't_E':100})
    model_3.coords = '17:00:00 -27:32:14'
    assert model_3.coords.to_string('hmsdms') == '17h00m00s -27d32m14s'
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def test_data_coords():
    coords = SkyCoord('18:00:00 -30:00:00', unit=(u.hourangle, u.deg))
    data_1 = MulensData(
        file_name=SAMPLE_FILE_01,
        coords='18:00:00 -30:00:00')
    assert isinstance(data_1.coords, SkyCoord)
    assert data_1.coords.ra == coords.ra
    assert data_1.coords.dec == coords.dec
    assert data_1.coords.dec.deg == -30.00

    data_3 = MulensData(file_name=SAMPLE_FILE_01)
    data_3.coords = '17:00:00 -27:32:14'
    assert data_3.coords.to_string('hmsdms') == '17h00m00s -27d32m14s'
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def __init__(self,  *args, **kwargs):
        if not isinstance(args[0], SkyCoord) and 'unit' not in kwargs:
            kwargs['unit'] = (u.hourangle, u.deg)
        SkyCoord.__init__(self, *args, **kwargs)
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def xyz(self):
        """
        *Astropy.CartesianRepresentation*

        return X,Y,Z positions based on RA, DEC and distance
        """
        if self._xyz is None:
            ra_dec = [
                text.decode('UTF-8') for text in self.data_lists['ra_dec']]
            self._xyz = SkyCoord(
                ra_dec, distance=self.data_lists['distance'],
                unit=(u.hourangle, u.deg, u.au)).cartesian
        return self._xyz
项目:atoolbox    作者:liweitianux    | 项目源码 | 文件源码
def parse_coord(c):
    if len(c) == 6:
        # h m s d m s
        ra = Angle((float(c[0]), float(c[1]), float(c[2])), unit=au.hourangle)
        dec = Angle((float(c[3]), float(c[4]), float(c[5])), unit=au.deg)
    elif len(c) == 2:
        ra = Angle(float(c[0]), unit=au.deg)
        dec = Angle(float(c[1]), unit=au.deg)
    else:
        raise ValueError("invalid coordinate: {0}".format(c))
    return (ra, dec)
项目:DARKphot    作者:DARK-coding-wg    | 项目源码 | 文件源码
def _check_coords(self, position):
        """
        Check that a source position is in the correct format.
        If not, change to default coords.
        Args:
            position - source position. Must be 2-element list-like object with
                       position[0] = RA, position[1] = dec.
                       Acceptable formats for RA & dec are decimal degrees as
                       single floats or ints, or sexagisimal as 3-element
                       list-like object of (h,m,s), or strings with h:m:s.
        Returns:
            source_pos - Tuple of (RA,dec) in degrees.
        """
        if len(position) != 2:
            raise IOError('Position {:} has the wrong number of elements'.format(position))
        else:
            if not self._in_degrees(position):
                if isinstance(position[0], (np.ndarray, list)):
                    # SkyCoord interprets lists as multiple sources, not hour/min/sec
                    position = (tuple(position[0]), tuple(position[1]))
                try:
                    coords = SkyCoord(position[0], position[1], unit=(u.hourangle, u.deg))
                    new_pos = (coords.ra.deg, coords.dec.deg)
                except ValueError as exc:
                    logger.critical(exc)
                    raise
                except:
                    logger.critical('WARNING: RA and dec format cannot be read')
                    raise
            else:
                new_pos = (float(position[0]), float(position[1]))
            if not (0 <= new_pos[0] <= 360):
                raise ValueError('RA = {:.2f}, but should be in the range [0,360]'.format(new_pos[0]))
            if not (-90 <= new_pos[1] <= 90):
                raise ValueError('dec should be in the range [-90,90]')
        return new_pos