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*Query the sherlock-catalogues helper tables to generate a map of the important columns of each catalogue* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

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

12from fundamentals import tools 

13from fundamentals.mysql import readquery 

14 

15def get_crossmatch_catalogues_column_map( 

16 dbConn, 

17 log): 

18 """*Query the sherlock-catalogues helper tables to generate a map of the important columns of each catalogue* 

19 

20 Within your sherlock-catalogues database you need to manually map the inhomogeneous column-names from the sherlock-catalogues to an internal homogeneous name-set which includes *ra*, *dec*, *redshift*, *object name*, *magnitude*, *filter* etc. 

21 The column-name map is set within the two database helper tables called `tcs_helper_catalogue_views_info` and `tcs_helper_catalogue_views_info`. See the *'Checklist for Adding A New Reference Catalogue to the Sherlock Catalogues Database'* for more information. 

22 

23 .. todo:: 

24 

25 - write a checklist for adding a new catalogue to the sherlock database and reference it from here (use the image below of the tcs_helper_catalogue_views_info table) 

26 

27 .. image:: https://farm5.staticflickr.com/4604/38429536400_eafa991580_o.png 

28 :width: 200 px 

29 

30 **Key Arguments** 

31 

32 - ``dbConn`` -- the sherlock-catalogues database connection 

33 - ``log`` -- logger 

34  

35 

36 **Return** 

37 

38 - ``colMaps`` -- dictionary of dictionaries with the name of the database-view (e.g. `tcs_view_agn_milliquas_v4_5`) as the key and the column-name dictary map as value (`{view_name: {columnMap}}`). 

39  

40 

41 **Usage** 

42 

43 To collect the column map dictionary of dictionaries from the catalogues database, use the ``get_crossmatch_catalogues_column_map`` function: 

44 

45 ```python 

46 from sherlock.commonutils import get_crossmatch_catalogues_column_map 

47 colMaps = get_crossmatch_catalogues_column_map( 

48 log=log, 

49 dbConn=cataloguesDbConn 

50 ) 

51 ``` 

52  

53 """ 

54 log.debug('starting the ``get_crossmatch_catalogues_column_map`` function') 

55 

56 # GRAB THE NAMES OF THE IMPORTANT COLUMNS FROM DATABASE 

57 sqlQuery = u""" 

58 SELECT  

59 * 

60 FROM 

61 tcs_helper_catalogue_views_info v, 

62 tcs_helper_catalogue_tables_info t 

63 WHERE 

64 v.table_id = t.id 

65 """ % locals() 

66 rows = readquery( 

67 log=log, 

68 sqlQuery=sqlQuery, 

69 dbConn=dbConn, 

70 quiet=False 

71 ) 

72 colMaps = {} 

73 for row in rows: 

74 colMaps[row["view_name"]] = row 

75 

76 log.debug('completed the ``get_crossmatch_catalogues_column_map`` function') 

77 return colMaps