Python astropy.units.hourangle() Examples

The following are 30 code examples of astropy.units.hourangle(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module astropy.units , or try the search function .
Example #1
Source File: fits_utils.py    From banzai with GNU General Public License v3.0 6 votes vote down vote up
def parse_ra_dec(header):
    try:
        coord = SkyCoord(header.get('CRVAl1'), header.get('CRVAL2'), unit=(units.degree, units.degree))
        ra = coord.ra.deg
        dec = coord.dec.deg
    except (ValueError, TypeError):
        # Fallback to RA and DEC
        try:
            coord = SkyCoord(header.get('RA'), header.get('DEC'), unit=(units.hourangle, units.degree))
            ra = coord.ra.deg
            dec = coord.dec.deg
        except (ValueError, TypeError):
            # Fallback to Cat-RA and CAT-DEC
            try:
                coord = SkyCoord(header.get('CAT-RA'), header.get('CAT-DEC'), unit=(units.hourangle, units.degree))
                ra = coord.ra.deg
                dec = coord.dec.deg
            except (ValueError, TypeError) as e:
                logger.error('Could not get initial pointing guess. {0}'.format(e),
                             extra_tags={'filename': header.get('ORIGNAME')})
                ra, dec = np.nan, np.nan
    return ra, dec 
Example #2
Source File: test_formatting.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_to_string_precision():
    # There are already some tests in test_api.py, but this is a regression
    # test for the bug in issue #1319 which caused incorrect formatting of the
    # seconds for precision=0

    angle = Angle(-1.23456789, unit=u.degree)

    assert angle.to_string(precision=3) == '-1d14m04.444s'
    assert angle.to_string(precision=1) == '-1d14m04.4s'
    assert angle.to_string(precision=0) == '-1d14m04s'

    angle2 = Angle(-1.23456789, unit=u.hourangle)

    assert angle2.to_string(precision=3, unit=u.hour) == '-1h14m04.444s'
    assert angle2.to_string(precision=1, unit=u.hour) == '-1h14m04.4s'
    assert angle2.to_string(precision=0, unit=u.hour) == '-1h14m04s'

    # Regression test for #7141
    angle3 = Angle(-0.5, unit=u.degree)
    assert angle3.to_string(precision=0, fields=3) == '-0d30m00s'
    assert angle3.to_string(precision=0, fields=2) == '-0d30m'
    assert angle3.to_string(precision=0, fields=1) == '-1d' 
Example #3
Source File: test_formatting.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_to_string_decimal():

    # There are already some tests in test_api.py, but this is a regression
    # test for the bug in issue #1323 which caused decimal formatting to not
    # work

    angle1 = Angle(2., unit=u.degree)

    assert angle1.to_string(decimal=True, precision=3) == '2.000'
    assert angle1.to_string(decimal=True, precision=1) == '2.0'
    assert angle1.to_string(decimal=True, precision=0) == '2'

    angle2 = Angle(3., unit=u.hourangle)

    assert angle2.to_string(decimal=True, precision=3) == '3.000'
    assert angle2.to_string(decimal=True, precision=1) == '3.0'
    assert angle2.to_string(decimal=True, precision=0) == '3'

    angle3 = Angle(4., unit=u.radian)

    assert angle3.to_string(decimal=True, precision=3) == '4.000'
    assert angle3.to_string(decimal=True, precision=1) == '4.0'
    assert angle3.to_string(decimal=True, precision=0) == '4' 
Example #4
Source File: test_representation.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_init_lonlat(self):

        s2 = SphericalRepresentation(Longitude(8, u.hour),
                                     Latitude(5, u.deg),
                                     Distance(10, u.kpc))

        assert s2.lon == 8. * u.hourangle
        assert s2.lat == 5. * u.deg
        assert s2.distance == 10. * u.kpc

        assert isinstance(s2.lon, Longitude)
        assert isinstance(s2.lat, Latitude)
        assert isinstance(s2.distance, Distance)

        # also test that wrap_angle is preserved
        s3 = SphericalRepresentation(Longitude(-90, u.degree,
                                               wrap_angle=180*u.degree),
                                     Latitude(-45, u.degree),
                                     Distance(1., u.Rsun))
        assert s3.lon == -90. * u.degree
        assert s3.lon.wrap_angle == 180 * u.degree 
Example #5
Source File: test_representation_methods.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setup(self):
        lon = Longitude(np.arange(0, 24, 4), u.hourangle)
        lat = Latitude(np.arange(-90, 91, 30), u.deg)

        # With same-sized arrays
        self.s0 = SphericalRepresentation(
            lon[:, np.newaxis] * np.ones(lat.shape),
            lat * np.ones(lon.shape)[:, np.newaxis],
            np.ones(lon.shape + lat.shape) * u.kpc)

        self.diff = SphericalDifferential(
            d_lon=np.ones(self.s0.shape)*u.mas/u.yr,
            d_lat=np.ones(self.s0.shape)*u.mas/u.yr,
            d_distance=np.ones(self.s0.shape)*u.km/u.s)
        self.s0 = self.s0.with_differentials(self.diff)

        # With unequal arrays -> these will be broadcasted.
        self.s1 = SphericalRepresentation(lon[:, np.newaxis], lat, 1. * u.kpc,
                                          differentials=self.diff)

        # For completeness on some tests, also a cartesian one
        self.c0 = self.s0.to_cartesian() 
Example #6
Source File: test_representation_arithmetic.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_unit_spherical(self):
        s = UnitSphericalRepresentation(lon=[0., 6., 21.] * u.hourangle,
                                        lat=[0., -30., 85.] * u.deg)

        e = s.unit_vectors()
        self.check_unit_vectors(e)
        sf = s.scale_factors()
        self.check_scale_factors(sf, s)

        s_lon = s + 1e-5 * np.cos(s.lat) * e['lon']
        assert_quantity_allclose(s_lon.lon, s.lon + 1e-5*u.rad,
                                 atol=1e-10*u.rad)
        assert_quantity_allclose(s_lon.lat, s.lat, atol=1e-10*u.rad)
        s_lon2 = s + 1e-5 * u.radian * sf['lon'] * e['lon']
        assert_representation_allclose(s_lon2, s_lon)

        s_lat = s + 1e-5 * e['lat']
        assert_quantity_allclose(s_lat.lon, s.lon)
        assert_quantity_allclose(s_lat.lat, s.lat + 1e-5*u.rad,
                                 atol=1e-10*u.rad)
        s_lat2 = s + 1.e-5 * u.radian * sf['lat'] * e['lat']
        assert_representation_allclose(s_lat2, s_lat) 
Example #7
Source File: get_catalog.py    From mirage with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_target_coords(xml_filename):
    '''Parse APT xml file to extract RA and Dec from each target

    Parameters
    ----------
    xml_filename : str
        Path to APT .xml file

    Returns
    -------
    target_coords : list
        List of astropy SkyCoord objects for all targets
    '''
    xml_info = ReadAPTXML()
    xml_info.read_xml(xml_filename)
    targ_dict = xml_info.target_info
    target_list = []
    target_coords = []
    for key in targ_dict:
        target_list.append(key)
        ra_str, dec_str = targ_dict[key]
        target_coords.append(SkyCoord('{} {}'.format(ra_str, dec_str), unit=(u.hourangle, u.deg)))

    return target_list, target_coords 
Example #8
Source File: core.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _erfa_sidereal_time(self, model):
        """Calculate a sidereal time using a IAU precession/nutation model."""

        from astropy.coordinates import Longitude

        erfa_function = model['function']
        erfa_parameters = [getattr(getattr(self, scale)._time, jd_part)
                           for scale in model['scales']
                           for jd_part in ('jd1', 'jd2_filled')]

        sidereal_time = erfa_function(*erfa_parameters)

        if self.masked:
            sidereal_time[self.mask] = np.nan

        return Longitude(sidereal_time, u.radian).to(u.hourangle) 
Example #9
Source File: gauss_method.py    From orbitdeterminator with MIT License 6 votes vote down vote up
def radec_obs_vec_mpc(inds, mpc_object_data):
    """Compute vector of observed ra,dec values for MPC tracking data.

       Args:
           inds (int array): line numbers of data in file
           mpc_object_data (ndarray): MPC observation data for object

       Returns:
           rov (1xlen(inds) array): vector of ra/dec observed values
    """
    rov = np.zeros((2*len(inds)))
    for i in range(0,len(inds)):
        indm1 = inds[i]-1
        # extract observations data
        timeobs = Time( datetime(mpc_object_data['yr'][indm1],
                                 mpc_object_data['month'][indm1],
                                 mpc_object_data['day'][indm1]) + timedelta(days=mpc_object_data['utc'][indm1]) )
        obs_t_ra_dec = SkyCoord(mpc_object_data['radec'][indm1], unit=(uts.hourangle, uts.deg), obstime=timeobs)
        rov[2*i-2], rov[2*i-1] = obs_t_ra_dec.ra.rad, obs_t_ra_dec.dec.rad
    return rov

# compute residuals vector for ra/dec observations with pre-computed observed radec values vector 
Example #10
Source File: test_formatter_locator.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_values_unit(self):

        # Make sure that the intrinsic unit and format unit are correctly
        # taken into account when using the locator

        fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.arcsec, decimal=True)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [1000., 1200., 1400., 1600., 1800., 2000.] * u.arcsec)

        fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.degree, decimal=False)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [15., 20., 25., 30., 35.] * u.arcmin)

        fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.hourangle, decimal=False)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [60., 75., 90., 105., 120., 135.] * (15 * u.arcsec))

        fl = AngleFormatterLocator(unit=u.arcsec)
        fl.format = 'dd:mm:ss'
        assert_quantity_allclose(fl.locator(0.9, 1.1)[0], [1] * u.arcsec)

        fl = AngleFormatterLocator(unit=u.arcsec, spacing=0.2 * u.arcsec)
        assert_quantity_allclose(fl.locator(0.3, 0.9)[0], [0.4, 0.6, 0.8] * u.arcsec) 
Example #11
Source File: formatter_locator.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, values=None, number=None, spacing=None, format=None,
                 unit=None, decimal=None, format_unit=None, show_decimal_unit=True):

        if unit is None:
            unit = u.degree

        if format_unit is None:
            format_unit = unit

        if format_unit not in (u.degree, u.hourangle, u.hour):
            if decimal is False:
                raise UnitsError("Units should be degrees or hours when using non-decimal (sexagesimal) mode")

        self._decimal = decimal
        self._sep = None
        self.show_decimal_unit = show_decimal_unit

        super().__init__(values=values, number=number, spacing=spacing,
                         format=format, unit=unit, format_unit=format_unit) 
Example #12
Source File: formatter_locator.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def base_spacing(self):

        if self.decimal:

            spacing = self._format_unit / (10. ** self._precision)

        else:

            if self._fields == 1:
                spacing = 1. * u.degree
            elif self._fields == 2:
                spacing = 1. * u.arcmin
            elif self._fields == 3:
                if self._precision == 0:
                    spacing = 1. * u.arcsec
                else:
                    spacing = u.arcsec / (10. ** self._precision)

        if self._format_unit is u.hourangle:
            spacing *= 15

        return spacing 
Example #13
Source File: test_formatter_locator.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_decimal_values(self):

        # Regression test for a bug that meant that the spacing was not
        # determined correctly for decimal coordinates

        fl = AngleFormatterLocator()
        fl.format = 'd.dddd'
        assert_quantity_allclose(fl.locator(266.9730, 266.9750)[0],
                                 [266.9735, 266.9740, 266.9745, 266.9750] * u.deg)

        fl = AngleFormatterLocator(decimal=True, format_unit=u.hourangle, number=4)
        assert_quantity_allclose(fl.locator(266.9730, 266.9750)[0],
                                 [17.79825, 17.79830] * u.hourangle) 
Example #14
Source File: utils.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def select_step_hour(dv):

    if dv > 15. * u.arcsec:

        hour_limits_ = [1.5, 2.5, 3.5, 5, 7, 10, 15, 21, 36]
        hour_steps_ = [1, 2, 3, 4, 6, 8, 12, 18, 24]
        hour_units = [u.hourangle] * len(hour_steps_)

        minsec_limits_ = [1.5, 2.5, 3.5, 4.5, 5.5, 8, 11, 14, 18, 25, 45]
        minsec_steps_ = [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30]

        minute_limits_ = np.array(minsec_limits_) / 60.
        minute_units = [15. * u.arcmin] * len(minute_limits_)

        second_limits_ = np.array(minsec_limits_) / 3600.
        second_units = [15. * u.arcsec] * len(second_limits_)

        hour_limits = np.concatenate([second_limits_,
                                      minute_limits_,
                                      hour_limits_])

        hour_steps = minsec_steps_ + minsec_steps_ + hour_steps_
        hour_units = second_units + minute_units + hour_units

        n = hour_limits.searchsorted(dv.to(u.hourangle))
        step = hour_steps[n]
        unit = hour_units[n]

        return step * unit

    else:

        return select_step_scalar(dv.to_value(15. * u.arcsec)) * (15. * u.arcsec) 
Example #15
Source File: test_representation_arithmetic.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _setup(self, omit_coslat):
        if omit_coslat:
            self.SD_cls = SphericalCosLatDifferential
        else:
            self.SD_cls = SphericalDifferential

        s = SphericalRepresentation(lon=[0., 6., 21.] * u.hourangle,
                                    lat=[0., -30., 85.] * u.deg,
                                    distance=[1, 2, 3] * u.kpc)
        self.s = s
        self.e = s.unit_vectors()
        self.sf = s.scale_factors(omit_coslat=omit_coslat) 
Example #16
Source File: angles.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _convert_unit_to_angle_unit(unit):
        return u.hourangle if unit is u.hour else unit 
Example #17
Source File: formatter_locator.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def decimal(self):
        decimal = self._decimal
        if self.format_unit not in (u.degree, u.hourangle, u.hour):
            if self._decimal is None:
                decimal = True
            elif self._decimal is False:
                raise UnitsError("Units should be degrees or hours when using non-decimal (sexagesimal) mode")
        elif self._decimal is None:
            decimal = False
        return decimal 
Example #18
Source File: angles.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _tuple_to_float(angle, unit):
        """
        Converts an angle represented as a 3-tuple or 2-tuple into a floating
        point number in the given unit.
        """
        # TODO: Numpy array of tuples?
        if unit == u.hourangle:
            return util.hms_to_hours(*angle)
        elif unit == u.degree:
            return util.dms_to_degrees(*angle)
        else:
            raise u.UnitsError("Can not parse '{}' as unit '{}'"
                               .format(angle, unit)) 
Example #19
Source File: test_format.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_double_superscript():
    """Regression test for #5870, #8699, #9218; avoid double superscripts."""
    assert (u.deg).to_string("latex") == r'$\mathrm{{}^{\circ}}$'
    assert (u.deg**2).to_string("latex") == r'$\mathrm{deg^{2}}$'
    assert (u.arcmin).to_string("latex") == r'$\mathrm{{}^{\prime}}$'
    assert (u.arcmin**2).to_string("latex") == r'$\mathrm{arcmin^{2}}$'
    assert (u.arcsec).to_string("latex") == r'$\mathrm{{}^{\prime\prime}}$'
    assert (u.arcsec**2).to_string("latex") == r'$\mathrm{arcsec^{2}}$'
    assert (u.hourangle).to_string("latex") == r'$\mathrm{{}^{h}}$'
    assert (u.hourangle**2).to_string("latex") == r'$\mathrm{hourangle^{2}}$'
    assert (u.electron).to_string("latex") == r'$\mathrm{e^{-}}$'
    assert (u.electron**2).to_string("latex") == r'$\mathrm{electron^{2}}$' 
Example #20
Source File: test_skycoord.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_skycoord_fk4(tmpdir):

    coords = ["1:12:43.2 +1:12:43", "1 12 43.2 +1 12 43"]
    c = SkyCoord(coords, frame=FK4, unit=(u.deg, u.hourangle), obstime="J1992.21")
    tree = dict(coord=c)
    assert_roundtrip_tree(tree, tmpdir) 
Example #21
Source File: test_shape_manipulation.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setup(self):
        lon = Longitude(np.arange(0, 24, 4), u.hourangle)
        lat = Latitude(np.arange(-90, 91, 30), u.deg)
        # With same-sized arrays, no attributes
        self.s0 = ICRS(lon[:, np.newaxis] * np.ones(lat.shape),
                       lat * np.ones(lon.shape)[:, np.newaxis])
        # Make an AltAz frame since that has many types of attributes.
        # Match one axis with times.
        self.obstime = (Time('2012-01-01') +
                        np.arange(len(lon))[:, np.newaxis] * u.s)
        # And another with location.
        self.location = EarthLocation(20.*u.deg, lat, 100*u.m)
        # Ensure we have a quantity scalar.
        self.pressure = 1000 * u.hPa
        # As well as an array.
        self.temperature = np.random.uniform(
            0., 20., size=(lon.size, lat.size)) * u.deg_C
        self.s1 = AltAz(az=lon[:, np.newaxis], alt=lat,
                        obstime=self.obstime,
                        location=self.location,
                        pressure=self.pressure,
                        temperature=self.temperature)
        # For some tests, also try a GCRS, since that has representation
        # attributes.  We match the second dimension (via the location)
        self.obsgeoloc, self.obsgeovel = self.location.get_gcrs_posvel(
            self.obstime[0, 0])
        self.s2 = GCRS(ra=lon[:, np.newaxis], dec=lat,
                       obstime=self.obstime,
                       obsgeoloc=self.obsgeoloc,
                       obsgeovel=self.obsgeovel)
        # For completeness, also some tests on an empty frame.
        self.s3 = GCRS(obstime=self.obstime,
                       obsgeoloc=self.obsgeoloc,
                       obsgeovel=self.obsgeovel)
        # And make a SkyCoord
        self.sc = SkyCoord(ra=lon[:, np.newaxis], dec=lat, frame=self.s3) 
Example #22
Source File: test_representation_arithmetic.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setup(self):
        self.s = SphericalRepresentation(lon=[0., 6., 21.] * u.hourangle,
                                         lat=[0., -30., 85.] * u.deg,
                                         distance=[1, 2, 3] * u.kpc) 
Example #23
Source File: test_representation_arithmetic.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _setup(self, omit_coslat):
        if omit_coslat:
            self.USD_cls = UnitSphericalCosLatDifferential
        else:
            self.USD_cls = UnitSphericalDifferential

        s = UnitSphericalRepresentation(lon=[0., 6., 21.] * u.hourangle,
                                        lat=[0., -30., 85.] * u.deg)
        self.s = s
        self.e = s.unit_vectors()
        self.sf = s.scale_factors(omit_coslat=omit_coslat) 
Example #24
Source File: test_sky_coord.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_no_copy():
    c1 = SkyCoord(np.arange(10.) * u.hourangle, np.arange(20., 30.) * u.deg)
    c2 = SkyCoord(c1, copy=False)
    # Note: c1.ra and c2.ra will *not* share memory, as these are recalculated
    # to be in "preferred" units.  See discussion in #4883.
    assert np.may_share_memory(c1.data.lon, c2.data.lon)
    c3 = SkyCoord(c1, copy=True)
    assert not np.may_share_memory(c1.data.lon, c3.data.lon) 
Example #25
Source File: test_representation_arithmetic.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_physical_spherical(self):

        s = PhysicsSphericalRepresentation(phi=[0., 6., 21.] * u.hourangle,
                                           theta=[90., 120., 5.] * u.deg,
                                           r=[1, 2, 3] * u.kpc)

        e = s.unit_vectors()
        self.check_unit_vectors(e)
        sf = s.scale_factors()
        self.check_scale_factors(sf, s)

        s_phi = s + s.r * 1e-5 * np.sin(s.theta) * e['phi']
        assert_quantity_allclose(s_phi.phi, s.phi + 1e-5*u.rad,
                                 atol=1e-10*u.rad)
        assert_quantity_allclose(s_phi.theta, s.theta, atol=1e-10*u.rad)
        assert_quantity_allclose(s_phi.r, s.r)
        s_phi2 = s + 1e-5 * u.radian * sf['phi'] * e['phi']
        assert_representation_allclose(s_phi2, s_phi)

        s_theta = s + s.r * 1e-5 * e['theta']
        assert_quantity_allclose(s_theta.phi, s.phi)
        assert_quantity_allclose(s_theta.theta, s.theta + 1e-5*u.rad,
                                 atol=1e-10*u.rad)
        assert_quantity_allclose(s_theta.r, s.r)
        s_theta2 = s + 1.e-5 * u.radian * sf['theta'] * e['theta']
        assert_representation_allclose(s_theta2, s_theta)

        s_r = s + 1. * u.pc * e['r']
        assert_quantity_allclose(s_r.phi, s.phi, atol=1e-10*u.rad)
        assert_quantity_allclose(s_r.theta, s.theta, atol=1e-10*u.rad)
        assert_quantity_allclose(s_r.r, s.r + 1.*u.pc)
        s_r2 = s + 1. * u.pc * sf['r'] * e['r']
        assert_representation_allclose(s_r2, s_r) 
Example #26
Source File: test_representation_arithmetic.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_spherical(self):
        s = SphericalRepresentation(lon=[0., 6., 21.] * u.hourangle,
                                    lat=[0., -30., 85.] * u.deg,
                                    distance=[1, 2, 3] * u.kpc)
        e = s.unit_vectors()
        self.check_unit_vectors(e)
        sf = s.scale_factors()
        self.check_scale_factors(sf, s)

        s_lon = s + s.distance * 1e-5 * np.cos(s.lat) * e['lon']
        assert_quantity_allclose(s_lon.lon, s.lon + 1e-5*u.rad,
                                 atol=1e-10*u.rad)
        assert_quantity_allclose(s_lon.lat, s.lat, atol=1e-10*u.rad)
        assert_quantity_allclose(s_lon.distance, s.distance)
        s_lon2 = s + 1e-5 * u.radian * sf['lon'] * e['lon']
        assert_representation_allclose(s_lon2, s_lon)

        s_lat = s + s.distance * 1e-5 * e['lat']
        assert_quantity_allclose(s_lat.lon, s.lon)
        assert_quantity_allclose(s_lat.lat, s.lat + 1e-5*u.rad,
                                 atol=1e-10*u.rad)
        assert_quantity_allclose(s_lon.distance, s.distance)
        s_lat2 = s + 1.e-5 * u.radian * sf['lat'] * e['lat']
        assert_representation_allclose(s_lat2, s_lat)

        s_distance = s + 1. * u.pc * e['distance']
        assert_quantity_allclose(s_distance.lon, s.lon, atol=1e-10*u.rad)
        assert_quantity_allclose(s_distance.lat, s.lat, atol=1e-10*u.rad)
        assert_quantity_allclose(s_distance.distance, s.distance + 1.*u.pc)
        s_distance2 = s + 1. * u.pc * sf['distance'] * e['distance']
        assert_representation_allclose(s_distance2, s_distance) 
Example #27
Source File: test_representation.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_readonly(self):

        s1 = PhysicsSphericalRepresentation(phi=[8, 9] * u.hourangle,
                                            theta=[5, 6] * u.deg,
                                            r=[10, 20] * u.kpc)

        with pytest.raises(AttributeError):
            s1.phi = 1. * u.deg

        with pytest.raises(AttributeError):
            s1.theta = 1. * u.deg

        with pytest.raises(AttributeError):
            s1.r = 1. * u.kpc 
Example #28
Source File: test_representation.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_broadcasting_mismatch(self):

        with pytest.raises(ValueError) as exc:
            s1 = PhysicsSphericalRepresentation(phi=[8, 9, 10] * u.hourangle,
                                                theta=[5, 6] * u.deg,
                                                r=[1, 2] * u.kpc)
        assert exc.value.args[0] == "Input parameters phi, theta, and r cannot be broadcast" 
Example #29
Source File: test_representation.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_broadcasting(self):

        s1 = PhysicsSphericalRepresentation(phi=[8, 9] * u.hourangle,
                                            theta=[5, 6] * u.deg,
                                            r=10 * u.kpc)

        assert_allclose_quantity(s1.phi, [120, 135] * u.degree)
        assert_allclose_quantity(s1.theta, [5, 6] * u.degree)
        assert_allclose_quantity(s1.r, [10, 10] * u.kpc) 
Example #30
Source File: test_representation.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_reprobj(self):

        s1 = PhysicsSphericalRepresentation(phi=8 * u.hourangle, theta=5 * u.deg, r=10 * u.kpc)

        s2 = PhysicsSphericalRepresentation.from_representation(s1)

        assert_allclose_quantity(s2.phi, 8. * u.hourangle)
        assert_allclose_quantity(s2.theta, 5. * u.deg)
        assert_allclose_quantity(s2.r, 10 * u.kpc)