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/bin/env python
2# encoding: utf-8
3"""
4*Plots and stats for ESO PhaseIII Data Products*
6:Author:
7 David Young
8"""
9import sys
10import os
11import re
12import khufu
15def plot_wells(
16 log,
17 request,
18 releaseVersion
19):
20 """The sofi/efosc imaging/spectra plot well for the stats page of the marshall
22 **Key Arguments**
24 - ``log`` -- the logger
25 - ``request`` -- the pyramid request
28 **Return**
30 - ``plotWells`` -- the sofi/efosc imaging/spectra plot well
32 """
34 plotWells = ""
36 instruments = ["sofi", "efosc"]
37 dataTypes = ["spectra", "imaging"]
39 for instrument in instruments:
40 for dataType in dataTypes:
41 well = _generate_plot_well(
42 log=log,
43 request=request,
44 instrument=instrument,
45 dataType=dataType,
46 releaseVersion=releaseVersion
47 )
48 plotWells = """%(plotWells)s%(well)s""" % locals()
50 return plotWells
53def _generate_plot_well(
54 log,
55 request,
56 instrument,
57 dataType,
58 releaseVersion):
59 """ generate plot well
61 **Key Arguments**
63 - ``log`` -- the logger
64 - ``request`` -- the pyramid request
65 - ``instrument``
66 - ``dataType``
67 - ``releaseVersion`` - the release versions to seperate
70 **Return**
72 - ``plotWell`` -- the well of plots
74 """
75 log.debug('starting the ``_generate_plot_well`` function')
77 # format attributes for titles
78 instrument = instrument.upper()
79 dataType = dataType[0].upper() + dataType[1:].lower()
80 title = "%(instrument)s %(dataType)s" % locals()
82 # GENERATE THE EMPTY WELL
83 imageWell = khufu.imageWell(
84 log=log,
85 title=title,
86 description="Metrics from the %(releaseVersion)s %(title)s" % locals(
87 )
88 )
90 # REFORMAT ATTRIBUTES FOR DETECTING FILENAMES
91 instrument = instrument.lower()
92 dataType = dataType.lower()
94 # SETUP THE PHASEIII STATS CACHE DIRECTORY
95 statsCache = request.registry.settings["cache-directory"] + "/stats/"
96 esoPhaseIII = """%(statsCache)s/phaseIII""" % locals()
98 # FIND EACH SOFI/EFOSC IMAGING/SPECTRA PNG IN THE PHASEIII STATS CACHE AND APPEND IT TO
99 # THE IMAGING WELL
100 from os.path import expanduser
101 home = expanduser("~")
102 basePath = esoPhaseIII.replace("~", home)
103 count = 0
104 for d in os.listdir(basePath):
105 filepath = os.path.join(basePath, d)
106 if os.path.isfile(filepath) and "png" in d and instrument in d and dataType in d:
107 count += 1
108 log.debug(
109 'instrument, instrument, d: %(instrument)s %(dataType)s %(d)s' %
110 locals())
111 fulltitle = d.replace(".png", "").replace(
112 "_", " ")
113 title = fulltitle.replace(
114 "%(releaseVersion)s %(instrument)s %(dataType)s " % locals(), "").lower()
115 filepath = 'caches/stats/phaseIII/%(d)s' % locals()
116 filepath = request.static_url(f'marshall_webapp:{filepath}')
117 link = khufu.a(
118 content='view in new tab',
119 href=filepath,
120 openInNewTab=True,
121 )
123 popover = khufu.popover(
124 tooltip=True,
125 placement="bottom", # [ top | bottom | left | right ]
126 trigger="hover", # [ False | click | hover | focus | manual ]
127 title="view plot in new tab",
128 content=False,
129 delay=20
130 )
132 imageButton = khufu.button(
133 buttonText="""<i class="icon-file-pdf"></i>""",
134 # [ default | primary | info | success | warning | danger | inverse | link ]
135 buttonStyle='success',
136 buttonSize='small', # [ large | default | small | mini ]
137 htmlId=False,
138 href=filepath,
139 pull=False, # right, left, center
140 submit=False,
141 block=False,
142 disable=False,
143 dataToggle=False, # [ modal ]
144 popover=popover
145 )
147 matchObject = re.search(
148 r'.*?(imaging|spectra)_(.*)_vs_(.*)\.png',
149 d,
150 flags=0 # re.S
151 )
153 if matchObject:
154 dataType = matchObject.group(1)
155 xKey = matchObject.group(2)
156 yKey = matchObject.group(3)
158 import urllib
159 sqlQuery = urllib.parse.quote("""select currentFilename, %(xKey)s ,%(yKey)s from %(instrument)s_%(dataType)s where data_rel = "%(releaseVersion)s" and currentFilename not like "%%weight%%" order by %(yKey)s;""" % locals(
160 ))
161 csvType = urllib.parse.quote("human") # human or machine
162 csvTitle = urllib.parse.quote("ESO Phase III %(instrument)s %(dataType)s for %(releaseVersion)s" % locals(
163 ))
164 csvFilename = urllib.parse.quote(
165 "%(xKey)s_vs_%(yKey)s.csv" % locals())
166 returnFormat = urllib.parse.quote("webpageView")
168 popover = khufu.popover(
169 tooltip=True,
170 placement="bottom", # [ top | bottom | left | right ]
171 trigger="hover", # [ False | click | hover | focus | manual ]
172 title="view csv file in browser",
173 content=False,
174 delay=20
175 )
177 viewCsvButton = khufu.button(
178 buttonText="""<i class="icon-pilcrow"></i>""",
179 # [ default | primary | info | success | warning | danger | inverse | link ]
180 buttonStyle='success',
181 buttonSize='small', # [ large | default | small | mini ]
182 htmlId=False,
183 href="/marshall/scripts/python/sqlquery_to_csv.py?sqlQuery=%(sqlQuery)s&csvType=%(csvType)s&csvFilename=%(csvFilename)s&returnFormat=%(returnFormat)s&csvTitle=%(csvTitle)s" % locals(
184 ),
185 pull=False, # right, left, center
186 submit=False,
187 block=False,
188 disable=False,
189 dataToggle=False, # [ modal ]
190 popover=popover
191 )
193 buttonGroup = khufu.buttonGroup(
194 buttonList=[imageButton, viewCsvButton],
195 format='default' # [ default | toolbar | vertical ]
196 )
198 returnFormat = urllib.parse.quote("webpageDownload")
199 popover = khufu.popover(
200 tooltip=True,
201 placement="bottom", # [ top | bottom | left | right ]
202 trigger="hover", # [ False | click | hover | focus | manual ]
203 title="download csv file of plot data",
204 content=False,
205 delay=20
206 )
207 downloadCsv = khufu.button(
208 buttonText="""<i class="icon-pilcrow"></i>""",
209 # [ default | primary | info | success | warning | danger | inverse | link ]
210 buttonStyle='primary',
211 buttonSize='small', # [ large | default | small | mini ]
212 htmlId=False,
213 href="/marshall/scripts/python/sqlquery_to_csv.py?sqlQuery=%(sqlQuery)s&csvType=%(csvType)s&csvFilename=%(csvFilename)s&returnFormat=%(returnFormat)s&csvTitle=%(csvTitle)s" % locals(
214 ),
215 pull=False, # right, left, center
216 submit=False,
217 block=False,
218 disable=False,
219 dataToggle=False, # [ modal ]
220 popover=popover
221 )
223 imageWell.appendImage(
224 imagePath=filepath,
225 imageTitle=title,
226 modalHeaderContent=fulltitle,
227 modalFooterContent="""view in browser: %(buttonGroup)s    downloads: """ % locals(
228 ),
229 modalFooterButtons=[downloadCsv])
230 else:
231 log.debug('NOTHING FOUND TO PLOT')
233 log.debug('completed the ``_generate_plot_well`` function')
234 if count:
235 thisImageWell = imageWell.get()
236 else:
237 thisImageWell = ""
239 return thisImageWell
241# use the tab-trigger below for new function