Skip to content

psana.detector.calibconstants

CalibConstants wraps the calibration constants of one detector (det.calibconst, a dict {ctype: (data, metadata)} fetched from the calibration database when the run is opened) and provides convenience accessors (pedestals(), rms(), gain(), gain_factor(), status()), geometry (geo(), pixel coordinates and indexes) and image(nda, ...). Area detectors create it on demand (det.raw._calibconstants()).

The constructor is CalibConstants(calibconst, detname, **kwa). The "Usage" block in the module docstring below writes CalibConstants(calibconst, **kwa) and leaves out detname, which is required: one instance is kept per detname, and creating it again with the same name returns that instance, reset to the new calibconst.

See Calibration constants.

psana.detector.calibconstants

Class CalibConstants with convenience methods to access info from dict returned from DB
=======================================================================================

Usage::

  from psana.detector.calibconstants import CalibConstants

  o = CalibConstants(calibconst, detname, **kwa)
  v = o.calibconst()
  v = o.cons_and_meta_for_ctype(ctype='pedestals')
  v = o.cached_array(p, ctype='pedestals')
  v = o.pedestals()
  v = o.rms()
  v = o.status(ctype='pixel_status') # for ctype pixel_status or specified
  v = o.status_extra()               # for ctype status_extra
  v = o.mask_calib()
  v = o.common_mode()
  v = o.gain()
  v = o.gain_factor()
  v = o.shape_as_daq()
  v = o.number_of_segments_total()
  v = o.geotxt_and_meta()
  v = o.geo()
  v = o.pixel_coords(**kwa)
  v = o.pixel_coord_indexes(**kwa)
  v = o.cached_pixel_coord_indexes(segnums, **kwa)
  v = o.image(nda, segnums=None, **kwa)
  v = o.pix_rc()
  v = o.pix_xyz()
  v = o.interpol_pars()
  s = o.info_calibconst()

2022-07-07 created by Mikhail Dubrovin

CalibConstants

CalibConstants(calibconst, detname, **kwa)

Access to one detector's calibration constants and to the geometry-based image mapping.

calibconst is the dict from the calibration DB that maps a constant type to a (data, metadata) tuple. Instances are shared per detname: creating the class again with the same name returns the existing instance, reset to the new calibconst.

Parameters:

Name Type Description Default
calibconst
required
calib_constants_all_types
required
**kwa
{}
used
required

calibconst

calibconst()

Return the calibration dict, or None (with a debug message) if it is None.

cons_and_meta_for_ctype

cons_and_meta_for_ctype(ctype='pedestals')

Return the (data, metadata) tuple stored for ctype, or (None, None) if the calibration dict or that entry is missing.

cached_array

cached_array(p, ctype='pedestals')

Returns cached array of constants for ctype.

pedestals

pedestals()

Return the 'pedestals' constant array, or None if it is absent.

Calls cached_array(self._pedestals, 'pedestals'). _pedestals is reset to None and never filled in this class, so the array is looked up in the calibration dict on each call.

rms

rms()

Return the 'pixel_rms' constant array, or None if it is absent.

Calls cached_array(self._rms, 'pixel_rms'). _rms is reset to None and never filled in this class, so the array is looked up in the calibration dict on each call.

common_mode

common_mode()

Return the 'common_mode' constant array, or None if it is absent.

Calls cached_array(self._common_mode, 'common_mode'). _common_mode is reset to None and never filled in this class, so the array is looked up in the calibration dict on each call.

gain

gain()

Return the 'pixel_gain' constant array, or None if it is absent.

Calls cached_array(self._gain, 'pixel_gain'). _gain is reset to None and never filled in this class, so the array is looked up in the calibration dict on each call.

offset

offset()

Return the 'pixel_offset' constant array, or None if it is absent.

Calls cached_array(self._offset, 'pixel_offset'). _offset is reset to None and never filled in this class, so the array is looked up in the calibration dict on each call.

mask_calib

mask_calib()

Return the 'pixel_mask' constant array converted to DTYPE_MASK, or None if it is absent.

Looked up with cached_array(self._mask_calib, 'pixel_mask').

status

status(ctype='pixel_status')

for ctype pixel_status

status_extra

status_extra()

for ctype status_extra

gain_factor

gain_factor()

Evaluates and returns gain factor as 1/gain if gain is available in calib constants else 1.

shape_as_daq

shape_as_daq()

Return the DAQ data shape derived from the pedestals, or None if there are no pedestals.

This is the pedestal shape when it has fewer than 4 dimensions, otherwise its last three dimensions.

number_of_segments_total

number_of_segments_total()

Return the total number of segments derived from shape_as_daq().

None if that shape is None, 1 if it has fewer than 3 dimensions, otherwise its third-from-last dimension.

segment_numbers_total

segment_numbers_total()

Returns total list of segment numbers.

geotxt_and_meta

geotxt_and_meta()

Return the (geometry text, metadata) tuple stored under 'geometry'.

Returns (None, None) if that entry is missing, and a single None if the calibration dict itself is None.

geo

geo()

Return GeometryAccess() object.

seg_geo

seg_geo()

returns SegGeometry object from full GeometryAccess object or None if GeometryAccess is None

pixel_coords

pixel_coords(**kwa)

DEPRECATED - can't load detector-dependent default geometry here... returns x, y, z - three np.ndarray

pixel_coord_indexes

pixel_coord_indexes(**kwa)

DEPRECATED - can't load detector-dependent default geometry here... returns ix, iy - two np.ndarray

seed_cached_pixel_coord_indexes_shared

seed_cached_pixel_coord_indexes_shared(segnums=None, **kwa)

Precompute and package CalibConstants image-mapping artifacts for shared memory.

Returns a payload dict containing a shared-memory cache key (meta), array specifications (specs), and the computed numpy arrays (arrays). The caller is responsible for allocating shared arrays and copying these data into them.

cached_pixel_coord_indexes

cached_pixel_coord_indexes(segnums=None, **kwa)

Compute and store the pixel row/column indexes and image-mapping tables; returns None.

segnums defaults to all segments. When the shared calib cache (_shared_calibc_cache) is enabled and holds every array for this key they are taken from it; otherwise the indexes come from pixel_coord_indexes(**kwa) (nothing is stored if that is None), and multi-pixel statistics, hole tables (fillholes, default True) or, for mapmode 4, interpolation parameters are computed (mapmode default 2).

Notes

The mapmode-4 path calls self._pixel_coords, which this class does not define.

image

image(nda, segnums=None, **kwa)

Create 2-d image.

Parameters:

Name Type Description Default
nda

array shaped as daq raw data.

required
segnums
None
mapmode

control on overlapping pixels on image map. 0/1/2/3/4: statistics of entries / last / max / mean pixel intensity / interpolated (TBD) - ascending data index.

required
fillholes

control on map bins inside the panel with 0 entries from data. True/False: fill empty bin with minimal intensity of four neares neighbors/ do not fill.

required
vbase

value substituted for all image map bins without entry from data.

required

Returns:

Name Type Description
image np.array, ndim=2

pix_rc

pix_rc()

Return the stored (rows, cols) pixel index arrays; (None, None) until cached_pixel_coord_indexes fills them.

pix_xyz

pix_xyz()

Return the stored (x, y, z) pixel coordinate arrays; (None, None, None) unless the mapmode-4 path filled them.

interpol_pars

interpol_pars()

Return the stored interpolation parameters; None unless the mapmode-4 path set them.

info_calibconst

info_calibconst()

grabs det.raw._calibconst from self and returns info about available constants

is_none

is_none(par, msg, logger_method=logger.debug)

Return True if par is None, calling logger_method(msg) in that case; otherwise return False.

is_dict_like

is_dict_like(d)

Return True if d is a dict or a weakref.WeakValueDictionary.