Skip to content

psana.detector.areadetector

Methods common to area (pixel) detectors. AreaDetector adds access to calibration constants and geometry (underscore-prefixed helpers such as _pedestals(), _gain(), _mask(), _pixel_coords()) and image(evt, ...); AreaDetectorRaw adds raw(evt) and the generic calib(evt), (raw - pedestals) * gain_factor * mask. Concrete detector classes (ePix, Jungfrau, Opal, ...) in psana/psana/detector/ derive from these and override calib where needed. This module is the example area-detector module for the API reference; epix10ka.py and jungfrau.py follow the same pattern.

Notes for reading the reference below:

  • Unlike the other API pages, this page also lists the methods whose names start with one underscore, because user code calls them as det.raw._pedestals(), det.raw._mask(**kwa), det.raw._calibconstants() and so on.
  • det.raw._uniqueid is an attribute, not a method, and is not listed: it is set in DetectorImpl._reset (psana/psana/detector/detector_impl.py) from the Configure data. It is the detector type followed by the id of each segment, joined with _ (built in psana/psana/dgrammanager.py), and is the detector name used to fetch calibration constants (except for exp="xpptut15", for which Run._setup_run_calibconst in psana/psana/psexp/run.py uses the fixed name cspad_detnum1234; see Calibration constants).
  • raw(evt, copy=True): copy is a parameter, although the generated section lists it under "Returns". For a detector with more than one segment the segments are stacked into a buffer that the next call reuses (while shape and dtype stay the same); copy=False returns that buffer instead of a copy. For a single segment the segment's array is returned in both cases.

See Detector interface and Calibration constants.

psana.detector.areadetector

Data access methods common for all AREA DETECTORS
=================================================

Usage::

  from psana.detector.areadetector import AreaDetector, AreaDetectorRaw

  o = AreaDetector(*args, **kwa)    # inherits from DetectorImpl(*args, **kwa)

  a = o._segment_numbers  # alias of o._sorted_segment_inds, where inds stands for indices
  a = o._det_calibconst()

  a = o._pedestals(all_segs=False)
  a = o._offset(all_segs=False)
  a = o._gain(all_segs=False)
  a = o._rms(all_segs=False)
  a = o._status(all_segs=False)
  a = o._mask_calib(all_segs=False)
  a = o._common_mode()
  a = o._det_geotxt_and_meta()
  a = o._det_geotxt_default()
  a = o._det_geo()
  a = o._pixel_coord_indexes(pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True, cframe=0, all_segs=False, **kwa)
  a = o._pixel_coords(do_tilt=True, cframe=0, all_segs=False, **kwa)

  a = o._shape_as_daq()
  a = o._number_of_segments_total()

  a = o._mask_default(dtype=DTYPE_MASK, all_segs=False)
  a = o._mask_calib()
  a = o._mask_calib_or_default(dtype=DTYPE_MASK)
  a = o._mask_from_status(status_bits=(1<<64)-1,                          stextra_bits=(1<<64)-1,                          dtype=DTYPE_MASK, **kwa) # gain_range_inds=(0,1,2,3,4)
  a = o._mask_neighbors(mask, rad=9, ptrn='r')
  a = o._mask_edges(width=0, edge_rows=1, edge_cols=1, dtype=DTYPE_MASK, **kwa)
  a = o._mask_center(wcenter=0, center_rows=1, center_cols=1, dtype=DTYPE_MASK, **kwa)
  a = o._mask_comb(**kwa) # the same as _mask but w/o caching
  a = o._mask(status=True, status_bits=0xffff, stextra_bits=(1<<64)-1, gain_range_inds=(0,1,2,3,4),              neighbors=False, rad=3, ptrn='r',              edges=True, width=0, edge_rows=10, edge_cols=5,              center=True, wcenter=0, center_rows=5, center_cols=3,              calib=False,              umask=None,              force_update=False,              all_segs=False)
  a = o.image(self, evt, nda=None, value_for_missing_segments=None, **kwa)


  o = AreaDetectorRaw(*args, **kwa) # inherits from AreaDetector(*args, **kwa), adds raw and calib methods
  a = o.raw(evt)
  a = o.calib(evt, cmpars=(7,2,100,10), **kwa)
  a = o.calib(evt, **kwa)

2020-11-06 created by Mikhail Dubrovin

AreaDetector

AreaDetector(*args, **kwargs)

Bases: DetectorImpl

Collection of methods common for self = det.raw, det.fex, etc.

_calibconstants

_calibconstants(**kwa)

Returns cached object of CalibConstants derived from DetectorImpl._calibconst - dict from DB.

_info_calibconst

_info_calibconst()

_arr_for_daq_segments

_arr_for_daq_segments(arr, **kwa)

Returns unchanged arr if all_segs=True, othervise returns sub-array for presented in daq segments.

_det_calibconst

_det_calibconst(metname, **kwa)

Returns constants of ctype metname for daq segments of for entire detector is all_segs=True.

_pedestals

_pedestals(**kwa)

_offset

_offset(**kwa)

_rms

_rms(**kwa)

_status

_status(**kwa)

_mask_calib

_mask_calib(**kwa)

_common_mode

_common_mode(**kwa)

_gain

_gain(**kwa)

_gain_factor

_gain_factor(**kwa)

_det_geotxt_and_meta

_det_geotxt_and_meta()

_fname_geotxt_default

_fname_geotxt_default()

returns (str) file name for default geometry constants lcls2/psana/psana/pscalib/geometry/data/geometry-def-*.data

_det_geotxt_default

_det_geotxt_default()

returns (str) default geometry constants from lcls2/psana/psana/pscalib/geometry/data/geometry-def-*.data

_det_geo

_det_geo()

Returns cached object self._geo of GeometryAccess() from CalibConstants, loads it from default file if missing in CalibConstants.

_pixel_coord_indexes

_pixel_coord_indexes(**kwa)

_pixel_coords

_pixel_coords(**kwa)

_pixel_xy_at_z

_pixel_xy_at_z(**kwa)

_number_of_segments_daq

_number_of_segments_daq()

_number_of_segments_total

_number_of_segments_total()

_shape_as_daq

_shape_as_daq()

_shape_total

_shape_total()

_substitute_value_for_missing_segments

_substitute_value_for_missing_segments(nda_daq, value) -> Array3d

image

image(evt, nda=None, value_for_missing_segments=None, **kwa) -> Array2d

Returns 2-d image. If value_for_missing_segments is specified, all missing segments will be substituted with this value and shape = shape for all segments, otherwice image for available self._segment_numbers will be generated.

_maskalgos

_maskalgos(logger_method=logger.debug)

returns cached (in self.maskalgos) MaskAlgos. Uses self._kwargs from AreaDetector to initialize MaskAlgos

_mask_method_wrapper

_mask_method_wrapper(metname, **kwa)

wrapper for all mask* methods to utilise them from class MaskAlgos. Use it in stead of similar decorator

_mask_default

_mask_default(dtype=DTYPE_MASK, **kwa)

_mask_calib_or_default

_mask_calib_or_default(dtype=DTYPE_MASK, **kwa)

_mask_from_status

_mask_from_status(status_bits=65535, stextra_bits=(1 << 64) - 1, stci_bits=(1 << 64) - 1, gain_range_inds=None, dtype=DTYPE_MASK, **kwa)

_mask_neighbors

_mask_neighbors(mask, rad=9, ptrn='r', **kwa)

_mask_edges

_mask_edges(width=0, edge_rows=1, edge_cols=1, dtype=DTYPE_MASK, **kwa)

_mask_center

_mask_center(wcenter=0, center_rows=1, center_cols=1, dtype=DTYPE_MASK, **kwa)

_mask_comb

_mask_comb(status=True, neighbors=False, edges=False, center=False, calib=False, umask=None, dtype=DTYPE_MASK, **kwa)

Returns combined mask controlled by the keyword arguments.

Returns:

Type Description
np.array: dtype=np.uint8, shape as det.raw - mask array of 1 or 0 or None if all switches are False.

_mask

_mask(**kwa)

Returns cached mask. kwargs passed from Detector(..., kwargs)

AreaDetectorRaw

AreaDetectorRaw(*args, **kwargs)

Bases: AreaDetector

Collection of methods for self = det.raw, e.g. det.raw.raw(...)/calib/image etc.

raw

raw(evt, copy=True) -> Array3d

Returns dense 3-d numpy array of segment data from dict self._segments(evt).

With more than one segment, the segment arrays are stacked into an internal buffer that is reused across calls while their shape and dtype stay the same. With one segment, that segment's raw array is returned as is (not stacked and not copied, whatever copy is).

Parameters:

Name Type Description Default
evt event

psana event object, ex. next(run.events()).

required
copy bool

If True, returns a copy of the stacked buffer to avoid view aliasing across events; if False, returns a view of that buffer, which later calls can overwrite.

True

Returns:

Type Description
ndarray or None

Raw data, ndim=3, shape: as data (with one segment, that segment's raw array unchanged). None if evt is None or self._segments(evt) is None.

calib

calib(evt, **kwa) -> Array3d

Returns calibrated array of data shaped as daq: calib = (raw - peds) * gfac * mask. Should be overridden for more complicated cases.