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*Convert single values of RA, DEC or list of RA and DEC to numpy arrays* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

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

12from fundamentals import tools 

13import numpy as np 

14from astrocalc.coords import unit_conversion 

15 

16def coordinates_to_array( 

17 log, 

18 ra, 

19 dec): 

20 """*Convert a single value RA, DEC or list of RA and DEC to numpy arrays* 

21 

22 **Key Arguments** 

23 

24 - ``ra`` -- list, numpy array or single ra value 

25 - ``dec`` --list, numpy array or single dec value 

26 - ``log`` -- logger 

27  

28 

29 **Return** 

30 

31 - ``raArray`` -- input RAs as a numpy array of decimal degree values 

32 - ``decArray`` -- input DECs as a numpy array of decimal degree values 

33  

34 

35 **Usage** 

36 

37 .. todo:: 

38 

39 add usage info 

40 create a sublime snippet for usage 

41 

42 ```python 

43 ra, dec = coordinates_to_array( 

44 log=log, 

45 ra=ra, 

46 dec=dec 

47 ) 

48 ``` 

49  

50 """ 

51 log.debug('starting the ``coordinates_to_array`` function') 

52 

53 if isinstance(ra, np.ndarray) and isinstance(dec, np.ndarray): 

54 return ra, dec 

55 

56 # ASTROCALC UNIT CONVERTER OBJECT 

57 converter = unit_conversion( 

58 log=log 

59 ) 

60 # CONVERT RA AND DEC TO NUMPY ARRAYS 

61 if isinstance(ra, float): 

62 pass 

63 elif isinstance(ra, ("".__class__, u"".__class__)): 

64 try: 

65 ra = float(ra) 

66 except: 

67 ra = converter.ra_sexegesimal_to_decimal(ra=ra) 

68 elif isinstance(ra, list): 

69 try: 

70 ra = np.array(ra).astype(np.float) 

71 except: 

72 raList = [] 

73 raList[:] = [converter.ra_sexegesimal_to_decimal(ra=r) for r in ra] 

74 ra = raList 

75 

76 if isinstance(dec, float): 

77 pass 

78 elif isinstance(dec, ("".__class__, u"".__class__)): 

79 try: 

80 dec = float(dec) 

81 except: 

82 dec = converter.dec_sexegesimal_to_decimal(dec=dec) 

83 elif isinstance(dec, list): 

84 try: 

85 dec = np.array(dec).astype(np.float) 

86 except: 

87 decList = [] 

88 decList[:] = [ 

89 converter.dec_sexegesimal_to_decimal(dec=d) for d in dec] 

90 dec = decList 

91 

92 raArray = np.array(ra, dtype='f8', ndmin=1, copy=False) 

93 decArray = np.array(dec, dtype='f8', ndmin=1, copy=False) 

94 

95 log.debug('completed the ``coordinates_to_array`` function') 

96 return raArray, decArray