def _initialize_default_detectors(self): self._default_detectors = [] for detector_name in ['EBeam', 'PhaseCavity', 'FEEGasDetEnergy']: try: det = Detector(detector_name) self._default_detectors.append(det) except KeyError as e: pass # add all Evrs (there may be more than one) self._evr_cfgcodes = [] for n in DetNames(): if ':Evr.' in n[0]: det = Detector(n[0]) self._default_detectors.append(det) cfg = det._fetch_configs() assert len(cfg) == 1 self._evr_cfgcodes += [e.code() for e in cfg[0].eventcodes()] self._evr_cfgcodes = set(self._evr_cfgcodes) self._evr_cfgcodes = list(self._evr_cfgcodes) self._evr_cfgcodes.sort() return
def get_calib_file_path(env, address, run): """ Findes the path to the SLAC metrology file stored in a psana environment object's calibration store @param env psana environment object @param address address string for a detector @param run psana run object or run number """ from psana import Detector try: # try to get it from the detector interface psana_det = Detector(address, run.env()) return psana_det.pyda.geoaccess(run).path except Exception, e: pass
def env_dxtbx_from_slac_metrology(run, address, metro=None): """ Loads a dxtbx cspad cbf header only object from the metrology path stored in a psana run object's calibration store @param env psana run object @param address address string for a detector """ if metro is not None: # FIXME: get metrology from a pickle file until det interface is ready cbf = get_cspad_cbf_handle(None, metro, 'cbf', None, "test", None, 100, verbose = True, header_only = True) from dxtbx.format.FormatCBFCspad import FormatCBFCspadInMemory return FormatCBFCspadInMemory(cbf) from psana import Detector try: # try to load the geometry from the detector interface psana_det = Detector(address, run.env()) geometry = psana_det.pyda.geoaccess(run) except Exception, e: geometry = None
def get_calib_file_path(env, address, run): """ Findes the path to the SLAC metrology file stored in a psana environment object's calibration store @param env psana environment object @param address address string for a detector @param run psana run object or run number """ from psana import Detector # # try to get it from the detector interface # try: start("load geometry from detector") psana_det = Detector(address, run.env()) ret = psana_det.pyda.geoaccess(run.run()).path stop("load geometry from detector") return ret except Exception as e: pass # # try to get it from the calib store directly # from psana import ndarray_uint8_1, Source start("load geometry from calib store") cls = env.calibStore() src = Source('DetInfo(%s)' % address) path_nda = cls.get(ndarray_uint8_1, src, 'geometry-calib') stop("load geometry from calib store") if path_nda is None: return None return ''.join(map(chr, path_nda))
def env_dxtbx_from_slac_metrology(run, address): """ Loads a dxtbx cspad cbf header only object from the metrology path stored in a psana run object's calibration store @param env psana run object @param address address string for a detector """ from xfel.command_line.xtc_process import PSANA2_VERSION if PSANA2_VERSION: det = run.ds.Detector(address) geometry = det.geometry(run) else: from psana import Detector try: # try to load the geometry from the detector interface psana_det = Detector(address, run.env()) geometry = psana_det.pyda.geoaccess(run.run()) except Exception as e: geometry = None if geometry is None: metro_path = get_calib_file_path(run.env(), address, run) elif geometry.valid: metro_path = None else: from libtbx.utils import Sorry import socket, os raise Sorry("Could not read geometry, hostname: %s"%socket.gethostname()) if metro_path is None and geometry is None: return None metro = read_slac_metrology(metro_path, geometry) cbf = get_cspad_cbf_handle(None, metro, 'cbf', None, "test", None, 100, verbose = True, header_only = True) from dxtbx.format.FormatCBFCspad import FormatCBFCspadInMemory return FormatCBFCspadInMemory(cbf)
#!/usr/bin/env python #-------------------- import numpy as np from psana import DataSource, Detector ds = DataSource('exp=amox27716:run=100') det = Detector('AmoEndstation.0:Acqiris.1') myrun = next(ds.runs()) for n,evt in enumerate(myrun.events()): v = det.raw(evt) print 'Event:%03d'%n, '\n' if v is not None else '', v if v is not None : break nda = np.array(v) print 'raw.shape:', nda.shape #nbins = nda.shape[-1]; img.shape = (nda.size/nbins, nbins) import matplotlib.pyplot as plt style = ('b-', 'r-', 'g-', 'k-', 'm-', 'y-', 'c-', ) plt.figure(figsize=(16,4)) for ch in range(2,7) : w = nda[0,ch,5000:30000] print 'ch:%02d wave.shape: %s'%(ch,str(w.shape)) plt.plot(w, style[ch]) #t = nda[1,ch,5000:30000] #plt.plot(t, w, style[ch]) plt.xlabel('bin', fontsize=14) plt.ylabel('intensity', fontsize=14)
#!/usr/bin/env python #-------------------- import sys import numpy as np from psana import DataSource, Detector from pypsalg import find_edges #dsname = 'exp=xpptut15:run=280' dsname = 'exp=amox27716:run=100' detname = 'AmoEndstation.0:Acqiris.1' #detname = 'AmoEndstation.0:Acqiris.2' # for xpptut15 ch:0 - MCP ds = DataSource(dsname) det = Detector(detname) ch = int(sys.argv[1]) if len(sys.argv) > 1 else 2 # Acqiris chanel for nevent, evt in enumerate(ds.events()): r = det.raw(evt) nda = np.array(r) print 'Event:%03d' % nevent, '\n' if r is not None else '', r if r is None: continue waveforms, times = r # find edges for channel 0 # parameters: baseline, threshold, fraction, deadtime, leading_edges edges = find_edges(waveforms[ch], 0.0, -0.05, 1.0, 5.0, True) # pairs of (amplitude,sampleNumber) print 'edges for channel %02d:' % ch for n, (v, bin) in enumerate(edges): print ' edge:%02d bin:%05d value:%6.3f' % (n, bin, v)