diff --git a/admit/Summary.py b/admit/Summary.py old mode 100644 new mode 100755 index ee3f727..6ff15a2 --- a/admit/Summary.py +++ b/admit/Summary.py @@ -1020,6 +1020,8 @@ def html(self,outdir,flowmanager,dotdiagram="",editor=True): f.close() def _imageIsSVG(self,image): + if not image: return False + if image[len(image)-3:len(image)+1] == 'svg': return True else: @@ -1154,7 +1156,11 @@ def _process(self,taskname,tid,titems,thetask,outdir): if tlower == "cubespectrum_at": spectra = titems.get('spectra',None) - if (spectra) != None: + if spectra == None: + allspecs = "

%s produced no output for image %s

" % (taskname, casaimage) + elif spectra.getNoPlot(): + allspecs = "

%s created output but was told not to create images for display.

" % (taskname) + else: count = 0 # task arguments are the same in all entries. taskargs = spectra.taskargs @@ -1181,8 +1187,6 @@ def _process(self,taskname,tid,titems,thetask,outdir): banner = '

%s output for image %s

' % (taskname, casaimage) allspecs = banner + allspecs - else: - allspecs = "

%s produced no output for image %s

" % (taskname, casaimage) retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,taskargs,tid,allspecs,tid) @@ -1204,7 +1208,11 @@ def _process(self,taskname,tid,titems,thetask,outdir): if tlower == "cubesum_at": cubesum = titems.get('cubesum',None) - if cubesum != None: + if cubesum == None: + allspecs = "

%s produced no output

" % (taskname) + elif cubesum.getNoPlot(): + allspecs = "

%s created output but was told not to create images for display.

" % (taskname) + else: allspecs = "" taskargs = cubesum.taskargs val = cubesum.getValue() @@ -1222,13 +1230,17 @@ def _process(self,taskname,tid,titems,thetask,outdir): specval = SPAN4VALB % (image, thumb, caption, caption, caption,button,button2) banner = "

%s output for %s

" % (taskname, casaimage) allspecs = banner + allspecs + "\n" + specval - else: - allspecs = "

%s computed nothing for the input image

" % taskname + retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,taskargs,tid,allspecs,tid) if tlower == "continuumsub_at": continuumsub = titems.get('continuumsub',None) - if continuumsub != None: + if continuumsub == None: + allspecs = "

%s produced no continuum subtraction for the input image

" % taskname + + elif continuumsub.getNoPlot(): + allspecs = "

%s subtracted continuum from the input image but was told not to create any images for display

" % taskname + else: allspecs = "" taskargs = continuumsub.taskargs val = continuumsub.getValue() @@ -1244,8 +1256,6 @@ def _process(self,taskname,tid,titems,thetask,outdir): banner = "

%s output for %s

" % (taskname, "casaimage") #banner = "

%s output for %s

" % (taskname, casaimage) allspecs = banner + allspecs + "\n" + specval - else: - allspecs = "

%s no continuum subtracted for the input image

" % taskname retval = header % (taskclass,tid,thetask.statusicons(),taskname,tid,taskargs,tid,allspecs,tid) if tlower == "cubestats_at": @@ -1278,8 +1288,14 @@ def _process(self,taskname,tid,titems,thetask,outdir): else: datamean = '%.3E' % sumentry.value[0] + specval = "" + sumentry = titems.get('spectra',None) - if sumentry != None: + if sumentry == None: + specval = specval + "

%s did not create an emission summary for this cube

" % taskname + elif sumentry.getNoPlot(): + specval = specval + "

%s created output but was told not to create an emission summary for this cube

" % taskname + else: val = sumentry.getValue() #@todo do something with position and box? position = "(%s,%s)" % ( str(val[0]),str(val[1]) ) @@ -1291,7 +1307,11 @@ def _process(self,taskname,tid,titems,thetask,outdir): specval = specval + (SPAN4VAL % ( image, thumb, caption, caption, caption)) sumentry = titems.get('peakpnt',None) - if sumentry != None: + if sumentry == None: + specval = specval + "

%s did not create a peak point plot for this cube

" % taskname + elif sumentry.getNoPlot(): + specval = specval + "

%s created output but was told not to create a peak point plot for this cube

" % taskname + else: val = sumentry.getValue() image = val[0] thumb = val[1] @@ -1319,6 +1339,8 @@ def _process(self,taskname,tid,titems,thetask,outdir): spectra = titems.get('spectra',None) if spectra == None: retval = header % (taskclass, tid, thetask.statusicons(),taskname, tid, the_item.taskargs, tid, bigstr, tid) + elif spectra.getNoPlot(): + allspecs = "

%s identified spectral lines but was told to no create images for display.

" % taskname else: allspecs = '' count = 0 @@ -1346,13 +1368,19 @@ def _process(self,taskname,tid,titems,thetask,outdir): specval = specval + (SPAN4VAL % ( image, thumb, caption, caption, caption)) allspecs = allspecs + "\n" + specval count = count + 1 - bigstr = bigstr + STARTROW + allspecs + ENDROW - retval = header % (taskclass, tid, thetask.statusicons(),taskname, tid, the_item.taskargs, tid, tid, bigstr, tid) + + bigstr = bigstr + STARTROW + allspecs + ENDROW + + retval = header % (taskclass, tid, thetask.statusicons(),taskname, tid, the_item.taskargs, tid, tid, bigstr, tid) if tlower == "moment_at": moments = titems.get('moments',None) - allspecs = "" - if moments != None: + if moments == None: + allspecs = "

No moments were computed for this cube

" + elif moments.getNoPlot(): + allspecs = "

%s computed moments but was told not to create images for display

" % taskname + else: + allspecs = "" count = 0 auximage = [] auxthumb = [] @@ -1372,25 +1400,30 @@ def _process(self,taskname,tid,titems,thetask,outdir): auximage.append(val[5]) auxthumb.append(val[6]) auxcaption.append(val[7]) + + # @todo Put the buttons on even if no PNGs were created casaimage = val[8] casamoment = image[:-4] # remove '.png' to get name of moment CASA format image button = utils.getButton(casamoment,"viewimage","View in CASA") # can't have two buttons with same html ID, so add ".fits" button2 = utils.getButton(casamoment+".fits","exportimage","Export to FITS") + specval = specval + (SPAN4VALB % ( image, thumb, caption, caption, caption, button,button2)) allspecs = allspecs + "\n" + specval count = count + 1 - banner = "

%s output for %s

" % (taskname, casaimage) - allspecs = banner + allspecs - else: - allspecs = "

No moments were computed for this cube

" + banner = "

%s output for %s

" % (taskname, casaimage) + allspecs = banner + allspecs retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,taskargs,tid,allspecs,tid) if tlower == "pvslice_at": pvslices = titems.get('pvslices',None) - if pvslices != None: + if pvslices == None: + specval = "

No PV slices were computed for this cube

" + elif pvslices.getNoPlot(): + specval = "

%s created output but was told not to create images for display.

" % (taskname) + else: for val in pvslices.value: specval = STARTROW slicetype = val[0] @@ -1416,8 +1449,7 @@ def _process(self,taskname,tid,titems,thetask,outdir): banner = "

%s output for %s

" % (taskname, slicename) specval = banner + specval - else: - specval = "

No PV slices were computed for this cube

" + retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,pvslices.taskargs,tid,specval,tid) if tlower == "linecube_at": @@ -1451,7 +1483,11 @@ def _process(self,taskname,tid,titems,thetask,outdir): if tlower == "pvcorr_at": the_item = titems.get('pvcorr',None) - if the_item != None: + if the_item == None: + specval = "

No PV correlation diagrams were computed from the input cube

" + elif the_item.getNoPlot(): + specval = "

%s created output but was told not to create images for display.

" % (taskname) + else: val = the_item.getValue() image = val[0] thumb = val[1] @@ -1460,8 +1496,7 @@ def _process(self,taskname,tid,titems,thetask,outdir): specval = STARTROW + (SPAN4VAL % ( image, thumb, caption, caption, caption)) + ENDROW banner = "

%s output for %s

" % (taskname, pvcorrname) specval = banner + specval - else: - specval = "

No PV correlation diagrams were computed from the input cube

" + retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,the_item.taskargs,tid,specval,tid) # @todo move table formatting to here. @@ -1483,7 +1518,11 @@ def _process(self,taskname,tid,titems,thetask,outdir): if tlower == "sfind2d_at": the_item = titems.get('sources',None) #SummaryEntry - if the_item != None: + if the_item == None: + tablestr = "

%s identified no sources

" % taskname + elif the_item.getNoPlot(): # probably will never happen + tablestr = "

%s created output but was told not to create a table for display.

" % (taskname) + else: summarydata = the_item.getValue() if summarydata == None or len(summarydata) == 0: tablestr = "

%s identified no sources

" % taskname @@ -1499,13 +1538,14 @@ def _process(self,taskname,tid,titems,thetask,outdir): tablestr = "

%s identified no sources


%s" % (taskname,imstr) else: tablestr = STARTROW + imstr + (SPANXVAL % ("8",atable.html('class="table table-admit table-bordered table-striped"'))) + ENDROW - else: - tablestr = "

%s identified no sources

" % taskname + retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,the_item.taskargs,tid,tablestr,tid) if tlower == "overlapintegral_at": the_item = titems.get('overlap',None) - if the_item != None: + if the_item == None: + tablestr = "

%s produced no output.

" % taskname + else: # summary info format: #[table,image,thumb,caption] summarydata = the_item.getValue() @@ -1517,21 +1557,25 @@ def _process(self,taskname,tid,titems,thetask,outdir): if len(atable) == 0: tablestr = "

%s produced no output.

" % taskname else: + tablestr = SPANXVAL % ("8",atable.html('class="table table-admit table-bordered table-striped"')) + if the_item.getNoPlot(): + imstr = "

%s was told not to create any images for display

" % taskname + else: image = summarydata[1] thumb = summarydata[2] caption = summarydata[3] - tablestr = SPANXVAL % ("8",atable.html('class="table table-admit table-bordered table-striped"')) imstr = SPAN4VAL % (image, thumb, caption, caption, caption) - tablestr = STARTROW + tablestr + imstr + ENDROW - else: - tablestr = "

%s produced no output.

" % taskname + tablestr = STARTROW + tablestr + imstr + ENDROW + retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,the_item.taskargs,tid,tablestr,tid) if tlower == "principalcomponent_at": # PCA returns two two tables in a list [[table1 h,u,d],[table2 h,u,d]]. tablestr = '' the_item = titems.get('pca',None) #SummaryEntry - if the_item != None: + if the_item == None: + tablestr = "

%s produced no output

" % taskname + else: summarydata = the_item.getValue() if summarydata == None or len(summarydata) == 0: tablestr = "

%s produced no output

" % taskname @@ -1543,19 +1587,23 @@ def _process(self,taskname,tid,titems,thetask,outdir): tablestr = tablestr + "

No covariance data available for this summary. Try lowering covarmin in the PrincipalComponent_AT task arguments.

" else: tablestr = tablestr + atable.html('class="table table-admit table-bordered table-striped"')+os.linesep+os.linesep + if the_item.getNoPlot(): + tablestr = tablestr + "

%s was told not to create images for display

" % taskname - else: - tablestr = "

%s produced no output

" % taskname retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,the_item.taskargs,tid,tablestr,tid) if tlower == "template_at": # Template returns one table (in a list) and two plots. the_item = titems.get('template',None) #SummaryEntry - tablestr = '' - if the_item != None: + if the_item == None: + tablestr = "

%s produced no table output

" % (taskname) + elif the_item.getNoPlot(): # probably will never happen + tablestr = "

%s created output but was told not to create a table for display.

" % (taskname) + else: + tablestr = '' summarydata = the_item.getValue() - if summarydata == None or len(summarydata) == 0: - tablestr = "

%s produced no output

" % taskname + if summarydata == None or len(summarydata) == 0: + tablestr = "

%s produced no table output

" % taskname else: atable = admit.util.Table() atable.deserialize(summarydata[0]) @@ -1563,13 +1611,15 @@ def _process(self,taskname,tid,titems,thetask,outdir): tablestr = tablestr + "

No data available for this summary.

" else: tablestr = tablestr + atable.html('class="table table-admit table-bordered table-striped"')+os.linesep+os.linesep - else: - tablestr = "

%s produced no output

" % taskname # Output plots. allspecs = tablestr + "\n" spectra = titems.get('spectra',None) - if (spectra) != None: + if spectra == None: + allspecs = allspecs + "

%s produced no spectral output

" % (taskname) + elif the_item.getNoPlot(): + allspecs = allspecs + "

%s created output but was told not to create images for display.

" % (taskname) + else: count = 0 # task arguments are the same in all entries. taskargs = spectra.taskargs @@ -1595,8 +1645,6 @@ def _process(self,taskname,tid,titems,thetask,outdir): banner = '

%s output for %s

' % (taskname, casaimage) allspecs = banner + allspecs - else: - allspecs = allspecs + "

No spectra were produced by %s

" % taskname retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,taskargs,tid,allspecs,tid) @@ -1615,8 +1663,12 @@ def _process(self,taskname,tid,titems,thetask,outdir): bigstr = '
' + STARTROW + tablestr + ENDROW spectra = titems.get('spectra',None) specval="" - if spectra != None: - allspecs = '' + allspecs = '' + if spectra == None: + allspecs = allspecs + "

%s created no spectral output.

" % (taskname) + elif the_item.getNoPlot(): + allspecs = allspecs + "

%s created spectral output but was told not to create images for display.

" % (taskname) + else: count = 0 for val in spectra.value: # default bootstrap width is 12 columns. We are using 'span4' so @@ -1642,8 +1694,9 @@ def _process(self,taskname,tid,titems,thetask,outdir): allspecs = allspecs + "\n" + specval count = count + 1 - bigstr = bigstr + STARTROW + allspecs + ENDROW - retval = header % (taskclass, tid, thetask.statusicons(),taskname, tid, the_item.taskargs, tid, bigstr, tid) + + bigstr = bigstr + STARTROW + allspecs + ENDROW + retval = header % (taskclass, tid, thetask.statusicons(),taskname, tid, the_item.taskargs, tid, bigstr, tid) if tlower == "bdpingest_at": the_item = titems.get('bdpingest',None) #SummaryEntry @@ -1664,7 +1717,11 @@ def _process(self,taskname,tid,titems,thetask,outdir): if tlower == "generatespectrum_at": spectra = titems.get('spectra',None) - if (spectra) != None: + if spectra == None: + allspecs = "

%s produced no output

" % (taskname) + elif spectra.getNoPlot(): + allspecs = "

%s created output but was told not to create images for display.

" % (taskname) + else: count = 0 # task arguments are the same in all entries. taskargs = spectra.taskargs @@ -1688,8 +1745,6 @@ def _process(self,taskname,tid,titems,thetask,outdir): banner = '

%s output

' % (taskname) allspecs = banner + allspecs - else: - allspecs = "

%s produced no output

" % (taskname) retval = header % (taskclass, tid,thetask.statusicons(),taskname,tid,taskargs,tid,allspecs,tid) @@ -1861,10 +1916,9 @@ def _test(self): class SummaryEntry: """ Defines a single 'row' of a Summary data entry. A Summary key can refer to a list of SummaryEntry. - This class makes management of complicated data entries easier. It was getting tough - to slice and unzip all those lists! + This class makes management of complicated data entries easier. """ - def __init__(self,value=[],taskname="",taskid=-1,taskargs=""): + def __init__(self,value=[],taskname="",taskid=-1,taskargs="",noplot=False): if isinstance(value,list): self._value = value else: @@ -1873,6 +1927,8 @@ def __init__(self,value=[],taskname="",taskid=-1,taskargs=""): self._taskid = taskid self._taskargs = taskargs self._type = bt.SUMMARYENTRY + # True if the task that created this entry did NOT create plots + self._noplot = noplot def getValue(self): """Get the underlying data value from this SummaryEntry. Value will be list @@ -1930,8 +1986,6 @@ def getTaskArgs(self): The string task arguments""" return self._taskargs; - - def setTaskname(self,name): """Set the name of the task that created this SummaryEntry. @@ -1974,6 +2028,31 @@ def setTaskArgs(self,args): """ self._taskargs = args; + def getNoPlot(self): + """Discover if the task that created this SummaryEntry made plots. + + Returns + ------- + True if no plots were created + False otherwise + """ + return self._noplot + + def setNoPlot(self,noplot): + """Indicate if the task that created this SummaryEntry made plots. + + Parameters + ---------- + noplot: boolean + True if no plots were created + + Returns + ------- + None + """ + self._noplot = noplot + + #------------------------------- # Make the internal data be well-behaved properties. # See e.g. http://www.programiz.com/python-programming/property @@ -1981,6 +2060,7 @@ def setTaskArgs(self,args): taskname = property(getTaskname, setTaskname, None, 'The name of the task that created this SummaryEntry') taskid = property(getTaskID, setTaskID, None, 'The integer task ID that created this SummaryEntry') taskargs = property(getTaskArgs, setTaskArgs, None, 'The arguments of the task to display in the data browser web page.') + noplot = property(getNoPlot,setNoPlot,None,'True if the task that created this SummaryEntry did NOT create plots') #------------------------------- def unset(self): @@ -2010,7 +2090,7 @@ def write(self,root): """ snode = et.SubElement(root,"summaryEntry") snode.set("type",bt.SUMMARYENTRY) - writer = XmlWriter.XmlWriter(self,["_value","_taskname","_taskid","_taskargs"],{"_value":bt.LIST,"_taskname":bt.STRING,"_taskid":bt.INT,"_taskargs":bt.STRING},snode,None) + writer = XmlWriter.XmlWriter(self,["_value","_taskname","_taskid","_taskargs","_noplot"],{"_value":bt.LIST,"_taskname":bt.STRING,"_taskid":bt.INT,"_taskargs":bt.STRING,"_noplot":bt.BOOL},snode,None) # Two SummaryEntrys are equal if their taskids are equal def __eq__(self,other): @@ -2032,8 +2112,8 @@ def __hash__(self): return self._taskid def __str__(self): - return "SummaryEntry(value=%s, taskname=%s, taskid=%d, taskargs=%s)" % \ - (str(self._value), self._taskname, self._taskid,self._taskargs) + return "SummaryEntry(value=%s, taskname=%s, taskid=%d, taskargs=%s, noplot=%s)" % \ + (str(self._value), self._taskname, self._taskid,self._taskargs,str(self._noplot)) # ensure that printing a list of SummaryEntry will print the # individual values and not just addresses. @@ -2047,7 +2127,7 @@ def __str__(self): qq = SummaryEntry("Hqwl","AT1",1,"blah") rr = SummaryEntry("Hrwl","AT1",1,"blah") ss = SummaryEntry("FOOS","AT2",1,"blah") - tt = SummaryEntry("FOOT","AT3",2,"blah") + tt = SummaryEntry("FOOT","AT3",2,"blah",noplot=True) print "qq == rr (True?):" + str(qq == rr) print "qq == ss (True?):" + str(qq == ss) print "ss == tt (False?):" + str(qq == tt) diff --git a/admit/at/BDPIngest_AT.py b/admit/at/BDPIngest_AT.py index cb1993f..831208b 100644 --- a/admit/at/BDPIngest_AT.py +++ b/admit/at/BDPIngest_AT.py @@ -12,6 +12,7 @@ import admit.util.utils as utils from admit.util.Table import Table from admit.Summary import SummaryEntry +#import admit.util.PlotControl as PlotControl class BDPIngest_AT(AT): @@ -110,4 +111,4 @@ def run(self): table.addRow(["Associated File",f]) table.description = "Information about the ingested BDP" taskargs = "file=%s" % self.getkey('file') - self._summary["bdpingest"] = SummaryEntry(table.serialize(),"BDPIngest_AT",self.id(True),taskargs) + self._summary["bdpingest"] = SummaryEntry(table.serialize(),"BDPIngest_AT",self.id(True),taskargs,noplot=True) diff --git a/admit/at/ContinuumSub_AT.py b/admit/at/ContinuumSub_AT.py index fb19808..1a6a2aa 100644 --- a/admit/at/ContinuumSub_AT.py +++ b/admit/at/ContinuumSub_AT.py @@ -18,6 +18,7 @@ from admit.bdp.LineList_BDP import LineList_BDP from admit.bdp.LineSegment_BDP import LineSegment_BDP import admit.util.utils as utils +import admit.util.PlotControl as PlotControl import admit.util.filter.Filter1D as Filter1D from admit.util.AdmitLogging import AdmitLogging as logging import numpy as np @@ -207,19 +208,28 @@ def run(self): rdata = casautil.getdata(self.dir(f3)).data logging.regression("CSUB: %f %f" % (rdata.min(),rdata.max())) - # Create two output images for html and their thumbnails, too - implot = ImPlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) - implot.plotter(rasterfile=f3,figname=f3,colorwedge=True) - figname = implot.getFigure(figno=implot.figno,relative=True) - thumbname = implot.getThumbnail(figno=implot.figno,relative=True) b2.setkey("image", Image(images={bt.CASA:f2})) - b3.setkey("image", Image(images={bt.CASA:f3, bt.PNG : figname})) + + # Create two output images for html and their thumbnails, too + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + thumbname = "not created" + imcaption = "not created" + b3.setkey("image", Image(images={bt.CASA:f3})) + noplot = True + else: + implot = ImPlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + implot.plotter(rasterfile=f3,figname=f3,colorwedge=True) + figname = implot.getFigure(figno=implot.figno,relative=True) + thumbname = implot.getThumbnail(figno=implot.figno,relative=True) + b3.setkey("image", Image(images={bt.CASA:f3, bt.PNG : figname})) + noplot = False dt.tag("implot") if len(ch) > 0: taskargs = "pad=%d fitorder=%d contsub=%s" % (pad,fitorder,str(contsub)) imcaption = "Continuum map" - self._summary["continuumsub"] = SummaryEntry([figname,thumbname,imcaption],"ContinuumSub_AT",self.id(True),taskargs) + self._summary["continuumsub"] = SummaryEntry([figname,thumbname,imcaption],"ContinuumSub_AT",self.id(True),taskargs,noplot=noplot) dt.tag("done") dt.end() diff --git a/admit/at/CubeSpectrum_AT.py b/admit/at/CubeSpectrum_AT.py index 05ce041..02a671e 100644 --- a/admit/at/CubeSpectrum_AT.py +++ b/admit/at/CubeSpectrum_AT.py @@ -20,6 +20,7 @@ import admit.util.Image as Image from admit.util import APlot import admit.util.utils as utils +import admit.util.PlotControl as PlotControl from admit.util.AdmitLogging import AdmitLogging as logging from copy import deepcopy @@ -267,9 +268,10 @@ def run(self): planes = range(npos) # labels for the tables (placeholder) images = {} # png's accumulated + noplot = True for i in range(npos): # loop over pos, they can have mixed types now sd = [] - caption = "Spectrum" + imcaption = "Spectrum" xpos = pos[i][0] ypos = pos[i][1] if type(xpos) != type(ypos): @@ -282,7 +284,7 @@ def run(self): cbox = '(%d,%d,%d,%d)' % (xpos,ypos,xpos,ypos) # use extend here, not append, we want individual values in a list sd.extend([xpos,ypos,cbox]) - caption = "Average Spectrum at %s" % cbox + imcaption = "Average Spectrum at %s" % cbox if False: # this will fail on 3D cubes (see CAS-7648) imval[i] = casa.imval(self.dir(fin),box=box) @@ -291,12 +293,12 @@ def run(self): # another approach is the ia.getprofile(), see CubeStats, this will # also integrate over regions, imval will not (!!!) region = 'centerbox[[%dpix,%dpix],[1pix,1pix]]' % (xpos,ypos) - caption = "Average Spectrum at %s" % region + imcaption = "Average Spectrum at %s" % region imval[i] = casa.imval(self.dir(fin),region=region) elif type(xpos)==str: # this is tricky, to stay under 1 pixel , or you get a 2x2 back. region = 'centerbox[[%s,%s],[1pix,1pix]]' % (xpos,ypos) - caption = "Average Spectrum at %s" % region + imcaption = "Average Spectrum at %s" % region sd.extend([xpos,ypos,region]) imval[i] = casa.imval(self.dir(fin),region=region) else: @@ -354,14 +356,22 @@ def run(self): else: title = '%s %d @ %s,%s' % (bdp_name,i,xpos,ypos) # or use box, once we allow non-points - myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode, abspath=self.dir()) - ylab = 'Flux (%s)' % unit - p1 = "%s_%d" % (bdp_name,i) - myplot.plotter(x,y,title,p1,xlab=xlab,ylab=ylab,thumbnail=True) - # Why not use p1 as the key? - ii = images["pos%d" % i] = myplot.getFigure(figno=myplot.figno,relative=True) - thumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) - sd.extend([ii, thumbname, caption, fin]) + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + thumbname = "not created" + imcaption = "not created" + noplot = True + else: + myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode, abspath=self.dir()) + ylab = 'Flux (%s)' % unit + p1 = "%s_%d" % (bdp_name,i) + myplot.plotter(x,y,title,p1,xlab=xlab,ylab=ylab,thumbnail=True) + # Why not use p1 as the key? + figname = images["pos%d" % i] = myplot.getFigure(figno=myplot.figno,relative=True) + thumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) + noplot = False + + sd.extend([figname, thumbname, imcaption, fin]) self.spec_description.append(sd) logging.regression("CSP: %s" % str(smax)) @@ -385,7 +395,11 @@ def run(self): # SummaryEntry([[data for spec1]], "CubeSpectrum_AT",taskid) # For multiple spectra this is # SummaryEntry([[data for spec1],[data for spec2],...], "CubeSpectrum_AT",taskid) - self._summary["spectra"] = SummaryEntry(self.spec_description,"CubeSpectrum_AT",self.id(True)) + + # @todo if range(npos) is [] don't create a summary entry + # so that check against None in Summary.py does the right thing, + # although len(npos) == 0 is trapped earlier so perhaps not necessary + self._summary["spectra"] = SummaryEntry(self.spec_description, "CubeSpectrum_AT", self.id(True), noplot=noplot) taskargs = "pos="+str(pos) taskargs += '            ' + fin.split('/')[0] + ' ' for v in self._summary: diff --git a/admit/at/CubeStats_AT.py b/admit/at/CubeStats_AT.py index 18196aa..c1f0c2e 100644 --- a/admit/at/CubeStats_AT.py +++ b/admit/at/CubeStats_AT.py @@ -19,6 +19,7 @@ from admit.util.segmentfinder import ADMITSegmentFinder from admit.Summary import SummaryEntry import admit.util.casautil as casautil +import admit.util.PlotControl as PlotControl from admit.util.AdmitLogging import AdmitLogging as logging from copy import deepcopy @@ -400,24 +401,34 @@ def run(self): y4 = np.zeros(len(minval)) y5 = y1-y4 y = [y1,y2,y3,y4] - title = 'CubeStats: ' + bdp_name+'_0' - xlab = 'Channel' - ylab = 'log(Peak,Noise,Peak/Noise)' - labels = ['log(peak)','log(rms noise)','log(peak/noise)','log(|minval|)'] - myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) - segp = [[chans[0],chans[nchan-1],math.log10(sigma0),math.log10(sigma0)]] - myplot.plotter(chans,y,title,bdp_name+"_0",xlab=xlab,ylab=ylab,segments=segp,labels=labels,thumbnail=True) - imfile = myplot.getFigure(figno=myplot.figno,relative=True) - thumbfile = myplot.getThumbnail(figno=myplot.figno,relative=True) - - image0 = Image(images={bt.PNG:imfile},thumbnail=thumbfile,thumbnailtype=bt.PNG,description="CubeStats_0") - b2.addimage(image0,"im0") + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + imfile = "not created" + thumbfile = "not created" + else: + noplot = False + title = 'CubeStats: ' + bdp_name+'_0' + xlab = 'Channel' + ylab = 'log(Peak,Noise,Peak/Noise)' + labels = ['log(peak)','log(rms noise)','log(peak/noise)','log(|minval|)'] + myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + segp = [[chans[0],chans[nchan-1],math.log10(sigma0),math.log10(sigma0)]] + myplot.plotter(chans,y,title,bdp_name+"_0",xlab=xlab,ylab=ylab,segments=segp,labels=labels,thumbnail=True) + imfile = myplot.getFigure(figno=myplot.figno,relative=True) + thumbfile = myplot.getThumbnail(figno=myplot.figno,relative=True) + + image0 = Image(images={bt.PNG:imfile},thumbnail=thumbfile,thumbnailtype=bt.PNG,description="CubeStats_0") + b2.addimage(image0,"im0") if use_ppp: - # new trial for Lee - title = 'PeakSum: (numsigma=%.1f)' % (numsigma) - ylab = 'Jy*N_ppb' - myplot.plotter(chans,[peaksum],title,bdp_name+"_00",xlab=xlab,ylab=ylab,thumbnail=False) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + # new trial for Lee + title = 'PeakSum: (numsigma=%.1f)' % (numsigma) + ylab = 'Jy*N_ppb' + myplot.plotter(chans,[peaksum],title,bdp_name+"_00",xlab=xlab,ylab=ylab,thumbnail=False) if True: # hack ascii table @@ -441,24 +452,29 @@ def run(self): caption += " green: noise per channel," caption += " blue: peak value per channel," caption += " red: peak/noise per channel)." - self._summary["spectra"] = SummaryEntry([0, 0, str(specbox), 'Channel', imfile, thumbfile , caption, fin], "CubeStats_AT", self.id(True)) - self._summary["chanrms"] = SummaryEntry([float(sigma0), fin], "CubeStats_AT", self.id(True)) + self._summary["spectra"] = SummaryEntry([0, 0, str(specbox), 'Channel', imfile, thumbfile , caption, fin], "CubeStats_AT", self.id(True),noplot=noplot) + + self._summary["chanrms"] = SummaryEntry([float(sigma0), fin], "CubeStats_AT", self.id(True),noplot=noplot) # @todo Will imstat["max"][0] always be equal to s['datamax']? If not, why not? if 'datamax' in s: - self._summary["dynrange"] = SummaryEntry([float(s['datamax']/sigma0), fin], "CubeStats_AT", self.id(True)) + self._summary["dynrange"] = SummaryEntry([float(s['datamax']/sigma0), fin], "CubeStats_AT", self.id(True),noplot=noplot) else: self._summary["dynrange"] = SummaryEntry([float(imstat0["max"][0]/sigma0), fin], "CubeStats_AT", self.id(True)) - self._summary["datamean"] = SummaryEntry([imstat0["mean"][0], fin], "CubeStats_AT", self.id(True)) + self._summary["datamean"] = SummaryEntry([imstat0["mean"][0], fin], "CubeStats_AT", self.id(True),noplot=noplot) - title = bdp_name + "_1" - xlab = 'log(Peak,Noise,P/N)' - myplot.histogram([y1,y2,y3],title,bdp_name+"_1",xlab=xlab,thumbnail=True) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + title = bdp_name + "_1" + xlab = 'log(Peak,Noise,P/N)' + myplot.histogram([y1,y2,y3],title,bdp_name+"_1",xlab=xlab,thumbnail=True) - imfile = myplot.getFigure(figno=myplot.figno,relative=True) - thumbfile = myplot.getThumbnail(figno=myplot.figno,relative=True) - image1 = Image(images={bt.PNG:imfile},thumbnail=thumbfile,thumbnailtype=bt.PNG,description="CubeStats_1") - b2.addimage(image1,"im1") + imfile = myplot.getFigure(figno=myplot.figno,relative=True) + thumbfile = myplot.getThumbnail(figno=myplot.figno,relative=True) + image1 = Image(images={bt.PNG:imfile},thumbnail=thumbfile,thumbnailtype=bt.PNG,description="CubeStats_1") + b2.addimage(image1,"im1") # note that the 'y2' can have been clipped, which can throw off stats.robust() # @todo should set a mask for those. @@ -470,7 +486,11 @@ def run(self): y2_mean = ry2.mean() y2_std = ry2.std() if n>9: logging.debug("NORMALTEST2: %s" % str(scipy.stats.normaltest(ry2))) - myplot.hisplot(y2,title,bdp_name+"_2",xlab=xlab,gauss=[y2_mean,y2_std],thumbnail=True) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + myplot.hisplot(y2,title,bdp_name+"_2",xlab=xlab,gauss=[y2_mean,y2_std],thumbnail=True) title = bdp_name + "_3" xlab = 'log(diff[Noise])' @@ -481,7 +501,11 @@ def run(self): dy2_mean = rdy2.mean() dy2_std = rdy2.std() if n>9: logging.debug("NORMALTEST3: %s" % str(scipy.stats.normaltest(rdy2))) - myplot.hisplot(dy2,title,bdp_name+"_3",xlab=xlab,gauss=[dy2_mean,dy2_std],thumbnail=True) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + myplot.hisplot(dy2,title,bdp_name+"_3",xlab=xlab,gauss=[dy2_mean,dy2_std],thumbnail=True) title = bdp_name + "_4" @@ -491,7 +515,11 @@ def run(self): y3_mean = ry3.mean() y3_std = ry3.std() if n>9: logging.debug("NORMALTEST4: %s" % str(scipy.stats.normaltest(ry3))) - myplot.hisplot(y3,title,bdp_name+"_4",xlab=xlab,gauss=[y3_mean,y3_std],thumbnail=True) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + myplot.hisplot(y3,title,bdp_name+"_4",xlab=xlab,gauss=[y3_mean,y3_std],thumbnail=True) title = bdp_name + "_5" xlab = 'log(diff[Signal/Noise)])' @@ -501,7 +529,11 @@ def run(self): dy3_mean = rdy3.mean() dy3_std = rdy3.std() if n>9: logging.debug("NORMALTEST5: %s" % str(scipy.stats.normaltest(rdy3))) - myplot.hisplot(dy3,title,bdp_name+"_5",xlab=xlab,gauss=[dy3_mean,dy3_std],thumbnail=True) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + myplot.hisplot(dy3,title,bdp_name+"_5",xlab=xlab,gauss=[dy3_mean,dy3_std],thumbnail=True) title = bdp_name + "_6" @@ -511,7 +543,11 @@ def run(self): y5_mean = ry5.mean() y5_std = ry5.std() if n>9: logging.debug("NORMALTEST6: %s" % str(scipy.stats.normaltest(ry5))) - myplot.hisplot(y5,title,bdp_name+"_6",xlab=xlab,gauss=[y5_mean,y5_std],thumbnail=True) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + myplot.hisplot(y5,title,bdp_name+"_6",xlab=xlab,gauss=[y5_mean,y5_std],thumbnail=True) logging.debug("LogPeak: m,s= %f %f min/max %f %f" % (y1.mean(),y1.std(),y1.min(),y1.max())) logging.debug("LogNoise: m,s= %f %f %f %f min/max %f %f" % (y2.mean(),y2.std(),y2_mean,y2_std,y2.min(),y2.max())) @@ -534,12 +570,18 @@ def run(self): s = np.pi * ( smax * (z0**gamma) )**2 cmds = ["grid", "axis equal"] title = "Peak Points per channel" - pppimage = bdp_name + '_ppp' - myplot.scatter(xpos,ypos,title=title,figname=pppimage,size=s,color=chans,cmds=cmds,thumbnail=True) - pppimage = myplot.getFigure(figno=myplot.figno,relative=True) - pppthumbnail = myplot.getThumbnail(figno=myplot.figno,relative=True) caption = "Peak point plot: Locations of per-channel peaks in the image cube " + fin - self._summary["peakpnt"] = SummaryEntry([pppimage, pppthumbnail, caption, fin], "CubeStats_AT", self.id(True)) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + pppimage = "not created" + pppthumbnail = "not created" + else: + noplot = False + pppimage = bdp_name + '_ppp' + myplot.scatter(xpos,ypos,title=title,figname=pppimage,size=s,color=chans,cmds=cmds,thumbnail=True) + pppimage = myplot.getFigure(figno=myplot.figno,relative=True) + pppthumbnail = myplot.getThumbnail(figno=myplot.figno,relative=True) + self._summary["peakpnt"] = SummaryEntry([pppimage, pppthumbnail, caption, fin], "CubeStats_AT", self.id(True),noplot=noplot) dt.tag("plotting") # making PeakStats plot @@ -552,7 +594,11 @@ def run(self): ylab = 'FWHM (channels)' pppimage = bdp_name + '_peakstats' cval = mval - myplot.scatter(pval,wval,title=title,xlab=xlab,ylab=ylab,color=cval,figname=pppimage,thumbnail=False) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + pppimage = "not created" + else: + myplot.scatter(pval,wval,title=title,xlab=xlab,ylab=ylab,color=cval,figname=pppimage,thumbnail=False) dt.tag("peakstats") diff --git a/admit/at/CubeSum_AT.py b/admit/at/CubeSum_AT.py index 5054d9d..74650a6 100644 --- a/admit/at/CubeSum_AT.py +++ b/admit/at/CubeSum_AT.py @@ -19,6 +19,7 @@ from admit.bdp.LineList_BDP import LineList_BDP from admit.bdp.Moment_BDP import Moment_BDP import admit.util.utils as utils +import admit.util.PlotControl as PlotControl import admit.util.filter.Filter1D as Filter1D from admit.util.AdmitLogging import AdmitLogging as logging import numpy as np @@ -347,45 +348,60 @@ def run(self): logging.info("Sum: %f (beam parameters missing)" % (st['sum'])) logging.regression("CSM: %s" % str(rdata)) - # Create two output images for html and their thumbnails, too - implot = ImPlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) - implot.plotter(rasterfile=bdp_name,figname=bdp_name, - colorwedge=True,zoom=self.getkey("zoom")) - figname = implot.getFigure(figno=implot.figno,relative=True) - thumbname = implot.getThumbnail(figno=implot.figno,relative=True) - - dt.tag("implot") - - thumbtype = bt.PNG # really should be correlated with self._plot_type!! - - # 2. Create a histogram of the map data - # get the data for a histogram - data = casautil.getdata(image_out,zeromask=True).compressed() - dt.tag("getdata") - - # get the label for the x axis - bunit = casa.imhead(imagename=image_out, mode="get", hdkey="bunit") - - # Make the histogram plot - # Since we give abspath in the constructor, figname should be relative - myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) - auxname = bdp_name + "_histo" - auxtype = bt.PNG # really should be correlated with self._plot_type!! - myplot.histogram(columns = data, - figname = auxname, - xlab = bunit, - ylab = "Count", - title = "Histogram of CubeSum: %s" % (bdp_name), - thumbnail=True) - auxname = myplot.getFigure(figno=myplot.figno,relative=True) - auxthumb = myplot.getThumbnail(figno=myplot.figno,relative=True) - - images = {bt.CASA : bdp_name, bt.PNG : figname} - casaimage = Image(images = images, - auxiliary = auxname, - auxtype = auxtype, - thumbnail = thumbname, - thumbnailtype = thumbtype) + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + thumbname = "not created" + imcaption = "not created" + auxname = "not created" + auxcaption = "not created" + auxthumb = "not created" + images = {bt.CASA : bdp_name} + casaimage = Image(images = images) + noplot = True + else: + + # Create two output images for html and their thumbnails, too + implot = ImPlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + implot.plotter(rasterfile=bdp_name,figname=bdp_name, + colorwedge=True,zoom=self.getkey("zoom")) + figname = implot.getFigure(figno=implot.figno,relative=True) + thumbname = implot.getThumbnail(figno=implot.figno,relative=True) + + dt.tag("implot") + + thumbtype = bt.PNG # really should be correlated with self._plot_type!! + + # 2. Create a histogram of the map data + # get the data for a histogram + data = casautil.getdata(image_out,zeromask=True).compressed() + dt.tag("getdata") + + # get the label for the x axis + bunit = casa.imhead(imagename=image_out, mode="get", hdkey="bunit") + + # Make the histogram plot + # Since we give abspath in the constructor, figname should be relative + myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + auxname = bdp_name + "_histo" + auxtype = bt.PNG # really should be correlated with self._plot_type!! + myplot.histogram(columns = data, + figname = auxname, + xlab = bunit, + ylab = "Count", + title = "Histogram of CubeSum: %s" % (bdp_name), + thumbnail=True) + auxname = myplot.getFigure(figno=myplot.figno,relative=True) + auxthumb = myplot.getThumbnail(figno=myplot.figno,relative=True) + + images = {bt.CASA : bdp_name, bt.PNG : figname} + casaimage = Image(images = images, + auxiliary = auxname, + auxtype = auxtype, + thumbnail = thumbname, + thumbnailtype = thumbtype) + imcaption = "Integral (moment 0) of all emission in image cube" + auxcaption = "Histogram of cube sum for image cube" + noplot = False if hasattr(b1,"line"): # SpwCube doesn't have Line line = deepcopy(getattr(b1,"line")) @@ -395,10 +411,8 @@ def run(self): line = Line(name="Undetermined") # fake a Line if there wasn't one self.addoutput(Moment_BDP(xmlFile=bdp_name,moment=0,image=deepcopy(casaimage),line=line)) - imcaption = "Integral (moment 0) of all emission in image cube" - auxcaption = "Histogram of cube sum for image cube" taskargs = "numsigma=%.1f sigma=%g smooth=%s" % (numsigma, sigma, str(smooth)) - self._summary["cubesum"] = SummaryEntry([figname,thumbname,imcaption,auxname,auxthumb,auxcaption,bdp_name,infile],"CubeSum_AT",self.id(True),taskargs) + self._summary["cubesum"] = SummaryEntry([figname,thumbname,imcaption,auxname,auxthumb,auxcaption,bdp_name,infile],"CubeSum_AT",self.id(True),taskargs,noplot=noplot) ia.done() diff --git a/admit/at/Export_AT.py b/admit/at/Export_AT.py index b340abb..0d120c7 100644 --- a/admit/at/Export_AT.py +++ b/admit/at/Export_AT.py @@ -17,6 +17,7 @@ from admit.bdp.LineList_BDP import LineList_BDP from admit.bdp.Moment_BDP import Moment_BDP import admit.util.utils as utils +import admit.util.PlotControl as PlotControl import admit.util.filter.Filter1D as Filter1D from admit.util.AdmitLogging import AdmitLogging as logging import numpy as np diff --git a/admit/at/FeatureList_AT.py b/admit/at/FeatureList_AT.py index 5b1e60a..1046608 100644 --- a/admit/at/FeatureList_AT.py +++ b/admit/at/FeatureList_AT.py @@ -11,6 +11,7 @@ import admit.util.bdp_types as bt from admit.util.Image import Image from admit.util.utils import Dtime +import admit.util.PlotControl as PlotControl from admit.bdp.CubeStats_BDP import CubeStats_BDP from admit.bdp.Image_BDP import Image_BDP diff --git a/admit/at/Flow11_AT.py b/admit/at/Flow11_AT.py index a0ffc20..1f62346 100755 --- a/admit/at/Flow11_AT.py +++ b/admit/at/Flow11_AT.py @@ -191,9 +191,9 @@ def summarize(self): # finally, set some parameters for the ADMIT summary abc_list= ['robust', 'chauvenet', 21.3, 123] - self._summary['datamin'] = SummaryEntry(3.14159,"Flow11_AT",taskid=self.id(True)) - self._summary['datamax'] = SummaryEntry(2.71828,"Flow11_AT",taskid=self.id(True)) - self._summary['rmsmethd'] = SummaryEntry(abc_list,"Flow11_AT",taskid=self.id(True)) + self._summary['datamin'] = SummaryEntry(3.14159,"Flow11_AT",taskid=self.id(True),noplot=True) + self._summary['datamax'] = SummaryEntry(2.71828,"Flow11_AT",taskid=self.id(True),noplot=True) + self._summary['rmsmethd'] = SummaryEntry(abc_list,"Flow11_AT",taskid=self.id(True),noplot=True) print "Flow11_AT taskid = %d" % self.id(True) diff --git a/admit/at/GenerateSpectrum_AT.py b/admit/at/GenerateSpectrum_AT.py index 5312250..7c7af5e 100644 --- a/admit/at/GenerateSpectrum_AT.py +++ b/admit/at/GenerateSpectrum_AT.py @@ -15,6 +15,7 @@ from admit.util import APlot import admit.util.Image as Image from admit.util import SpectralLineSearch +import admit.util.PlotControl as PlotControl from admit.Summary import SummaryEntry import os @@ -208,6 +209,7 @@ def run(self): nspectra = self.getkey("nspectra") taskargs = " contin=%f freq=%f delta=%f nspectra=%f " % (contin,f0,df,nspectra) spec = range(nspectra) + noplot = True dt.tag("start") if self.getkey("file") != "": print "READING spectrum from",self.getkey("file") @@ -274,7 +276,7 @@ def run(self): images = {} # png's accumulated for i in range(nspectra): sd = [] - caption = "Generated Spectrum %d" % i + imcaption = "Generated Spectrum %d" % i # construct the Table for CubeSpectrum_BDP # @todo note data needs to be a tuple, later to be column_stack'd labels = ["channel" ,"frequency" ,"flux" ] @@ -291,20 +293,28 @@ def run(self): xlab = 'Channel' y = [spec[i]] sd.append(xlab) + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + thumbname = "not created" + imcaption = "not created" + noplot = True + else: + + myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode, abspath=self.dir()) + ylab = 'Flux' + p1 = "%s_%d" % (bdp_name,i) + myplot.plotter(x,y,"",p1,xlab=xlab,ylab=ylab,thumbnail=True) + # Why not use p1 as the key? + figname = images["pos%d" % i] = myplot.getFigure(figno=myplot.figno,relative=True) + thumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) - myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode, abspath=self.dir()) - ylab = 'Flux' - p1 = "%s_%d" % (bdp_name,i) - myplot.plotter(x,y,"",p1,xlab=xlab,ylab=ylab,thumbnail=True) - # Why not use p1 as the key? - ii = images["pos%d" % i] = myplot.getFigure(figno=myplot.figno,relative=True) - thumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) + image = Image(images=images, description="CubeSpectrum") + noplot = False - image = Image(images=images, description="CubeSpectrum") - sd.extend([ii, thumbname, caption]) + sd.extend([figname, thumbname, imcaption]) self.spec_description.append(sd) - self._summary["spectra"] = SummaryEntry(self.spec_description,"GenerateSpectrum_AT",self.id(True), taskargs) + self._summary["spectra"] = SummaryEntry(self.spec_description,"GenerateSpectrum_AT",self.id(True), taskargs, noplot=noplot) dt.tag("table") diff --git a/admit/at/Ingest_AT.py b/admit/at/Ingest_AT.py index df6dc5c..fa4dc34 100644 --- a/admit/at/Ingest_AT.py +++ b/admit/at/Ingest_AT.py @@ -15,6 +15,7 @@ import admit.util.utils as utils import admit.util.casautil as casautil import admit.util.ImPlot as ImPlot +import admit.util.PlotControl as PlotControl from admit.bdp.SpwCube_BDP import SpwCube_BDP from admit.bdp.Image_BDP import Image_BDP from admit.util.AdmitLogging import AdmitLogging as logging @@ -867,3 +868,4 @@ def _summarize(self, fitsname, casaname, header, shape, taskargs): self._summary[k].setTaskname("Ingest_AT") self._summary[k].setTaskID(self.id(True)) self._summary[k].setTaskArgs(taskargs) + self._summary[k].setNoPlot(True) diff --git a/admit/at/LineCube_AT.py b/admit/at/LineCube_AT.py index fdfdb27..4977953 100644 --- a/admit/at/LineCube_AT.py +++ b/admit/at/LineCube_AT.py @@ -16,6 +16,7 @@ from admit.util.Image import Image import admit.util.Table import admit.util.utils as utils +import admit.util.PlotControl as PlotControl from admit.util.AdmitLogging import AdmitLogging as logging diff --git a/admit/at/LineID_AT.py b/admit/at/LineID_AT.py index 88856ef..d5282f7 100644 --- a/admit/at/LineID_AT.py +++ b/admit/at/LineID_AT.py @@ -22,6 +22,7 @@ from admit.bdp.CubeSpectrum_BDP import CubeSpectrum_BDP from admit.bdp.CubeStats_BDP import CubeStats_BDP from admit.bdp.PVCorr_BDP import PVCorr_BDP +import admit.util.PlotControl as PlotControl import admit.util.filter.Filter1D as Filter1D from admit.util import APlot from admit.util.Image import Image @@ -3101,7 +3102,11 @@ def run(self): self._plot_type = admit.util.PlotControl.SVG # instantiate a plotter for all plots made herein - myplot = APlot(ptype=self._plot_type, pmode=self._plot_mode, abspath=self.dir()) + if self._plot_mode != PlotControl.NOPLOT: + noplot = False + myplot = APlot(ptype=self._plot_type, pmode=self._plot_mode, abspath=self.dir()) + else: + noplot = True ############################################################################ # Smoothing and continuum (baseline) subtraction of input spectra # @@ -3254,65 +3259,80 @@ def run(self): if i == 1: mult = -1. # print("MWP plot cutoff[%d] = %f, contin=%f" % (i, (spec.contin() + mult*(spec.noise() * self.getkey("numsigma")))[0], spec.contin()[0] ) ) - myplot.segplotter(x=spec.freq(), y=spec.spec(csub=False), - title="Potential Line Locations", xlab=xlabel, - ylab=label[i], figname=imbase + "_statspec%i" % i, segments=freqs, - cutoff=(spec.contin() + mult * (spec.noise() * self.getkey("numsigma"))), - continuum=spec.contin(), thumbnail=True) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption[i]) - llbdp.image.addimage(image, "statspec%i" % i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.segplotter(x=spec.freq(), y=spec.spec(csub=False), + title="Potential Line Locations", xlab=xlabel, + ylab=label[i], figname=imbase + "_statspec%i" % i, segments=freqs, + cutoff=(spec.contin() + mult * (spec.noise() * self.getkey("numsigma"))), + continuum=spec.contin(), thumbnail=True) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=caption[i]) + llbdp.image.addimage(image, "statspec%i" % i) self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, caption[i], self.infile]) for i, spec in enumerate(self.specs): freqs = [] + _caption = "Potential lines overlaid on input spectrum #%i." % (i) for ch in self.specseg[i]: freqs.append([min(spec.freq()[ch[0]], spec.freq()[ch[1]]), max(spec.freq()[ch[0]], spec.freq()[ch[1]])]) - myplot.segplotter(x=spec.freq(), y=spec.spec(csub=False), - title="Potential Line Locations", xlab=xlabel, - ylab="Intensity", figname=imbase + "_spec%03d" % i, segments=freqs, - cutoff=spec.contin() + (spec.noise() * self.getkey("numsigma")), - continuum=spec.contin(), thumbnail=True) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, - relative=True) - _caption = "Potential lines overlaid on input spectrum #%i." % (i) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=_caption) - llbdp.image.addimage(image, "spec%03d" % i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + else: + myplot.segplotter(x=spec.freq(), y=spec.spec(csub=False), + title="Potential Line Locations", xlab=xlabel, + ylab="Intensity", figname=imbase + "_spec%03d" % i, segments=freqs, + cutoff=spec.contin() + (spec.noise() * self.getkey("numsigma")), + continuum=spec.contin(), thumbnail=True) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, + relative=True) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=_caption) + llbdp.image.addimage(image, "spec%03d" % i) + self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, _caption, self.infile]) if self.pvspec is not None: freqs = [] + _caption = "Potential lines overlaid on Correlation plot from PVCorr_BDP." for ch in self.pvseg: freqs.append([min(self.pvspec.freq()[ch[0]], self.pvspec.freq()[ch[1]]), max(self.pvspec.freq()[ch[0]], self.pvspec.freq()[ch[1]])]) - myplot.segplotter(x=self.pvspec.freq(), y=self.pvspec.spec(csub=False), - title="Potential Line Locations", xlab=xlabel, - ylab="Corr. Coef.", figname=imbase + "_pvspec", - segments=freqs, cutoff=self.pvspec.noise() * self.getkey("numsigma"), - thumbnail=True) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, - relative=True) - _caption = "Potential lines overlaid on Correlation plot from PVCorr_BDP." - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=_caption) - llbdp.image.addimage(image, "pvspec") + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + else: + myplot.segplotter(x=self.pvspec.freq(), y=self.pvspec.spec(csub=False), + title="Potential Line Locations", xlab=xlabel, + ylab="Corr. Coef.", figname=imbase + "_pvspec", + segments=freqs, cutoff=self.pvspec.noise() * self.getkey("numsigma"), + thumbnail=True) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, + relative=True) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=_caption) + llbdp.image.addimage(image, "pvspec") + self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, _caption, self.infile]) self._summary["linelist"] = SummaryEntry(llbdp.table.serialize(), "LineID_AT", - self.id(True), taskargs) + self.id(True), taskargs,noplot=noplot) self._summary["spectra"] = [SummaryEntry(self.spec_description, "LineID_AT", - self.id(True), taskargs)] + self.id(True), taskargs,noplot=noplot)] self.addoutput(llbdp) self.dt.tag("done") @@ -3462,54 +3482,69 @@ def run(self): mult = 1. if i == 1: mult = -1. - myplot.makespec(x=spec.freq(), y=spec.spec(csub=False), chan=spec.chans(), - cutoff=(spec.contin() + mult * (spec.noise() * self.getkey("numsigma"))), - figname=imbase +"_statspec%i" % i, title="Line ID (vlsr=%.2f)" % self.vlsr, - xlabel=xlabel, lines={}, force=self.force, blends=[], - continuum=spec.contin(), ylabel=label[i], - thumbnail=True, references=line_ref) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption[i]) - llbdp.image.addimage(image, "statspec%i" % i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.makespec(x=spec.freq(), y=spec.spec(csub=False), chan=spec.chans(), + cutoff=(spec.contin() + mult * (spec.noise() * self.getkey("numsigma"))), + figname=imbase +"_statspec%i" % i, title="Line ID (vlsr=%.2f)" % self.vlsr, + xlabel=xlabel, lines={}, force=self.force, blends=[], + continuum=spec.contin(), ylabel=label[i], + thumbnail=True, references=line_ref) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=caption[i]) + llbdp.image.addimage(image, "statspec%i" % i) self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, caption[i], self.infile]) # cubespec output (1 for each input spectra, there could be many from a single BDP) for i, spec in enumerate(self.specs): - myplot.makespec(x=spec.freq(), y=spec.spec(csub=False), chan=spec.chans(), - cutoff=spec.contin() + spnoise[i], - figname=imbase +"_spec%03d" % i, - title="Line ID (vlsr=%.2f)" % self.vlsr, xlabel=xlabel, - lines={}, force=self.force, blends=[], - continuum=spec.contin(), thumbnail=True, - references=line_ref) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, - relative=True) _caption = "Identified lines overlaid on input spectrum #%i." % (i) - image = Image(images={bt.SVG: imname}, - thumbnail=thumbnailname, thumbnailtype=bt.PNG, - description=_caption) - llbdp.image.addimage(image, "spec%03d" % i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.makespec(x=spec.freq(), y=spec.spec(csub=False), chan=spec.chans(), + cutoff=spec.contin() + spnoise[i], + figname=imbase +"_spec%03d" % i, + title="Line ID (vlsr=%.2f)" % self.vlsr, xlabel=xlabel, + lines={}, force=self.force, blends=[], + continuum=spec.contin(), thumbnail=True, + references=line_ref) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, + relative=True) + image = Image(images={bt.SVG: imname}, + thumbnail=thumbnailname, thumbnailtype=bt.PNG, + description=_caption) + llbdp.image.addimage(image, "spec%03d" % i) self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, _caption, self.infile]) if self.pvspec is not None: - myplot.makespec(x=self.pvspec.freq(), y=self.pvspec.spec(csub=False), chan=self.pvspec.chans(), - cutoff=self.pvcutoff, - figname=imbase + "_pvspec", title="Line ID (vlsr=%.2f)" % self.vlsr, - xlabel=xlabel, lines={}, force=self.force, blends=[], - continuum=[0.0] * len(self.pvspec), ylabel="Corr. Coeff.", - thumbnail=True, references=line_ref) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - _caption = "Identified lines overlaid on Correlation Coefficient plot from PVCorr_BDP." - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=_caption) - llbdp.image.addimage(image, "pvspec") + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.makespec(x=self.pvspec.freq(), y=self.pvspec.spec(csub=False), chan=self.pvspec.chans(), + cutoff=self.pvcutoff, + figname=imbase + "_pvspec", title="Line ID (vlsr=%.2f)" % self.vlsr, + xlabel=xlabel, lines={}, force=self.force, blends=[], + continuum=[0.0] * len(self.pvspec), ylabel="Corr. Coeff.", + thumbnail=True, references=line_ref) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=_caption) + llbdp.image.addimage(image, "pvspec") self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, _caption, self.infile]) @@ -3988,21 +4023,26 @@ def run(self): mult = 1. if i == 1: mult = -1. - myplot.makespec(x=self.statspec[i].freq(), y=self.statspec[i].spec(csub=False), - chan=self.statspec[i].chans(), - cutoff=(self.statspec[i].contin() + mult * (self.statspec[i].noise() * - self.getkey("numsigma"))), - figname=imbase + "_statspec%i" % i, title="Line ID (vlsr=%.2f)" % self.vlsr, - xlabel=xlabel, lines=mlist, force=self.force, - blends=peaks["stats"][i].blends, continuum=self.statspec[i].contin(), - ylabel=label[i], thumbnail=True, references=line_ref) - imname = myplot.getFigure(figno=myplot.figno, relative=True) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.makespec(x=self.statspec[i].freq(), y=self.statspec[i].spec(csub=False), + chan=self.statspec[i].chans(), + cutoff=(self.statspec[i].contin() + mult * (self.statspec[i].noise() * + self.getkey("numsigma"))), + figname=imbase + "_statspec%i" % i, title="Line ID (vlsr=%.2f)" % self.vlsr, + xlabel=xlabel, lines=mlist, force=self.force, + blends=peaks["stats"][i].blends, continuum=self.statspec[i].contin(), + ylabel=label[i], thumbnail=True, references=line_ref) + imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption[i]) - llbdp.image.addimage(image, "statspec%i" % i) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=caption[i]) + llbdp.image.addimage(image, "statspec%i" % i) self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, caption[i], self.infile]) @@ -4046,22 +4086,27 @@ def run(self): mlist += ulist xlabel = "%s Frequency (GHz)" % (t) - myplot.makespec(x=self.specs[i].freq(), y=self.specs[i].spec(csub=False), - chan=self.specs[i].chans(), - cutoff=self.specs[i].contin() + (self.specs[i].noise() * - self.getkey("numsigma")), - figname=imbase + "_spec%03d" % i, - title="Line ID (vlsr=%.2f)" % self.vlsr, xlabel=xlabel, lines=mlist, - force=self.force, blends=peaks["specs"][i].blends, - continuum=self.specs[i].contin(), thumbnail=True, references=line_ref) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, - relative=True) _caption = "Identified lines overlaid on input spectrum #%i." % (i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.makespec(x=self.specs[i].freq(), y=self.specs[i].spec(csub=False), + chan=self.specs[i].chans(), + cutoff=self.specs[i].contin() + (self.specs[i].noise() * + self.getkey("numsigma")), + figname=imbase + "_spec%03d" % i, + title="Line ID (vlsr=%.2f)" % self.vlsr, xlabel=xlabel, lines=mlist, + force=self.force, blends=peaks["specs"][i].blends, + continuum=self.specs[i].contin(), thumbnail=True, references=line_ref) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, + relative=True) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=_caption) - llbdp.image.addimage(image, "spec%03d" % i) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=_caption) + llbdp.image.addimage(image, "spec%03d" % i) self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, _caption, self.infile]) @@ -4104,19 +4149,24 @@ def run(self): xlabel = "%s Frequency (GHz)" % (t) - myplot.makespec(x=self.pvspec.freq(), y=self.pvspec.spec(csub=False), chan=self.pvspec.chans(), - cutoff=self.pvspec.noise() * self.getkey("numsigma"), - figname=imbase + "_pvspec", title="Line ID (vlsr=%.2f)" % self.vlsr, - xlabel=xlabel, lines=mlist, force=self.force, blends=peaks["pvc"].blends, - continuum=[0.0] * len(self.pvspec), ylabel="Correlation", - thumbnail=True, references=line_ref) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) _caption = "Identified lines overlaid on correlation coefficient plot from PVCorr_BDP." + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.makespec(x=self.pvspec.freq(), y=self.pvspec.spec(csub=False), chan=self.pvspec.chans(), + cutoff=self.pvspec.noise() * self.getkey("numsigma"), + figname=imbase + "_pvspec", title="Line ID (vlsr=%.2f)" % self.vlsr, + xlabel=xlabel, lines=mlist, force=self.force, blends=peaks["pvc"].blends, + continuum=[0.0] * len(self.pvspec), ylabel="Correlation", + thumbnail=True, references=line_ref) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=_caption) - llbdp.image.addimage(image, "pvspec") + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=_caption) + llbdp.image.addimage(image, "pvspec") self.spec_description.append([llbdp.ra, llbdp.dec, "", xlabel, imname, thumbnailname, _caption, self.infile]) @@ -4407,18 +4457,23 @@ def run(self): llbdp.addRow(m) logging.regression("LINEID: %s %.5f %d %d" % (m.getkey("formula"), m.getkey("frequency"), m.getstart(), m.getend())) - # Need to adjust plot DPI = 72 for SVG; stick to PNG for now... - myplot._plot_type = admit.util.PlotControl.PNG - myplot._plot_mode = admit.util.PlotControl.NONE - myplot.summaryspec(self.statspec, self.specs, self.pvspec, imbase + "_summary", llist, force=self.force) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + _caption = "Identified lines overlaid on Signal/Noise plot of all spectra." + # Need to adjust plot DPI = 72 for SVG; stick to PNG for now... + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot._plot_type = admit.util.PlotControl.PNG + myplot.summaryspec(self.statspec, self.specs, self.pvspec, imbase + "_summary", llist, force=self.force) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - image = Image(images={bt.PNG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=_caption) + image = Image(images={bt.PNG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=_caption) - llbdp.image.addimage(image, "summary") + llbdp.image.addimage(image, "summary") self.spec_description.append([llbdp.ra, llbdp.dec, "", "Signal/Noise", imname, thumbnailname, _caption, self.infile]) diff --git a/admit/at/LineSegment_AT.py b/admit/at/LineSegment_AT.py index e583703..0ca84a4 100644 --- a/admit/at/LineSegment_AT.py +++ b/admit/at/LineSegment_AT.py @@ -18,6 +18,7 @@ from admit.bdp.LineSegment_BDP import LineSegment_BDP from admit.bdp.CubeSpectrum_BDP import CubeSpectrum_BDP from admit.bdp.CubeStats_BDP import CubeStats_BDP +import admit.util.PlotControl as PlotControl from admit.util import APlot from admit.util.Image import Image from admit.util.AdmitLogging import AdmitLogging as logging @@ -210,7 +211,11 @@ def run(self): # instantiate a plotter for all plots made herein self._plot_type = admit.util.PlotControl.SVG - myplot = APlot(ptype=self._plot_type, pmode=self._plot_mode, abspath=self.dir()) + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + else: + noplot = False + myplot = APlot(ptype=self._plot_type, pmode=self._plot_mode, abspath=self.dir()) dt.tag("start") ############################################################################ @@ -326,54 +331,68 @@ def run(self): if i == 1: mult = -1. # print("MWP statspec plot cutoff[%d] = %f, contin=%f" % (i, (statspec[i].contin() + mult*(statspec[i].noise() * self.getkey("numsigma")))[0], statspec[i].contin()[0] ) ) - myplot.segplotter(spec.freq(), spec.spec(csub=False), - title="Detected Line Segments", xlab=xlabel, - ylab=label[i], figname=imbase + "_statspec%i" % i, - segments=freqs, cutoff= (spec.contin() + mult*(spec.noise() * self.getkey("numsigma"))), - continuum=spec.contin(), thumbnail=True) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption[i]) - lsbdp.image.addimage(image, "statspec%i" % i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + # leave captions unchanged for now + else: + myplot.segplotter(spec.freq(), spec.spec(csub=False), + title="Detected Line Segments", xlab=xlabel, + ylab=label[i], figname=imbase + "_statspec%i" % i, + segments=freqs, cutoff= (spec.contin() + mult*(spec.noise() * self.getkey("numsigma"))), + continuum=spec.contin(), thumbnail=True) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=caption[i]) + lsbdp.image.addimage(image, "statspec%i" % i) spec_description.append([lsbdp.ra, lsbdp.dec, "", xlabel, imname, thumbnailname, caption[i], infile]) for i in range(len(specs)): freqs = [] + caption = "Detected line segments from input spectrum #%i." % (i) for ch in specseg[i]: frq = [min(specs[i].freq()[ch[0]], specs[i].freq()[ch[1]]), max(specs[i].freq()[ch[0]], specs[i].freq()[ch[1]])] freqs.append(frq) rdata.append(frq) - myplot.segplotter(specs[i].freq(), specs[i].spec(csub=False), - title="Detected Line Segments", xlab=xlabel, - ylab="Intensity", figname=imbase + "_spec%03d" % i, - segments=freqs, cutoff=specs[i].contin() + (specs[i].noise() * self.getkey("numsigma")), - continuum=specs[i].contin(), thumbnail=True) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, - relative=True) - caption = "Detected line segments from input spectrum #%i." % (i) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption) - lsbdp.image.addimage(image, "spec%03d" % i) + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + else: + myplot.segplotter(specs[i].freq(), specs[i].spec(csub=False), + title="Detected Line Segments", xlab=xlabel, + ylab="Intensity", figname=imbase + "_spec%03d" % i, + segments=freqs, cutoff=specs[i].contin() + (specs[i].noise() * self.getkey("numsigma")), + continuum=specs[i].contin(), thumbnail=True) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, + relative=True) + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=caption) + lsbdp.image.addimage(image, "spec%03d" % i) + spec_description.append([lsbdp.ra, lsbdp.dec, "", xlabel, imname, thumbnailname, caption, infile]) caption = "Merged segments overlaid on CubeStats spectrum" + if self._plot_mode == PlotControl.NOPLOT: + imname = "not created" + thumbnailname = "not created" + else: + myplot.summaryspec(statspec, specs, None, imbase + "_summary", llist) + imname = myplot.getFigure(figno=myplot.figno, relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) + caption = "Identified segments overlaid on Signal/Noise plot of all spectra." - myplot.summaryspec(statspec, specs, None, imbase + "_summary", llist) - imname = myplot.getFigure(figno=myplot.figno, relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno, relative=True) - caption = "Identified segments overlaid on Signal/Noise plot of all spectra." + image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, + thumbnailtype=bt.PNG, description=caption) - image = Image(images={bt.SVG: imname}, thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption) + lsbdp.image.addimage(image, "summary") - lsbdp.image.addimage(image, "summary") spec_description.append([lsbdp.ra, lsbdp.dec, "", "Signal/Noise", imname, thumbnailname, caption, infile]) @@ -381,10 +400,10 @@ def run(self): self._summary["segments"] = SummaryEntry(lsbdp.table.serialize(), "LineSegment_AT", - self.id(True), taskargs) + self.id(True), taskargs,noplot=noplot) self._summary["spectra"] = [SummaryEntry(spec_description, "LineSegment_AT", - self.id(True), taskargs)] + self.id(True), taskargs,noplot=noplot)] self.addoutput(lsbdp) logging.regression("LINESEG: %s" % str(rdata)) diff --git a/admit/at/Moment_AT.py b/admit/at/Moment_AT.py index b08fdc2..abbfb2d 100644 --- a/admit/at/Moment_AT.py +++ b/admit/at/Moment_AT.py @@ -16,6 +16,7 @@ from admit.bdp.CubeStats_BDP import CubeStats_BDP import admit.util.Image as Image import admit.util.Line as Line +import admit.util.PlotControl as PlotControl import admit.util.ImPlot as ImPlot import admit.util.utils as utils import admit.util.casautil as casautil @@ -283,8 +284,12 @@ def run(self): # loop over moments to rename them to _0, _1, _2 etc. # apply a mask as well for proper histogram creation map = {} - myplot = APlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) - implot = ImPlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) + if self._plot_mode != PlotControl.NOPLOT: + myplot = APlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) + implot = ImPlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) + noplot = False + else: + noplot = True for mom in moments: figname = imagename = "%s_%i" % (basename, mom) @@ -305,13 +310,20 @@ def run(self): dt.tag("makemask") if mom == 0: beamarea = nppb(self.dir(imagename)) - implot.plotter(rasterfile=imagename,figname=figname, - colorwedge=True,zoom=self.getkey("zoom")) - imagepng = implot.getFigure(figno=implot.figno,relative=True) - thumbname = implot.getThumbnail(figno=implot.figno,relative=True) - images = {bt.CASA : imagename, bt.PNG : imagepng} - thumbtype=bt.PNG - dt.tag("implot") + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + imagepng = "not created" + thumbname = "not created" + imcaption = "not created" + images = {bt.CASA : imagename} + else: + implot.plotter(rasterfile=imagename,figname=figname, + colorwedge=True,zoom=self.getkey("zoom")) + imagepng = implot.getFigure(figno=implot.figno,relative=True) + thumbname = implot.getThumbnail(figno=implot.figno,relative=True) + images = {bt.CASA : imagename, bt.PNG : imagepng} + thumbtype=bt.PNG + dt.tag("implot") # get the data for a histogram (ia access is about 1000-2000 faster than imval()) map[mom] = casautil.getdata(self.dir(imagename)) @@ -325,24 +337,6 @@ def run(self): # object for the caption objectname = casa.imhead(imagename=self.dir(imagename), mode="get", hdkey="object") - # Make the histogram plot - # Since we give abspath in the constructor, figname should be relative - auxname = imagename + '_histo' - auxtype = bt.PNG - myplot.histogram(columns = data, - figname = auxname, - xlab = bunit, - ylab = "Count", - title = "Histogram of Moment %d: %s" % (mom, imagename), thumbnail=True) - - casaimage = Image(images = images, - auxiliary = auxname, - auxtype = auxtype, - thumbnail = thumbname, - thumbnailtype = thumbtype) - auxname = myplot.getFigure(figno=myplot.figno,relative=True) - auxthumb = myplot.getThumbnail(figno=myplot.figno,relative=True) - if hasattr(self._bdp_in[0], "line"): # SpwCube doesn't have Line line = deepcopy(getattr(self._bdp_in[0], "line")) if not isinstance(line, Line): @@ -350,13 +344,38 @@ def run(self): else: # fake a Line if there wasn't one line = Line(name="Unidentified") + + # Make the histogram plot + # Since we give abspath in the constructor, figname should be relative + if self._plot_mode == PlotControl.NOPLOT: + auxname = "not created" + auxthumb = "not created" + auxcaption = "not created" + casaimage = Image(images = images) + else: + auxname = imagename + '_histo' + auxtype = bt.PNG + myplot.histogram(columns = data, + figname = auxname, + xlab = bunit, + ylab = "Count", + title = "Histogram of Moment %d: %s" % (mom, imagename), thumbnail=True) + auxname = myplot.getFigure(figno=myplot.figno,relative=True) + auxthumb = myplot.getThumbnail(figno=myplot.figno,relative=True) + imcaption = "%s Moment %d map of Source %s" % (line.name, mom, objectname) + auxcaption = "Histogram of %s Moment %d of Source %s" % (line.name, mom, objectname) + + casaimage = Image(images = images, + auxiliary = auxname, + auxtype = auxtype, + thumbnail = thumbname, + thumbnailtype = thumbtype) + # add the BDP to the output array self.addoutput(Moment_BDP(xmlFile=imagename, moment=mom, image=deepcopy(casaimage), line=line)) dt.tag("ren+mask_%d" % mom) - imcaption = "%s Moment %d map of Source %s" % (line.name, mom, objectname) - auxcaption = "Histogram of %s Moment %d of Source %s" % (line.name, mom, objectname) thismomentsummary = [line.name, mom, imagepng, thumbname, imcaption, auxname, auxthumb, auxcaption, infile] momentsummary.append(thismomentsummary) @@ -408,6 +427,9 @@ def run(self): # create a histogram of flux per channel + # NOTE THERE IS NO BDP ASSOCIATED WITH THIS! + # Run it anyway even if noplot==True. + # grab the X coordinates for the histogram, we want them in km/s # restfreq should also be in summary restfreq = casa.imhead(self.dir(infile),mode="get",hdkey="restfreq")['value']/1e9 # in GHz @@ -425,10 +447,11 @@ def run(self): # @todo make a flux1 with fluxes derived from a good mask flux1 = flux0 # construct histogram - title = 'Flux Spectrum (%g)' % flux0sum - xlab = 'VLSR (km/s)' - ylab = 'Flux (Jy)' - myplot.plotter(x,[flux0,flux1],title=title,figname=fluxname,xlab=xlab,ylab=ylab,histo=True) + if self._plot_mode != PlotControl.NOPLOT: + title = 'Flux Spectrum (%g)' % flux0sum + xlab = 'VLSR (km/s)' + ylab = 'Flux (Jy)' + myplot.plotter(x,[flux0,flux1],title=title,figname=fluxname,xlab=xlab,ylab=ylab,histo=True) dt.tag("flux-spectrum") self._summary["moments"] = SummaryEntry(momentsummary, "Moment_AT", diff --git a/admit/at/OverlapIntegral_AT.py b/admit/at/OverlapIntegral_AT.py index 5f33b0c..f35cde0 100644 --- a/admit/at/OverlapIntegral_AT.py +++ b/admit/at/OverlapIntegral_AT.py @@ -21,6 +21,7 @@ import admit.util.utils as utils import admit.util.APlot as APlot import admit.util.Line as Line +import admit.util.PlotControl as PlotControl import admit.util.ImPlot as ImPlot import admit.util.Table from admit.bdp.Image_BDP import Image_BDP @@ -33,7 +34,7 @@ import casa import taskinit except: - print "WARNING: No scipy or casa; OverlapIntegral task cannot function." + print("WARNING: No scipy or casa; OverlapIntegral task cannot function.") class OverlapIntegral_AT(AT): @@ -140,7 +141,6 @@ def run(self): normalize = self.getkey("normalize") doCross = True doCross = False - myplot = APlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) dt.tag("start") @@ -236,23 +236,28 @@ def run(self): pdata = np.rot90(out.squeeze()) logging.info("PDATA: %s" % str(pdata.shape)) - myplot.map1(pdata,title,"testOI",thumbnail=True,cmap=cmap) + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + thumbnailname = "not created" + imcaption = "not created" + noplot = True + else: + myplot = APlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) + myplot.map1(pdata,title,"testOI",thumbnail=True,cmap=cmap) + figname = myplot.getFigure(figno=myplot.figno,relative=True) + thumbnailname = myplot.getThumbnail(figno=myplot.figno,relative=True) + #@todo fill in imcaption with more info - line names, etc. + imcaption = "Need descriptive imcaption here" + noplot = False #----------------------------- # Populate summary information #----------------------------- taskargs = "chans=%s cmap=%s" % (chans, cmap) - imname = "" - thumbnailname = "" - # uncomment when ready. - imname = myplot.getFigure(figno=myplot.figno,relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno,relative=True) - #@todo fill in caption with more info - line names, etc. - caption = "Need descriptive caption here" - summaryinfo = [summarytable.serialize(),imname,thumbnailname,caption] + summaryinfo = [summarytable.serialize(),figname,thumbnailname,imcaption] self._summary["overlap"] = SummaryEntry(summaryinfo, "OverlapIntegral_AT", - self.id(True),taskargs) + self.id(True),taskargs,noplot=noplot) #----------------------------- dt.tag("done") dt.end() @@ -262,6 +267,10 @@ def crossn(data, myplot): CAUTION: Expensive routine @todo divide cross(i,j)/sqrt(auto(i)*auto(j)) """ + # even if self._plot_mode = PlotControl.NOPLOT, run through the + # computation because a) the user asked for it by doCross=True, + # b) it would be more consistent with any regression testing, + # and c) if this computation ever gets put into a BDP we'd want it that way. n = len(data) nx = data[0].shape[0] ny = data[0].shape[1] @@ -270,7 +279,8 @@ def crossn(data, myplot): idata = data[i].data.squeeze() out = scipy.signal.correlate2d(idata,idata,mode='same') auto[i] = np.rot90(out.reshape((nx,ny))) - myplot.map1(auto[i],"autocorr-%d" % i,"testOI-%d-%d" % (i,i),thumbnail=False) + if self._plot_mode != PlotControl.NOPLOT: + myplot.map1(auto[i],"autocorr-%d" % i,"testOI-%d-%d" % (i,i),thumbnail=False) for i in range(n): idata = data[i].data.squeeze() for j in range(i+1,n): @@ -278,7 +288,8 @@ def crossn(data, myplot): out = scipy.signal.correlate2d(idata,jdata,mode='same') #outd = np.rot90(out.reshape((nx,ny))) / np.sqrt(auto[i]*auto[j]) outd = np.rot90(out.reshape((nx,ny))) - myplot.map1(outd,"crosscorr-%d-%d" % (i,j),"testOI-%d-%d" % (i,j),thumbnail=False) + if self._plot_mode != PlotControl.NOPLOT: + myplot.map1(outd,"crosscorr-%d-%d" % (i,j),"testOI-%d-%d" % (i,j),thumbnail=False) def rgb1(r,g,b, normalize=False): diff --git a/admit/at/PVCorr_AT.py b/admit/at/PVCorr_AT.py index c3a61c1..13191b2 100644 --- a/admit/at/PVCorr_AT.py +++ b/admit/at/PVCorr_AT.py @@ -17,6 +17,7 @@ from admit.bdp.CubeStats_BDP import CubeStats_BDP from admit.bdp.PVCorr_BDP import PVCorr_BDP from admit.bdp.Image_BDP import Image_BDP +import admit.util.PlotControl as PlotControl from admit.util import APlot from admit.util import stats from admit.util.AdmitLogging import AdmitLogging as logging @@ -136,7 +137,10 @@ def run(self): b1 = self._bdp_in[0] # PVSlice_BDP fin = b1.getimagefile(bt.CASA) # CASA image data = casautil.getdata_raw(self.dir(fin)) # grab the data as a numpy array - self.myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + bdp_name = self.mkext(fin,"pvc") # output PVCorr_BDP + b3 = PVCorr_BDP(bdp_name) + self.addoutput(b3) + #print 'DATA[0,0]:',data[0,0] #print 'pv shape: ',data.shape npos = data.shape[0] @@ -189,9 +193,6 @@ def run(self): dt.tag("imstat") - bdp_name = self.mkext(fin,"pvc") # output PVCorr_BDP - b3 = PVCorr_BDP(bdp_name) - self.addoutput(b3) if ch0<0 or ch1>=nvel: # this probably only happens to small cubes (problematic for PVCorr) @@ -255,22 +256,34 @@ def run(self): segp = [] segp.append( [0,len(ch),0.0,0.0] ) segp.append( [0,len(ch),3.0*rms, 3.0*rms] ) - # @todo: in principle we know with given noise and size of box, what the sigma in pvcorr should be - self.myplot.plotter(x,y,title,figname=p1,xlab=xlab,ylab=ylab,segments=segp, thumbnail=True) - #out1 = np.rot90 (data.reshape((nvel,npos)) ) - if mode > 1: - self.myplot.map1(data=out,title="testing PVCorr_AT: mode%d"%mode,figname='testPVCorr', thumbnail=True) + # @todo: in principle we know with given noise and size of box, what the sigma in pvcorr should be taskargs = "numsigma=%.1f range=[%d,%d]" % (numsigma,ch0,ch1) - caption = "Position-velocity correlation plot" - thumbname = self.myplot.getThumbnail(figno=self.myplot.figno,relative=True) - figname = self.myplot.getFigure(figno=self.myplot.figno,relative=True) - image = Image(images={bt.PNG: figname}, thumbnail=thumbname, thumbnailtype=bt.PNG, - description=caption) + + if self._plot_mode == PlotControl.NOPLOT: + noplot = True + thumbname = "not created" + figname = "not created" + imcaption = "not created" + image = Image(description=imcaption) + else: + noplot = False + self.myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + self.myplot.plotter(x,y,title,figname=p1,xlab=xlab,ylab=ylab,segments=segp, thumbnail=True) + + #out1 = np.rot90 (data.reshape((nvel,npos)) ) + if mode > 1: + self.myplot.map1(data=out,title="testing PVCorr_AT: mode%d"%mode,figname='testPVCorr', thumbnail=True) + + imcaption = "Position-velocity correlation plot" + thumbname = self.myplot.getThumbnail(figno=self.myplot.figno,relative=True) + figname = self.myplot.getFigure(figno=self.myplot.figno,relative=True) + image = Image(images={bt.PNG: figname}, thumbnail=thumbname, thumbnailtype=bt.PNG, description=imcaption) + b3.image.addimage(image, "pvcorr") - self._summary["pvcorr"] = SummaryEntry([figname,thumbname,caption,fin],"PVCorr_AT",self.id(True),taskargs) + self._summary["pvcorr"] = SummaryEntry([figname,thumbname,imcaption,fin],"PVCorr_AT",self.id(True),taskargs,noplot=noplot) else: self._summary["pvcorr"] = None logging.warning("No summary") @@ -304,7 +317,8 @@ def mode3(self, data, v0, v1, dmin=0.0): fmax = f.max() print "PVCorr mode3:",f1.sum(),'/',f0.sum(),'min/max',smin,fmax out = scipy.signal.correlate2d(data,f,mode='same') - self.myplot.map1(data=f,title="PVCorr 2D Kernel",figname='PVCorrKernel', thumbnail=True) + if self._plot_mode != PlotControl.NOPLOT: + self.myplot.map1(data=f,title="PVCorr 2D Kernel",figname='PVCorrKernel', thumbnail=True) print 'PVCorr min/max:',out.min(),out.max() n1,m1,s1,n2,m2,s2 = stats.mystats(out.flatten()) diff --git a/admit/at/PVSlice_AT.py b/admit/at/PVSlice_AT.py index 5185b19..ab8c4af 100644 --- a/admit/at/PVSlice_AT.py +++ b/admit/at/PVSlice_AT.py @@ -15,6 +15,7 @@ from admit.util.Image import Image +import admit.util.PlotControl as PlotControl from admit.util import APlot from admit.util import utils from admit.util import stats @@ -272,87 +273,97 @@ def run(self): logging.info("PV stats: mean/std/max %f %f %f" % (r_mean, r_std, r_max)) logging.regression("PVSLICE: %f %f %f" % (r_mean, r_std, r_max)) - myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) - - # hack to get a slice on a mom0map - # @todo if pmode is not png, can viewer handle this? - figname = pvname + ".png" - slicename = self.dir(figname) - overlay = pvname+"_overlay" - if b11 != None: - f11 = b11.getimagefile(bt.CASA) - tb = taskinit.tbtool() - tb.open(self.dir(f11)) - data = tb.getcol('map') - nx = data.shape[0] - ny = data.shape[1] - tb.close() - d1 = np.flipud(np.rot90 (data.reshape((nx,ny)))) - if len(pvslice) == 4: - segm = [[pvslice[0],pvslice[2],pvslice[1],pvslice[3]]] - pa = np.arctan2(pvslice[2]-pvslice[0],pvslice[1]-pvslice[3])*180.0/np.pi - title = "PV Slice location : slice PA=%.1f" % pa - xcen = (pvslice[0]+pvslice[2])/2.0 - ycen = (pvslice[1]+pvslice[3])/2.0 - elif len(pvslit) == 4: - # can only do this now if using pixel coordinates - xcen = pvslit[0] - ycen = pvslit[1] - slen = pvslit[2] - pard = pvslit[3]*np.pi/180.0 - cosp = np.cos(pard) - sinp = np.sin(pard) - halflen = 0.5*slen - segm = [[xcen-halflen*sinp,xcen+halflen*sinp,ycen+halflen*cosp,ycen-halflen*cosp]] - pa = pvslit[3] - title = "PV Slice location : slit PA=%g" % pa - else: - # bogus, some error in pvslice - logging.warning("bogus segm since pvslice=%s" % str(pvslice)) - segm = [[10,20,10,20]] - pa = -999.999 - title = "PV Slice location - bad PA" - logging.info("MAP1 segm %s %s" % (str(segm),str(pvslice))) - if d1.max() < clip: - logging.warning("datamax=%g, clip=%g" % (d1.max(), clip)) - title = title + ' (no signal over %g?)' % clip - myplot.map1(d1,title,overlay,segments=segm,thumbnail=True, - zoom=self.getkey("zoom"),star=[xcen,ycen]) - else: - myplot.map1(d1,title,overlay,segments=segm,range=[clip],thumbnail=True, - zoom=self.getkey("zoom"),star=[xcen,ycen]) - dt.tag("plot") - overlayname = myplot.getFigure(figno=myplot.figno,relative=True) - overlaythumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) - Qover = True + pvcaption = "Position-velocity diagram through emission centroid" + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + overlayname = "not created" + overlaythumbname = "not created" + overlaycaption = "not created" + thumbname = "not created" + noplot = True + pvimage = Image(images={bt.CASA : pvname}, description=pvcaption) else: - Qover = False - - implot = ImPlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) - implot.plotter(rasterfile=pvname, figname=pvname, colorwedge=True) - thumbname = implot.getThumbnail(figno=implot.figno,relative=True) - figname = implot.getFigure(figno=implot.figno,relative=True) - if False: - # debug: - # - # @todo tmp1 is ok, tmp2 is not displaying the whole thing - # use casa_imview, not casa.imview - if this is enabled. - # old style: viewer() seems to plot full image, but imview() wants square pixels? - casa.viewer(infile=self.dir(pvname), outfile=self.dir('tmp1.pv.png'), gui=False, outformat="png") - casa.imview(raster={'file':self.dir(pvname), 'colorwedge' : True, 'scaling':-1}, - axes={'y':'Declination'}, - out=self.dir('tmp2.pv.png')) - # - # -> this one works, axes= should be correct - # imview(raster={'file':'x.pv', 'colorwedge' : True, 'scaling':-1},axes={'y':'Frequency'}) - # - # @TODO big fixme, we're going to reuse 'tmp1.pv.png' because implot give a broken view - figname = 'tmp1.pv.png' + noplot = False + myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + + # hack to get a slice on a mom0map + # @todo if pmode is not png, can viewer handle this? + overlay = pvname+"_overlay" + + if b11 != None: + f11 = b11.getimagefile(bt.CASA) + tb = taskinit.tbtool() + tb.open(self.dir(f11)) + data = tb.getcol('map') + nx = data.shape[0] + ny = data.shape[1] + tb.close() + d1 = np.flipud(np.rot90 (data.reshape((nx,ny)))) + if len(pvslice) == 4: + segm = [[pvslice[0],pvslice[2],pvslice[1],pvslice[3]]] + pa = np.arctan2(pvslice[2]-pvslice[0],pvslice[1]-pvslice[3])*180.0/np.pi + title = "PV Slice location : slice PA=%.1f" % pa + xcen = (pvslice[0]+pvslice[2])/2.0 + ycen = (pvslice[1]+pvslice[3])/2.0 + elif len(pvslit) == 4: + # can only do this now if using pixel coordinates + xcen = pvslit[0] + ycen = pvslit[1] + slen = pvslit[2] + pard = pvslit[3]*np.pi/180.0 + cosp = np.cos(pard) + sinp = np.sin(pard) + halflen = 0.5*slen + segm = [[xcen-halflen*sinp,xcen+halflen*sinp,ycen+halflen*cosp,ycen-halflen*cosp]] + pa = pvslit[3] + title = "PV Slice location : slit PA=%g" % pa + else: + # bogus, some error in pvslice + logging.warning("bogus segm since pvslice=%s" % str(pvslice)) + segm = [[10,20,10,20]] + pa = -999.999 + title = "PV Slice location - bad PA" + logging.info("MAP1 segm %s %s" % (str(segm),str(pvslice))) + if d1.max() < clip: + logging.warning("datamax=%g, clip=%g" % (d1.max(), clip)) + title = title + ' (no signal over %g?)' % clip + myplot.map1(d1,title,overlay,segments=segm,thumbnail=True, + zoom=self.getkey("zoom"),star=[xcen,ycen]) + else: + myplot.map1(d1,title,overlay,segments=segm,range=[clip],thumbnail=True, + zoom=self.getkey("zoom"),star=[xcen,ycen]) + dt.tag("plot") + overlayname = myplot.getFigure(figno=myplot.figno,relative=True) + overlaythumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) + Qover = True + else: + Qover = False + + implot = ImPlot(pmode=self._plot_mode,ptype=self._plot_type,abspath=self.dir()) + implot.plotter(rasterfile=pvname, figname=pvname, colorwedge=True) + thumbname = implot.getThumbnail(figno=implot.figno,relative=True) + figname = implot.getFigure(figno=implot.figno,relative=True) + if False: + # debug: + # + # @todo tmp1 is ok, tmp2 is not displaying the whole thing + # use casa_imview, not casa.imview - if this is enabled. + # old style: viewer() seems to plot full image, but imview() wants square pixels? + casa.viewer(infile=self.dir(pvname), outfile=self.dir('tmp1.pv.png'), gui=False, outformat="png") + casa.imview(raster={'file':self.dir(pvname), 'colorwedge' : True, 'scaling':-1}, + axes={'y':'Declination'}, + out=self.dir('tmp2.pv.png')) + # + # -> this one works, axes= should be correct + # imview(raster={'file':'x.pv', 'colorwedge' : True, 'scaling':-1},axes={'y':'Frequency'}) + # + # @TODO big fixme, we're going to reuse 'tmp1.pv.png' because implot give a broken view + figname = 'tmp1.pv.png' # @todo technically we don't know what map it was overlay'd on.... CubeSum/Moment0 - overlaycaption = "Location of position-velocity slice overlaid on a CubeSum map" - pvcaption = "Position-velocity diagram through emission centroid" - pvimage = Image(images={bt.CASA : pvname, bt.PNG : figname},thumbnail=thumbname,thumbnailtype=bt.PNG, description=pvcaption) + overlaycaption = "Location of position-velocity slice overlaid on a CubeSum map" + pvimage = Image(images={bt.CASA : pvname, bt.PNG : figname},thumbnail=thumbname,thumbnailtype=bt.PNG, description=pvcaption) + b2.setkey("image",pvimage) b2.setkey("mean",float(r_mean)) b2.setkey("sigma",float(r_std)) @@ -364,7 +375,7 @@ def run(self): # Yes, this is a nested list. Against the day when PVSLICE can # compute multiple slices per map. pvslicesummary.append(thispvsummary) - self._summary["pvslices"] = SummaryEntry(pvslicesummary,"PVSlice_AT",self.id(True),taskargs) + self._summary["pvslices"] = SummaryEntry(pvslicesummary,"PVSlice_AT",self.id(True),taskargs,noplot=noplot) dt.tag("done") dt.end() diff --git a/admit/at/PrincipalComponent_AT.py b/admit/at/PrincipalComponent_AT.py index 63018f9..e3bc060 100644 --- a/admit/at/PrincipalComponent_AT.py +++ b/admit/at/PrincipalComponent_AT.py @@ -9,6 +9,7 @@ import admit import admit.util.bdp_types as bt +import admit.util.PlotControl as PlotControl class PrincipalComponent_AT(admit.Task): """ @@ -40,7 +41,7 @@ class PrincipalComponent_AT(admit.Task): the number of input maps; the default empty list implies all zeroes. **covarmin**: float - Minimum pairwise covariance for summary output (only); default: 0.90. + Minimum pairwise covariance for summary output (only); default: 0.90. **Input BDPs** @@ -52,7 +53,7 @@ class PrincipalComponent_AT(admit.Task): **Output BDPs** **Table_BDP**: count: 3 - First table contains the input mean and standard deviation plus output + First table contains the input mean and standard deviation plus output eigenimage filename and variance fractions. Second table is the calculated projection matrix transforming (mean-subtracted and variance-normalized) input data to principal component space. Third @@ -148,151 +149,155 @@ def run(self): ------- None """ - self._summary = {} + self._summary = {} - # BDP output uses the alias name if provided, else a flow-unique one. - stem = self._alias - if not stem: stem = "pca%d" % (self.id()) + # BDP output uses the alias name if provided, else a flow-unique one. + stem = self._alias + if not stem: stem = "pca%d" % (self.id()) - inum = 0 - data = [] - icols = [] + inum = 0 + data = [] + icols = [] for ibdp in self._bdp_in: - # Convert input CASA images to numpy arrays. - istem = ibdp.getimagefile(bt.CASA) - ifile = ibdp.baseDir() + istem - icols.append(os.path.splitext(istem)[0]) - if os.path.dirname(icols[-1]): - icols[-1] = os.path.dirname(icols[-1]) # Typical line cube case. - img = admit.casautil.getdata(ifile, zeromask=True).data - data.append(img) - admit.logging.info("%s shape=%s min=%g max=%g" % - (icols[-1], str(img.shape), np.amin(img), np.amax(img))) - assert len(data[0].shape) == 2, "Only 2-D input images supported" - assert data[0].shape == data[inum].shape, "Input shapes must match" - inum += 1 - - # At least two inputs required for meaningful PCA! - assert inum >= 2, "At least two input images required" - - # Each 2-D input image is a plane in a single multi-color image. - # Each color multiplet (one per pixel) is an observation. - # For PCA we collate the input images into a vector of observations. - shape = data[0].shape - npix = shape[0] * shape[1] - clip = self.getkey('clipvals') - if not clip: clip = [0 for i in range(inum)] - assert len(clip) >= inum, "Too few clipvals provided" - - # Clip input values and stack into a vector of observations. - pca_data = [] + # Convert input CASA images to numpy arrays. + istem = ibdp.getimagefile(bt.CASA) + ifile = ibdp.baseDir() + istem + icols.append(os.path.splitext(istem)[0]) + if os.path.dirname(icols[-1]): + icols[-1] = os.path.dirname(icols[-1]) # Typical line cube case. + img = admit.casautil.getdata(ifile, zeromask=True).data + data.append(img) + admit.logging.info("%s shape=%s min=%g max=%g" % + (icols[-1], str(img.shape), np.amin(img), np.amax(img))) + assert len(data[0].shape) == 2, "Only 2-D input images supported" + assert data[0].shape == data[inum].shape, "Input shapes must match" + inum += 1 + + # At least two inputs required for meaningful PCA! + assert inum >= 2, "At least two input images required" + + # Each 2-D input image is a plane in a single multi-color image. + # Each color multiplet (one per pixel) is an observation. + # For PCA we collate the input images into a vector of observations. + shape = data[0].shape + npix = shape[0] * shape[1] + clip = self.getkey('clipvals') + if not clip: clip = [0 for i in range(inum)] + assert len(clip) >= inum, "Too few clipvals provided" + + # Clip input values and stack into a vector of observations. + pca_data = [] for i in range(inum): nd = data[i] - nd[nd < clip[i]] = 0.0 - pca_data.append(np.reshape(nd, (npix,1))) - pca_in = np.hstack(pca_data) - pca = mlab.PCA(pca_in) - - # Input statistics and output variance fractions. - #print "fracs:", pca.fracs - #print "mean:", pca.mu - #print "sdev:", pca.sigma - obdp = admit.Table_BDP(stem+"_stats") - obdp.table.setData(np.vstack([pca.mu, pca.sigma,pca.fracs]).T) - obdp.table.columns = ["Input mean", "Input deviation", - "Eigenimage variance fraction"] - obdp.table.description = "PCA Image Statistics" - self.addoutput(obdp) - - # Pre-format columns for summary output. - # This is required when mixing strings and numbers in a table. - # (NumPy will output the array as all strings.) - table1 = admit.Table() - table1.setData(np.vstack([[i for i in range(inum)], - icols, - ["%.3e" % x for x in pca.mu], - ["%.3e" % x for x in pca.sigma], - ["%s_eigen/%d.im" % (stem, i) - for i in range(inum)], - ["%.4f" % x for x in pca.fracs]]).T) - table1.columns = ["Index", "Input", "Input mean", - "Input deviation", - "Eigenimage", - "Eigenimage variance fraction"] - table1.description = "PCA Image Statistics" - - # Projection matrix (eigenvectors). - #print "projection:", pca.Wt - obdp = admit.Table_BDP(stem + "_proj") - obdp.table.setData(pca.Wt) - obdp.table.columns = icols - obdp.table.description = \ - "PCA Projection Matrix (normalized input to output)" - self.addoutput(obdp) - - # Covariance matrix. - covar = np.cov(pca.a, rowvar=0, bias=1) - #print "covariance:", covar - obdp = admit.Table_BDP(stem + "_covar") - obdp.table.setData(covar) - obdp.table.columns = icols - obdp.table.description = "PCA Covariance Matrix" - self.addoutput(obdp) - - # Collate projected observations into eigenimages and save output. - os.mkdir(self.baseDir()+stem+"_eigen") - pca_out = np.hsplit(pca.Y, inum) - odata = [] + nd[nd < clip[i]] = 0.0 + pca_data.append(np.reshape(nd, (npix,1))) + pca_in = np.hstack(pca_data) + pca = mlab.PCA(pca_in) + + # Input statistics and output variance fractions. + #print "fracs:", pca.fracs + #print "mean:", pca.mu + #print "sdev:", pca.sigma + obdp = admit.Table_BDP(stem+"_stats") + obdp.table.setData(np.vstack([pca.mu, pca.sigma,pca.fracs]).T) + obdp.table.columns = ["Input mean", "Input deviation", + "Eigenimage variance fraction"] + obdp.table.description = "PCA Image Statistics" + self.addoutput(obdp) + + # Pre-format columns for summary output. + # This is required when mixing strings and numbers in a table. + # (NumPy will output the array as all strings.) + table1 = admit.Table() + table1.setData(np.vstack([[i for i in range(inum)], + icols, + ["%.3e" % x for x in pca.mu], + ["%.3e" % x for x in pca.sigma], + ["%s_eigen/%d.im" % (stem, i) + for i in range(inum)], + ["%.4f" % x for x in pca.fracs]]).T) + table1.columns = ["Index", "Input", "Input mean", + "Input deviation", + "Eigenimage", + "Eigenimage variance fraction"] + table1.description = "PCA Image Statistics" + + # Projection matrix (eigenvectors). + #print "projection:", pca.Wt + obdp = admit.Table_BDP(stem + "_proj") + obdp.table.setData(pca.Wt) + obdp.table.columns = icols + obdp.table.description = \ + "PCA Projection Matrix (normalized input to output)" + self.addoutput(obdp) + + # Covariance matrix. + covar = np.cov(pca.a, rowvar=0, bias=1) + #print "covariance:", covar + obdp = admit.Table_BDP(stem + "_covar") + obdp.table.setData(covar) + obdp.table.columns = icols + obdp.table.description = "PCA Covariance Matrix" + self.addoutput(obdp) + + # Collate projected observations into eigenimages and save output. + os.mkdir(self.baseDir()+stem+"_eigen") + pca_out = np.hsplit(pca.Y, inum) + odata = [] for i in range(inum): - ofile = "%s_eigen/%d" % (stem, i) - img = np.reshape(pca_out[i], shape) + ofile = "%s_eigen/%d" % (stem, i) + img = np.reshape(pca_out[i], shape) odata.append(img) - #print ofile, "shape, min, max:", img.shape, np.amin(img), np.amax(img) - - aplot = admit.util.APlot(figno=inum, abspath=self.baseDir(), - ptype=admit.util.PlotControl.PNG) - aplot.map1(np.rot90(img), title=ofile, figname=ofile) - aplot.final() - - # Currently the output eigenimages are stored as PNG files only. - admit.casautil.putdata_raw(self.baseDir()+ofile+".im", img, ifile) - oimg = admit.Image() - oimg.addimage(admit.imagedescriptor(ofile+".im", format=bt.CASA)) - oimg.addimage(admit.imagedescriptor(ofile+".png", format=bt.PNG)) + #print ofile, "shape, min, max:", img.shape, np.amin(img), np.amax(img) + + + # Currently the output eigenimages are stored as PNG files only. + admit.casautil.putdata_raw(self.baseDir()+ofile+".im", img, ifile) + oimg = admit.Image() + oimg.addimage(admit.imagedescriptor(ofile+".im", format=bt.CASA)) + if self._plot_mode != PlotControl.NOPLOT: + noplot = False + aplot = admit.util.APlot(figno=inum, abspath=self.baseDir(), + ptype=PlotControl.PNG) + aplot.map1(np.rot90(img), title=ofile, figname=ofile) + aplot.final() + oimg.addimage(admit.imagedescriptor(ofile+".png", format=bt.PNG)) + else: + noplot = True obdp = admit.Image_BDP(ofile) - obdp.addimage(oimg) - self.addoutput(obdp) + obdp.addimage(oimg) + self.addoutput(obdp) - # As a cross-check, reconstruct input images and compute differences. + # As a cross-check, reconstruct input images and compute differences. for k in range(inum): - ximg = pca.Wt[0][k]*odata[0] - for l in range(1,inum): - ximg += pca.Wt[l][k]*odata[l] + ximg = pca.Wt[0][k]*odata[0] + for l in range(1,inum): + ximg += pca.Wt[l][k]*odata[l] - ximg = pca.mu[k] + pca.sigma[k]*ximg + ximg = pca.mu[k] + pca.sigma[k]*ximg admit.logging.regression("PCA: %s residual: " % icols[k] + - str(np.linalg.norm(ximg - data[k]))) + str(np.linalg.norm(ximg - data[k]))) - # Collect large covariance values for summary. - cvmin = self.getkey('covarmin') - cvsum = [] + # Collect large covariance values for summary. + cvmin = self.getkey('covarmin') + cvsum = [] cvmax = 0.0 - for i in range(inum): - for j in range(i+1, inum): - if abs(covar[i][j]) >= cvmax: - cvmax = abs(covar[i][j]) - if abs(covar[i][j]) >= cvmin: - cvsum.append([icols[i], icols[j], "%.4f" % (covar[i][j])]) + for i in range(inum): + for j in range(i+1, inum): + if abs(covar[i][j]) >= cvmax: + cvmax = abs(covar[i][j]) + if abs(covar[i][j]) >= cvmin: + cvsum.append([icols[i], icols[j], "%.4f" % (covar[i][j])]) admit.logging.regression("PCA: Covariances > %.4f: %s (max: %.4f)" % (cvmin,str(cvsum),cvmax)) - table2 = admit.Table() - table2.columns = ["Input1", "Input2", "Covariance"] - table2.setData(cvsum) - table2.description = "PCA High Covariance Summary" + table2 = admit.Table() + table2.columns = ["Input1", "Input2", "Covariance"] + table2.setData(cvsum) + table2.description = "PCA High Covariance Summary" - keys = "covarmin=%.4f clipvals=%s" % (cvmin, str(clip)) + keys = "covarmin=%.4f clipvals=%s" % (cvmin, str(clip)) self._summary["pca"] = admit.SummaryEntry([table1.serialize(), - table2.serialize() - ], - "PrincipalComponent_AT", - self.id(True), keys) + table2.serialize() + ], + "PrincipalComponent_AT", + self.id(True), keys,noplot=noplot) diff --git a/admit/at/Regrid_AT.py b/admit/at/Regrid_AT.py index 1f1d55a..e715347 100644 --- a/admit/at/Regrid_AT.py +++ b/admit/at/Regrid_AT.py @@ -11,6 +11,7 @@ import admit.util.bdp_types as bt import admit.util.Table import admit.util.utils as utils +import admit.util.PlotControl as PlotControl from admit.bdp.SpwCube_BDP import SpwCube_BDP import numpy as np import os as os @@ -258,6 +259,6 @@ def run(self): #keys = "pixsize=%.4g naxis1=%d naxis2=%d mean_ra=%0.4f mean_dec=%0.4f reffreq=%g chan_width=%g" % (pix_scale/(4.848137E-6), npix_ra, npix_dec, mean_ra,mean_dec,min_nu,chan_width) taskargs = "pix_scale = " + str(self.getkey("pix_scale")) + " chan_width = "+str(self.getkey("chan_width")) - self._summary["regrid"] = SummaryEntry(atable.serialize(),"Regrid_AT",self.id(True),taskargs) + self._summary["regrid"] = SummaryEntry(atable.serialize(),"Regrid_AT",self.id(True),taskargs,noplot=True) dt.tag("done") dt.end() diff --git a/admit/at/SFind2D_AT.py b/admit/at/SFind2D_AT.py index 7a8fbbe..ff099cf 100644 --- a/admit/at/SFind2D_AT.py +++ b/admit/at/SFind2D_AT.py @@ -13,6 +13,7 @@ import admit.util.casautil as casautil import admit.util.Image as Image import admit.util.Line as Line +import admit.util.PlotControl as PlotControl import admit.util.ImPlot as ImPlot from admit.bdp.Image_BDP import Image_BDP from admit.bdp.CubeStats_BDP import CubeStats_BDP @@ -394,48 +395,55 @@ def run(self): logging.info(" Restoring Beam: Major axis: %10.3g %s , Minor axis: %10.3g %s , PA: %5.1f %s" % (beammaj, beamunit, beammin, beamunit, beamang, angunit)) # form into a xml table + slbdp.table.description="Table of source locations and sizes (not deconvolved)" # output is a table_bdp self.addoutput(slbdp) - # instantiate a plotter for all plots made herein - myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) - - # make output png with circles marking sources found - if mpl: - circles=[] - nx = data.shape[1] # data[] array was already flipud(rot90)'d - ny = data.shape[0] # - for (x,y) in zip(xtab,ytab): - circles.append([x,y,1]) - # @todo variable name - if logscale: - logging.warning("LogScaling applied") - data = data/sigma - data = np.where(data<0,-np.log10(1-data),+np.log10(1+data)) - if nsources == 0: - title = "SFind2D: 0 sources above S/N=%.1f" % (nsigma) - elif nsources == 1: - title = "SFind2D: 1 source (%.1f < S/N < %.1f)" % (nsigma,sn0) - else: - title = "SFind2D: %d sources (%.1f < S/N < %.1f)" % (nsources,nsigma,sn0) - myplot.map1(data,title,slbase,thumbnail=True,circles=circles, - zoom=self.getkey("zoom")) - - #--------------------------------------------------------- - # Get the figure and thumbmail names and create a caption - #--------------------------------------------------------- - imname = myplot.getFigure(figno=myplot.figno,relative=True) - thumbnailname = myplot.getThumbnail(figno=myplot.figno,relative=True) - caption = "Image of input map with sources found by SFind2D overlayed in green." - slbdp.table.description="Table of source locations and sizes (not deconvolved)" + if self._plot_mode == PlotControl.NOPLOT: + figname = "not created" + thumbname = "not created" + imcaption = "not created" + noplot = True + else: + # instantiate a plotter for all plots made herein + myplot = APlot(ptype=self._plot_type,pmode=self._plot_mode,abspath=self.dir()) + + # make output png with circles marking sources found + if mpl: + circles=[] + nx = data.shape[1] # data[] array was already flipud(rot90)'d + ny = data.shape[0] # + for (x,y) in zip(xtab,ytab): + circles.append([x,y,1]) + # @todo variable name + if logscale: + logging.warning("LogScaling applied") + data = data/sigma + data = np.where(data<0,-np.log10(1-data),+np.log10(1+data)) + if nsources == 0: + title = "SFind2D: 0 sources above S/N=%.1f" % (nsigma) + elif nsources == 1: + title = "SFind2D: 1 source (%.1f < S/N < %.1f)" % (nsigma,sn0) + else: + title = "SFind2D: %d sources (%.1f < S/N < %.1f)" % (nsources,nsigma,sn0) + myplot.map1(data,title,slbase,thumbnail=True,circles=circles, + zoom=self.getkey("zoom")) + + #--------------------------------------------------------- + # Get the figure and thumbmail names and create a caption + #--------------------------------------------------------- + figname = myplot.getFigure(figno=myplot.figno,relative=True) + thumbname = myplot.getThumbnail(figno=myplot.figno,relative=True) + imcaption = "Image of input map with sources found by SFind2D overlayed in green." - #--------------------------------------------------------- - # Add finder image to the BDP - #--------------------------------------------------------- - image = Image(images={bt.PNG: imname}, - thumbnail=thumbnailname, - thumbnailtype=bt.PNG, description=caption) - slbdp.image.addimage(image, "finderimage") + #--------------------------------------------------------- + # Add finder image to the BDP + #--------------------------------------------------------- + image = Image(images={bt.PNG: figname}, + thumbnail=thumbname, + thumbnailtype=bt.PNG, description=imcaption) + slbdp.image.addimage(image, "finderimage") + noplot=False #------------------------------------------------------------- # Create the summary entry for the table and image @@ -443,7 +451,7 @@ def run(self): self._summary["sources"] = SummaryEntry([slbdp.table.serialize(), slbdp.image.serialize()], "SFind2D_AT", - self.id(True), taskargs) + self.id(True), taskargs, noplot=noplot) dt.tag("done") dt.end() diff --git a/admit/at/Smooth_AT.py b/admit/at/Smooth_AT.py index b41e032..8bb4ae3 100644 --- a/admit/at/Smooth_AT.py +++ b/admit/at/Smooth_AT.py @@ -10,6 +10,7 @@ import admit.util.bdp_types as bt import admit.util.Image as Image import admit.util.utils as utils +import admit.util.PlotControl as PlotControl import admit.util.Line as Line from admit.bdp.SpwCube_BDP import SpwCube_BDP from admit.util.AdmitLogging import AdmitLogging as logging diff --git a/admit/at/Template_AT.py b/admit/at/Template_AT.py index eb6ea8c..e9c79a2 100644 --- a/admit/at/Template_AT.py +++ b/admit/at/Template_AT.py @@ -10,6 +10,7 @@ import admit import admit.util.bdp_types as bt +import admit.util.PlotControl as PlotControl class Template_AT(admit.Task): """ @@ -211,8 +212,8 @@ def run(self): # Image data must be rotated to match matplotlib axis order. oimgtitle="Template Image Slice @ channel %d" % imgslice aplot = admit.APlot(figno=1, abspath=self.baseDir(), - pmode=admit.PlotControl.BATCH, - ptype=admit.PlotControl.PNG) + pmode=PlotControl.BATCH, + ptype=PlotControl.PNG) aplot.map1(np.rot90(oimg), xlab="R.A. (pixels)", ylab="Dec (pixels)", title=oimgtitle, figname=oimgstem) @@ -242,7 +243,7 @@ def run(self): # Create a PNG plot (standalone). ospectitle = "Template Spectrum @ position %s" % str(specpos) aplot = admit.APlot(figno=2, abspath=self.baseDir(), - pmode=admit.PlotControl.BATCH, + pmode=PlotControl.BATCH, ptype=admit.PlotControl.PNG) aplot.plotter(x=ochan, y=[ospec], xlab="Channel", ylab="Intensity", @@ -251,9 +252,9 @@ def run(self): # # Output data product (spectrum table). obdp3 = admit.Table_BDP(ospecstem) - obdp3.table.description = "Template 1-D Spectrum" - obdp3.table.columns = ["Channel", "Spectrum @ (%d, %d)" % specpos] - obdp3.table.setData(np.transpose(np.vstack([ochan, ospec]))) + obdp3.table.description = "Template 1-D Spectrum" + obdp3.table.columns = ["Channel", "Spectrum @ (%d, %d)" % specpos] + obdp3.table.setData(np.transpose(np.vstack([ochan, ospec]))) self.addoutput(obdp3) @@ -286,6 +287,7 @@ def run(self): oimgstem+".png", oimgstem+"_thumb.png", oimgtitle, ocubeim], [specpos[0], specpos[1], "", "Channel", ospecstem+".png", ospecstem+"_thumb.png", ospectitle, ocubeim]] + # If no plots are produced by your task, change noplot to True self._summary["spectra"] = admit.SummaryEntry(spec_description, "Template_AT", - self.id(True), keys) + self.id(True), keys, noplot=False) diff --git a/admit/bdp/BDP.py b/admit/bdp/BDP.py index 8fa4136..d0e0f73 100644 --- a/admit/bdp/BDP.py +++ b/admit/bdp/BDP.py @@ -126,10 +126,11 @@ def getfiles(self): files = [] for i in self.__dict__: if isinstance(getattr(self, i), Image): - #print getattr(self, i).images for key in getattr(self, i).images: files.append(getattr(self, i).images[key]) - #files.append(getattr(self, i).fileName) + if isinstance(getattr(self, i), MultiImage): + for key in getattr(self, i).mimages: + files.append(getattr(self, i).mimages[key]) return files def show(self): diff --git a/admit/bdp/Image_BDP.py b/admit/bdp/Image_BDP.py index efee9c3..e6feb28 100644 --- a/admit/bdp/Image_BDP.py +++ b/admit/bdp/Image_BDP.py @@ -105,4 +105,11 @@ def getimagefile(self, imtype=bt.CASA, name=""): String containing the image name, or None if it does not exist """ - return self.image.getimage(imtype, name).file + try: + retimage = self.image.getimage(imtype, name) + except KeyError: + return None + if retimage != None: + return retimage.file + else: + return None diff --git a/admit/util/AbstractPlot.py b/admit/util/AbstractPlot.py index de25cd5..c26261f 100644 --- a/admit/util/AbstractPlot.py +++ b/admit/util/AbstractPlot.py @@ -152,13 +152,22 @@ def getThumbnail(self,figno,relative): ------- str Thumbnail file name + None + If figno doesn't exist and plotmode is PlotControl.NOPLOT + Raises exception + If figno doesn't exist and plotmode is not PlotControl.NOPLOT """ try: if relative: return self._thumbnailfiles[figno].replace(self._abspath,"") else: return self._thumbnailfiles[figno] - except KeyError: + except KeyError: + # note: we don't put this return at the top of the method + # because a figure may have been created and then plotmode + # changed, in which case a figure for figno may exist. + if self._plot_mode == PlotControl.NOPLOT: + return None raise Exception, "Thumbnail for figure %d was not created by this %s ." % (figno,self.__class__.__name__) def getFigure(self,figno,relative): @@ -177,6 +186,10 @@ def getFigure(self,figno,relative): ------- str Figure file name + None + If figno doesn't exist and plotmode is PlotControl.NOPLOT + Raises exception + If figno doesn't exist and plotmode is not PlotControl.NOPLOT """ try: if relative: @@ -184,6 +197,11 @@ def getFigure(self,figno,relative): else: return self._figurefiles[figno] except KeyError: + # note: we don't put this return at the top of the method + # because a figure may have been created and then plotmode + # changed, in which case a figure for figno may exist. + if self._plot_mode == PlotControl.NOPLOT: + return None raise Exception, "Figure %d was not created by this %s." % (figno, self.__class__.__name__ ) def figure(self,figno=1): @@ -219,6 +237,8 @@ def makeThumbnail(self,figno=None, scale=0.33, fig=None): None """ + if self._plot_mode == PlotControl.NOPLOT: return + if figno: fno = figno else: diff --git a/admit/util/Image.py b/admit/util/Image.py index 67f3f04..7b972ec 100644 --- a/admit/util/Image.py +++ b/admit/util/Image.py @@ -140,11 +140,14 @@ def setkey(self, name="", value=""): for k1, v1 in v.iteritems(): if k1 == bt.THUMB or k1 == bt.AUX: raise Exception("Thumnails and auxiliary files cannot be added as part of the images item, they must be added under the thumbnail or auxiliary item.") - if hasattr(self, k): + if hasattr(self, k): + if v==None: + print('WARNING: v was None, set to ""') + v='' if type(v) == type(getattr(self, k)): setattr(self, k, v) else: - raise Exception("Cannot change data type for %s, expected %s but got %s" % (k, str(type(getattr(self, k))), str(type(v)))) + raise Exception("Cannot change data type for %s, expected %s but got %s" % (k, str(type(getattr(self, k))), str(type(v)))) else: raise Exception("Invalid key given to Image class: %s" % (k)) elif not name == "": diff --git a/admit/util/casautil.py b/admit/util/casautil.py index 9af0379..fdde402 100644 --- a/admit/util/casautil.py +++ b/admit/util/casautil.py @@ -16,8 +16,6 @@ except: print "WARNING: No CASA; casautil can't function" -# imview was left out of the casa namespace in CASA5 -from imview import imview as casa_imview import PlotControl @@ -73,10 +71,15 @@ def implot(rasterfile, figname, contourfile=None, plottype=PlotControl.PNG, #can't support this until imview out= is fixed! (see below) #orientation=PlotControl.LANDSCAPE - - + if plotmode == PlotControl.NOPLOT: return + # imview creates a casa viewer which in turn can result in errors when run in parallel mode. Therefore + # although not standard practice, the import is only done in the function when needed. + + # imview was left out of the casa namespace in CASA5 + from imview import imview as casa_imview + if contourfile==None and rasterfile==None: raise Exception, "You must provide rasterfile and/or contourfile" diff --git a/admit/xmlio/dtd/admit.dtd b/admit/xmlio/dtd/admit.dtd index f3626e1..608fefa 100644 --- a/admit/xmlio/dtd/admit.dtd +++ b/admit/xmlio/dtd/admit.dtd @@ -16,7 +16,7 @@ - + @@ -28,6 +28,8 @@ + +