示例#1
0
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_acqiris_mpi(detectorObject, thisEvent):

    nevent = detectorObject['event_number']
    comm = detectorObject['myComm']
    rank = detectorObject['rank']

    selfName = detectorObject['self_name']
    y = detectorObject[selfName](thisEvent)[0][1]

    all_traces = {}
    all_traces[rank] = y

    if (sum(y) > -430):
        gatheredSummary = comm.gather(y, root=0)
    else:
        gatheredSummary = comm.gather(zeros([15000]), root=0)

    if rank == 0:
        for i in gatheredSummary:
            try:
                to_plot = XYPlot(time.time(), "x vs y", arange(len(i)), i)
                publish.send('my_plot', to_plot)
                print(sum(i))
            except:
                pass

        print(len(gatheredSummary))
示例#3
0
文件: master.py 项目: dasc01/PSANA
def plot(hd):

    for j in range(0,len(ftop)-1):
	ftop[j]=ftop[j+1]
	fmid[j]=fmid[j+1]
        fids[j]=fids[j+1]

    ftop[len(ftop)-1]=hd.myorig
    fmid[len(fmid)-1]=hd.myfit

    comp=hd.myobj['comp']
  
    fids[len(fids)-1]=comp['et'].fiducial()
    
    multop = MultiPlot(1, 'Original Image')
    mulmid = MultiPlot(1, 'Fitted   Image')

    for j in range(0,len(ftop)):
        if ftop[j] is not None :
      	    plottop = Image(fids[j],"Original",ftop[j])
      	    plotmid = Image(fids[j],"Fitted",fmid[j])
            multop.add(plottop)
            mulmid.add(plotmid)

    publish.send('ORIG', multop)
    publish.send('FIT', mulmid)
def plot_acqiris(detectorObject, thisEvent):
    selfName = detectorObject['self_name']
    y = detectorObject[selfName](thisEvent)[0][1]

    if (None != y):
        to_plot = XYPlot(time.time(), "x vs y", arange(len(y)), y)
        publish.send('my_plot', to_plot)
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 DebugPlot(x, y, title):
     """
     Publishes a debugspectrum
     """
     from psmon.plots import Image,XYPlot, MultiPlot
     from psmon import publish
     #publish.local = True
     plot = XYPlot(0, title, x, y)
     publish.send("UXSDebug", plot)
 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)
示例#8
0
def pushToHist(histName, n):
    global histList
    if(n > histList[histName].xaxis.high):
	n = histList[histName].xaxis.high - histList[histName].xaxis.binsize/2
    if(n < histList[histName].xaxis.low):
	n = histList[histName].xaxis.low + histList[histName].xaxis.binsize/2
    
    histList[histName].fill(n)
    xax = np.arange(histList[histName].xaxis.low, histList[histName].xaxis.high+histList[histName].xaxis.binsize, histList[histName].xaxis.binsize)
    histplot = Hist(0, histName, xax, histList[histName].data)
    publish.send(histName, histplot)
示例#9
0
    def endrun(self, evt, env):
        multi = psmonPlots.MultiPlot(self.eventcounter, 'MULTI', ncols=2)
        self.m_test = 5
        for chan in range(4):
            keystring = "acq_" + str(chan)
            matrix = evt.get(psana.ndarray_float64_2, keystring)
            title = keystring
            subplot = psmonPlots.Image(self.eventcounter, title, matrix)
            multi.add(subplot)

        psmonPublish.send('MULTI', multi)
示例#10
0
def plotOld(md, img_raw, img_fft, peak_plot, width_plot, dataDict):

    #plot1.ts = np.mean(normed)
    img_raw.image = md.img0
    img_fft.image = md.F0
    img_raw.ts = dataDict['nevents'][-1]
    img_fft.ts = dataDict['nevents'][-1]
    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]

    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)

    peak_plot.xdata = [eventMask, eventMask, eventMask, eventMask]
    peak_plot.ydata = [h_peak, v_peak, h_smooth, v_smooth]
    width_plot.xdata = [eventMask, eventMask, eventMask, eventMask]
    width_plot.ydata = [h_width, v_width, hw_smooth, vw_smooth]

    publish.send("RAW", img_raw)  # send to the display
    publish.send("FFT", img_fft)
    publish.send("peak", peak_plot)
    publish.send("width", width_plot)
示例#11
0
文件: image.py 项目: slaclab/psmon
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)
示例#12
0
文件: test.py 项目: slac-lcls/tmo
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'])
示例#13
0
    def publish_traces(self):
        # Calculate accumulated absorptions:
        abs_lon_mp = -np.log(
            self.lon_hists['signal_mp'] / self.lon_hists['norm_mp'])
        abs_lon_mm = -np.log(
            self.lon_hists['signal_mm'] / self.lon_hists['norm_mm'])
        abs_loff_mp = -np.log(
            self.loff_hists['signal_mp'] / self.loff_hists['norm_mp'])
        abs_loff_mm = -np.log(
            self.loff_hists['signal_mm'] / self.loff_hists['norm_mm'])
        # Make MultiPlot to hold plots:
        plots_title = 'XMCD Scan'
        xmcd_plots = MultiPlot(plots_title, plots_title, ncols=3)
        # Make traces plot:
        trace_plot_title = 'XAS Traces'
        trace_plot = XYPlot(trace_plot_title,
                            trace_plot_title,
                            [self.bin_edges[1:], self.bin_edges[1:]],
                            [(abs_lon_mp + abs_lon_mm) / 2,
                             (abs_loff_mm + abs_loff_mp) / 2],
                            xlabel=self.scan_key)
        # Make laser on/laser off difference plots:
        diff_plot_title = 'XMCD Traces'
        diff_plot = XYPlot(diff_plot_title,
                           diff_plot_title,
                           [self.bin_edges[1:], self.bin_edges[1:]],
                           [(abs_lon_mp - abs_lon_mm),
                            (abs_loff_mp - abs_loff_mm)],
                           xlabel=self.scan_key)
        # Make histogram plot of amounts of data collected
        norm_title = 'Normalization signal sums'
        norm_plot = XYPlot(
            norm_title,
            norm_title, [
                self.bin_edges[1:], self.bin_edges[1:], self.bin_edges[1:],
                self.bin_edges[1:]
            ], [
                self.lon_hists['norm_mp'], self.lon_hists['norm_mm'],
                self.loff_hists['signal_mp'], self.loff_hists['signal_mm']
            ],
            xlabel=self.scan_key)

        # Update plots:
        xmcd_plots.add(trace_plot)
        xmcd_plots.add(diff_plot)
        xmcd_plots.add(norm_plot)
        publish.send('xmcd_plots', xmcd_plots)
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)
示例#15
0
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
示例#16
0
def runmaster(args,nClients, mask):
    hd = hitdata()

    inith5(args)
    initHist('DropSize',50,500,2000)
    initHist('TOFhits',1000,-500,1000)
    initHist('IMGhits',1000,0,5000)

    bkgTOF = np.empty(10000)
    nTOF = 0

    startTime = time.time()

    while nClients > 0:
        # Remove client if the run ended
        if hd.recv():
#            print "end run called"
            nClients -= 1
            bkgTOF += hd.myobj['tof']
            nTOF = nTOF+hd.myobj['ntof']
        else:
#            print "Calling plot?"
            if hd.myobj['diodeDrop']:
                print 'master detected drop'
                plotDDrop = Image(0,"Diode Drop Image",hd.myobj['img'])
                publish.send('DDROP',plotDDrop)
                continue


            comp = hd.myobj['comp']
            size=(comp['drop']['a']+comp['drop']['b'])/2.0
            plot(hd, args)
            pushToHist('DropSize',size)
            pushToHist('TOFhits',comp['tofsum'])
            pushToHist('IMGhits',comp['imgsum'])
            writeh5(hd)
            
    endTime = time.time()
    hitRate = nHits / (endTime - startTime)
    print('Hitrate = ', hitRate)
    closeh5(mask, bkgTOF/nTOF, hitRate)
示例#17
0
 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)
示例#18
0
def main():
    args = parse_cli()
    max_updates = args.num_updates
    period = 1 / args.rate
    status_rate = 100
    bin_n = 100
    points_n = bin_n

    #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'

    counter = 0
    if args.plot_type == Hist:
        bins = np.arange(bin_n + 1)
    else:
        bins = np.arange(bin_n)
    val1 = np.zeros(bin_n)
    val2 = np.zeros(bin_n)
    val3 = np.zeros(bin_n)
    while counter < max_updates or max_updates < 1:
        # add data to val arrays
        pos = bin_n / 4.0
        width = bin_n / 16.0
        rnd1 = np.random.normal(pos, width, points_n)
        rnd2 = np.random.normal(3 * pos, width, points_n)
        rnd3 = np.random.normal(2 * pos, width, points_n)
        if args.plot_type == Hist:
            tmp_val1, _ = np.histogram(rnd1, bins)
            tmp_val2, _ = np.histogram(rnd2, bins)
            tmp_val3, _ = np.histogram(rnd3, bins)
            val1 += tmp_val1
            val2 += tmp_val2
            val3 += tmp_val3
        else:
            val1 = rnd1
            val2 = rnd2
            val3 = rnd3

        plot1, plot2, plot3 = args.func(counter, args.plot_type, bins, val1,
                                        val2, val3)

        publish.send('plot1', plot1)
        publish.send('plot2', plot2)
        publish.send('plot3', plot3)

        counter += 1

        if counter % status_rate == 0:
            print("Processed %d updates so far" % counter)

        time.sleep(period)
示例#19
0
def plot(hd, args):




    for j in range(0,len(ftop)-1):
	ftop[j]=ftop[j+1]
	fmid[j]=fmid[j+1]
	fbot[j]=fbot[j+1]
        fids[j]=fids[j+1]

    ftop[len(ftop)-1]=hd.myorig
    fmid[len(fmid)-1]=np.log10(100+abs(np.amin(hd.myfit))+hd.myfit)

    comp=hd.myobj['comp']

    ttPos = comp['epics']['TTSPEC:FLTPOS']
    delay = (ttA*ttPos**2 + ttB*ttPos + ttC)*1000 - 300

    #fids[len(fids)-1]=comp['tofsum']
    fids[len(fids)-1]=comp['imgsum']
    fbot[len(ftop)-1]=comp['tof']
    
    multop = MultiPlot(1, 'Original Image')
    mulmid = MultiPlot(1, 'Fitted   Image')
    mulbot = MultiPlot(1, 'TOF plot')# + args.exprun+'_' + args.label)

    for j in range(0,len(ftop)):
        if ftop[j] is not None :
      	    plottop = Image(fids[j],"Original",ftop[j])
      	    plotmid = Image(fids[j],"Fitted",fmid[j])
            plotbot = XYPlot(fids[j], "TOF", comp['tofAxis'], fbot[j])
            multop.add(plottop)
            mulmid.add(plotmid)
            mulbot.add(plotbot)

    publish.send('ORIG', multop)
    publish.send('FIT', mulmid)
    publish.send('TOFXY', mulbot)
示例#20
0
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])
示例#21
0
文件: fee_view.py 项目: dials/cctbx
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
示例#22
0
                     ' 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)

        time.sleep(arc_wait_time)

        continue  # don't accumulate data for the arced shot

    #%%
    cent_pe = l3Proc.CentPE(evt)
    if not (cent_pe < max_cent_pe and cent_pe > min_cent_pe):
        print '\'Central\' photon energy = '+str(np.round(cent_pe,2))+\
        '-> outside specified range, skipping event'

    image_buff[rolling_count] = opal_image
    x_proj_buff[rolling_count] = x_proj
    counts_buff.append(count_estimate)
示例#23
0
numbins_L3EnergyWeighted=100
minhistlim_L3EnergyWeighted=3300
maxhistlim_L3EnergyWeighted=3400

hist_L3_elec1mom = Histogram((numbins_L3_elec1mom_L3,minhistlim_L3_elec1mom_L3,\
                           mmaxhistlim_L3_elec1mom_L3),(numbins_L3_elec1mom_elec1mom,\
                           minhistlim_L3_elec1mom_elec1mom,maxhistlim_L3_elec1mom_elec1mom))

hist_L3Energy=Histogram((numbins_L3Energy,minhistlim_L3Energy,maxhistlim_L3Energy))
hist_L3EnergyWeighted=Histogram((numbins_L3EnergyWeighted,minhistlim_L3EnergyWeighted,maxhistlim_L3EnergyWeighted))

for nevt, evt in enumerate(ds.events()):
    print nevt
    energyL3=procL3Energy.L3Energy(evt)
    moments, numhits=procSHES.CalibProcess(evt, inPix=True)
    mom1=moments[0]

    hist_L3Energy.fill(energyL3)
    hist_L3EnergyWeighted.fill([energyL3], weights=[numhits])

    if nevt>100:
        break

avShotsPerL3Energy=hist_L3EnergyWeighted/np.float(hist_L3Energy.values)

L3_weighted_plot = XYPlot(nevt, 'L3_weighted', hist_L3EnergyWeighted.centers[0], hist_L3EnergyWeighted.values)
publish.send('L3 weighted', L3_weighted_plot)



示例#24
0
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)
                #xproj_int_avg_buff.append(xproj_int_sum_all[0]/(len(xproj_int_buff)*size))
                #moments_avg_buff.append(moments_sum_all[0]/(len(moments_buff)*size))
                ### moments history
                moments_buff.append(s)
                #moments_sum = np.array([sum(moments_buff)])#/len(moments_buff)

                if not 'opal_xproj_last_intenseshot' in locals():
                    opal_xproj_last_intenseshot = np.zeros_like(opal_thresh_xproj)

                if not 'hist_last_intense_single_shot' in locals():
                    hist_last_intense_single_shot = np.zeros_like(hithist.data)

                # Exquisit plotting
                ax = range(0,len(opal_thresh_xproj))
                xproj_plot = XYPlot(evtGood, "X Projection", ax, opal_thresh_xproj,formats=".-") # make a 1D plot
                publish.send("XPROJ", xproj_plot) # send to the display

                xproj_intenseshot_plot = XYPlot(evtGood, "X Projection of Last Intense Shot", ax, opal_xproj_last_intenseshot,formats=".-") # make a 1D plot
                publish.send("INTENSESHOTXPROJ", xproj_intenseshot_plot) # send to the display

                # #
                opal_hit_avg_arr = np.array(list(opal_hit_avg_buff))
                # print opal_hit_avg_buff
                ax2 = range(0,len(opal_hit_avg_arr))
                hitrate_avg_plot = XYPlot(evtGood, "Hitrate history", ax2, opal_hit_avg_arr,formats=".-") # make a 1D plot
                # print 'publish',opal_hit_avg_arr
                publish.send("HITRATE", hitrate_avg_plot) # send to the display
                # #
                #xproj_int_avg_arr = np.array(list(xproj_int_avg_buff))
                #ax3 = range(0,len(xproj_int_avg_arr))
                #xproj_int_plot = XYPlot(evtGood, "XProjection running avg history", ax3, xproj_int_avg_arr) # make a 1D plot
示例#26
0
def plot(plot1, xdata, ydata, nevent, plotName):
    plot1.xdata = xdata
    plot1.ydata = ydata
    plot1.ts = nevent
    publish.send(plotName, plot1)  # send to the display
示例#27
0
def histPlot(plot1, bins, values, nevent, plotName):
    plot1.bins = bins
    plot1.values = values
    plot1.ts = nevent
    publish.send(plotName, plot1)
示例#28
0
                ###### calculating moments of the hithist.data
                m,s = moments(hitxprojjitter_sum_all) #changed from hitxprojhist_sum_all

                ###### History on master
                print eventCounter*size, 'total events processed.'
                opal_hit_avg_buff.append(opal_hit_sum_all[0]/(len(opal_hit_buff)*size))
                #xproj_int_avg_buff.append(xproj_int_sum_all[0]/(len(xproj_int_buff)*size))
                #moments_avg_buff.append(moments_sum_all[0]/(len(moments_buff)*size))
                ### moments history
                moments_buff.append(s)
                #moments_sum = np.array([sum(moments_buff)])#/len(moments_buff)

                # Exquisit plotting
                ax = range(0,len(opal_thresh_xproj))
                xproj_plot = XYPlot(evtGood, "X Projection", ax, opal_thresh_xproj,formats=".-") # make a 1D plot
                publish.send("XPROJ", xproj_plot) # send to the display

                # #
                opal_hit_avg_arr = np.array(list(opal_hit_avg_buff))
                # print opal_hit_avg_buff
                ax2 = range(0,len(opal_hit_avg_arr))
                hitrate_avg_plot = XYPlot(evtGood, "Hitrate history", ax2, opal_hit_avg_arr,formats=".-") # make a 1D plot
                # print 'publish',opal_hit_avg_arr
                publish.send("HITRATE", hitrate_avg_plot) # send to the display
                # #
                #xproj_int_avg_arr = np.array(list(xproj_int_avg_buff))
                #ax3 = range(0,len(xproj_int_avg_arr))
                #xproj_int_plot = XYPlot(evtGood, "XProjection running avg history", ax3, xproj_int_avg_arr) # make a 1D plot
                #publish.send("XPROJRUNAVG", xproj_int_plot) # send to the display
                # #
                moments_avg_arr = np.array(list(moments_buff))
示例#29
0
                largestRun = c
                
if (largestRun[1] == 999): largestRun[1] = 'end'
print('final file choice is ' + str(largestRun[0]) + '-' + str(largestRun[1]) + '.txt')

import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('thresholds/' + str(largestRun[0]) + '-' + str(largestRun[1]) + '.txt')

# getfloat() raises an exception if the value is not a float
# getint() and getboolean() also do this for their respective types
thresh =dict()
thresh['tof'] = config.getfloat('Thresholds', 'tof')
thresh['diode'] = config.getfloat('Thresholds', 'diode')
thresh['tofUpper'] = config.getfloat('Thresholds', 'tofUpper')
thresh['image'] = config.getfloat('Thresholds', 'image')


print('threshs', thresh['tof'], thresh['diode'])

if rank==0:
    maskplot = Image(0,'mask',mask)
    publish.send('mask', maskplot)
    runmaster(args,numClients, mask)
else:
    runclient(args, mask, thresh)


MPI.Finalize()
示例#30
0
def imshow(im0, imName, img, eventNum):
    im0.image = img
    im0.ts = np.max(eventNum, 0)
    publish.send(imName, im0)
示例#31
0
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)
示例#32
0
        #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))
        #counts = np.roll(counts, -frameidx)
        #counts = scipy.ndimage.gaussian_filter1d(counts,1)
        #plotxy = XYPlot(0, "UXS Counts {}".format(str(evt.get(EventId))), range(numframes), counts)
        #publish.send("UXSMonitorCounts", plotxy)
 
    # Iterate framenumber
    frameidx += 1
    frameidx = frameidx%numframes

    # Save to file
    if saveNow:
        while os.path.exists(savePath.format(saveIterator)):
示例#33
0
                ###### calculating moments of the hithist.data
                m,s = moments(hitxprojhist_sum_all)

                ###### History on master
                print eventCounter*size, 'total events processed.'
                #opal_hit_avg_buff.append(opal_hit_sum_all[0]/(len(opal_hit_buff)*size))
                #gdet_avg_buff.append(gasdet_sum_all[0]/(len(gdet_buff)*size))
                #moments_avg_buff.append(moments_sum_all[0]/(len(moments_buff)*size))
                ### moments history
                moments_buff.append(s)
                #moments_sum = np.array([sum(moments_buff)])#/len(moments_buff)

                # Exquisit plotting
                ax = range(0,len(opal_thresh_xproj))
                xproj_plot = XYPlot(eventCounter*size, "X Projection", ax, opal_thresh_xproj,formats=".-") # make a 1D plot
                publish.send("XPROJ", xproj_plot) # send to the display

                # #
                opal_hit_avg_arr = np.array(list(opal_hit_avg_buff))
                # print opal_hit_avg_buff
                ax2 = range(0,len(opal_hit_avg_arr))
                hitrate_avg_plot = XYPlot(eventCounter*size, "Hitrate history", ax2, opal_hit_avg_arr,formats=".-") # make a 1D plot
                # print 'publish',opal_hit_avg_arr
                publish.send("HITRATE", hitrate_avg_plot) # send to the display
                # #

                gdet_avg_buff_arr = np.array(list(gdet_avg_buff))
                ax3 = range(0,len(gdet_avg_buff_arr))
                gdet_avg_buff_plot = XYPlot(eventCounter*size, "Gas detector running avg history", ax3, gdet_avg_buff_arr) # make a 1D plot
                publish.send("GASDET", gdet_avg_buff_plot) # send to the display
                # #
示例#34
0
        print nevt
        multi = MultiPlot(nevt, 'MULTI')
        vShotsPerL3Energy = np.nan_to_num(hist_L3EnergyWeighted.values /
                                          hist_L3Energy.values)
        L3_weighted_plot = XYPlot(nevt, 'L3', hist_L3EnergyWeighted.centers[0],
                                  vShotsPerL3Energy)
        #publish.send('L3', L3_weighted_plot)
        multi.add(L3_weighted_plot)
        vShotsPerL3Energy_un = np.nan_to_num(
            hist_L3EnergyWeighted_unnorm.values / hist_L3Energy.values)
        L3_weighted_plot_un = XYPlot(nevt, 'L3UN',
                                     hist_L3EnergyWeighted.centers[0],
                                     vShotsPerL3Energy_un)
        #publish.send('L3UN', L3_weighted_plot_un)
        multi.add(L3_weighted_plot_un)
        publish.send('MULTI', multi)
        filename = "../npz/ana_itof_run_%d" % run
        np.savez(filename,
                 vShotsPerL3Energy=vShotsPerL3Energy,
                 vShotsPerL3Energy_un=vShotsPerL3Energy_un,
                 hist_L3Energy_centers=hist_L3EnergyWeighted.centers[0])

    #break
vShotsPerL3Energy = np.nan_to_num(hist_L3EnergyWeighted.values /
                                  hist_L3Energy.values)

print "tset"

L3_weighted_plot = XYPlot(nevt, 'L3', hist_L3EnergyWeighted.centers[0],
                          vShotsPerL3Energy)
publish.send('L3', L3_weighted_plot)
示例#35
0
    mytimes = [times[i] for i in xrange(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', 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

if __name__ == "__main__":
  run(sys.argv[1:])
示例#36
0
  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 xrange(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)
示例#37
0
            #moments_sum = np.array([sum(moments_buff)])#/len(moments_buff)
            opal_pers_xproj = np.sum(opal_perspective, axis=0)
            hitrate_roi_buff.append(
                np.sum(hitxprojhist_sum_all[40:60]) /
                (len(hitxprojhist_buff) * size))

            #####################################################################################################

            ###################################### EXQUISIT PLOTTING ############################################
            ax = range(0, len(opal_thresh_xproj))
            xproj_plot = XYPlot(evtGood,
                                "X Projection",
                                ax,
                                opal_thresh_xproj,
                                formats=".-")  # make a 1D plot
            publish.send("XPROJ", xproj_plot)  # send to the display

            # #
            opal_hit_avg_arr = np.array(list(opal_hit_avg_buff))
            # print opal_hit_avg_buff
            ax2 = range(0, len(opal_hit_avg_arr))
            hitrate_avg_plot = XYPlot(evtGood,
                                      "Hitrate history",
                                      ax2,
                                      opal_hit_avg_arr,
                                      formats=".-")  # make a 1D plot
            # print 'publish',opal_hit_avg_arr
            publish.send("HITRATE", hitrate_avg_plot)  # send to the display
            # #
            axroihit = range(0, len(hitrate_roi_buff))
            hitrate_avg_plot2 = XYPlot(evtGood,
示例#38
0
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)
示例#39
0
    cam1 = evt.get(ndarray_float64_3,src1,'calibrated')
    cam2 = evt.get(ndarray_float64_3,src2,'calibrated')
    cam2x2 = evt.get(ndarray_float64_3,src2x2,'calibrated')
    if cam1 is None or cam2 is None or cam2x2 is None:
        print cam1.shape
        print cam2.shape
        print cam2x2.shape
    cam1img = evt.get(ndarray_float64_2,src1,'image')
    cam2img = evt.get(ndarray_float64_2,src2,'image')

    if cam1img is None or cam2img is None:
        print cam1img.shape
        print cam2img.shape

    cam = Image(1, "cspad", cam1img) # make a 2D plot
    publish.send("CSPAD", cam) # send to the display

    X = cls.get(ndarray_float64_1, src1, 'x-pix-coords').reshape((32,185,388))
    Y = cls.get(ndarray_float64_1, src1, 'y-pix-coords').reshape((32,185,388))
    #unbondedMask = cls.get(ndarray_int32_1, src1, 'pix_mask')

    cff = CalibFileFinder(ds.env().calibDir(), 'CsPad::CalibV1', pbits=0)
    statusfile = cff.findCalibFile(det1, 'pixel_status', evt.run())
    print statusfile
    pixStatus = np.loadtxt(statusfile)
    print pixStatus.shape
    
    print cam1.shape
    print X.shape
    print Y.shape
    #print unbondedMask.shape
示例#40
0
def plot(plot0, plotName, xdata, ydata):
    plot0.xdata = xdata
    plot0.ydata = ydata
    publish.send(plotName, plot0)
示例#41
0
def main():
    my_list = []

    #pv_list = [gdet, gmd, ebeam]

    gdet, gmd, e_beam = get_time_stamped_data()
    e_beam_mean = np.mean(e_beam)
    e_beam_std = np.std(e_beam)
    e_range = 20 + 0 * 6 * e_beam_std
    n_bins = 100
    my_bins = arange(e_beam_mean - e_range, e_beam_mean + e_range,
                     2 * e_range / n_bins)

    e_beam_histogram = np.histogram(e_beam, my_bins)[0]
    e_beam_histogram /= sum(e_beam_histogram)
    plot_ebeam_hist = XYPlot(0, "counts vs. e_beam", my_bins[1:],
                             e_beam_histogram)

    gmd_histogram = np.histogram(e_beam * gmd, my_bins)[0] / e_beam_histogram
    plot_gmd_hist = XYPlot(0, "counts vs. e_beam", my_bins[1:], gmd_histogram)

    #publish.local = True
    hist_size = 2400

    gdet_list, gmd_list, e_beam_list = (array([]), array([]), array([]))

    while (True):

        try:

            gdet, gmd, e_beam = get_time_stamped_data()

            e_beam_mean = np.mean(e_beam)
            e_beam_std = np.std(e_beam)
            e_range = 10 + 0 * 6 * e_beam_std
            n_bins = 100
            my_bins = arange(e_beam_mean - e_range, e_beam_mean + e_range,
                             2 * e_range / n_bins)

            e_beam_list = append(e_beam_list[-hist_size:], e_beam)
            gmd_list = append(gmd_list[-hist_size:], gmd)
            gdet_list = append(gdet_list[-hist_size:], gdet)

            e_beam_histogram = np.histogram(e_beam_list, my_bins)[0]
            gmd_histogram = np.histogram(
                e_beam_list, my_bins,
                weights=gmd_list)[0] * 1.0 / (e_beam_histogram + 1e-12)
            gdet_histogram = np.histogram(
                e_beam_list, my_bins,
                weights=gdet_list)[0] * 1.0 / (e_beam_histogram + 1e-12)

            plot_ebeam_hist = XYPlot(0, "counts vs. e_beam", my_bins[1:],
                                     e_beam_histogram)
            publish.send('counts_ebeam', plot_ebeam_hist)

            plot_gmd_hist = XYPlot(0, "gmd vs. e_beam", my_bins[1:],
                                   gmd_histogram)
            publish.send('gmd_ebeam', plot_gmd_hist)

            normalized_e_beam_histogram = e_beam_histogram * 1.0 / sum(
                nan_to_num(e_beam_histogram) + 1e-12)
            normalized_gmd_histogram = gmd_histogram * 1.0 / sum(
                nan_to_num(gmd_histogram))
            normalized_gdet_histogram = gdet_histogram * 1.0 / sum(
                nan_to_num(gdet_histogram))

            plot_overlay = XYPlot(
                0, "gmd and ebeam", [my_bins[1:], my_bins[1:]],
                [normalized_e_beam_histogram, normalized_gmd_histogram])
            #plot_overlay = XYPlot(0,"gmd and ebeam",[my_bins[1:],my_bins[1:],my_bins[1:]],[normalized_e_beam_histogram,normalized_gmd_histogram,normalized_gdet_histogram])
            x_temp = arange(-10, 10, 1)
            publish.send('both_gmd_ebeam', plot_overlay)

        except KeyboardInterrupt:
            break
        except ValueError:
            print("GMD likely down")
            time.sleep(2)
def make_acq_svd_basis(detectorObject, thisEvent, previousProcessing):
    selfName = detectorObject['self_name']
    config_parameters = {
        "thresh_hold": 0.05,
        "waveform_mask": arange(1200, 1230),
        "eigen_basis_size": 25,
        "offset_mask": arange(300)
    }

    eigen_system = {}

    ##############################
    #### initializing arrays #####
    ##############################
    if None is detectorObject[selfName](thisEvent):
        return None

    if (len(detectorObject[selfName](thisEvent)) == 4):
        the_wave_forms = detectorObject[selfName](thisEvent)
    else:
        the_wave_forms = detectorObject[selfName](thisEvent)[0]

    for i in arange(len(the_wave_forms)):

        try:
            eigen_system["ch" + str(i)] = previousProcessing["ch" + str(i)]
        except (KeyError, TypeError) as e:
            try:
                y = 1.0 * the_wave_forms[i]
                y -= mean(y[config_parameters['offset_mask']])
                eigen_system["ch" + str(i)] = {
                    'eigen_wave_forms': y,
                    'eigen_weightings': [1],
                    'norm_eigen_wave_forms': [1]
                }
            except (KeyError, TypeError) as e:
                eigen_system["ch" + str(i)] = {
                    'eigen_wave_forms': None,
                    'eigen_weightings': None,
                    'norm_eigen_wave_forms': None
                }

    ##############################
    ###main part of calculation###
    ##############################
    new_eigen_system = {}
    for i in arange(len(the_wave_forms)):

        y = 1.0 * the_wave_forms[i]
        y -= mean(y[config_parameters['offset_mask']])
        start_time = time.time()
        new_eigen_system["ch" + str(i)] = svd_update(
            eigen_system["ch" + str(i)], y, config_parameters)

    #print(time.time() - start_time)
    #for j in eigen_system["ch"+str(i)]:
    #	print(str(j)+", "+str(eigen_system["ch"+str(i)][j].shape))

    ########################################################
    ########plotting for real time SVD debugging############
    ########################################################
    publish.local = True
    try:
        wave_to_plot = new_eigen_system["ch2"]['norm_eigen_wave_forms']
        to_plot = XYPlot(
            time.time(), "eigen_system",
            [arange(len(wave_to_plot[0])),
             arange(len(wave_to_plot[0]))], [wave_to_plot[0], wave_to_plot[1]])
        publish.send('eigen_system_' + selfName, to_plot)
        #psplot -s hostname -p 12303 eigen_system
    except:
        pass

    ########################################################
    ########end of  SVD debugging###########################
    ########################################################

    return new_eigen_system