def sendPlots(x_proj_sum, image_sum, counts_buff, counts_buff_regint, opal_image, hist_L3PhotEnergy, \ hist_FeeGasEnergy, nevt, numshotsforacc): # Define plots plotxproj = XYPlot(nevt,'Accumulated electron spectrum over past '+\ str(numshotsforacc)+' good shots', \ np.arange(x_proj_sum.shape[0]), x_proj_sum) plotcumimage = Image( nevt, 'Accumulated sum (' + str(numshotsforacc) + ' good shots)', image_sum) plotcounts = XYPlot(nevt,'Estimated number of identified electron counts over past '+ \ str(len(counts_buff))+' good shots', np.arange(len(counts_buff)), \ np.array(counts_buff)) plotcountsregint = XYPlot(nevt,'Estimated number of identified electron counts over past '+ \ str(len(counts_buff_regint))+' good shots in region '+str(np.round(region_int_lower_act,2))+\ ' eV - '+str(np.round(region_int_upper_act,2))+' eV (inclusive)', \ np.arange(len(counts_buff_regint)), np.array(counts_buff_regint)) plotshot = Image(nevt, 'Single shot', opal_image) plotL3PhotEnergy = Hist(nevt,'Histogram of L3 \'central\' photon energies (plotting for '+str(np.round(min_cent_pe, 2))+\ '- '+str(np.round(min_cent_pe, 2))+')', hist_L3PhotEnergy.edges[0], \ np.array(hist_L3PhotEnergy.values)) plotFeeGasEnergy = Hist(nevt,'Histogram of FEE gas energy (plotting for above '+str(np.round(fee_gas_threshold, 2))+\ ' only)', hist_FeeGasEnergy.edges[0], np.array(hist_FeeGasEnergy.values)) # Publish plots publish.send('AccElectronSpec', plotxproj) publish.send('OPALCameraAcc', plotcumimage) publish.send('ElectronCounts', plotcounts) publish.send('ElectronCountsRegInt', plotcountsregint) publish.send('OPALCameraSingShot', plotshot) publish.send('L3Histogram', plotL3PhotEnergy) publish.send('FEEGasHistogram', plotFeeGasEnergy)
def publish_corr_plots(self): """Publish correlation plots between x and y """ # Make MultiPlot to hold correlation plots plots_title = ''.join( [self.x_name, ' Vs ', self.y_name, ' Correlation Plots']) corr_plots = MultiPlot(plots_title, plots_title, ncols=3) # Make scatter plot scat_plot_title = ''.join( [self.y_name, ' Vs ', self.x_name, ' Scatter Plot']) scat_plot_text = ''.join([ 'Pearson: ', str(format(self.pearson, '.3f')), ' Update Pearson: ', str(format(self.upd_pearson, '.3f')), '\n SNR: ', str(format(self.snr, '.3f')), ' Update SNR: ', str(format(self.upd_snr, '.3f')) ]) scat_plot = XYPlot(scat_plot_text, scat_plot_title, np.copy(self.upd_x_data), np.copy(self.upd_y_data), xlabel=self.x_name, ylabel=self.y_name, formats='b.') # Make linearity plot lin_data = self._linearity_data(self.upd_x_data, self.upd_y_data) lin_plot_title = ''.join( [self.y_name, ' Vs ', self.x_name, ' Linearity Plot']) lin_plot_text = 'Red is Binned Data, Green is Linear Fit' lin_plot = XYPlot(lin_plot_text, lin_plot_title, [lin_data['x_avgs'], lin_data['x_avgs']], [lin_data['lin_y_vals'], lin_data['y_avgs']], xlabel=self.x_name, ylabel=self.y_name, formats=['g-', 'r-']) # Make histogram plot using filtered data filt_idx = self._filt_idx(self.upd_x_data, self.perc_too_high, self.perc_too_low) x_filt = self.upd_x_data[filt_idx] y_filt = self.upd_y_data[filt_idx] norm_data = y_filt / x_filt norm_data = norm_data / np.average(norm_data, weights=x_filt) hist_data, hbin_edges = np.histogram(norm_data, bins=20, weights=x_filt) hbin_centers = (hbin_edges[1:] + hbin_edges[:-1]) / 2 hist_plot_title = ''.join( [self.y_name, ' Normalized by ', self.x_name, ' Histogram']) hist_plot = Hist('', hist_plot_title, hbin_edges, hist_data) # Add created plots to plot list corr_plots.add(scat_plot) corr_plots.add(lin_plot) corr_plots.add(hist_plot) publish.send(self.plots_name, corr_plots)
def __init__(self, topic, title=None, xlabel=None, ylabel=None, pubrate=None, publisher=None): super(HistOverlayHelper, self).__init__(topic, title, pubrate, publisher) self.nhist = 0 self.nbins = [] self.ranges = [] self.bins = [] self.values = [] self.formats = [] self.data = Hist(None, self.title, self.bins, self.values, xlabel=xlabel, ylabel=ylabel, formats=self.formats)
def __init__(self, topic, nbins, bmin, bmax, title=None, xlabel=None, ylabel=None, format='-', pubrate=None, publisher=None): super(HistHelper, self).__init__(topic, title, pubrate, publisher) self.nbins = int(nbins) self.bmin = float(bmin) self.bmax = float(bmax) self.range = (bmin, bmax) self.data = Hist(None, self.title, make_bins(self.nbins, self.bmin, self.bmax), np.zeros(self.nbins), xlabel=xlabel, ylabel=ylabel, formats=format)
def runmaster(nClients, pars, args): # get data source parameters expName = pars['expName'] runNum = args.run runString = 'exp=' + expName + ':run=' + runNum # get number of events between updates updateEvents = pars['updateEvents'] # expected delay nomDelay = args.delay # plotting things plotFormat = 'ro' xdata = np.zeros(updateEvents) ydata = np.zeros(updateEvents) # initialize plots # plot for pulse 1 vs pulse 2 amplitude Amplitudes = XYPlot(0, "Amplitudes", xdata, ydata, formats=plotFormat, xlabel='Pulse 1 amplitude', ylabel='Pulse 2 amplitude') publish.send("AMPLITUDES", Amplitudes) # plot for MCP trace and fit x1 = np.linspace(0, 2500, 20000) y1 = np.zeros(20000) x1 = [x1[12500:13500], x1[12500:13500]] y1 = [y1[12500:13500], y1[12500:13500] + 1] plotFormat = ['b-', 'r-'] legend = ['Raw', 'Fit'] Trace = XYPlot(0, "Trace", x1, y1, formats=plotFormat, leg_label=legend, xlabel='Time (ns)', ylabel='MCP Signal') publish.send("TRACE", Trace) # histogram of delays based on fit (to make sure fit is working) DelayHist = Hist(0, "Delay", np.linspace(nomDelay - 1.0, nomDelay + 1.0, 101), np.zeros(100), xlabel='Delay (ns)', ylabel='Number of Events') publish.send("DELAYHIST", DelayHist) # initialize arrays for plotting wf = np.zeros(20000) fit1 = np.zeros(20000) a1 = np.empty(0) a2 = np.empty(0) delay = np.empty(0) # keep plotting until all clients stop while nClients > 0: # Remove client if the run ended # # set up data receiving md = mpidata() # check which client we're receiving from rank1 = md.recv() # check if this client is finished if md.small.endrun: nClients -= 1 else: # add new data to arrays a1 = np.append(a1, md.a1) a2 = np.append(a2, md.a2) delay = np.append(delay, md.delay) wf = md.wf fit1 = md.fit # plot if we're receiving from the last client if rank1 == size - 1: # make histogram of delays hist1, bins = np.histogram(delay, bins=np.linspace( nomDelay - 5, nomDelay + 5, 101)) # update plots plot(Trace, x1, [wf[12500:13500], fit1[12500:13500]], md.small.event, "TRACE") plot(Amplitudes, a1, a2, md.small.event, "AMPLITUDES") histPlot(DelayHist, bins, hist1, md.small.event, "DELAYHIST") # re-initialize arrays a1 = np.empty(0) a2 = np.empty(0) delay = np.empty(0)
multi = MultiPlot(0, "UXSMonitor {} Hz {}".format(speed, metadata[frameidx]), ncols=2) multi.add(plotimglive) multi.add(plotimgacc) multi.add(plotxylive) multi.add(plotxyacc) publish.send("UXSMonitor", multi) # 2nd UXSMonitor multi = MultiPlot(0, "UXSMonitor2 {} Hz {}".format(speed, metadata[frameidx]), ncols=3) plotsigma = XYPlot(0, "Sigma1: {:.2f}<br>Sigma2: {:.2f}".format(sigma1,sigma2), 2*[range(numhistory)], [np.roll(s, -histidx-1) for s in sigmamonitor], formats='.') plotheight = XYPlot(0, "Height1: {:.2f}<br>Height2: {:.2f}".format(int1,int2), 2*[range(numhistory)], [np.roll(h, -histidx-1) for h in heightmonitor], formats='.') plotpos = XYPlot(0, "Pos1: {:.2f}<br>Pos2:{:.2f}".format(pos1,pos2), 2*[range(numhistory)], [np.roll(p, -histidx-1) for p in posmonitor], formats='.') plotintensity = XYPlot(0, "Intensity", range(numhistory), np.roll(intensitymonitor, -histidx-1), formats='.') plotfiltintensity = XYPlot(0, "Filtered Intensity", range(numhistory), np.roll(filtintensitymonitor, -histidx-1), formats='.') pulsehistogram, pulsehistogramedges = np.histogram(pulsemonitor,3) plotpulsemonitor = Hist(0, "Pulse count histogram", pulsehistogramedges, pulsehistogram) multi.add(plotsigma) multi.add(plotheight) multi.add(plotpos) multi.add(plotintensity) multi.add(plotfiltintensity) multi.add(plotpulsemonitor) publish.send("UXSMonitor2", multi) # Iterate framenumber frameidx += 1 frameidx = frameidx%numframes # Numhistory histidx +=1 histidx = histidx%numhistory
def publish(self, image=None, saxs=None, c2=None, ind=None, n_a=None, n_saxs=None, n_c2=None, n_i=None, n_q=None, n_bin=None): """Publish Intermediate results: @image Average image @saxs Averaged saxs data @c2 Averaged c2 data @ind Indexed data @n_a Nr of averaged images @n_saxs Nr of averaged saxs curves @n_c2 Nr of averaged c2 data @n_i Nr of indexed images @n_q Nr of q-rings to plot @n_bin Nr of bins for size histogram KEYWORDS FOR PLOTS AVE : Average image C2_IMAGE : Heat plot of C2 C2 : Individual C2 plots SAXS : Saxs curve IND : Index data ex: psplot -s psanaXXXX AVE C2 SAXS IND C2_IMAGE """ if n_q is None: n_q = min(15, len(self.q)) if n_q > len(self.q): # Ascert that there is enough q's n_q = len(self.q) if n_bin is None: n_bin = n_i / 10 if image is not None: # Average Image title = 'AVERAGE Run ' + str(self.run_nr) AVEimg = Image(n_a, title, image) publish.send('AVE', AVEimg) if saxs is not None: # SAXS plot title = 'SAXS Run ' + str(self.run_nr) SAXSimg = XYPlot(n_saxs, title, self.q, saxs, xlabel='q (1/A)', formats='b') publish.send('SAXS', SAXSimg) if c2 is not None: # C2 plots title = 'C2 Run ' + str(self.run_nr) # C2 heatmap plot C2img = Image(n_c2, title, c2) publish.send('C2_IMAGE', C2img) # Multiplot, plot C2 for 10 q-points multi = MultiPlot(n_c2, title, ncols=5) step = round(len(self.q) / (n_q + 1)) for p in range(n_q): R = XYPlot(n_c2, 'q = ' + str(np.around(self.q[(p + 1) * step], decimals=3)), self.phi, c2[(p + 1) * step], xlabel='dPhi') multi.add(R) publish.send('C2', multi) if ind is not None: if n_bin is None: n_bin = n_i / 10 # Last non-zero intensity nz = np.nonzero(ind[:, 0]) last = nz[0][-1] ind = ind[0:last, :] # Check if we manged to estimate sizes sind = ind[:, 2] > 0.98 if sind.any(): title = 'INDEX Run ' + str(self.run_nr) # INDEX plot multi2 = MultiPlot(n_i, title, ncols=1) # Intensity plot title = 'Intensity Run ' + str(self.run_nr) I = XYPlot(n_i, title, np.arange(last), ind[:, 0], xlabel='N', formats='rs') multi2.add(I) # Size plot title = 'Size Run ' + str(self.run_nr) diam = ind[sind, 1] * (2 / 10) # Diameter in nm hist, bins = np.histogram(diam, n_bin) S = Hist(n_i, title, bins, hist, xlabel='Size [nm]') multi2.add(S) publish.send('IND', multi2) else: title = 'Intensity Run ' + str(self.run_nr) I = XYPlot(n_i, title, np.arange(last), ind[:, 0], xlabel='N', formats='rs') publish.send('IND', I)
'%) over past '+str(numshotsforacc)+' shots', calib_array, x_proj_sum) plotcumimage = Image(nevt, 'Accumulated sum of good shots ('+str(np.round(good_shot_count_pcage, 2))+\ '%) over past '+str(numshotsforacc)+' shots', image_sum) plotcounts = XYPlot(nevt,'Estimated number of identified electron counts over past '+ \ str(len(counts_buff))+' shots', np.arange(len(counts_buff)), np.array(counts_buff)) plotcountsregint = XYPlot(nevt,'Estimated number of identified electron counts in region '+\ str(np.round(roi_lower_act,2))+' eV - '+\ str(np.round(roi_upper_act,2))+' eV (inclusive) over past '+ \ str(len(counts_buff_roi))+' shots', \ np.arange(len(counts_buff_roi)), np.array(counts_buff_roi)) opal_image[:, roi_idx_lower - 3:roi_idx_lower - 1] = 900 opal_image[:, roi_idx_upper + 1:roi_idx_upper + 3] = 900 plotshot = Image(nevt, 'Single shot, ROI marked from '+str(np.round(roi_lower_act,2))+' eV - '+\ str(np.round(roi_upper_act,2))+' eV', opal_image) plotL3PhotEnergy = Hist(nevt,'Histogram of L3 \'central\' photon energies (getting electron data for '+str(np.round(min_cent_pe, 2))+\ ' eV - '+str(np.round(max_cent_pe, 2))+' eV)', hist_L3PhotEnergy_edges[0], hist_L3PhotEnergy_all) plotFeeGasEnergy = Hist(nevt,'Histogram of FEE gas energy (getting electron data for above '+str(np.round(fee_gas_threshold, 2))+\ ' mJ only)', hist_FeeGasEnergy_edges[0], hist_FeeGasEnergy_all) plotFeeGasEnergy_CountsROI = Image(nevt,'Histogram of FEE gas energy vs ROI ('+str(np.round(roi_lower_act,2))+' eV - '+\ str(np.round(roi_upper_act,2))+' eV) counts', hist_FeeGasEnergy_CountsROI, \ hist_FeeGasEnergy_CountsROI_edges[1], hist_FeeGasEnergy_CountsROI_edges[0]) return plotxproj, plotcumimage, plotcounts, plotcountsregint, plotshot, plotL3PhotEnergy, plotFeeGasEnergy, plotFeeGasEnergy_CountsROI def sendPlots(x_proj_sum, image_sum, counts_buff, counts_buff_roi, opal_image, (hist_L3PhotEnergy, \ hist_L3PhotEnergy_edges), (hist_FeeGasEnergy, hist_FeeGasEnergy_edges), (hist_FeeGasEnergy_CountsROI, hist_FeeGasEnergy_CountsROI_edges), nevt, numshotsforacc,\ good_shot_count_pcage, speed): plotxproj, plotcumimage, plotcounts, plotcountsregint, plotshot, plotL3PhotEnergy, plotFeeGasEnergy, \ plotFeeGasEnergy_CountsROI=\ definePlots(x_proj_sum, image_sum, counts_buff, counts_buff_roi, opal_image, (hist_L3PhotEnergy, \