def CurvatureMain(): # We will probably do this in ipython notebook # Otherwise here we can run it # Read input file filename = "./UXSAlign/0.out.accimage" print "Reading {}".format(filename) image = readImage(filename) uxspre = UXSDataPreProcessing(image.copy()) uxspre.CalculateProjection() uncorrspectrum = uxspre.wf # Produce curvaturecorrection zippdxy = CurvatureFinder(image) xshifts = CreateXshifts(zippdxy) # Monkey path the correction uxspre.xshifts = xshifts uxspre.CorrectImageGeometry() uxspre.CalculateProjection() # Plot difference with and without calibration multi = MultiPlot(0, "UXSCalibration {}".format(filename), ncols=2) image = AddCurvLine(image, xshifts) uncorrimage = Image(0, "Uncorrected", image) multi.add(uncorrimage) corrimage = Image(0, "Corrected", uxspre.image) multi.add(corrimage) uncorrspec = XYPlot(0, "Uncorrected", range(len(uncorrspectrum)), uncorrspectrum) multi.add(uncorrspec) corrspec = XYPlot(0, "Corrected", range(len(uxspre.wf)), uxspre.wf) multi.add(corrspec) for i in range(10): publish.send("UXSCalibration", multi) saveXshifts(filename, xshifts) print "fin"
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 main(): args = parse_cli() max_updates = args.num_updates period = 1 / args.rate status_rate = 100 image_n = args.images col_n = args.columns windows = args.windows pixels_n = 1024 width = 50 pos = 25 topic = 'image' title = 'Image Test' multi_topic = 'multi-image' multi_title = 'Mulit Image Test' #optional port, buffer-depth arguments. publish.local = args.local publish.client_opts.daemon = True if args.mpl: publish.client_opts.renderer = 'mpl' elif args.pyqt: publish.client_opts.renderer = 'pyqt' publish.plot_opts.zrange = (-250., 250.) counter = 0 while counter < max_updates or max_updates < 1: multi_image = MultiPlot(counter, multi_title, ncols=min(col_n, image_n), use_windows=windows) for num in range(image_n): image_data = Image( counter, '%s %d' % (title, num), np.random.normal((-1)**num * pos * num, width, (pixels_n, pixels_n))) multi_image.add(image_data) publish.send(multi_topic, multi_image) image_data = Image(counter, title, np.random.normal(0, width, (pixels_n, pixels_n))) publish.send(topic, image_data) counter += 1 if counter % status_rate == 0: print("Processed %d updates so far" % counter) time.sleep(period)
def my_smalldata(data_dict): # one core gathers all data from mpi workers global numevents, lastimg, numendrun, mydeque if 'endrun' in data_dict: numendrun += 1 if numendrun == numworkers: print('Received endrun from all workers. Resetting data.') numendrun = 0 numevents = 0 mydeque = deque(maxlen=25) return numevents += 1 if 'opal' in data_dict: lastimg = data_dict['opal'] mydeque.append(data_dict['opalsum']) if numevents % 100 == 0: # update plots around 1Hz print('event:', numevents) myxyplot = XYPlot(numevents, "Last 25 Sums", np.arange(len(mydeque)), np.array(mydeque), formats='o') publish.send("OPALSUMS", myxyplot) if lastimg is not None: # opal image is not sent all the time myimgplot = Image(numevents, "Opal Image", lastimg) publish.send("OPALIMG", myimgplot)
def plot(sumDict, event_ts_str): #print sumDict['n_off'], sumDict['n_early'], sumDict['n_late'] #publish.local=True publish.plot_opts.palette = 'spectrum' multi_plot_data = MultiPlot(event_ts_str, 'normImg') multi_plot_dataDiff = MultiPlot(event_ts_str, 'normImgDiff') if 'img_off' in sumDict.keys(): sumDict['img_off'] = sumDict['img_off'].astype(float) if 'img_early' in sumDict.keys(): sumDict['img_early'] = sumDict['img_early'].astype(float) if 'img_late' in sumDict.keys(): sumDict['img_late'] = sumDict['img_late'].astype(float) if sumDict['n_off'] > 0: #plotImgOffNorm = Image(0,'off_norm',sumDict['img_off']/sumDict['i0_off']) plotImgOffNorm = Image(0, 'off_norm', sumDict['img_off'] / sumDict['n_off']) multi_plot_data.add(plotImgOffNorm) if sumDict['n_early'] > 0: #plotImgEarlyNorm = Image(0,'early_norm',sumDict['img_early']/sumDict['i0_early']) plotImgEarlyNorm = Image(0, 'early_norm', sumDict['img_early'] / sumDict['n_early']) multi_plot_data.add(plotImgEarlyNorm) if sumDict['n_late'] > 0: #plotImgLateNorm = Image(0,'late_norm',sumDict['img_late']/sumDict['i0_late']) plotImgLateNorm = Image(0, 'late_norm', sumDict['img_late'] / sumDict['n_late']) multi_plot_data.add(plotImgLateNorm) #uncomment to see plots. if sumDict['n_early'] > 0 and sumDict['n_late'] > 0: publish.send('normImg', multi_plot_data) plotImgDiffT0 = Image( 0, 'late_early', sumDict['img_late'] / sumDict['i0_late'] - sumDict['img_early'] / sumDict['i0_early']) multi_plot_dataDiff.add(plotImgDiffT0) if sumDict['n_off'] > 0 and sumDict['n_late'] > 0: plotImgDiffOff = Image( 0, 'late_off', sumDict['img_late'] / sumDict['i0_late'] - sumDict['img_off'] / sumDict['i0_off']) multi_plot_dataDiff.add(plotImgDiffOff) if sumDict['n_early'] > 0 and sumDict['n_late'] > 0 and sumDict[ 'n_off'] > 0: publish.send('normImgDiff', multi_plot_dataDiff)
def CallBack(evt_dict): global dat,t0,t500,num img = Image(0,'atm',evt_dict['atm']) xy = XYPlot(0,'atm_proj',range(len(evt_dict['atm_proj'])),evt_dict['atm_proj']) publish.local = True publish.send('ATM',img) publish.send('ATMP',xy) num += 1 if num==500: t500 = time.time() elif num>500: print('t500:',t500-t0,'num:',num,'rank:',evt_dict['rank'],'tstamp:',evt_dict['tstamp'],'index:',evt_dict['index']) #dat.append(evt_dict['evr']) else: print('num:',num,'rank:',evt_dict['rank'],'tstamp:',evt_dict['tstamp'],'index:',evt_dict['index'])
def populateMyImageQueue(): while(True): time.sleep(.05) for i in arange(maxRank): myData = numpysocket.startServer(basePortNumber+i) myImageQueue.put(myData) populateMyImageQueueThread = threading.Thread(target=populateMyImageQueue) populateMyImageQueueThread.start() while not queue.empty(): #pyqt graph code to show image fast plotimg = Image(0,"CsPad", myImageQueue.get()) publish.send('IMAGE',plotimg) #line below is used to display image
def update(self,md): self.nupdate+=1 if self.spectrumsum is None: self.spectrumsum = md.spectrumsum self.roisum = md.roisum self.nevents = md.small.nevents self.nevents_on_off = md.nevents_on_off else: self.spectrumsum += md.spectrumsum self.roisum += md.roisum self.nevents += md.small.nevents self.nevents_on_off += md.nevents_on_off self.avgroisum = self.roisum/self.nevents self.deque.append(md.spectrumsum[0,:]+md.spectrumsum[1,:]) # lasing on and off if self.nupdate%updaterate==0: print('Client updates',self.nupdate,'Master received events:',self.nevents) if self.lasttime is not None: print('Rate:',(self.nevents-self.lastnevents)/(time.time()-self.lasttime)) self.lasttime = time.time() self.lastnevents = self.nevents spectrum_recent = None for entry in self.deque: if spectrum_recent is None: spectrum_recent=entry else: spectrum_recent+=entry spectrum_on_plot = XYPlot(self.nupdate,"Spectrum On",np.arange(md.spectrumsum.shape[1]),self.spectrumsum[0,:]) publish.send('SPECTRUM_ON',spectrum_on_plot) spectrum_off_plot = XYPlot(self.nupdate,"Spectrum Off",np.arange(md.spectrumsum.shape[1]),self.spectrumsum[1,:]) publish.send('SPECTRUM_OFF',spectrum_off_plot) spectrum_diff_plot = XYPlot(self.nupdate,"Spectrum Diff",np.arange(md.spectrumsum.shape[1]),self.spectrumsum[0,:]*self.nevents_on_off[1]-self.spectrumsum[1,:]*self.nevents_on_off[0]) publish.send('SPECTRUM_DIFF',spectrum_diff_plot) spectrum_recent_plot = XYPlot(self.nupdate,"Recent Spectrum",np.arange(md.spectrumsum.shape[1]),spectrum_recent) publish.send('RECENT_SPECTRUM',spectrum_recent_plot) roi_plot = Image(self.nupdate,"Epix ROI",self.avgroisum) publish.send('EPIX_ROI',roi_plot)
fity = UXSDataPreProcessing.DoubleGaussianFunction(x,a1,c1,w1,a2,c2,w2) print fity """ # Send single plots #plotimglive = Image(0, "UXS Monitor Live image {} {}Hz {}".format(frameidx, speed, metadata[frameidx]), uxspre.image) #plotimgacc = Image(0, "UXS Monitor Accumulated image {} {}Hz {}".format(frameidx, speed, metadata[frameidx]), summedimage) #plotxylive = XYPlot(0, "UXS Monitor Live Spectrum {}".format(metadata[frameidx]), range(1024), uxspre.wf) #plotxyacc = XYPlot(0, "UXS Monitor Accumulated Spectrum {}".format(metadata[frameidx]), range(1024), summedspectrum) #publish.send("UXSMonitorLive", plotimglive) #publish.send("UXSMonitorAcc", plotimgacc) #publish.send("UXSMonitorLiveSpectrum", plotxylive) #publish.send("UXSMonitorAccSpectrum", plotxy) # Send a multiplot plotimglive = Image(0, "Live", uxspre.image) plotimgacc = Image(0, "Acc", accimage) plotxylive = XYPlot(0, "Live", energyscale, spectrum) plotxyacc = XYPlot(0, "Acc", energyscale, accspectrum) ###plotxyfit = XYPlot(0, "Fit", energyscale, fity) multi = MultiPlot(0, "UXSMonitor {} Hz {}".format(speed, metadata[frameidx]), ncols=2) multi.add(plotimglive) multi.add(plotimgacc) multi.add(plotxylive) multi.add(plotxyacc) ###multi.add(plotxyfit) publish.send("UXSMonitor", multi) # Count rate evolution over the frames. #counts = np.sum(images, axis=(0,1))
def runmaster(nClients, pars, args): # initialize arrays dataDict = {} dataDict['nevents'] = np.ones(10000) * -1 dataDict['h_peak'] = np.zeros(10000) dataDict['v_peak'] = np.zeros(10000) dataDict['h_width'] = np.zeros(10000) dataDict['v_width'] = np.zeros(10000) dataDict['x_prime'] = np.zeros(10000) dataDict['x_res'] = np.zeros(10000) dataDict['y_prime'] = np.zeros(10000) dataDict['y_res'] = np.zeros(10000) dataDict['x_grad'] = np.zeros(10000) dataDict['y_grad'] = np.zeros(10000) dataDict['intensity'] = np.zeros(10000) roi = pars['roi'] xmin = roi[0] xmax = roi[1] ymin = roi[2] ymax = roi[3] padSize = pars['pad'] xSize = (xmax - xmin) * padSize ySize = (ymax - ymin) * padSize # initialize plots img_measured = Image(0, "RAW", np.zeros((ySize, xSize))) img_fft = Image(0, "FFT", np.zeros((ySize, xSize))) img_focus = Image(0, "FOCUS", np.zeros((ySize, xSize))) img_amp = Image(0, "AMP", np.zeros((ySize, xSize))) # peak_plot = XYPlot(0, "peak", [dataDict['nevents'],dataDict['nevents'],dataDict['nevents']],[dataDict['h_peak'],dataDict['v_peak'],dataDict['h_peak']], formats=['bo','ro','bo'],leg_label=['Horizontal','Vertical','smooth']) focus_dist_plot = XYPlot(0, "focus_dist", [ dataDict['nevents'], dataDict['nevents'], dataDict['nevents'], dataDict['nevents'] ], [ dataDict['h_peak'], dataDict['v_peak'], dataDict['h_peak'], dataDict['v_peak'] ], formats=['bo', 'ro', 'c.', 'm.'], leg_label=[ 'Horizontal', 'Vertical', 'Horizontal Smooth', 'Vertical Smooth' ]) focus_dist_plot.xlabel = 'Event number' focus_dist_plot.ylabel = 'Focus position (mm)' x_grad_plot = XYPlot(0, "x_grad", dataDict['x_prime'], dataDict['x_grad']) x_grad_plot.xlabel = 'x (microns)' x_grad_plot.ylabel = 'Phase gradient' y_grad_plot = XYPlot(0, "y_grad", dataDict['y_prime'], dataDict['y_grad']) y_grad_plot.xlabel = 'y (microns)' y_grad_plot.ylabel = 'Phase gradient' x_res_plot = XYPlot(0, "x_res", dataDict['x_prime'], dataDict['x_res']) x_res_plot.xlabel = 'x (microns)' x_res_plot.ylabel = 'Residual phase (rad)' y_res_plot = XYPlot(0, "y_res", dataDict['y_prime'], dataDict['y_res']) y_res_plot.xlabel = 'y (microns)' y_res_plot.ylabel = 'Residual phase (rad)' rms_plot = XYPlot(0, "rms", [dataDict['nevents'], dataDict['nevents'], 0, 0], [dataDict['h_width'], dataDict['v_width'], 0, 0], formats=['bo', 'ro', 'c.', 'm.'], leg_label=[ 'Horizontal', 'Vertical', 'Horizontal Smooth', 'Vertical Smooth' ]) rms_plot.xlabel = 'Event number' rms_plot.ylabel = 'RMS Residual Phase (rad)' intensity_plot = XYPlot(0, "intensity", dataDict['nevents'], dataDict['intensity'], formats='bo') intensity_plot.xlabel = 'Event number' intensity_plot.ylabel = 'Peak intensity (a.u.)' publish.send("peak", focus_dist_plot) publish.send("rms", rms_plot) publish.send("FFT", img_fft) publish.send("RAW", img_measured) publish.send("x_res", x_res_plot) publish.send("y_res", y_res_plot) #publish.send("x_grad",x_grad_plot) #publish.send("y_grad",y_grad_plot) publish.send("FOCUS", img_focus) publish.send("intensity", intensity_plot) #publish.send("v_grad",img_v_grad) publish.send("AMP", img_amp) nevent = -1 while nClients > 0: # Remove client if the run ended md = mpidata() rank1 = md.recv() print(rank1) if md.small.endrun: nClients -= 1 else: #nevents = np.append(nevents,md.nevents) dataDict['nevents'] = update(md.nevents, dataDict['nevents']) dataDict['h_peak'] = update(md.h_peak, dataDict['h_peak']) dataDict['v_peak'] = update(md.v_peak, dataDict['v_peak']) dataDict['h_width'] = update(md.h_width, dataDict['h_width']) dataDict['v_width'] = update(md.v_width, dataDict['v_width']) dataDict['intensity'] = update(md.intensity, dataDict['intensity']) if md.nevents > nevent: nevent = md.nevents F0 = md.F0 focus = md.focus img0 = md.img0 x_res = md.x_res y_res = md.y_res focus_distance = md.focus_distance amp = md.amp #if len(nevents)>1000: # nevents = nevents[len(nevents)-1000:] #counterSum += md.counter if rank1 == size - 1: #if True: #plot(md,img_measured,img_fft,peak_plot,width_plot,dataDict) mask = dataDict['nevents'] > 0 eventMask = dataDict['nevents'][mask] order = np.argsort(eventMask) eventMask = eventMask[order] h_peak = dataDict['h_peak'][mask][order] v_peak = dataDict['v_peak'][mask][order] h_width = dataDict['h_width'][mask][order] v_width = dataDict['v_width'][mask][order] intensity = dataDict['intensity'][mask][order] h_smooth = pandas.rolling_mean(h_peak, 10) v_smooth = pandas.rolling_mean(v_peak, 10) hw_smooth = pandas.rolling_mean(h_width, 10) vw_smooth = pandas.rolling_mean(v_width, 10) plot(focus_dist_plot, "focus_dist", [eventMask, eventMask, eventMask[10:], eventMask[10:]], [h_peak, v_peak, h_smooth[10:], v_smooth[10:]]) plot(rms_plot, "rms", [eventMask, eventMask, eventMask[10:], eventMask[10:]], [h_width, v_width, hw_smooth[10:], vw_smooth[10:]]) plot(intensity_plot, "intensity", eventMask, intensity) imshow(img_measured, "RAW", img0, nevent) imshow(img_fft, "FFT", F0, nevent) imshow(img_focus, "FOCUS", focus, focus_distance) #imshow(img_v_grad,"v_grad",md.v_grad,md.small.event) imshow(img_amp, "AMP", amp, nevent) plot(x_res_plot, "x_res", md.x_prime, md.x_res) plot(y_res_plot, "y_res", md.y_prime, md.y_res) #plot(x_grad_plot,"x_grad",md.x_prime,md.x_grad) #plot(y_grad_plot,"y_grad",md.y_prime,md.y_grad) fileName = '/reg/d/psdm/' + pars['hutch'] + '/' + pars['hutch'] + pars[ 'exp_name'] + '/results/wfs/' + args.run + '_2d_data.h5' mask = dataDict['nevents'] >= 0 for key in dataDict.keys(): dataDict[key] = dataDict[key][mask] i1 = np.argsort(dataDict['nevents']) for key in dataDict.keys(): dataDict[key] = dataDict[key][i1] with h5py.File(fileName, 'w') as f: for key in dataDict.keys(): f.create_dataset(key, data=dataDict[key])
import numpy as np from psana import * from Detector.PyDetector import PyDetector import sys filename = sys.argv[1] plottype = sys.argv[2] print filename, plottype from psmon import publish from psmon.plots import MultiPlot, XYPlot, Image ds = DataSource('exp=cxif5315:run=169') env = ds.env() evt = ds.events().next() data = np.load(filename) src = Source('DetInfo(CxiDs2.0:Cspad.0)') det = PyDetector(src, env) img = det.image(evt, data[plottype]) publish.local = True plt = Image(0, filename, img) publish.send('image', plt)
if arced: print '***WARNING - ARC DETECTED!!!***' cv2.putText(opal_image, 'ARCING DETECTED!!!', (50, int(i_len / 2)), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 0, 0), 10) cv2.putText(image_sum, 'ARCING DETECTED!!!', (50, int(i_len / 2)), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 0, 0), 10) #%% Now send plots (only counts updated from last time) and wait 2 seconds # Define plots plotxproj = XYPlot(0,'Accumulated electron spectrum over past '+\ str((len(x_proj_sum_buff)-1)*plot_every)+ \ ' shots', np.arange(x_proj_sum.shape[0]), x_proj_sum) plotcumimage = Image(0, 'Accumulated sum', image_sum) plotcounts = XYPlot(0,'Estimated number of identified electron counts over past '+ \ str(len(counts_buff))+' shots', np.arange(len(counts_buff)), \ np.array(counts_buff)) plotshot = Image(0, 'Single shot', opal_image) multi = MultiPlot(0, 'Multi', ncols=2) multi.add(plotcounts) multi.add(plotshot) multi.add(plotxproj) multi.add(plotcumimage) # Publish plots publish.send('SHESOnline', multi)
ref_time = time.time() # for estimating rate of data acquisition print 'Monitoring counts in region between ' +str(np.round(roi_lower_act,2))+\ ' eV - '+str(np.round(roi_upper_act,2))+' eV' if rem_a != 0: print 'For efficient monitoring of accumulated electron spectra require history_len divisible by \ refresh_rate*size, set history_len to ' + str(history_len) #%% Define plotting function def definePlots(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): # Define plots plotxproj = XYPlot(nevt,'Accumulated electron spectrum from good shots ('+str(np.round(good_shot_count_pcage, 2))+\ '%) 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))+\
for i, t in enumerate(mytimes): evt = run.event(t) accepted, data, spectrum, dc_offset, all_data, all_data_raw = spf.filter_event( evt, filter_name) if not accepted: continue print cspad_tbx.evt_timestamp( cspad_tbx.evt_time(evt)), "Publishing data for event", i #header = "Event %d, m/f: %7.7f, f: %d"%(i, peak_max/flux, flux) header = "Event %d" % (i) if rank == 0: fee = Image(header, "FEE", data) # make a 2D plot publish.send("FEE", fee) # send to the display spectrumplot = XYPlot(header, 'summed 1D trace', range(data.shape[1]), spectrum) # make a 1D plot publish.send("SPECTRUM", spectrumplot) # send to the display fee = Image(header, "DC_OFFSET", dc_offset) # make a 2D plot publish.send("DC_OFFSET", fee) # send to the display fee = Image(header, "ALL_FEE", all_data) # make a 2D plot publish.send("ALL_FEE", fee) # send to the display fee = Image(header, "ALL_FEE_RAW", all_data_raw) # make a 2D plot publish.send("ALL_FEE_RAW", fee) # send to the display
def __init__(self, topic, title=None, pubrate=None, publisher=None): super(ImageHelper, self).__init__(topic, title, pubrate, publisher) self.data = Image(None, self.title, None)
def run(args): user_phil = [] for arg in args: if os.path.isfile(arg): try: user_phil.append(parse(file_name=arg)) except Exception as e: print(str(e)) raise Sorry("Couldn't parse phil file %s" % arg) else: try: user_phil.append(parse(arg)) except Exception as e: print(str(e)) raise Sorry("Couldn't parse argument %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() # cxid9114, source fee: FeeHxSpectrometer.0:Opal1000.1, downstream: CxiDg3.0:Opal1000.0 # cxig3614, source fee: FeeHxSpectrometer.0:OrcaFl40.0 src = psana.Source(params.spectra_filter.detector_address) dataset_name = "exp=%s:run=%s:idx" % (params.experiment, params.runs) print("Dataset string:", dataset_name) ds = psana.DataSource(dataset_name) spf = spectra_filter(params) if params.selected_filter == None: filter_name = params.spectra_filter.filter[0].name else: filter_name = params.selected_filter rank = 0 size = 1 max_events = sys.maxsize for run in ds.runs(): print("starting run", run.run()) # list of all events times = run.times() if params.skip_events is not None: times = times[params.skip_events:] nevents = min(len(times), max_events) # chop the list into pieces, depending on rank. This assigns each process # events such that the get every Nth event where N is the number of processes mytimes = [times[i] for i in range(nevents) if (i + rank) % size == 0] for i, t in enumerate(mytimes): evt = run.event(t) accepted, data, spectrum, dc_offset, all_data, all_data_raw = spf.filter_event( evt, filter_name) if not accepted: continue print(cspad_tbx.evt_timestamp(cspad_tbx.evt_time(evt)), "Publishing data for event", i) #header = "Event %d, m/f: %7.7f, f: %d"%(i, peak_max/flux, flux) header = "Event %d" % (i) if rank == 0: fee = Image(header, "FEE", data) # make a 2D plot publish.send("FEE", fee) # send to the display spectrumplot = XYPlot(header, 'summed 1D trace', list(range(data.shape[1])), spectrum) # make a 1D plot publish.send("SPECTRUM", spectrumplot) # send to the display fee = Image(header, "DC_OFFSET", dc_offset) # make a 2D plot publish.send("DC_OFFSET", fee) # send to the display fee = Image(header, "ALL_FEE", all_data) # make a 2D plot publish.send("ALL_FEE", fee) # send to the display fee = Image(header, "ALL_FEE_RAW", all_data_raw) # make a 2D plot publish.send("ALL_FEE_RAW", fee) # send to the display
from psana import * ds = DataSource('exp=xpptut15:run=54:smd') det = Detector('cspad') for nevent,evt in enumerate(ds.events()): img = det.image(evt) y = img.sum(axis=0) break from psmon.plots import Image,XYPlot from psmon import publish publish.local = True plotimg = Image(0,"CsPad",img) publish.send('IMAGE',plotimg) plotxy = XYPlot(0,"Y vs. X",range(len(y)),y) publish.send('XY',plotxy)
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)
theseEventCodes = evrDetectorObject.eventCodes(thisEvent) tssOpalImage = tssOpalDetectorObject.image(thisEvent) tempTss = 0 + tssOpalImage tssOpalImage = tssOpalImage[tssOpalROI[0][0]:tssOpalROI[0][1], tssOpalROI[1][0]:tssOpalROI[1][1]] opal1Image = opal1DetectorObject.image(thisEvent)[ opal1ROI[0][0]:opal1ROI[0][1], opal1ROI[1][0]:opal1ROI[1][1]] if any([None is k for k in [tssOpalImage, opal1Image]]): continue tssProfile = sum(tssOpalImage, axis=tssAxis) opal1Profile = sum(opal1Image, axis=opal1Axis) if (nEvent % 5 == 1): tssOpalPublishedImage = Image(0, "TSS_OPAL", tssOpalImage) publish.send('TSS_OPAL', tssOpalPublishedImage) opal1PublishedImage = Image(0, "OPAL1", opal1Image) publish.send('OPAL1', opal1PublishedImage) if 162 in theseEventCodes: byKickTssOpalProfile = 0 + tssProfile byKickOpal1Profile = 0 + opal1Profile byKickOpal1Image = 0 + opal1Image print("got bY kick " + str(nEvent)) continue #tssCorrelation = array(pandas.rolling_corr(pandas.Series(byKickTssOpalProfile),pandas.Series(tssProfile),21)) #opal1Correlation = array(pandas.rolling_corr(pandas.Series(opal1Profile),pandas.Series(byKickOpal1Profile),21))
for run in ds.runs(): times = run.times() mylength = len(times)//size mytimes= times[rank*mylength:(rank+1)*mylength] for n,t in enumerate(mytimes): evt = run.event(t) # random access if img is None: img = det.image(evt) # many complex run-dependent calibrations else: img += det.image(evt) if n>5: break import numpy as np img_all = np.empty_like(img) MPI.COMM_WORLD.Reduce(img,img_all) if rank==0: from pypsalg.AngularIntegrationM import * # algorithms ai = AngularIntegratorM() ai.setParameters(img_all.shape[0],img_all.shape[1], mask=np.ones_like(img_all)) bins,intensity = ai.getRadialHistogramArrays(img_all) from psmon import publish # real time plotting from psmon.plots import Image publish.local = True img = Image(0,"CsPad",img_all) publish.send('image',img) MPI.Finalize()
hitxprojhist_sum_all / (len(hitxprojhist_buff) * size), formats=".-") # make a 1D plot publish.send("HITHIST", hithist_plot) # send to the display # histogram of single shot ax6 = range(0, hithist.values.shape[0]) hit1shot_plot = XYPlot(evtGood, "Hit Hist 1 shot", ax6, hithist.values, formats=".-") # make a 1D plot publish.send("HIT1SHOT", hit1shot_plot) # send to the display # # opal_plot = Image(evtGood, "Opal", opal) # make a 2D plot publish.send("OPAL", opal_plot) # send to the display # # #opalscreen_plot = Image(evtGood, "Opal screen", opal_screen) # make a 2D plot #publish.send("OPALSCREEN", opalscreen_plot) # send to the display # Perspective transformation opal_plot2 = Image(evtGood, "Opal perspective transformed", opal_perspective) # make a 2D plot publish.send("OPALPERS", opal_plot2) # send to the display # Perspective transformation avg opal_plot3 = Image( evtGood, "Opal average perspective transformed", cv2.warpPerspective(opal_sum_all, M,
ax4 = range(0,len(moments_avg_arr)) moments_avg_plot = XYPlot(evtGood, "Standard Deviation of avg Histogram", ax4, moments_avg_arr,formats=".-") # make a 1D plot publish.send("MOMENTSRUNAVG", moments_avg_plot) # send to the display # average histogram of hits ax5 = range(0,hitxprojhist_sum_all.shape[0]) hithist_plot = XYPlot(evtGood, "Hit Hist2", ax5, hitxprojhist_sum_all/(len(hitxprojhist_buff)*size),formats=".-") # make a 1D plot publish.send("HITHIST", hithist_plot) # send to the display # histogram of single shot ax6 = range(0,hithist.data.shape[0]) hit1shot_plot = XYPlot(evtGood, "Hit Hist 1 shot", ax6, hithist.data,formats=".-") # make a 1D plot publish.send("HIT1SHOT", hit1shot_plot) # send to the display # # opal_plot = Image(evtGood, "Opal", opal) # make a 2D plot publish.send("OPAL", opal_plot) # send to the display # # opal_plot_avg = Image(evtGood, "Opal Average", opal_sum_all/(len(opal_circ_buff)*size)) # make a 2D plot publish.send("OPALAVG", opal_plot_avg) # send to the display # Exquisit plotting, acqiris ax_wf = range(0,len(wf)) wf_plot = XYPlot(evtGood, "TOF Trace", ax_wf, wf,formats=".-") # make a 1D plot publish.send("WF", wf_plot) # send to the display # Exquisit plotting, ion yield ax_ion = range(0,len(ion_yield)) ion_yield_plot = XYPlot(evtGood, "Ion Yield", ax_ion, ion_yield,formats=".-") # make a 1D plot publish.send("ION", ion_yield_plot) # send to the display