Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*Calculations to translate coordinates across the sky* 

5 

6:Author: 

7 David Young 

8""" 

9from __future__ import division 

10from builtins import object 

11from past.utils import old_div 

12import sys 

13import os 

14import math 

15os.environ['TERM'] = 'vt100' 

16from fundamentals import tools 

17from astrocalc.coords import unit_conversion 

18 

19class translate(object): 

20 """ 

21 *Translate a set of coordinates north and east by distances given in arcsecs* 

22 

23 **Key Arguments** 

24 

25 - ``log`` -- logger 

26 - ``settings`` -- the settings dictionary. Default *False* 

27 - ``ra`` -- ra (decimal or sexegesimal) 

28 - ``dec`` -- dec (decimal or sexegesimal) 

29 - ``northArcsec`` -- number of arcsecs to move location to the north 

30 - ``eastArcsec`` -- number of arcsecs to move location to the east 

31  

32 

33 .. todo:: 

34 

35 - replace shift_coordinates class in all other code 

36 

37 **Usage** 

38 

39 To shift a set of coordinates north and east by given distances: 

40 

41 ```python 

42 # TRANSLATE COORDINATES ACROSS SKY 

43 from astrocalc.coords import translate 

44 ra, dec = translate( 

45 log=log, 

46 settings=settings, 

47 ra="14.546438", 

48 dec="-45.34232334", 

49 northArcsec=4560, 

50 eastArcsec=+967800 

51 ).get()  

52 ``` 

53  

54 """ 

55 # Initialisation 

56 

57 def __init__( 

58 self, 

59 log, 

60 ra, 

61 dec, 

62 northArcsec, 

63 eastArcsec, 

64 settings=False, 

65 ): 

66 self.log = log 

67 log.debug("instansiating a new 'translate' object") 

68 self.settings = settings 

69 self.ra = ra 

70 self.dec = dec 

71 self.north = northArcsec / 3600. 

72 self.east = eastArcsec / 3600. 

73 # xt-self-arg-tmpx 

74 

75 # CONSTANTS 

76 self.pi = (4 * math.atan(1.0)) 

77 self.DEG_TO_RAD_FACTOR = self.pi / 180.0 

78 self.RAD_TO_DEG_FACTOR = 180.0 / self.pi 

79 

80 # INITIAL ACTIONS 

81 # CONVERT RA AND DEC INTO DECIMAL DEGREES 

82 converter = unit_conversion( 

83 log=log 

84 ) 

85 self.ra = converter.ra_sexegesimal_to_decimal( 

86 ra=self.ra 

87 ) 

88 self.dec = converter.dec_sexegesimal_to_decimal( 

89 dec=self.dec 

90 ) 

91 

92 return None 

93 

94 def get(self): 

95 """ 

96 *translate the coordinates* 

97 

98 **Return** 

99 

100 - ``ra`` -- the right-ascension of the translated coordinate 

101 - ``dec`` -- the declination of the translated coordinate 

102  

103 """ 

104 self.log.debug('starting the ``get`` method') 

105 

106 # PRECISION TEST 

107 decprecision = len(repr(self.dec).split(".")[-1]) 

108 raprecision = len(repr(self.ra).split(".")[-1]) 

109 

110 dec2 = self.dec + self.north 

111 

112 ra2 = self.ra + \ 

113 (old_div((self.east), 

114 (math.cos((self.dec + dec2) * self.DEG_TO_RAD_FACTOR / 2.)))) 

115 

116 # FIX VALUES THAT CROSS RA/DEC LIMITS 

117 while ra2 > 360. or ra2 < 0.: 

118 while ra2 > 360.: 

119 ra2 = ra2 - 360. 

120 while ra2 < 0.: 

121 ra2 = ra2 + 360. 

122 while dec2 > 90. or dec2 < -90.: 

123 while dec2 > 90.: 

124 dec2 = 180. - dec2 

125 while dec2 < -90.: 

126 dec2 = -180. - dec2 

127 

128 ra2 = "%0.*f" % (raprecision, ra2) 

129 dec2 = "%0.*f" % (decprecision, dec2) 

130 

131 self.log.debug('completed the ``get`` method') 

132 return ra2, dec2 

133 

134 # xt-class-method