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 master lightcurve block for the object ticket* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

11import re 

12import datetime as datetime 

13from marshall_webapp.templates.commonelements import commonutils as cu 

14import khufu 

15 

16 

17def survey_lightcurves_block( 

18 log, 

19 request, 

20 discoveryDataDictionary, 

21 lightcurveData, 

22 displayTitle=True): 

23 """get ticket lightcurve block 

24 

25 **Key Arguments** 

26 

27 - ``log`` -- logger 

28 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient. 

29 - ``lightcurveData`` -- the lightcurve data for the objects displayed on the webpage 

30 - ``displayTitle`` -- display the title for this block? 

31 

32 

33 **Return** 

34 

35 - ``survey_lightcurves_block`` -- the ticket identity block for the pesssto object 

36 

37 """ 

38 log.debug('starting the ``survey_lightcurves_block`` function') 

39 

40 ## VARIABLES ## 

41 lightCurveImages = [] 

42 tinyDict = {} 

43 transientBucketId = discoveryDataDictionary["transientBucketId"] 

44 

45 # TURNING THE TITLE FOR THE BLOCK ON OR OFF 

46 if displayTitle: 

47 title = cu.block_title( 

48 log, 

49 title="survey lightcurves" 

50 ) 

51 else: 

52 title = "" 

53 

54 # THE SURVEYS AND LIGHTCURVE EXTENSIONS USED 

55 surveyList = [{"lsq": "gif"}, {"ogle": "png"}, 

56 {"css": "png"}, {"mls": "png"}, {"sss": "png"}] 

57 

58 # FOR EACH POSSIBLE SURVEY WITH LIGHTCURVE INFO ... 

59 for survey in surveyList: 

60 thisSurvey = list(survey.keys())[0] 

61 thisExt = list(survey.values())[0] 

62 lightCurveFlag = "%(thisSurvey)s_lightcurve" % locals() 

63 

64 # IF THE SURVEY LIGHTCURVE EXISTS 

65 if discoveryDataDictionary[lightCurveFlag]: 

66 tinyDict = {} 

67 tinyDict["url"] = "" 

68 tinyDict["survey"] = thisSurvey 

69 tinyDict["lc"] = request.static_url(f'marshall_webapp:caches/transients/{transientBucketId}/{thisSurvey}_lightcurve.{thisExt}') 

70 

71 tinyDict[ 

72 "filename"] = "%(thisSurvey)s_lightcurve.%(thisExt)s" % locals() 

73 

74 for row in lightcurveData: 

75 if row["survey"] and thisSurvey.lower() in row["survey"].lower() and row["surveyObjectUrl"] and transientBucketId == row["transientBucketId"]: 

76 tinyDict["url"] = row["surveyObjectUrl"] 

77 if thisSurvey.lower() == "lsq": 

78 user = request.registry.settings[ 

79 "credentials"]["lsq"]["username"] 

80 pwd = request.registry.settings[ 

81 "credentials"]["lsq"]["password"] 

82 tinyDict["url"] = tinyDict["url"].replace( 

83 "portal.", "%(user)s:%(pwd)s@portal." % locals()) 

84 lightCurveImages.append(tinyDict) 

85 

86 surveyLightcurves = "" 

87 colors = ["blue", "green", "orange", "magenta", "cyan", "red"] 

88 for i, tinyDict in enumerate(lightCurveImages): 

89 count = i 

90 while count > len(colors): 

91 count = count - len(colors) 

92 # add text color 

93 link = khufu.a( 

94 content=tinyDict["survey"].upper(), 

95 href=tinyDict["url"] 

96 ) 

97 link = khufu.coloredText( 

98 text=link, 

99 color=colors[i], 

100 size=False, # 1-10 

101 pull=False, # "left" | "right" 

102 ) 

103 

104 survey = tinyDict["survey"].upper() 

105 masterName = discoveryDataDictionary["masterName"] 

106 filename = tinyDict["filename"] 

107 filename = """%(masterName)s_%(survey)s_lightcurve""" % locals() 

108 

109 imageSource = khufu.a( 

110 content='lightcurve source', 

111 href=tinyDict["url"], 

112 ) 

113 

114 href = request.route_path( 

115 'download', _query={'url': tinyDict["lc"], "webapp": "marshall_webapp", "filename": filename}) 

116 

117 log.debug("""image download link: `%(href)s`""" % locals()) 

118 

119 imageModal = khufu.imagingModal( 

120 log=log, 

121 imagePath=tinyDict["lc"], 

122 display="polaroid", # [ rounded | circle | polaroid | False ] 

123 modalHeaderContent="%(survey)s lightcurve for %(masterName)s" % locals( 

124 ), 

125 modalFooterContent=imageSource, 

126 stampWidth="100%", 

127 modalImageWidth=400, 

128 downloadLink=href) 

129 imageModal = imageModal.get() 

130 

131 surveyLightcurves = "%(surveyLightcurves)s%(link)s%(imageModal)s" % locals( 

132 ) 

133 

134 return "%(title)s %(surveyLightcurves)s" % locals()