Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Averaging Over Scan Steps With An Integrating Detector

In this case the images being summed are uint16, so the sums overflow, but the idea is correct.Run with "mpirun -n 5 python myscript.py"

Code Block
languagepy
from psana import DataSource
import os
import numpy as np
os.environ['PS_SMD_N_EVENTS'] = '50' # Number of integrating detector events
os.environ['PS_SRV_NODES']='1'

ds = DataSource(exp='rixx1003721', run=161, intg_det='epixhr')
smd = ds.smalldata(filename='phil.h5')
myrun = next(ds.runs())
epix = myrun.Detector('epixhr')
nevt=0
step_sumsavgs = {}
for nstep,step in enumerate(myrun.steps()):
    localsum = None
    for nevt,evt in enumerate(step.events()):
        if localsum is None:
            localsum = epix.raw.raw(evt)
        else:
            # convert from uint16 to uint32 so we don't overflow the sum
            localsum += epix.raw.raw(evt).astype(np.uint32)
    step_sums[str(nstep)]sum = smd.sum(localsum)
    step_count = smd.sum(localsum)nevt+1) # plus 1 since python counts from 0
if smd.summary:
    # check if we are the one mpi rank that sees the sums
    if step_sum is not None:
        step_avgs[str(nstep)] = step_sum/step_count
        smd.save_summary(step_sumsavgs)
smd.done()