def display(self): """Plot data, fitted function for FWHM and optionally flux. """ # plot them through ds9 in parallel to the fit ds9DisplayThread = None if self.Ds9Display and self.xdisplay: # start thread ds9DisplayThread = Ds9DisplayThread(debug=self.debug, dataSxtr=self.dataSxtr, logger=self.logger) ds9DisplayThread.start() elif self.Ds9Display and not self.xdisplay: self.logger.warn('analyze: OOOOOOOOPS, no ds9 display available') if self.dataSxtr[0].assocFn is not None: ft = FitDisplay(date=self.date, comment='ASSOC', logger=self.logger) else: ft = FitDisplay(date=self.date, logger=self.logger) if self.i_flux is None: ft.fitDisplay(dataFit=self.dataFitFwhm, resultFit=self.resultFitFwhm, display=self.FitDisplay, xdisplay=self.xdisplay) else: # plot FWHM but don't show ft.fitDisplay(dataFit=self.dataFitFwhm, resultFit=self.resultFitFwhm, show=False, display=self.FitDisplay, xdisplay=self.xdisplay) ft.fitDisplay(dataFit=self.dataFitFlux, resultFit=self.resultFitFlux, display=self.FitDisplay, xdisplay=self.xdisplay) # very important (otherwise all plots show up in next show()) ft.ax1 = None # http://stackoverflow.com/questions/741877/how-do-i-tell-matplotlib-that-i-am-done-with-a-plot ft.fig.clf() ft.fig = None ft = None # stop ds9 display thread if self.Ds9Display and self.xdisplay: ds9DisplayThread.join(timeout=1.)
def test_FluxfitDisplay(self): logger.info('== {} =='.format(self._testMethodName)) ft = FitFunction(dataFit=self.dataFitFwhm, logger=logger) min_focpos_fwhm, val_fwhm, par, flag = ft.fitData() if flag != None: resultFitFwhm = ResultFit(ambientTemp='20.1', ftName='UNK', extrFitPos=min_focpos_fwhm, extrFitVal=val_fwhm, fitPar=par, fitFlag=flag, color='blue', ylabel='FWHM [px]: blue', titleResult='fwhm:{0:5d}'.format( int(min_focpos_fwhm))) fd = FitDisplay(date=self.date, comment='unittest', logger=logger) fd.fitDisplay(dataFit=self.dataFitFwhm, resultFit=resultFitFwhm, xdisplay=False) x = np.array([p for p in self.dataFitFlux.pos]) y = np.array([v for v in self.dataFitFlux.val]) wmean = np.average(a=x, weights=y) xy = zip(x, y) wstd = np.std(a=xy) # scale the values [a.u.] sv = [ max(self.dataFitFwhm.val) / max(self.dataFitFlux.val) * z for z in self.dataFitFlux.val ] self.dataFitFlux.val = sv # gaussian self.parFlux = np.array([10., wmean, wstd / 4., 2.]) ft = FitFunction(dataFit=self.dataFitFlux, logger=logger) max_focpos_flux, val_flux, par, flag = ft.fitData() if flag != None: resultFitFlux = ResultFit( ambientTemp='20.1', ftName='UNK', extrFitPos=max_focpos_flux, extrFitVal=val_flux, fitPar=par, fitFlag=flag, color='red', ylabel='FWHM [px]: blue, Flux [a.u.]:red', titleResult='fwhm:{0:5d}, flux: {1:5d}'.format( int(resultFitFwhm.extrFitPos), int(max_focpos_flux))) fd.fitDisplay(dataFit=self.dataFitFlux, resultFit=resultFitFlux, xdisplay=False)
def test_FwhmfitDisplay(self): logger.info('== {} =='.format(self._testMethodName)) ft = FitFunction(dataFit=self.dataFitFwhm, logger=logger) min_focpos_fwhm, val_fwhm, par, flag = ft.fitData() resultFitFwhm = ResultFit(ambientTemp='20.1', ftName='UNK', extrFitPos=min_focpos_fwhm, extrFitVal=val_fwhm, fitPar=par, fitFlag=flag, color='blue', ylabel='FWHM [px]: blue', titleResult='fwhm:{0:5d}'.format( int(min_focpos_fwhm))) self.fd = FitDisplay(date=self.date, comment='unittest', logger=logger) self.fd.fitDisplay(dataFit=self.dataFitFwhm, resultFit=resultFitFwhm, xdisplay=False)