本文整理汇总了Python中astropy.units.hourangle方法的典型用法代码示例。如果您正苦于以下问题:Python units.hourangle方法的具体用法?Python units.hourangle怎么用?Python units.hourangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.units
的用法示例。
在下文中一共展示了units.hourangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: radec_obs_vec_mpc
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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
示例2: parse_ra_dec
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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
示例3: get_target_coords
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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
示例4: test_init_lonlat
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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
示例5: test_unit_spherical
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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)
示例6: test_to_string_precision
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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'
示例7: test_to_string_decimal
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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'
示例8: setup
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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()
示例9: _erfa_sidereal_time
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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)
示例10: test_values_unit
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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)
示例11: __init__
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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)
示例12: base_spacing
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
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
示例13: to_target
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
def to_target(self):
target = super().to_target()
target.type = 'SIDEREAL'
target.name = (self.catalog_data['name_prefix'] + self.catalog_data['name'])
c = SkyCoord('{0} {1}'.format(self.catalog_data['ra'], self.catalog_data['dec']), unit=(u.hourangle, u.deg))
target.ra, target.dec = c.ra.deg, c.dec.deg
return target
示例14: to_python
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
def to_python(self, value):
try:
a = float(value)
return a
except ValueError:
try:
if self.c_type == 'ra':
a = Angle(value, unit=u.hourangle)
else:
a = Angle(value, unit=u.degree)
return a.to(u.degree).value
except Exception:
raise ValidationError('Invalid format. Please use sexigesimal or degrees')
示例15: add_event
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import hourangle [as 别名]
def add_event(cat, event, convert_coords=True):
"""Add event to global arrays."""
apidata._all.append(event)
apidata._cat_keys[cat].update(list(apidata._catalogs[cat][event].keys()))
levent = apidata._catalogs[cat].get(event, {})
laliases = levent.get('alias', [])
lev = event.lower()
laliases = list(set([lev,
replace_multiple(lev, ['sn', 'at']) if lev.startswith(('sn', 'at')) else lev] + [
x['value'].lower() for x in laliases] + [
replace_multiple(x['value'].lower(), ['sn', 'at'])
for x in laliases if x['value'].lower().startswith((
'sn', 'at'))
]))
for alias in laliases:
apidata._aliases.setdefault(alias.lower().replace(' ', ''),
[]).append([cat, event, alias])
apidata._all_aliases.add(alias)
lra = levent.get('ra')
ldec = levent.get('dec')
if lra is None or ldec is None:
return
lra = lra[0].get('value')
ldec = ldec[0].get('value')
if lra is None or ldec is None:
return
if not raregex.match(lra) or not decregex.match(ldec):
return
apidata._rdnames.append(event)
if convert_coords:
apidata._coo = coord_concat(
(apidata._coo, coord(lra, ldec, unit=(un.hourangle, un.deg))))
else:
apidata._ras.append(lra)
apidata._decs.append(ldec)