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*The data model module for the `transients_obs_get` resource* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import zip 

10from builtins import object 

11import sys 

12import os 

13import khufu 

14from astrocalc.coords import unit_conversion 

15from dryxPyramid.models.models_base import base_model 

16 

17class models_transients_obs_get(base_model): 

18 """ 

19 The worker class for the models_transients_obs_get module 

20 

21 **Key Arguments** 

22 

23 - ``log`` -- logger 

24 - ``request`` -- the pyramid request 

25 - ``elementId`` -- the specific element id requests (or False) 

26  

27 """ 

28 

29 def __init__(self, log, request, elementId=False, search=False): 

30 super().__init__(log, request, elementId, search) 

31 self.resourceName = "transients_obs" 

32 self.defaultQs = { 

33 "objectClass": "SN", 

34 "instrument": "efosc", 

35 "spectrumOrImage": "spectrum", 

36 "grism": 13, 

37 "badSeeing": False 

38 } 

39 self._set_default_parameters() 

40 self._get_transient_info() 

41 

42 log.debug( 

43 "instansiating a new 'models_transients_obs_get' object") 

44 return None 

45 

46 def get(self): 

47 """execute the get method on the models_transients_obs_get object 

48 

49 **Return** 

50 

51 - ``responseContent`` -- the reponse to send to the browser 

52  

53 """ 

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

55 

56 elementId = self.elementId 

57 transient_ob_data = self.qs 

58 

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

60 return transient_ob_data 

61 

62 def _get_transient_info( 

63 self): 

64 """ get transient info 

65 """ 

66 self.log.debug('starting the ``_get_transient_info`` method') 

67 

68 elementId = self.elementId 

69 

70 # query database for the info needed 

71 sqlQuery = u""" 

72 select raDeg, decDeg, masterName from transientBucketSummaries where transientBucketId = %(elementId)s  

73 """ % locals() 

74 objectDataTmp = self.request.db.execute(sqlQuery).fetchall() 

75 objectData = [] 

76 objectData[:] = [dict(list(zip(list(row.keys()), row))) 

77 for row in objectDataTmp] 

78 objectData = objectData[0] 

79 

80 # ASTROCALC UNIT CONVERTER OBJECT 

81 converter = unit_conversion( 

82 log=self.log 

83 ) 

84 self.qs["ra"] = converter.ra_sexegesimal_to_decimal( 

85 ra=objectData["raDeg"] 

86 ) 

87 self.qs["dec"] = converter.dec_sexegesimal_to_decimal( 

88 dec=objectData["decDeg"] 

89 ) 

90 

91 self.qs["objectName"] = objectData["masterName"] 

92 

93 self.log.debug('completed the ``_get_transient_info`` method') 

94 return None 

95 

96 # use the tab-trigger below for new method 

97 # xt-class-method