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()):
    print('step',nstep)
    localsum = None
    nsum = 0
    for nevt,evt in enumerate(step.events()):
        # convert from uint16 to uint32 so we don't overflow the sum
        raw = epix.raw.raw(evt).astype(np.uint32)
        if raw is not None:
            nsum+=1
            if localsum is None:
                localsum = epix.raw.raw(evt)

            else:
                localsum += epix.raw.raw(evtraw
    step_sum = smd.sum(localsum)
    step_nsum = smd.sum(nsum)
    # check if we are the one mpi rank that sees the sums
    if step_sum is not None:
        step_avgs[str(nstep)] = smd.sum(localsum)step_sum/step_nsum
if smd.summary:
    smd.save_summary(step_sumsavgs)
smd.done()

Accessing Detector Calibration Constants

Code Block
languagepy
from psana import DataSource
ds = DataSource(exp='uedcom103',run=796)
myrun = next(ds.runs())
epix = myrun.Detector('epixquad')
print(epix.calibconst)