def display_cutout(exposure, x, y, title=None, frame=None, cutout_size=100): cutout_exp = make_cutout(exposure, x, y, cutout_size=cutout_size) xy = geom.PointI(x, y) afwDisplay.setDefaultBackend('matplotlib') display = afwDisplay.Display(frame=frame) display.mtv(cutout_exp) plt.title(title)
def expToPng(exp, saveFilename, title=None): fig = plt.figure(figsize=(15, 15)) afwDisplay.setDefaultBackend("matplotlib") display = afwDisplay.Display(fig, open=True) display.setImageColormap('viridis') display.scale('asinh', 'zscale') display.mtv(exp, title=title) plt.tight_layout() fig.savefig(saveFilename) return
def setUp(self): global oldBackend if backend != oldBackend: afwDisplay.setDefaultBackend(backend) afwDisplay.delAllDisplays() # as some may use the old backend oldBackend = backend dirName = os.path.split(__file__)[0] self.fileName = os.path.join(dirName, "data", "HSC-0908120-056-small.fits") self.display0 = afwDisplay.getDisplay(frame=0, verbose=True)
def __init__(self, butler, dataIdList, outputPath, outputFilename, *, remakePngs=False, clobberVideoAndGif=False, keepIntermediateGif=False, smoothImages=True, plotObjectCentroids=True, useQfmForCentroids=False, dataProductToPlot='calexp', ffMpegBinary='/home/mfl/bin/ffmpeg', debug=False): self.butler = butler self.dataIdList = dataIdList self.outputPath = outputPath self.outputFilename = os.path.join(outputPath, outputFilename) if not self.outputFilename.endswith(".mp4"): self.outputFilename += ".mp4" self.pngPath = os.path.join(outputPath, "pngs/") self.remakePngs = remakePngs self.clobberVideoAndGif = clobberVideoAndGif self.keepIntermediateGif = keepIntermediateGif self.smoothImages = smoothImages self.plotObjectCentroids = plotObjectCentroids self.useQfmForCentroids = useQfmForCentroids self.dataProductToPlot = dataProductToPlot self.ffMpegBinary = ffMpegBinary self.debug = debug # zfilled at the start as animation is alphabetical # if you're doing more than 1e6 files you've got bigger problems self.toAnimateTemplate = "%06d-%s-%s.png" self.basicTemplate = "%s-%s.png" qfmTaskConfig = QuickFrameMeasurementTaskConfig() self.qfmTask = QuickFrameMeasurementTask(config=qfmTaskConfig) afwDisplay.setDefaultBackend("matplotlib") self.fig = plt.figure(figsize=(15, 15)) self.disp = afwDisplay.Display(self.fig) self.disp.setImageColormap('gray') self.disp.scale('asinh', 'zscale') self.pngsToMakeDataIds = [] self.preRun() # sets the above list
def show_injection(exposure, x, y, x_ref=False, y_ref=False, title=None, frame=None, cutout_size=100): # x, y: center of the postage stamps, shown in red # x_ref, y_ref: a reference circle shown in green, it can be used to compared xy = geom.PointI(x, y) afwDisplay.setDefaultBackend('matplotlib') display = afwDisplay.Display(frame=frame) display.mtv(exposure) display.dot('o', xy.getX(), xy.getY(), ctype='red') if x_ref or y_ref: xy_ref = geom.PointI(x_ref, y_ref) display.dot('o', xy_ref.getX(), xy_ref.getY(), ctype='green') plt.title(title)
def __init__(self, *, butler=None, **kwargs): # TODO: rename psfRefObjLoader to refObjLoader super().__init__(**kwargs) self.makeSubtask("isr") self.makeSubtask("charImage", butler=butler, refObjLoader=None) self.debug = lsstDebug.Info(__name__) if self.debug.enabled: self.log.info("Running with debug enabled...") # If we're displaying, test it works and save displays for later. # It's worth testing here as displays are flaky and sometimes # can't be contacted, and given processing takes a while, # it's a shame to fail late due to display issues. if self.debug.display: try: import lsst.afw.display as afwDisp afwDisp.setDefaultBackend(self.debug.displayBackend) afwDisp.Display.delAllDisplays() # pick an unlikely number to be safe xxx replace this self.disp1 = afwDisp.Display(987, open=True) im = afwImage.ImageF(2, 2) im.array[:] = np.ones((2, 2)) self.disp1.mtv(im) self.disp1.erase() afwDisp.setDefaultMaskTransparency(90) except NameError: self.debug.display = False self.log.warn( 'Failed to setup/connect to display! Debug display has been disabled' ) if self.debug.notHeadless: pass # other backend options can go here else: # this stop windows popping up when plotting. When headless, use 'agg' backend too plt.interactive(False) self.config.validate() self.config.freeze()
def plotSourceLocationsOnObject(objId, objTable, sourceTable, repo, goodSrc=None, plotIdx=1): """Plot a difference imaging template used for a DIA Object in a postage stamp cutout, along with the locations of the DIA Object and all constituent DIA Sources. This is a deprecated gen2 function for the time being. Parameters ---------- objId : `int` DIA Object ID. objTable : `pandas.core.frame.DataFrame` DIA Object table loaded from the APDB. sourceTable : `pandas.core.frame.DataFrame` Pandas dataframe with DIA Sources from an APDB, plus unpacked flag values. This is an output called "sourceTableFlags" from the makeSrcTableFlags function. repo : `str` Repository corresponding to the output of an ap_pipe run. goodSrc : `pandas.core.frame.DataFrame` or `None` Filtered subset of sourceTable. Sources in this table will be plotted in green, while those not in this table will be plotted in red. If `None`, all sources will be plotted in blue. plotIdx : `int` Frame number to put the resulting plot in, default 1. Notes ----- The sourceTable is assumed to have flag fields added to it already! """ butler = dafPersist.Butler(repo) afwDisplay.setDefaultBackend('matplotlib') objRa = objTable.loc[objTable['diaObjectId'] == objId, 'ra'].values[0] objDec = objTable.loc[objTable['diaObjectId'] == objId, 'decl'].values[0] srcIds = list(sourceTable.loc[sourceTable['diaObjectId'] == objId, 'diaSourceId'].values) srcRas = sourceTable.loc[sourceTable['diaObjectId'] == objId, 'ra'].values srcDecs = sourceTable.loc[sourceTable['diaObjectId'] == objId, 'decl'].values srcVisits = sourceTable.loc[sourceTable['diaObjectId'] == objId, 'visit'].values srcCcds = sourceTable.loc[sourceTable['diaObjectId'] == objId, 'ccd'].values dataIds = [{'visit': int(visit), 'ccd': int(ccd)} for (visit, ccd) in zip(srcVisits, srcCcds)] objLoc = lsst.geom.SpherePoint(objRa, objDec, lsst.geom.degrees) calexpFirst = butler.get('calexp', dataId=dataIds[0]) templateCutout = getTemplateCutout(calexpFirst, repo, objLoc) if templateCutout is not None: imageToShow = templateCutout else: imageToShow = calexpFirst.getCutout(objLoc, size=lsst.geom.Extent2I(30, 30)) print('Failed to retrieve template; image displayed is first processed image') wcs = imageToShow.getWcs() disp = afwDisplay.Display(plotIdx, reopenPlot=True) disp.setMaskTransparency(100) disp.scale('asinh', 'zscale', Q=4) disp.mtv(imageToShow, title=objId) with disp.Buffering(): # obviously coordObj = wcs.skyToPixel(objLoc) disp.dot('+', *coordObj, ctype='C0', size=5) for dataId, srcId, ra, dec in zip(dataIds, srcIds, srcRas, srcDecs): calexp = butler.get('calexp', dataId=dataId) psf = calexp.getPsf() psfSize = psf.computeShape().getDeterminantRadius()*2.355 # sigma to FWHM coordSrc = wcs.skyToPixel(lsst.geom.SpherePoint(ra, dec, lsst.geom.degrees)) if goodSrc is not None: if srcId in goodSrc['diaSourceId'].values: disp.dot('o', *coordSrc, ctype='C3', size=psfSize) # green else: disp.dot('o', *coordSrc, ctype='C2', size=psfSize) # red else: disp.dot('o', *coordSrc, ctype='C0', size=psfSize) # blue
def plot_cameraGeom(repo_dir=os.path.join( '/project/scichris/aos/images/lsstCam/letter_lsstCam_entire_tiledF/DATA/'), detectorNameList=[ "R04_SW0", "R04_SW1", "R44_SW0", "R44_SW1", "R00_SW0", "R00_SW1", "R40_SW0", "R40_SW1", ], instrument='LSSTCam', binSize=16): afwDisplay.setDefaultBackend("matplotlib") #repo_dir = os.path.join('/project/scichris/aos/images/lsstCam/letter_lsstCam_entire_tiledF/DATA/') # need to specify the calib collections to be able to access the camera butler = dafButler.Butler(repo_dir, collections=[ f'{instrument}/raw/all', f'{instrument}/calib', 'run1', f'{instrument}/calib/unbounded' ]) dataId0 = dict(instrument=instrument) dataset = next( iter( butler.registry.queryDatasets(datasetType='postISRCCD', collections=['run1'], dataId=dataId0))) exposure = dataset.dataId["exposure"] camera = butler.get("camera", instrument=instrument, exposure=exposure) fig = plt.figure(figsize=(15, 15)) fig.subplots_adjust( hspace=0., wspace=0.0, ) ax = fig.add_subplot(1, 1, 1) disp = afwDisplay.Display(fig) disp.scale('asinh', 'zscale', Q=2) #disp.scale('linear', 'minmax') #disp.scale('asinh', 5, 7000, Q=2) disp.setImageColormap('viridis' if True else 'gray') dataType = "postISRCCD" # use that to limit what's shown #detectorNameList = ['R22_S11', 'R22_S20', 'R22_S10']# , 'R34_S20'] # set to None to plot everything mos = cameraGeomUtils.showCamera(camera, cameraGeomUtils.ButlerImage( butler, dataType, instrument=instrument, exposure=exposure, verbose=True), binSize=binSize, detectorNameList=detectorNameList, display=disp, overlay=True, title=f'{instrument}') disp.show_colorbar(False) ax.axis("off") #plt.savefig('LsstCam_letter_entire_tiledF_wfs.png', bbox_inches='tight') return mos
def setup_module(module, backend="virtualDevice"): lsst.utils.tests.init() try: afwDisplay.setDefaultBackend(backend) except: print("Unable to configure display backend: %s" % backend)
def initialise(self, exp, sourceCentroid, spectrumBbox, dispersionRelation): """xxx Docstring here. Parameters: ----------- par : `type Description """ # xxx if the rest of exp is never used, remove this # and just pass exp[spectrumBbox] self.expRaw = exp self.footprintExp = exp[spectrumBbox] self.footprintMi = self.footprintExp.maskedImage self.sourceCentroid = sourceCentroid self.spectrumBbox = spectrumBbox self.dispersionRelation = dispersionRelation self.spectrumWidth = self.spectrumBbox.getWidth() self.spectrumHeight = self.spectrumBbox.getHeight() # profiles - aperture and psf self.apertureFlux = np.zeros(self.spectrumHeight) self.rowWiseMax = np.zeros(self.spectrumHeight) # self.psfSigma = np.zeros(self.spectrumHeight) # self.psfMu = np.zeros(self.spectrumHeight) # self.psfFlux = np.zeros(self.spectrumHeight) # profiles - Moffat # self.moffatFlux = np.zeros(self.spectrumHeight) # self.moffatX0 = np.zeros(self.spectrumHeight) # self.moffatGamma = np.zeros(self.spectrumHeight) # self.moffatAlpha = np.zeros(self.spectrumHeight) # profiles - Gauss + Moffat # self.gmIntegralGM = np.zeros(self.spectrumHeight) # self.gmIntegralG = np.zeros(self.spectrumHeight) # probably delete these - from the GausMoffat fitting # self.amplitude_0 = np.zeros(self.spectrumHeight) # self.x_0_0 = np.zeros(self.spectrumHeight) # self.gamma_0 = np.zeros(self.spectrumHeight) # self.alpha_0 = np.zeros(self.spectrumHeight) # self.amplitude_1 = np.zeros(self.spectrumHeight) # self.mean_1 = np.zeros(self.spectrumHeight) # self.stddev_1 = np.zeros(self.spectrumHeight) # each will be an list of length self.spectrumHeight # with each element containing all the fit parameters self.psfFitPars = [None] * self.spectrumHeight self.moffatFitPars = [None] * self.spectrumHeight self.gausMoffatFitPars = [None] * self.spectrumHeight if self.debug.display: try: import lsst.afw.display as afwDisp afwDisp.setDefaultBackend(self.debug.displayBackend) # afwDisp.Display.delAllDisplays() self.disp1 = afwDisp.Display(0, open=True) self.disp1.mtv(self.expRaw[self.spectrumBbox]) self.disp1.erase() except Exception: self.log.warn('Failed to initialise debug display') self.debug.display = False # xxx probably need to change this once per-spectrum background is done # xsize = self.spectrumWidth - 2*self.config.perRowBackgroundSize # 20 # residuals = np.zeros([xsize, self.spectrumHeight]) self.backgroundMi = self._calculateBackground(self.footprintExp.maskedImage, # xxx remove hardcoding 15, smooth=self.config.doSmoothBackround) self.bgSubMi = self.footprintMi.clone() self.bgSubMi -= self.backgroundMi if self.debug.display and 'spectrumBgSub' in self.debug.displayItems: self.disp1.mtv(self.bgSubMi) return
def testSetAfwDisplayBackend(self): """Set the default backend to this package""" afwDisplay.setDefaultBackend("matplotlib")