PSCalib documentation

Class GeometryObject is a building block for hierarchical geometry

Usage:

# Methods of this class are used internally in :py:class:`GeometryAccess`
# and are not supposed to be used directly...

from PSCalib.GeometryObject import GeometryObject

# Instatiation of the geometry object
# d = <dictionary-of-input-parameters>
geo = GeometryObject(**d)

# test print methods:
geo.print_geo()
geo.print_geo_children()

# modification methods:
geo.set_geo_pars(self, x0, y0, z0, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x)
geo.move_geo(dx, dy, dz)
geo.tilt_geo(dt_x, dt_y, dt_z)

# access methods:
s      = geo.str_data()
parent = geo.get_parent()
list_of_children = geo.get_list_of_children()
oname  = geo.get_geo_name()
oindex = geo.get_geo_index()
pname  = geo.get_parent_name()
pindex = geo.get_parent_index()
X,Y,Z  = geo.get_pixel_coords(do_tilt=true)
X,Y    = geo.get_2d_pixel_coords(do_tilt=true)
area   = geo.get_pixel_area()
#mbits = +1-edges, +2-wide pixels, +4-non-bonded pixels, +8/+16 - four/eight neighbours of non-bonded
mask   = geo.get_pixel_mask(mbits=0377)
npixels= geo.get_size_geo_array()
pixsize= geo.get_pixel_scale_size()
x0, y0, z0             = geo.get_origin()
rot_z, rot_y, rot_x    = geo.get_rot()
tilt_z, tilt_y, tilt_x = geo.get_tilt()

# private methods for internal consumption:
geo.set_parent(parent)
geo.add_child(child)
Xt, Yt, Zt = geo.transform_geo_coord_arrays(X, Y, Z, do_tilt=True)
Xt, Yt     = geo.transform_2d_geo_coord_arrays(X, Y, do_tilt=True)

# global methods:
Xrot, Yrot = rotation_cs(X, Y, C, S)
Xrot, Yrot = rotation(X, Y, angle_deg)

# global methods only for CSPAD2x2 array conversion between (2,185,388) and (185,388,2):
arrTwo2x1 = data2x2ToTwo2x1(asData2x2)
asData2x2 = two2x1ToData2x2(arrTwo2x1)

See GeometryAccess

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

GeometryObject.data2x2ToTwo2x1(arr2x2)[source]

Converts array shaped as CSPAD2x2 data (185,388,2) to two 2x1 arrays with shape=(2,185,388)

GeometryObject.rotation(X, Y, angle_deg)[source]

For numpy arrays X and Y returns the numpy arrays of Xrot and Yrot rotated by angle_deg

GeometryObject.rotation_cs(X, Y, C, S)[source]

For numpy arrays X and Y returns the numpy arrays of Xrot and Yrot

GeometryObject.two2x1ToData2x2(arrTwo2x1)[source]

Converts array shaped as two 2x1 arrays (2,185,388) or (2*185,388) to CSPAD2x2 data shape=(185,388,2)

Class GeometryAccess - holds and access hierarchical geometry for generic pixel detector

Usage:

from PSCalib.GeometryAccess import GeometryAccess, img_from_pixel_arrays

fname_geometry = '/reg/d/psdm/CXI/cxitut13/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/geometry/0-end.data'
geometry = GeometryAccess(fname_geometry, 0377)

# load constants from geometry file
geometry.load_pars_from_file(path=None)

# load constants from next-line-symbol separated str / text object
geometry.load_pars_from_str(s)

# check if geometry info is available, returns bool
status = geometry.is_valid()

# get pixel coordinate [um] arrays
X, Y, Z = geometry.get_pixel_coords(oname=None, oindex=0, do_tilt=True)

# get pixel x,y coordinate [um] arrays projected toward origin on specified zplane, if zplane=None then zplane=Z.mean()
X, Y = geometry.get_pixel_xy_at_z(zplane=None, oname=None, oindex=0, do_tilt=True)

# print a portion of pixel X, Y, and Z coordinate arrays
geometry.print_pixel_coords(oname=None, oindex=0)

# get pixel area array; A=1 for regular pixels, =2.5 for wide.
area = geometry.get_pixel_areas(oname=None, oindex=0)

# returns (smallest) pixel size [um]
pixel_size = geometry.get_pixel_scale_size(oname=None, oindex=0)

# returns dictionary of comments associated with geometry (file)
dict_of_comments = geometry.get_dict_of_comments()

# print comments associated with geometry (file) 
geometry.print_comments_from_dict()

# print list of geometry objects
geometry.print_list_of_geos()

# print list of geometry object children
geometry.print_list_of_geos_children()

# get pixel mask array;
# mbits = +1-mask edges, +2-wide pixels, +4-non-bonded pixels, +8/+16 - four/eight neighbours of non-bonded
mask = geometry.get_pixel_mask(oname=None, oindex=0, mbits=0377)

# get index arrays for entire detector
iX, iY = geometry.get_pixel_coord_indexes(do_tilt=True)

# get index arrays for specified quad with offset
iX, iY = geometry.get_pixel_coord_indexes('QUAD:V1', 1, pix_scale_size_um=None, xy0_off_pix=(1000,1000), do_tilt=True)

# get index arrays for pixel coordinates projected toward origin on specified zplane
iX, iY = geometry.get_pixel_xy_inds_at_z(zplane=None, oname=None, oindex=0, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True)

# get ix and iy indexes for specified point in [um]. By default p_um=(0,0) - detector origin coordinates (center).
ix, iy = geometry.point_coord_indexes(p_um=(0,0))
# all other parameters should be the same as in get_pixel_coord_indexes method
ix, iy = geometry.point_coord_indexes(p_um=(0,0), 'QUAD:V1', 1, pix_scale_size_um=None, xy0_off_pix=(1000,1000), do_tilt=True)

# get 2-d image from index arrays
img = img_from_pixel_arrays(iX,iY,W=arr)

# Get specified object of the class GeometryObject, all objects are kept in the list self.list_of_geos
geo = geometry.get_geo('QUAD:V1', 1) 
# Get top GeometryObject - the object which includes all other geometry objects
geo = geometry.get_top_geo()

# modify currect geometry objects' parameters
geometry.set_geo_pars('QUAD:V1', 1, x0, y0, z0, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x)
geometry.move_geo('QUAD:V1', 1, 10, 20, 0)
geometry.tilt_geo('QUAD:V1', 1, 0.01, 0, 0)

# save current geometry parameters in file
geometry.save_pars_in_file(fname_geometry_new)

# change verbosity bit-control word; to print everythisg use pbits = 0xffff
geometry.set_print_bits(pbits=0)

# return geometry parameters in "psf" format as a tuple psf[32][3][3]
psf = geometry.get_psf()
geometry.print_psf()
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

class GeometryAccess.GeometryAccess(path=None, pbits=0)[source]

GeometryAccess

__init__(path=None, pbits=0)[source]

Constructor of the class GeometryAccess

Parameters

  • path : str - path to the geometry file
  • pbits : int - verbosity bitword
get_dict_of_comments()[source]

Returns dictionary of comments

get_geo(oname, oindex)[source]

Returns specified geometry object

get_pixel_areas(oname=None, oindex=0)[source]

Returns pixel areas array for top or specified geometry object

get_pixel_coord_indexes(oname=None, oindex=0, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True)[source]

Returns two pixel X,Y coordinate index arrays for top or specified geometry object

get_pixel_coords(oname=None, oindex=0, do_tilt=True)[source]

Returns three pixel X,Y,Z coordinate arrays for top or specified geometry object

get_pixel_mask(oname=None, oindex=0, mbits=255, **kwargs)[source]

Returns pixel mask array for top or specified geometry object.

mbits =+1 - mask edges
+2 - two wide-pixel central columns +4 - non-bonded pixels +8 - four nearest neighbours of non-bonded pixels +16- eight neighbours of non-bonded pixels
get_pixel_scale_size(oname=None, oindex=0)[source]

Returns pixel scale size for top or specified geometry object

get_pixel_xy_at_z(zplane=None, oname=None, oindex=0, do_tilt=True)[source]

Returns pixel coordinate arrays XatZ, YatZ, for specified zplane and geometry object.

This method projects pixel X, Y coordinates in 3-D on the specified Z plane along direction to origin.

get_pixel_xy_inds_at_z(zplane=None, oname=None, oindex=0, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True)[source]

Returns pixel coordinate index arrays iX, iY of size for specified zplane and geometry object

get_psf()[source]

Returns array of vectors in TJ format (psf stands for position-slow-fast vectors)

get_top_geo()[source]

Returns top geometry object

is_valid()[source]

returns True if geometry is loaded and presumably valid, otherwise False

load_pars_from_file(path=None)[source]

Reads input “geometry” file, discards empty lines and comments, fills the list of geometry objects for data lines

load_pars_from_str(s)[source]

Reads input geometry from str, discards empty lines and comments, fills the list of geometry objects for data lines

move_geo(oname=None, oindex=0, dx=0, dy=0, dz=0)[source]

Moves specified or top geometry object by dx, dy, dz

point_coord_indexes(p_um=(0, 0), oname=None, oindex=0, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True)[source]

Converts point (x_um, y_um) corrdinates [um] to pixel (ix, iy) indexes. All other parameters are the same as in get_pixel_coord_indexes. WARNING: indexes are not required to be inside the image. They are integer, may be negative or exceed pixel maximal index.

print_pixel_coords(oname=None, oindex=0)[source]

Partial print of pixel coordinate X,Y,Z arrays for selected or top(by default) geo

print_psf()[source]

Gets and prints psf array for test purpose

save_pars_in_file(path)[source]

Save geometry file with current content

set_geo_pars(oname=None, oindex=0, x0=0, y0=0, z0=0, rot_z=0, rot_y=0, rot_x=0, tilt_z=0, tilt_y=0, tilt_x=0)[source]

Sets geometry parameters for specified or top geometry object

set_print_bits(pbits=0)[source]

Sets printout control bitword

tilt_geo(oname=None, oindex=0, dt_x=0, dt_y=0, dt_z=0)[source]

Tilts specified or top geometry object by dt_x, dt_y, dt_z

GeometryAccess.divide_protected(num, den, vsub_zero=0)[source]

Returns result of devision of numpy arrays num/den with substitution of value vsub_zero for zero den elements.

GeometryAccess.img_default(shape=(10, 10), dtype=<type 'numpy.float32'>)[source]

Returns default image

GeometryAccess.img_from_pixel_arrays(iX, iY, W=None, dtype=<type 'numpy.float32'>, vbase=0)[source]

Returns image from iX, iY coordinate index arrays and associated weights W.

GeometryAccess.test_access(geometry)[source]

Tests geometry acess methods of the class GeometryAccess

GeometryAccess.test_cspad2x2()[source]

Test cspad2x2 geometry table

GeometryAccess.test_cspad_xy_at_z()[source]

Test cspad geometry table

GeometryAccess.test_epix100a()[source]

Test test_epix100a geometry table

GeometryAccess.test_img_default()[source]

Test default image

GeometryAccess.test_load_pars_from_file(geometry)[source]

Test default image

GeometryAccess.test_mask_quad(geometry, mbits)[source]

Tests geometry acess methods of the class GeometryAccess object for CSPAD quad

GeometryAccess.test_plot_cspad(geometry, fname_data, amp_range=(0, 0.5))[source]

The same test as previous, but use get_pixel_coord_indexes(…) method

GeometryAccess.test_plot_quad(geometry)[source]

Tests geometry acess methods of the class GeometryAccess object for CSPAD quad

GeometryAccess.test_save_pars_in_file(geometry)[source]

Test default image

Class SegGeometryStore is a factory class/method

Switches between different device-dependent segments/sensors to access their pixel geometry using SegGeometry interface.

Usage:

from PSCalib.SegGeometryStore import sgs

sg = sgs.Create('SENS2X1:V1', pbits=0377)
sg2= sgs.Create('EPIX100:V1', pbits=0377)
sg3= sgs.Create('PNCCD:V1',   pbits=0377)
sg4= sgs.Create('ANDOR3D:V1', pbits=0377)
sg5= sgs.Create('JUNGFRAU:V1',pbits=0377)

sg.print_seg_info(pbits=0377)
size_arr = sg.size()
rows     = sg.rows()
cols     = sg.cols()
shape    = sg.shape()
pix_size = sg.pixel_scale_size()
area     = sg.pixel_area_array()
mask     = sg.pixel_mask(mbits=0377)    
sizeX    = sg.pixel_size_array('X')
sizeX, sizeY, sizeZ = sg.pixel_size_array()
X        = sg.pixel_coord_array('X')
X,Y,Z    = sg.pixel_coord_array()
xmin = sg.pixel_coord_min('X')
ymax = sg.pixel_coord_max('Y')
xmin, ymin, zmin = sg.pixel_coord_min()
xmax, ymax, zmax = sg.pixel_coord_mas()
...
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2013-03-08 by Mikhail Dubrovin

class SegGeometryStore.SegGeometryStore(sp)[source]

Factory class for SegGeometry-base objects of different detectors

Create(sp, segname='SENS2X1:V1', pbits=0)[source]

Factory method returns device dependent SINGLETON object with interface implementation

SegGeometry - abstract class with interface description

Methods of this class should be re-implemented in derived classes with name pattern SegGeometry<SensorVers> for pixel geometry description of all sensors. For example, CSPAD 2x1 sensor is implemented in class PSCalib.SegGeometryCspad2x1V1. Access to all implemented sensors is available through the factory method in class PSCalib.SegGeometryStore.

Usage:

from SegGeometryCspad2x1V1 import cspad2x1_one as sg

sg.print_seg_info(pbits=0377)
size_arr = sg.size()
rows     = sg.rows()
cols     = sg.cols()
shape    = sg.shape()
pix_size = sg.pixel_scale_size()
area     = sg.pixel_area_array()
mask     = sg.pixel_mask(mbits=0377)    
sizeX    = sg.pixel_size_array('X')
sizeX, sizeY, sizeZ = sg.pixel_size_array()
X        = sg.pixel_coord_array('X')
X,Y,Z    = sg.pixel_coord_array()
xmin = sg.pixel_coord_min('X')
ymax = sg.pixel_coord_max('Y')
xmin, ymin, zmin = sg.pixel_coord_min()
xmax, ymax, zmax = sg.pixel_coord_mas()
...
print 'X.shape =', X.shape
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

SegGeometry.rotation(X, Y, C, S)[source]

For numpy arrays X and Y returns the numpy arrays of Xrot and Yrot

Class SegGeometryCspad2x1V1 describes the CSPAD 2x1 V1 sensor geometry

In this class we use natural matrix notations like in data array (that is different from the DAQ notations where rows and cols are swapped).

We assume that

  • 2x1 has 185 rows and 388 columns,
  • X-Y coordinate system origin is in the sensor center,
  • pixel (r,c)=(0,0) is in the top left corner of the matrix, has coordinates (xmin,ymax), as shown below
(Xmin,Ymax)      ^ Y          (Xmax,Ymax)
(0,0)            |            (0,387)
   ------------------------------
   |             |              |
   |             |              |
   |             |              |
 --|-------------+--------------|----> X
   |             |              |
   |             |              |
   |             |              |
   ------------------------------
(184,0)          |           (184,387)
(Xmin,Ymin)                  (Xmax,Ymin)

Usage:

from SegGeometryCspad2x1V1 import cspad2x1_one as sg

sg.print_seg_info(0377)

size_arr = sg.size()
rows     = sg.rows()
cols     = sg.cols()
shape    = sg.shape()
pix_size = pixel_scale_size()

area  = sg.pixel_area_array()
mask = sg.pixel_mask_array(mbits=0377)
# where mbits = +1  - edges,
#               +2  - wide pixels,
#               +4  - non-bonded pixels,
#               +8  - nearest four neighbours of non-bonded
#               +16 - eight neighbours of non-bonded

sizeX = sg.pixel_size_array('X')
sizeX, sizeY, sizeZ = sg.pixel_size_array()

X     = sg.pixel_coord_array('X')
X,Y,Z = sg.pixel_coord_array()
print 'X.shape =', X.shape

xmin, ymin, zmin = sg.pixel_coord_min()
xmax, ymax, zmax = sg.pixel_coord_max()
xmin = sg.pixel_coord_min('X')
ymax = sg.pixel_coord_max('Y')

# global method for rotation of numpy arrays:
Xrot, Yrot = rotation(X, Y, C, S)
...
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2013-03-08 by Mikhail Dubrovin

class SegGeometryCspad2x1V1.SegGeometryCspad2x1V1(sp, use_wide_pix_center=True)[source]

Bases: PSCalib.SegGeometry.SegGeometry

Self-sufficient class for generation of CSPad 2x1 sensor pixel coordinate array

cols(sp)[source]

Returns number of cols in segment

make_pixel_coord_arrs(sp)[source]

Makes [185,388] maps of x, y, and z 2x1 pixel coordinates with origin in the center of 2x1

make_pixel_size_arrs(sp)[source]

Makes [185,388] maps of x, y, and z 2x1 pixel size

pixel_area_array(sp)[source]

Returns pixel area array of shape=(rows, cols)

pixel_coord_array(sp, axis=None)[source]

Returns numpy array of segment pixel coordinates in um for AXIS

pixel_coord_max(sp, axis=None)[source]

Returns maximal value in the array of segment pixel coordinates in um for AXIS

pixel_coord_min(sp, axis=None)[source]

Returns minimal value in the array of segment pixel coordinates in um for AXIS

pixel_mask_array(sp, mbits=255)[source]

Returns numpy array of pixel mask: 1/0 = ok/masked, mbits=1 - mask edges, +2 - mask two central columns, +4 - mask non-bonded pixels, +8 - mask nearest four neighbours of nonbonded pixels, +16- mask eight neighbours of nonbonded pixels.

pixel_scale_size(sp)[source]

Returns pixel size in um for indexing

pixel_size_array(sp, axis=None)[source]

Returns numpy array of pixel sizes in um for AXIS

print_seg_info(sp, pbits=0)[source]

Prints segment info for selected bits pbits=0 - nothing, +1 - member data, +2 - coordinate maps in um, +4 - min, max coordinates in um, +8 - x, y 1-d pixel coordinate arrays in um.

rows(sp)[source]

Returns number of rows in segment

shape(sp)[source]

Returns shape of the segment (rows, cols)

size(sp)[source]

Returns number of pixels in segment

Class SegGeometryEpix100V1 describes the Epix100 V1 sensor geometry

In this class we use natural matrix notations like in data array

We assume that

  • 2x2 ASICs has 704 rows and 768 columns,
  • Epix100 has a pixel size 50x50um, wide pixel size 50x175um
  • Epix10k has a pixel size 100x100um,
  • X-Y coordinate system origin is in the sensor center,
  • pixel (r,c)=(0,0) is in the top left corner of the matrix, has coordinates (xmin,ymax), as shown below
(Xmin,Ymax)      ^ Y          (Xmax,Ymax)
(0,0)            |            (0,767)
   ------------------------------
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   |             |              |
 --|-------------+--------------|----> X
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   |             |              |
   ------------------------------
(703,0)          |           (703,767)
(Xmin,Ymin)                  (Xmax,Ymin)

Usage:

from SegGeometryEpix100V1 import epix2x2_one as sg

sg.print_seg_info(0377)

size_arr = sg.size()
rows     = sg.rows()
cols     = sg.cols()
shape    = sg.shape()
pix_size = pixel_scale_size()

area     = sg.pixel_area_array()
mask     = sg.pixel_mask_array(mbits=0377)
# where mbits = +1-edges, +2-wide pixels

sizeX = sg.pixel_size_array('X')
sizeX, sizeY, sizeZ = sg.pixel_size_array()

X     = sg.pixel_coord_array('X')
X,Y,Z = sg.pixel_coord_array()
print 'X.shape =', X.shape

xmin, ymin, zmin = sg.pixel_coord_min()
xmax, ymax, zmax = sg.pixel_coord_max()
xmin = sg.pixel_coord_min('X')
ymax = sg.pixel_coord_max('Y')

# global method for rotation of numpy arrays:
Xrot, Yrot = rotation(X, Y, C, S)
...
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2013-03-08 by Mikhail Dubrovin

class SegGeometryEpix100V1.SegGeometryEpix100V1(sp, use_wide_pix_center=True)[source]

Bases: PSCalib.SegGeometry.SegGeometry

Self-sufficient class for generation of Epix100 2x2 sensor pixel coordinate array

cols(sp)[source]

Returns number of cols in segment

make_pixel_coord_arrs(sp)[source]

Makes [704,768] maps of x, y, and z 2x2 pixel coordinates with origin in the center of 2x2

make_pixel_size_arrs(sp)[source]

Makes [704,768] maps of x, y, and z 2x2 pixel size

pixel_area_array(sp)[source]

Returns pixel area array of shape=(rows, cols)

pixel_coord_array(sp, axis=None)[source]

Returns numpy array of segment pixel coordinates in um for AXIS

pixel_coord_max(sp, axis=None)[source]

Returns maximal value in the array of segment pixel coordinates in um for AXIS

pixel_coord_min(sp, axis=None)[source]

Returns minimal value in the array of segment pixel coordinates in um for AXIS

pixel_mask_array(sp, mbits=255)[source]

Returns numpy array of pixel mask: 1/0 = ok/masked, mbits: +1 - mask edges, +2 - mask two central columns

pixel_scale_size(sp)[source]

Returns pixel size in um for indexing

pixel_size_array(sp, axis=None)[source]

Returns numpy array of pixel sizes in um for AXIS

print_seg_info(sp, pbits=0)[source]

Prints segment info for selected bits pbits = 0 - nothing, +1 - member data, +2 - coordinate maps in um, +4 - min, max coordinates in um, +8 - x, y 1-d pixel coordinate arrays in um.

rows(sp)[source]

Returns number of rows in segment

shape(sp)[source]

Returns shape of the segment (rows, cols)

size(sp)[source]

Returns number of pixels in segment

Class SegGeometryMatrixV1 defines the matrix V1 (pnCCD, 512x512) sensor pixel coordinates in its local frame

Default constructor parameters are set for pnCCD; 512x512 pixels with 75x75um pixel size. In this class we use natural matrix notations like in data array (that is different from the DAQ notations where rows and cols are swapped).

We assume that

  • segment has 512 rows and 512 columns,
  • X-Y coordinate system origin is in the top left corner,
  • ixel (r,c)=(0,0) is in the top left corner of the matrix which has coordinates (Xmin,Ymin) - is in origin.
MatrixV1 sensor coordinate frame has a matrix-style coordinate system:

@code
  (Xmin,Ymin)        (Xmin,Ymax)
  (0,0)              (0,511)
     +-----------------+----> Y
     |                 |
     |                 |
     |                 |
     |                 |
     |                 |
     |                 |
     |                 |
     |                 |
     +-----------------+
     |
   X V
  (511,0)           (511,511)
  (Xmax,Ymin)       (Xmax,Ymax)
@endcode

Usage of interface methods:

from SegGeometryMatrixV1 import cspad2x1_one as sg

sg.print_seg_info(0377)

size_arr = sg.size()
rows     = sg.rows()
cols     = sg.cols()
shape    = sg.shape()
pix_size = pixel_scale_size()

area  = sg.pixel_area_array()
mask = sg.pixel_mask_array(mbits=0377)
# where mbits = +1-edges, +2-wide pixels, +4-non-bonded pixels, +8-neighbours of non-bonded

sizeX = sg.pixel_size_array('X')
sizeX, sizeY, sizeZ = sg.pixel_size_array()

X     = sg.pixel_coord_array('X')
X,Y,Z = sg.pixel_coord_array()
print 'X.shape =', X.shape

xmin, ymin, zmin = sg.pixel_coord_min()
xmax, ymax, zmax = sg.pixel_coord_max()
xmin = sg.pixel_coord_min('X')
ymax = sg.pixel_coord_max('Y')

# global method for rotation of numpy arrays:
Xrot, Yrot = rotation(X, Y, C, S)
...
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2013-03-08 by Mikhail Dubrovin

class SegGeometryMatrixV1.SegGeometryMatrixV1(sp, rows=512, cols=512, pix_size_rows=75, pix_size_cols=75, pix_size_depth=400, pix_scale_size=75)[source]

Bases: PSCalib.SegGeometry.SegGeometry

Self-sufficient class for generation of CSPad 2x1 sensor pixel coordinate array

cols(sp)[source]

Returns number of cols in segment

make_pixel_coord_arrs(sp)[source]

Makes maps of x, y, and z of segment pixel coordinates

make_pixel_size_arrs(sp)[source]

Makes maps of x, y, and z segment pixel size

pixel_area_array(sp)[source]

Returns pixel area array of shape=(rows, cols)

pixel_coord_array(sp, axis=None)[source]

Returns numpy array of segment pixel coordinates in um for AXIS

pixel_coord_max(sp, axis=None)[source]

Returns maximal value in the array of segment pixel coordinates in um for AXIS

pixel_coord_min(sp, axis=None)[source]

Returns minimal value in the array of segment pixel coordinates in um for AXIS

pixel_mask_array(sp, mbits=255)[source]

Returns numpy array of pixel mask: 1/0 = ok/masked, mbits=1 - mask edges, +2 - mask two central columns, +4 - mask non-bonded pixels, +8 - mask nearest neighbours of nonbonded pixels.

pixel_scale_size(sp)[source]

Returns pixel size in um for indexing

pixel_size_array(sp, axis=None)[source]

Returns numpy array of pixel sizes in um for AXIS

print_seg_info(sp, pbits=0)[source]

Prints segment info for selected bits pbits=0 - nothing, +1 - member data, +2 - coordinate maps in um, +4 - min, max coordinates in um, +8 - x, y 1-d pixel coordinate arrays in um.

rows(sp)[source]

Returns number of rows in segment

shape(sp)[source]

Returns shape of the segment (rows, cols)

size(sp)[source]

Returns number of pixels in segment

SegGeometryMatrixV1.matrix_pars(segname)[source]

Returns the matrix sensor parameters from its string-name, ex: MTRX:512:512:54:54

Class SegGeometryJungfrauV1 describes the Jungfrau V1 sensor geometry

Data array for Jungfrau 512x1024 segment is shaped as (1,512,1024), has a matrix-like numeration for rows and columns with gaps between 2x4 ASICs

We assume that

  • 1x1 ASICs has 256 rows and 256 columns,
  • Jungfrau has a pixel size 75x75um
  • X-Y coordinate system origin is in the sensor center,
  • pixel (r,c)=(0,0) is in the top left corner of the matrix, has coordinates (xmin,ymax), as shown below
(Xmin,Ymax)                          ^ Y                          (Xmax,Ymax)
(0,0)                                |                               (0,1023)
  ----------------- -----------------|----------------- -----------------
  |               | |               |||               | |               |
  |     ASIC      | |               |||               | |               |
  |    256x256    | |               |||               | |               |
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  ----------------- -----------------|----------------- -----------------
-------------------------------------+-------------------------------------> X
  ----------------- -----------------|----------------- -----------------
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  |               | |               |||               | |               |
  ----------------- -----------------|----------------- -----------------
(511,0)                              |                             (1023,1023)
(Xmin,Ymin)                                                        (Xmax,Ymin)

Usage:

from PSCalib.SegGeometryJungfrauV1 import jungfrau_one as sg

sg.print_seg_info(0377)

size_arr = sg.size()
rows     = sg.rows()
cols     = sg.cols()
shape    = sg.shape()
pix_size = pixel_scale_size()

area     = sg.pixel_area_array()
mask     = sg.pixel_mask_array(mbits=0377, width=1)
# where mbits = +1-edges, +2-wide pixels

sizeX = sg.pixel_size_array('X')
sizeX, sizeY, sizeZ = sg.pixel_size_array()

X     = sg.pixel_coord_array('X')
X,Y,Z = sg.pixel_coord_array()
print 'X.shape =', X.shape

xmin, ymin, zmin = sg.pixel_coord_min()
xmax, ymax, zmax = sg.pixel_coord_max()
xmin = sg.pixel_coord_min('X')
ymax = sg.pixel_coord_max('Y')

# global method for rotation of numpy arrays:
Xrot, Yrot = rotation(X, Y, C, S)
...
See:

For more detail see Detector Geometry.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2017-10-12 by Mikhail Dubrovin

class SegGeometryJungfrauV1.SegGeometryJungfrauV1(sp)[source]

Bases: PSCalib.SegGeometry.SegGeometry

Self-sufficient class for generation of Jungfrau 2x4 sensor pixel coordinate array

cols(sp)[source]

Returns number of cols in segment

make_pixel_coord_arrs(sp)[source]

Makes [512,1024] maps of x, y, and z pixel coordinates with origin in the center of 2x4

make_pixel_size_arrs(sp)[source]

Makes [512,1024] maps of x, y, and z 2x2 pixel size

pixel_area_array(sp)[source]

Returns pixel area array of shape=(rows, cols)

pixel_coord_array(sp, axis=None)[source]

Returns numpy array of segment pixel coordinates in um for AXIS

pixel_coord_max(sp, axis=None)[source]

Returns maximal value in the array of segment pixel coordinates in um for AXIS

pixel_coord_min(sp, axis=None)[source]

Returns minimal value in the array of segment pixel coordinates in um for AXIS

pixel_mask_array(sp, mbits=255, width=1)[source]

Returns numpy array of pixel mask: 1/0 = ok/masked,

Parameters

mbits:
+1 - mask edges, +2 - mask central columns

width (uint) - width in pixels of masked edge

pixel_scale_size(sp)[source]

Returns pixel size in um for indexing

pixel_size_array(sp, axis=None)[source]

Returns numpy array of pixel sizes in um for AXIS

print_seg_info(sp, pbits=0)[source]

Prints segment info for selected bits pbits = 0 - nothing, +1 - member data, +2 - coordinate maps in um, +4 - min, max coordinates in um, +8 - x, y 1-d pixel coordinate arrays in um.

rows(sp)[source]

Returns number of rows in segment

shape(sp)[source]

Returns shape of the segment (rows, cols)

size(sp)[source]

Returns number of pixels in segment

DCMethods is a set of utilities for direct operations with calibration data

Usage:

# Import
import psana
import PSCalib.DCMethods as dcm

# Example of parameters
dsname = 'exp=cxif5315:run=129'
# or:
dsname = '/reg/g/psdm/detector/data_test/xtc/cxif5315-e545-r0169-s00-c00.xtc'
ds = psana.DataSource(dsname)
env=ds.env()
evt=ds.events().next()

src      = 'Cspad.' # 'Epix100a.', etc
ctype    = gu.PIXEL_MASK # | gu.PEDESTALS | gu.PIXEL_STATUS, etc.
vers     = None # or e.g. 5
calibdir = None # or e.g. './calib'
nda      = np.zeros((32,185,388))
pred     = 'CxiDs2.0:Cspad.0'
succ     = 'CxiDs2.0:Cspad.0'
range    = '1474587520-end'

par      = evt # psana.Event | float - tsec event time
parts    = env # psana.Env | psana.Event | float - tsec event time

# Methods with dynamically-reconstructed calib file name
dcm.add_constants(nda, par, env, src='Epix100a.', ctype=gu.PIXEL_MASK, calibdir=None, vers=None, pred=None, succ=None, cmt=None, verb=False)
dcm.print_content(env, src='Epix100a.', calibdir=None)
nda = dcm.get_constants(par, env, src='Epix100a.', ctype=gu.PIXEL_MASK, calibdir=None, vers=None, verb=False)
dcm.delete_version(evt, env, src='Epix100a.', ctype=gu.PIXEL_MASK, calibdir=None, vers=None, cmt=None, verb=False)
dcm.delete_range  (evt, env, src='Epix100a.', ctype=gu.PIXEL_MASK, calibdir=None, range=None, cmt=None, verb=False)
dcm.delete_ctype  (evt, env, src='Epix100a.', ctype=gu.PIXEL_MASK, calibdir=None, cmt=None, verb=False)

# Methods using fname
dcm.add_constants_to_file(data, fname, parts, env, ctype=gu.PIXEL_MASK, vers=None, pred=None, succ=None, cmt=None, verb=False)
dcm.print_content_from_file(fname)
nda = dcm.get_constants_from_file(fname, parts, ctype=gu.PIXEL_MASK, vers=None, verb=False)
dcm.delete_version_from_file(fname, parts, ctype=gu.PIXEL_MASK, vers=None, cmt=None, verb=False)
dcm.delete_range_from_file  (fname, ctype=gu.PIXEL_MASK, range=None, cmt=None, verb=False)
dcm.delete_ctype_from_file  (fname, ctype=gu.PIXEL_MASK, cmt=None, verb=False)
Methods
Classes:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016-09-23 by Mikhail Dubrovin

DCMethods.add_constants(data, par, env, src='Epix100a.', ctype=4, calibdir=None, vers=None, pred=None, succ=None, cmt=None, verb=False)[source]

Adds specified numpy array to the hdf5 file.

Parameters

  • data : numpy.array or str - array or string of calibration constants/data to save in file
  • env : psana.Env -> full detector name for psana.Source -> hdf5 file name
  • par : psana.Event | float time -> event time
  • src : str - source short/full name, alias or full -> hdf5 file name
  • ctype: gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
  • vers : int - calibration version
  • pred : str - predecessor name
  • succ : str - successor name
  • cmt : str - comment saved as a history record within DCRange
  • verb : bool - verbosity, default=False - do not prnt any message

See DCMethods

DCMethods.add_constants_to_file(data, fname, par, env=None, ctype=4, vers=None, pred=None, succ=None, cmt=None, verb=False)[source]

Adds specified numpy array to the hdf5 file.

Parameters

  • data : numpy.array or str - array or string of calibration constants/data to save in file
  • fname: full path to the hdf5 file
  • par : psana.Event | psana.Env | float - tsec event time
  • env : psana.Env -> is used to get exp=env.experiment() for comments etc.
  • ctype: gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • vers : int - calibration version
  • pred : str - predecessor name
  • succ : str - successor name
  • cmt : str - comment saved as a history record within DCRange
  • verb : bool - verbosity, default=False - do not print any message

See DCMethods

DCMethods.delete_ctype(evt, env, src='Epix100a.', ctype=4, calibdir=None, cmt=None, verb=False)[source]

Delete specified ctype from calibration constants.

Parameters

  • evt : psana.Event -> event time
  • env : psana.Env -> full detector name for psana.Source
  • src : str - source short/full name, alias or full
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
  • cmt : str - comment
  • verb : bool - verbousity

See DCMethods

DCMethods.delete_ctype_from_file(fname, ctype=4, cmt=None, verb=False)[source]

Delete specified ctype from calibration constants.

Parameters

  • fname : full path to the hdf5 file
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • cmt : str - comment
  • verb : bool - verbousity

See DCMethods

DCMethods.delete_range(evt, env, src='Epix100a.', ctype=4, calibdir=None, range=None, cmt=None, verb=False)[source]

Delete specified time range from calibration constants.

Parameters

  • evt : psana.Event -> event time
  • env : psana.Env -> full detector name for psana.Source
  • src : str - source short/full name, alias or full
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
  • range : str - range, e.g. ‘1474587520-end’
  • cmt : str - comment
  • verb : bool - verbousity

See DCMethods

DCMethods.delete_range_from_file(fname, ctype=4, range=None, cmt=None, verb=False)[source]

Delete specified time range from calibration constants.

Parameters

  • fname : full path to the hdf5 file
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • range : str - range, e.g. ‘1474587520-end’
  • cmt : str - comment
  • verb : bool - verbousity

See DCMethods

DCMethods.delete_version(evt, env, src='Epix100a.', ctype=4, calibdir=None, vers=None, cmt=None, verb=False)[source]

Delete specified version from calibration constants.

Parameters

  • evt : psana.Event -> event time
  • env : psana.Env -> full detector name for psana.Source
  • src : str - source short/full name, alias or full
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
  • vers : int - calibration version
  • cmt : str - comment
  • verb : bool - verbousity

See DCMethods

DCMethods.delete_version_from_file(fname, par, ctype=4, vers=None, cmt=None, verb=False)[source]

Delete specified version from calibration constants.

Parameters

  • fname : full path to the hdf5 file
  • par : psana.Event | psana.Env | float - tsec event time
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • vers : int - calibration version
  • cmt : str - comment
  • verb : bool - verbousity

See DCMethods

DCMethods.get_constants(par, env, src='Epix100a.', ctype=4, calibdir=None, vers=None, verb=False)[source]

Returns specified array of calibration constants.

Parameters

  • par: psana.Event | float - tsec event time
  • env: psana.Env - to get full detector name for psana.Source
  • src: str - source short/full name, alias or full
  • ctype: gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • calibdir: str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)
  • vers: int - calibration version

Return

numpy.array - array of calibratiopn constatnts.

See DCMethods

DCMethods.get_constants_from_file(fname, par, ctype=4, vers=None, verb=False)[source]

Returns specified array of calibration constants.

Parameters

  • fname : full path to the hdf5 file
  • par : psana.Event | psana.Env | float - tsec event time
  • ctype : gu.CTYPE - enumerated calibration type, e.g.: gu.PIXEL_MASK
  • vers : int - calibration version

Returns

  • np.array - specified array of calibration constants

See DCMethods

DCMethods.is_good_fname(fname, verb=False)[source]

Checks the hdf5 file name validity, returns True or False.

Parameters

  • fname : str - full path to the file
  • verb : bool - verbosity, default=False - do not print any message

Returns

True/False - for existing or not file

DCMethods.print_content(env, src='Epix100a.', calibdir=None)[source]

Defines the file name and prints file content.

Parameters

  • env : psana.Env -> full detector name for psana.Source
  • src : str - source short/full name, alias or full
  • calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)

See DCMethods

DCMethods.print_content_from_file(fname)[source]

Prints content of the file.

Parameters

  • fname : str - full path to the file

See DCMethods

Class DCStore for the Detector Calibration (DC) project

Usage:

# Import
from PSCalib.DCStore import DCStore

# Initialization
o = DCStore(fpath)

# Methods
tscfile     = o.tscfile()               # (double) time stamp of the file creation
dettype     = o.dettype()               # (str) detector type
detid       = o.detid()                 # (str) detector id
detname     = o.detname()               # (str) detector name of self object
predecessor = o.predecessor()           # (str) detname of predecessor or None
successor   = o.successor()             # (str) detname of successor or None
ctypes      = o.ctypes()                # (list) calibration types in the file
cto         = o.ctypeobj(ctype)         # (DCType ~ h5py.Group) calibration type object
o.set_tscfile(tsec)                     # set (double) time stamp of the file creation 
o.set_dettype(dettype)                  # set (str) detector type
o.set_detid(detid)                      # set (str) detector id
o.set_detname(detname)                  # set (str) detector name of self object
o.set_predecessor(pred)                 # set (str) detname of predecessor or None
o.set_successor(succ)                   # set (str) detname of successor or None
o.add_ctype(ctype)                      # add (str) calibration type to the DCStore object
ctype = o.mark_ctype(ctype)             # delete ctype (str) from the DCStore object, returns ctype or None
o.mark_ctypes()                         # delete all ctypes (str) from the DCStore object
o.clear_ctype()                         # clear all ctypes (str) from the DCStore object dictionary

o.save(group, mode='r+')                # saves object in hdf5 file. mode='r+'/'w' update/rewrite file.
o.load(group)                           # loads object content from the hdf5 file. 
o.print_obj()                           # print info about this object and its children
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016 by Mikhail Dubrovin

class DCStore.DCStore(path, cmt=None)[source]

Bases: PSCalib.DCInterface.DCStoreI

Class for the Detector Calibration (DC) project

Parameters

path : str - path to the hdf5 file with calibration info cmt : str - comment

mark_ctype(ctype, cmt=False)[source]

Marks child object for deletion in save()

mark_ctypes()[source]

Marks all child objects for deletion in save()

Class DCBase is a base class for the Detector Calibration (DC) project

Usage:

# Import
from PSCalib.DCBase import DCBase

o = DCBase()

# Dictionary of parameters
# ========================

o.set_pars_dict(d)                   # set (dict) dictionary of pars.
o.add_par(k,v)                       # add (k,v) par to the dictionary of pars.
o.del_par(k)                         # delete par with key k. 
o.clear_pars()                       # delete all pars from the dictionary.
d = o.pars_dict()                    # returns (dict) dictionary of pars.
p = o.par(k)                         # returns par value for key k.
t = o.pars_text()                    # returns (str) text of all pars.

# History records
# ===============

o.set_history_dict(d)                # set (dict) dictionary of history from specified dictionary
o.add_history_record(rec, tsec=None) # add (str) record with (int) time[sec] to the history dictionary of (tsec:rec).
                                     # If tsec is None - current time is used as a key.
o.del_history_record(tsec)           # Delete one history record from the dictionary by its time tsec.
o.clear_history()                    # Delete all history records from the dictionary.
d = o.history_dict()                 # returns (dict) history dictionary associated with current object .
r = o.history_record(tsec)           # returns (str) history record for specified time tsec.
t = o.history_text(tsfmt=None)       # returns (str) all history records preceded by the time stamp as a text.

# Save and Load
# =============

o.save_history_file(path='history.txt', verb=False) # save history in the text file
o.load_history_file(path='history.txt', verb=False) # load history from the text file

o.save_base(grp)                     # save everything in hdf5 group
o.load_base(name, grp)               # load from hdf5 group

# Time convertors
# ===============

t_str = o.tsec_to_tstr(tsec, tsfmt=None) # converts (float) time[sec] to the (str) time stamp
t_sec = o.tstr_to_tsec(tstr, tsfmt=None) # converts (str) time stamp to (float) time[sec]
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

class DCBase.DCBase(cmt=None)[source]

Bases: object

Base class for the Detector Calibration (DC) project.

Parameters

cmt : str - string of comment associated with derived class object.

__weakref__

list of weak references to the object (if defined)

history_text(tsfmt=None)[source]

Returns (str) history records preceded by the time stamp as a text

load_history_file(path='history.txt', verb=False)[source]

Load history from the text file

make_record(action='', key='', cmt=False)[source]

Returns string record combined with comment.

Parameters

action : str - description of method action, key : str - key for hdf5 group or dataset name, cmt : str/None/False - additional comment or no-comment: False is used to turn off history record, None - no-comment.

print_base(offset=' ')[source]

Print content of dictionaries of parameters and history

save_history_file(path='history.txt', verb=False)[source]

Save history in the text file

tsec_to_tstr(tsec, tsfmt=None, addfsec=True)[source]

converts float tsec like 1471035078.908067 to the string 2016-08-12T13:51:18.908067

tstr_to_tsec(tstr, tsfmt=None)[source]

converts string tstr like 2016-08-12T13:51:18.908067 to the float time in seconds 1471035078.908067

Class DCType for the Detector Calibration (DC) project

Usage:

# Import
from PSCalib.DCType import DCType

# Initialization
o = DCType(type)

# Methods
o.set_ctype(ctype)                 # add (str) of time ranges for ctype.
ctype  = o.ctype()                 # returns (str) of ctype name.
ranges = o.ranges()                # returns (dict) of time range objects.
range  = o.range(begin, end)       # returns time stamp validity range object.
ro     = o.range_for_tsec(tsec)    # (DCRange) range object for time stamp in (double) sec
ro     = o.range_for_evt(evt)      # (DCRange) range object for psana.Evt object 
o.add_range(begin, end)            # add (str) of time ranges for ctype.
kr = o.mark_range(begin, end)      # mark range from the DCType object, returns (str) key or None
kr = o.mark_range_for_key(keyrange)# mark range specified by (str) keyrange from the DCType object, returns (str) key or None
o.mark_ranges()                    # mark all ranges from the DCType object
o.clear_ranges()                   # delete all range objects from dictionary.

o.save(group)                      # saves object content under h5py.group in the hdf5 file.
o.load(group)                      # loads object content from the hdf5 file. 
o.print_obj()                      # print info about this object and its children
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016 by Mikhail Dubrovin

class DCType.DCType(ctype, cmt=None)[source]

Bases: PSCalib.DCInterface.DCTypeI

Class for the Detector Calibration (DC) project

Parameters

ctype : gu.CTYPE - enumerated calibration type cmt : str - comment

mark_range(begin, end=None)[source]

Marks child object for deletion in save()

mark_range_for_key(keyrng, cmt=False)[source]

Marks child object for deletion in save()

mark_ranges()[source]

Marks all child objects for deletion in save()

range_for_evt(evt)[source]

Return DCRange object from all available which range validity is matched to the evt time.

range_for_tsec(tsec)[source]

Return DCRange object from all available which range validity is matched to tsec.

Class DCRange for the Detector Calibration (DC) project

Usage:

# Import
from PSCalib.DCRange import DCRange

# Initialization
o = DCRange(begin, end=None, cmt=None)

# Methods
str_range   = o.range()               # (str) of the time stamp validity range
t_sec       = o.begin()               # (double) time stamp beginning validity range
t_sec       = o.end()                 # (double) time stamp ending validity range or (str) 'end'
dico        = o.versions()            # (list of uint) versions of calibrations
v           = o.vnum_def()            # returns default version number
v           = o.vnum_last()           # returns last version number 
vo          = o.version(vnum=None)    # returns version object for specified version
ts_in_range = o.tsec_in_range(tsec)   # (bool) True/False if tsec is/not in the validity range
evt_in_range= o.evt_in_range(evt)     # (bool) True/False if evt is/not in the validity range
o.set_begin(tsbegin)                  # set (int) time stamp beginning validity range
o.set_end(tsend)                      # set (int) time stamp ending validity range
o.add_version(vnum=None, tsec_prod=None, nda=None, cmt=None) # add object for new version of calibration data
o.set_vnum_def(vnum=None)             # set default version number, if available. vnum=None - use last available.
vd = o.mark_version(vnum=None)        # mark version for deletion, returns version number or None if nothing was deleted
o.mark_versions()                     # mark all registered versions for deletion

o.save(group)                         # saves object content under h5py.group in the hdf5 file. 
o.load(group)                         # loads object content from the hdf5 file. 
o.print_obj()                         # print info about this object and its children
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016-09-23 at Mikhail Dubrovin

class DCRange.DCRange(begin, end=None, cmt=None)[source]

Bases: PSCalib.DCInterface.DCRangeI

Class for the Detector Calibration (DC) project

Parameters

  • begin : double - time in sec
  • end : double - time in sec or None meaning infinity
  • cmt : str - comment
__cmp__(other)[source]

for comparison in sorted()

mark_version(vnum=None, cmt=False)[source]

Marks child object for deletion in save()

mark_versions()[source]

Marks all child objects for deletion in save()

DCRange.key(begin, end=None)[source]

Return range as a string, ex.: 1471285222-1471285555 or 1471285222-end from double time like 1471285222.123456

Class DCVersion for the Detector Calibration (DC) project

Usage:

# Import
from PSCalib.DCVersion import DCVersion

# Initialization
o = DCVersion(vnum, tsprod=None, arr=None, cmt=None)

# Methods
o.set_vnum(vnum)            # sets (int) version 
o.set_tsprod(tsprod)        # sets (double) time stamp of the version production
o.add_data(data)            # sets (str or np.array) calibration data
vnum   = o.vnum()           # returns (int) version number
s_vnum = o.str_vnum()       # returns (str) version number
tsvers = o.tsprod()         # returns (double) time stamp of the version production
data   = o.data()           # returns (np.array) calibration array
o.save(group)               # saves object content under h5py.group in the hdf5 file. 
o.load(group)               # loads object content from the h5py.group of hdf5 file. 
o.print_obj()               # print info about this object.

# and all methods inherited from PSCalib.DCBase
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016 by Mikhail Dubrovin

class DCVersion.DCVersion(vnum, tsprod=None, arr=None, cmt=None)[source]

Bases: PSCalib.DCInterface.DCVersionI

Class for the Detector Calibration (DC) project

Parameters

vnum : int - version number

tsprod : double - time in sec

arr : numpy.array - array of constants to save

cmt : str - comment

DCInterface - abstract interface for the Detector Calibration (DC) project

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

class DCInterface.DCRangeI(begin, end, cmt=None)[source]

Bases: PSCalib.DCBase.DCBase

Abstract interface class for the Detector Calibration (DC) project

o = DCRangeI(begin, end)

tsbegin = o.begin() # (int) time stamp beginning validity range tsend = o.end() # (int) time stamp ending validity range dico = o.versions() # (list of uint) versions of calibrations vnum = o.vnum_def() # (DCVersion ~ h5py.Group) reference to the default version in the time-range object vo = o.version(vers) # (DCVersion ~ h5py.Group) specified version in the time-range object bool = o.tsec_in_range(tsec) # (bool) True/False if tsec is/not in the validity range bool = o.evt_in_range(evt) # (bool) True/False if evt is/not in the validity range o.set_begin(tsbegin) # set (int) time stamp beginning validity range o.set_end(tsend) # set (int) time stamp ending validity range o.add_version(vers) # set (DCVersion ~ h5py.Group) versions of calibrations o.set_versdef(vers) # set (DCVersion ~ h5py.Group) versions of calibrations vnum = o.mark_version(vers) # del version o.mark_versions() # del all registered versions

class DCInterface.DCStoreI(fname, cmt=None)[source]

Bases: PSCalib.DCBase.DCBase

Abstract interface class for the Detector Calibration (DC) project

cs = DCStoreI(fname)

tscfile = cs.tscfile() # (int) time stamp of the file creation dettype = cs.dettype() # (str) detector type detid = cs.detid() # (str) detector id detname = cs.detname() # (str) detector name of self object predecessor = cs.predecessor() # (str) detname of predecessor or None successor = cs.successor() # (str) detname of successor or None ctypes = cs.ctypes() # (list) calibration types in the file cto = cs.ctypeobj(ctype) # (DCType ~ h5py.Group) calibration type object

cs.set_tscfile(ts) # set (int) time stamp of the file creation cs.set_dettype(dettype) # set (str) detector type cs.set_detid(detid) # set (str) detector id cs.set_detname(detname) # set (str) detector name of self object cs.set_predecessor(pred) # set (str) detname of predecessor or None cs.set_successor(succ) # set (str) detname of successor or None cs.add_ctype(ctype) # add (str) calibration type to the DCStore object ct = cs.mark_ctype(ctype) # mark ctype (str) from the DCStore object, returns (str) ctype or None cs.mark_ctypes() # mark all ctypes from the DCStore object cs.clear_ctypes(ctype) # clear dictionary of ctypes in the DCStore object cs.save(path, mode) # save current calibration in the file specified by path, if path is Null - update current file. cs.load(path) # load content of the file in DCStore object

class DCInterface.DCTypeI(ctype, cmt=None)[source]

Bases: PSCalib.DCBase.DCBase

Abstract interface class for the Detector Calibration (DC) project

cto = DCTypeI(type)

ctype = cto.ctype() # (str) of ctype name ranges = cto.ranges() # (list) of time ranges for ctype ro = cto.rangeobj(begin, end) # (DCRange ~ h5py.Group) time stamp validity range object ro = cto.range_for_tsec(tsec) # (DCRange) range object for time stamp in (double) sec ro = cto.range_for_evt(evt) # (DCRange) range object for psana.Evt object cto.add_range(tsr) # add (str) of time ranges for ctype keyr = cto.mark_range(begin, end) # mark range from the DCType object keyr = cto.mark_range_for_key(keyr) # mark range from the DCType object cto.mark_ranges(tsr) # mark all ranges from the DCType object cto.print_obj()

class DCInterface.DCVersionI(vnum, tsprod=None, arr=None, cmt=None)[source]

Bases: PSCalib.DCBase.DCBase

Abstract interface class for the Detector Calibration (DC) project

o = DCVersionI(vnum, tsprod=None, arr=None)

o.set_vnum(vnum) # sets (int) version o.set_tsprod(tsprod) # sets (double) time stamp of the version production o.add_data(nda) # sets (np.array) calibration array vnum = o.vnum() # returns (int) version number s_vnum = o.str_vnum() # returns (str) version number tsvers = o.tsprod() # returns (double) time stamp of the version production nda = o.data() # returns (np.array) calibration array o.save(group) # saves object content under h5py.group in the hdf5 file. o.load(group) # loads object content from the h5py.group of hdf5 file.

Class DCFileName - file name object for Detector Calibration Store (DCS) project

Usage:

# Import
from PSCalib.DCFileName import DCFileName

# Instatiation
o = DCFileName(env, 'Epix', calibdir='path-to/calib')
# Methods
o.set_dettype(env, src)
o.set_detid(env, src)
status = o.make_path_to_calib_file(mode=0770)

dt    = o.dettype()              # e.g., epix100a
did   = o.detid()                # e.g., 3925868555
dn    = o.detname()              # e.g., epix100a-3925868555
fname = o.calib_file_name()      # e.g., epix100a-3925868555.h5
fdir  = o.calib_file_dir()       # e.g., /reg/neh/home4/dubrovin/LCLS/rel-calib/calib
fpath = o.calib_file_path()      # e.g., /reg/neh/home4/dubrovin/LCLS/rel-calib/calib/epix100a/epix100a-3925868555.h5
fdir  = o.calib_file_dir_repo()  # e.g., /reg/d/psdm/detector/calib/epix100a/
fpath = o.calib_file_path_repo() # e.g., /reg/d/psdm/detector/calib/epix100a/epix100a-3925868555.h5
o.print_attrs() # print attributes
o.log_attrs()  # dump attributes in the logger
s = o.str_attrs() # returns a string of attributes
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

class DCFileName.DCFileName(env, src, calibdir=None)[source]

File name generator object for Detector Calibration Store (DCS) project.

Parameters

evt : psana.Event -> event time src : str - source short/full name, alias or full calibdir : str - fallback path to calib dir (if xtc file is copied - calib and experiment name are lost)

calib_file_dir()[source]

Returns file directory name, e.g.: …/calib/epix100a/

calib_file_dir_repo()[source]

Returns repository directory, e.g.: /reg/d/psdm/detector/calib/epix100a/

calib_file_name()[source]

Returns file name, e.g.: epix100a-3925868555.h5

calib_file_path()[source]

Returns path to the file, e.g.: …/calib/epix100a/epix100a-3925868555.h5

calib_file_path_repo()[source]

Returns path to the file in repository, e.g.: /reg/d/…/calib/epix100a/epix100a-3925868555.h5

detid()[source]

Returns detector id, e.g.: 3925868555

detname()[source]

Returns detector name, e.g.: epix100a-3925868555

dettype()[source]

Returns detector id, e.g.: epix100a

make_path_to_calib_file(depth=2, mode=509)[source]

Creates path beginning from calib directory, e.g.: …/calib/epix100a/ Returns True if path created and exists.

path_to_data()[source]

Returns path to data from env ‘SIT_PSDM_DATA’ else ‘/reg/d/psdm’

Class DCDetectorId for the Detector Calibration (DC) project

Usage:

# Import
from PSCalib.DCDetectorId import id_epix, id_cspad

# Parameters
dsn = 'exp=cxif5315:run=169'
# or
dsn = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc'
ds = psana.DataSource(dsn)
env = ds.env()
src = psana.Source('CxiDs2.0:Cspad.0') # or unique portion of the name ':Cspad.' or alias 'DsaCsPad'

# Access methods
ide = id_epix(env, src)
idc = id_cspad(env, src)
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

DCDetectorId.id_cspad(env, src)[source]

Returns detector full name for any src, e.g., XppGon.0:Cspad2x2.0

DCDetectorId.id_det_noid(env, src)[source]

Returns detector full name for any src, e.g., XppGon.0:Cspad2x2.0

DCDetectorId.id_epix(env, src)[source]

Returns Epix100 Id as a string, e.g., 3925999616-0996663297-3791650826-1232098304-0953206283-2655595777-0520093719

DCConfigParameters - class supporting configuration parameters for application

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment. Created: 2016-05-17 by Mikhail Dubrovin

class DCConfigParameters.DCConfigParameters(fname=None)[source]

Bases: CalibManager.ConfigParameters.ConfigParameters

A storage of configuration parameters for Detector Calibration Store (DCS) project.

__init__(fname=None)[source]

Constructor. - fname the file name with configuration parameters, if not specified then default value.

DCEmail - class for Detector Calibration Store (DCS) project

Usage:

# Import
from PSCalib.DCEmail import send_text_email

# Send message via e-mail
send_text_email(msg='Text message',               subject='Text subject',               email_from='do-not-reply@slac.stanford.edu',               email_to='do-not-send@slac.stanford.edu')
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

DCEmail.send_text_email(msg=None, subject=None, email_from=None, email_to=None)[source]

Sends e-mail.

Class DCLogger - logger for Detector Calibration Store

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016-05-17 by Mikhail Dubrovin

Class DCUtils contains a set of utilities

Usage:

# Import
import PSCalib.DCUtils as gu

# Methods
# Get string with time stamp, ex: 2016-01-26T10:40:53
ts    = gu.str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None)

usr   = gu.get_enviroment(env='USER')
usr   = gu.get_login()
host  = gu.get_hostname()
cwd   = gu.get_cwd()
gu.create_directory(dir, mode=0775)
gu.create_path(path, depth=2, mode=0775)
gu.save_string_as_dset(grp, name, s)
src   = gu.source_full_name(env, src)
dtype = gu.dettype_from_str_source(src)

src   = gu.string_from_source(source) # source is psana.Source object or string like
                                      # 'CxiDs2.0:Cspad.0' from 'DetInfo(CxiDs2.0:Cspad.0)'
dname  = gu.detector_full_name(env, src)
source = gu.psana_source(env, srcpar)
fid    = gu.evt_fiducials(evt)
t_sec  = gu.evt_time(evt)
t_sec  = gu.env_time(env)

# methods for HDF5 
sg = gu.get_subgroup(grp, subgr_name)
gu.delete_object(grp, oname)
gu.save_object_as_dset(grp, name, shape=None, dtype=None, data=0)
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2016 by Mikhail Dubrovin

DCUtils.delete_object(grp, oname)[source]

For hdf5: removes object from group.

DCUtils.detector_full_name(env, src)[source]

Returns full detector name like ‘XppGon.0:Cspad2x2.0’ for short src, alias src, or psana.Source.

DCUtils.dettype_from_str_source(src)[source]

Returns the detector type from full psana source name (Ex.: Cspad2x2 from DetInfo(XppGon.0:Cspad2x2.0)

DCUtils.env_time(env)[source]

Returns event (double) time for input psana.Env object.

DCUtils.evt_fiducials(evt)[source]

Returns event fiducials.

DCUtils.evt_time(evt)[source]

Returns event (double) time for input psana.Event object.

DCUtils.get_cwd()[source]

Returns current working directory

DCUtils.get_enviroment(env='USER')[source]

Returns the value of specified by string name environment variable

DCUtils.get_hostname()[source]

Returns login name

DCUtils.get_login()[source]

Returns login name

DCUtils.get_subgroup(grp, subgr_name)[source]

For hdf5: returns subgroup of the group if it exists or creates and returns new subgroup

DCUtils.par_to_tsec(par)[source]

Checks if par is float or assumes that it is psana.Event and returns event time in (float) sec or None.

Parameters

  • par : psana.Event | psana.Env | float - tsec event time | None

Returns

event time in (float) sec or None.

DCUtils.psana_source(env, srcpar)[source]

returns psana.Source(src) from other psana.Source brief src or alias.

Parameters

  • srcpar : str - regular source or its alias, ex.: ‘XppEndstation.0:Rayonix.0’ or ‘rayonix’
  • set_sub : bool - default=True - propagates source parameter to low level package
DCUtils.save_object_as_dset(grp, name, shape=None, dtype=None, data=0)[source]

Saves object as h5py dataset

Currently supports scalar int, double, string and numpy.array

DCUtils.save_string_as_dset(grp, name, s)[source]

Creates and returns the h5py dataset object with name for single string s

DCUtils.source_full_name(env, src)[source]

Returns full name like ‘DetInfo(XppGon.0:Cspad2x2.0)’ of the brief source or its alias using env.configStore().keys()

DCUtils.str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None)[source]

Returns string timestamp for specified format and time in sec or current time by default

DCUtils.string_from_source(source)[source]

Returns string like ‘CxiDs2.0:Cspad.0’ from ‘DetInfo(CxiDs2.0:Cspad.0)’ or ‘DsaCsPad’ from ‘Source(‘DsaCsPad’)’ form input string or psana.Source object

Class CalibFileFinder is a python version of CalibFileFinder.cpp - finds calibration file

Usage:

from PSCalib.CalibFileFinder import CalibFileFinder

cdir  = '/reg/d/psdm/CXI/cxi83714/calib/'
group = 'CsPad::CalibV1'   # optional parameter, if not available will be set for src from dict 
src   = 'CxiDs1.0:Cspad.0'
type  = 'pedestals'
rnum  = 137

cff = CalibFileFinder(cdir, group, pbits=0377)
#OR
cff = CalibFileFinder(cdir)
fname = cff.findCalibFile(src, type, rnum)

fname_new = cff.makeCalibFileName(src, type, run_start, run_end=None)

#-----------------------------------------------
# ALTERNATIVE usage of direct access methods

from PSCalib.CalibFileFinder import find_calib_file, make_calib_file_name

fname_existing = find_calib_file(cdir, src, type, rnum, pbits=1)
fname_new      = make_calib_file_name(cdir, src, type, run_start, run_end=None, pbits=1)

#-----------------------------------------------
# Deploy file or numpy array as a file in the calibration store

# use optional dictionary of comments to save in the HISTORY and file
arr = np.ones((32,185,388))
cmts = {'exp':'cxi12345', 'ifname':'input-file-name', 'app':'my-app-name', 'comment':'my-comment'}
deploy_calib_array(cdir, src, type, run_start, run_end, arr, cmts, fmt='%.1f', pbits=1)

cmts = {'exp':'cxi12345', 'app':'my-app-name', 'comment':'my-comment'}
ifname='path-to-my-own-calibtation-file/file-name.txt'
deploy_calib_file(cdir, src, type, run_start, run_end, ifnameq, cmts, pbits=1)

See GlobalUtils, NDArrIO

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibFileFinder.deploy_calib_array(cdir, src, type, run_start, run_end=None, arr=None, dcmts={}, fmt='%.1f', pbits=1)[source]

Deploys array in calibration file

  • makes the new file name using make_calib_file_name(…)
  • if file with this name already exists - rename it with current timestamp in the name
  • save array in file
  • add history record
CalibFileFinder.deploy_calib_file(cdir, src, type, run_start, run_end=None, ifname='', dcmts={}, pbits=1)[source]

Deploys calibration file

  • makes the new file name using make_calib_file_name(…)
  • if file with this name already exists - rename it with current timestamp in the name
  • save array in file
  • add history record

NDArrIO - i/o methods to read/write numpy array in the text file

Usage:

# Import
from PSCalib.NDArrIO import save_txt, load_txt, list_of_comments

# Save n-dimensional numpy array in the text file.
save_txt(fname, arr, cmts=(), fmt='%.1f')

# Load 1-, 2-, n-dimensional array (if metadata available) from file .
arr = load_txt(fname)    # this version unpacks data directly in this script
# or
arr = load_txt_v2(fname) # v2 uses numpy.loadtxt(...) to load data (~30% slower then the load_txt) 

# Get list of str objects - comment records with '#' in 1st position from file.
cmts = list_of_comments(fname)

#------------------------------
# Example of the file header:
#------------------------------
# TITLE      File to load ndarray of calibration parameters
# 
# EXPERIMENT amo12345
# DETECTOR   Camp.0:pnCCD.1
# CALIB_TYPE pedestals

# DATE_TIME  2014-05-06 15:24:10
# AUTHOR     <user-login-name>

# line of comment always begins with # 
# Mandatory fields to define the ndarray<TYPE,NDIM> and its shape as unsigned shape[NDIM] = (DIM1,DIM2,DIM3)
# DTYPE       float
# NDIM        3
# DIM:1       3
# DIM:2       4
# DIM:3       8
#------------------------------

See: AreaDetector

For more detail see AreaDetector.

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

NDArrIO.list_of_comments(fname)[source]

Returns list of str objects - comment records from file. - fname - file name for text file.

NDArrIO.load_txt(fname)[source]

Reads n-dimensional numpy array from text file with metadata. - fname - file name for text file.

NDArrIO.load_txt_v2(fname)[source]

Reads n-dimensional numpy array from text file with metadata. - fname - file name for text file.

NDArrIO.save_txt(fname='nda.txt', arr=None, cmts=(), fmt='%.1f', verbos=False, addmetad=True)[source]

Save n-dimensional numpy array to text file with metadata. - fname - file name for text file, - arr - numpy array, - cmts -list of comments which will be saved in the file header.

CalibPars - abstract interface for access to calibration parameters

Methods of this class should be re-implemented in derived classes with name pattern CalibPars<Detector> for different type of detectore. For example, CSPAD can be implemented in class CalibParsCspadV1 which enherits from CalibPars, etc. Currently implementation of this interface for all detectors is done in class GenericCalibPars. Access to all detectors is available through the factory method in class CalibParsStore.

Usage of (implemented) interface methods:

from PSCalib.CalibPars import CalibPars
import PSCalib.GlobalUtils as gu

cp = CalibPars()
cp.print_attrs()

size = cp.pedestals()
size = cp.pixel_status()
size = cp.pixel_datast()
size = cp.pixel_rms()
size = cp.pixel_gain()
size = cp.pixel_offset()
size = cp.pixel_mask()
size = cp.pixel_bkgd()
size = cp.common_mode()

ctype = gu.PEDESTALS # ex.: gu.PIXEL_STATUS, gu.PIXEL_RMS, gu.PIXEL_MASK, etc.
size = cp.ndim(ctype)
size = cp.size(ctype)
size = cp.shape(ctype)
size = cp.status(ctype)
Methods:
  • print_attrs()
  • pedestals()
  • pixel_status()
  • pixel_datast()
  • pixel_rms()
  • pixel_gain()
  • pixel_offset()
  • pixel_mask()
  • pixel_bkgd()
  • common_mode()
  • ndim()
  • shape()
  • size()
  • status()
See classes:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsStore - a factory class/method

Switches between different device-dependent calibration constants using CalibPars interface.

Usage:

# Import
from PSCalib.CalibParsStore import cps
from PSCalib.GlobalUtils import *

# Initialization
calibdir = env.calibDir()  # or e.g. '/reg/d/psdm/<INS>/<experiment>/calib'
group = None               # or e.g. 'CsPad::CalibV1'
source = 'Camp.0:pnCCD.1'
runnum = 10                # or e.g. evt.run()
pbits = 255
o = cps.Create(calibdir, group, source, runnum, pbits)

# or using different list of parameters to access calibration from hdf5 DCS file:
o = cps.CreateForEvtEnv(self, calibdir, group, source, evt, env, pbits=0)

# Access methods
nda = o.pedestals()
nda = o.pixel_status()
nda = o.pixel_datast()
nda = o.pixel_rms()
nda = o.pixel_mask()
nda = o.pixel_gain()
nda = o.pixel_offset()
nda = o.pixel_bkgd()
nda = o.common_mode()

status = o.status(ctype=PEDESTALS) # see list of ctypes in :py:class:`GlobalUtils`
shape  = o.shape(ctype)
size   = o.size(ctype)
ndim   = o.ndim(ctype)
Methods:
  • Create()
  • CreateForEvtEnv()
See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2013-03-08 by Mikhail Dubrovin

class CalibParsStore.CalibParsStore[source]

Factory class for CalibPars object of different detectors

Create(calibdir, group, source, runnum, pbits=0, fnexpc=None, fnrepo=None, tsec=None)[source]

Factory method

Parameters

  • calibdir : string - calibration directory, ex: /reg/d/psdm/AMO/amoa1214/calib
  • group : string - group, ex: PNCCD::CalibV1
  • source : string - data source, ex: Camp.0:pnCCD.0
  • runnum : int - run number, ex: 10
  • pbits=0 : int - print control bits, ex: 255

Returns

  • GenericCalibPars object
CreateForEvtEnv(calibdir, group, source, par, env, pbits=0)[source]

Factory method This method makes access to the calibration store with fallback access to hdf5 file.

Parameters

  • calibdir : string - calibration directory, ex: /reg/d/psdm/AMO/amoa1214/calib
  • group : string - group, ex: PNCCD::CalibV1
  • source : string - data source, ex: Camp.0:pnCCD.0
  • par : int runnum or psana.Event - is used to get run number
  • env : psana.Env - environment object - is used to retrieve file name to get dataset time to retrieve DCRange
  • pbits=0 : int - print control bits, ex: 255

Returns

  • GenericCalibPars object

Class GenericCalibPars - implementation of CalibPars interface methods for generic detectors

Usage:

# THIS CLASS IS NOT SUPPOSED TO BE USED AS SELF-DEPENDENT...
# USE :py:class:`PSCalib.CalibParsStore`

from PSCalib.GenericCalibPars import GenericCalibPars

from PSCalib.CalibParsBaseAndorV1     import CalibParsBaseAndorV1    
from PSCalib.CalibParsBaseCameraV1    import CalibParsBaseCameraV1   
from PSCalib.CalibParsBaseCSPad2x2V1  import CalibParsBaseCSPad2x2V1 
...
from PSCalib.CalibParsBasePnccdV1     import CalibParsBasePnccdV1    

cbase = CalibParsBasePnccdV1()    

calibdir = '/reg/d/psdm/CXI/cxif5315/calib'
group    = 'PNCCD::CalibV1'
source   = 'CxiDs2.0:Cspad.0'
runnum   = 60
pbits    = 255
ctype    = gu.PEDESTALS

gcp = GenericCalibPars(cbase, calibdir, group, source, runnum, pbits)

nda = gcp.pedestals()
nda = gcp.pixel_rms()
nda = gcp.pixel_mask()
nda = gcp.pixel_bkgd()
nda = gcp.pixel_status()
nda = gcp.pixel_datast()
nda = gcp.pixel_gain()
nda = gcp.pixel_offset()
nda = gcp.common_mode()

status = gcp.get_status(ctype=PEDESTALS) # see  list of ctypes in :py:class:`PSCalib.GlobalUtils`
shape  = gcp.get_shape(ctype)
size   = gcp.get_size(ctype)
ndim   = gcp.get_ndim(ctype)

nda = gcp.set_version(vers=None)
nda = gcp.constants_default(ctype)
nda = gcp.constants_calib(ctype)
nda = gcp.constants_dcs(ctype, vers=None, verb=False)
nda = gcp.constants(ctype, vers=None, verb=False)

See CalibPars, CalibParsStore, CalibParsCspad2x1V1, GlobalUtils

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsBaseAcqirisV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

Class CalibParsBaseAndor3dV1 holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsBaseAndorV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail S. Dubrovin

Class CalibParsBaseCameraV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsBaseCSPad2x2V1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

Class CalibParsBaseCSPadV1 holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsBaseEpix100aV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

Class CalibParsBaseImpV1 holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsBaseJungfrauV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

Class CalibParsBasePnccdV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

CalibParsBasePrincetonV1 - holds basic calibration metadata parameters for associated detector

See:

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Author: Mikhail Dubrovin

GlobalUtils - a set of utilities

Usage:

# Import
import PSCalib.GlobalUtils as gu

# Methods
#resp = gu.<method(pars)>

dettype = gu.det_type_from_source(source)
detname = gu.string_from_source(source)

mmask = gu.merge_masks(mask1=None, mask2=None, dtype=np.uint8)
mask  = gu.mask_neighbors(mask_in, allnbrs=True, dtype=np.uint8)
lo,hi = gu.evaluate_limits(arr, nneg=5, npos=5, lim_lo=1, lim_hi=1000, verbos=1, cmt='')

arr2d = gu.reshape_nda_to_2d(nda)
arr3d = gu.reshape_nda_to_3d(nda)

# Get string with time stamp, ex: 2016-01-26T10:40:53
ts    = gu.str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None)

usr   = gu.get_enviroment(env='USER')
usr   = gu.get_login()
host  = gu.get_hostname()
cwd   = gu.get_cwd()
rec   = gu.log_rec_on_start() # e.g. '2017-09-27T10:40:24 user:dubrovin@psanagpu104 cwd:/reg/neh/home4/dubrovin/LCLS/con-jungfrau ...'
gu.add_rec_to_log(lfname, rec, verbos=False)

exp  = gu.exp_name(env)
cdir = gu.calib_dir(env)
#### tsec, tnsec, fiducial, tsdate, tstime = gu.time_pars(evt) # needs in psana...

gu.create_directory(dir, verb=False)
gu.create_directory_with_mode(dir, mode=0777, verb=False)
exists = gu.create_path(path, depth=6, mode=0777, verb=True)

arr  = gu.load_textfile(path)
gu.save_textfile(text, path, mode='w') # mode: 'w'-write, 'a'-append 

path = gu.replace('/path/#YYYY-MM/fname.txt', '#YYYY-MM', gu.str_tstamp(fmt='%Y/%m'))

ifname = 'fname.txt'
ctypedir = '/some-path/calib/Jungfrau::CalibV1/CxiEndstation.0:Jungfrau.0/'
ctype = 'pedestals'
ofname = '123-end.data'
rec = gu.history_record(ifname, ctypedir, ctype, ofname, comment='')
path_clb = gu.path_to_calib_file(ctypedir, ctype, ofname)
path_his = gu.path_to_history_file(ctypedir, ctype)

cmd = gu.command_deploy_file(ifname, path_clb)
cmd = gu.command_add_record_to_file(rec, path_his)

tpl = gu.calib_fname_template(exp, runnum, tsec, tnsec, fid, tsdate, tstime, src, nevts, ofname)

gu.deploy_file(ifname, ctypedir, ctype, ofname, lfname=None, verbos=False)

See: other methods in CalibPars, CalibParsStore

This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.

Created: 2013-03-08 by Mikhail Dubrovin

GlobalUtils.ZYLA = 27

Enumetated detector types

GlobalUtils.add_rec_to_log(lfname, rec, verbos=False)[source]

Adds record rec to the log file with path lfname. If path does not exist, it is created beginning from depth=5.

GlobalUtils.calib_fname_template(exp, runnum, tsec, tnsec, fid, tsdate, tstime, src, nevts, ofname)[source]

Replaces parts of the file name ofname specified as #src, #exp, #run, #evts, #type, #date, #time, #fid, #sec, #nsec with actual values.

RETURNS

  • template (str) - file name template, e.g.: nda-cxi11216-r0009-CxiEndstation.0:Jungfrau.0-e000010-%s.txt,
    where %s stands for supplied late type.
GlobalUtils.command_add_record_to_file(rec, fname)[source]

Returns command to add record to file.

GlobalUtils.command_deploy_file(ifname, ofname)[source]

Returns command to deploys file with calibration constants in the calib store.

GlobalUtils.create_directory_with_mode(dir, mode=511, verb=False)[source]

Creates directory and sets its mode

GlobalUtils.create_path(path, depth=6, mode=511, verb=False)[source]

Creates missing path of specified depth from the beginning e.g. for ‘/reg/g/psdm/logs/calibman/2016/07/log-file-name.txt’ or ‘/reg/d/psdm/cxi/cxi11216/calib/Jungfrau::CalibV1/CxiEndstation.0:Jungfrau.0/pedestals/9-end.data’

Returns True if path to file exists, False othervise

GlobalUtils.deploy_file(ifname, ctypedir, ctype, ofname, lfname=None, verbos=False)[source]

Deploys file with calibration constants in the calib store, adds history record in file and in logfile.

Parameters

  • ifname : str - input file name, e.g.: ‘fname.txt’
  • ctypedir : str - path to calibtype directory, e.g. ‘/some-path/calib/Jungfrau::CalibV1/CxiEndstation.0:Jungfrau.0/’
  • ctype : str - calibration type, e.g.: ‘pedestals’
  • ofname : str - output file name, e.g.: ‘123-end.data’
  • lfname : str - log file path or None, to add history record
  • verbos : bool - verbosity
GlobalUtils.det_type_from_source(source)[source]

Returns enumerated detector type for string source

GlobalUtils.dic_det_type_to_calib_group = {0: 'UNDEFINED', 1: 'CsPad::CalibV1', 2: 'CsPad2x2::CalibV1', 3: 'Princeton::CalibV1', 4: 'PNCCD::CalibV1', 5: 'Camera::CalibV1', 6: 'Camera::CalibV1', 7: 'Camera::CalibV1', 8: 'Camera::CalibV1', 9: 'Camera::CalibV1', 10: 'Camera::CalibV1', 11: 'Epix::CalibV1', 12: 'Epix10k::CalibV1', 13: 'Epix100a::CalibV1', 14: 'Camera::CalibV1', 15: 'Andor::CalibV1', 16: 'Acqiris::CalibV1', 17: 'Imp::CalibV1', 18: 'Camera::CalibV1', 19: 'Camera::CalibV1', 20: 'EvrData::CalibV1', 21: 'Camera::CalibV1', 22: 'Timepix::CalibV1', 23: 'Fli::CalibV1', 24: 'Pimax::CalibV1', 25: 'Andor3d::CalibV1', 26: 'Jungfrau::CalibV1', 27: 'Camera::CalibV1'}

Dictionary for detector type : group

GlobalUtils.dic_det_type_to_name = {0: 'UNDEFINED', 1: 'Cspad', 2: 'Cspad2x2', 3: 'Princeton', 4: 'pnCCD', 5: 'Tm6740', 6: 'Opal1000', 7: 'Opal2000', 8: 'Opal4000', 9: 'Opal8000', 10: 'OrcaFl40', 11: 'Epix', 12: 'Epix10k', 13: 'Epix100a', 14: 'Fccd960', 15: 'Andor', 16: 'Acqiris', 17: 'Imp', 18: 'Quartz4A150', 19: 'Rayonix', 20: 'Evr', 21: 'Fccd', 22: 'Timepix', 23: 'Fli', 24: 'Pimax', 25: 'Andor3d', 26: 'Jungfrau', 27: 'Zyla'}

Dictionary for detector type : name

GlobalUtils.evaluate_limits(arr, nneg=5, npos=5, lim_lo=1, lim_hi=1000, verbos=1, cmt='')[source]

Evaluates low and high limit of the array, which are used to find bad pixels.

GlobalUtils.get_cwd()[source]

Returns current working directory

GlobalUtils.get_enviroment(env='USER')[source]

Returns the value of specified by string name environment variable

GlobalUtils.get_hostname()[source]

Returns login name

GlobalUtils.get_login()[source]

Returns login name

GlobalUtils.history_record(ifname, ctypedir, ctype, ofname, comment='')[source]

Returns (str) history record about deployed constants.

Parameters

  • ifname : str - input file name, e.g.: ‘fname.txt’
  • ctypedir : str - path to calibtype directory, e.g. ‘/some-path/calib/Jungfrau::CalibV1/CxiEndstation.0:Jungfrau.0/’
  • ctype : str - calibration type, e.g.: ‘pedestals’
  • ofname : str - output file name, e.g.: ‘123-end.data’
  • comment : str - any comment
  • verbos : bool - verbosity
GlobalUtils.list_of_calib_groups = ('UNDEFINED', 'CsPad::CalibV1', 'CsPad2x2::CalibV1', 'Princeton::CalibV1', 'PNCCD::CalibV1', 'Camera::CalibV1', 'Camera::CalibV1', 'Camera::CalibV1', 'Camera::CalibV1', 'Camera::CalibV1', 'Camera::CalibV1', 'Epix::CalibV1', 'Epix10k::CalibV1', 'Epix100a::CalibV1', 'Camera::CalibV1', 'Andor::CalibV1', 'Acqiris::CalibV1', 'Imp::CalibV1', 'Camera::CalibV1', 'Camera::CalibV1', 'EvrData::CalibV1', 'Camera::CalibV1', 'Timepix::CalibV1', 'Fli::CalibV1', 'Pimax::CalibV1', 'Andor3d::CalibV1', 'Jungfrau::CalibV1', 'Camera::CalibV1')

List of enumetated detector calibration groups

GlobalUtils.list_of_det_names = ('UNDEFINED', 'Cspad', 'Cspad2x2', 'Princeton', 'pnCCD', 'Tm6740', 'Opal1000', 'Opal2000', 'Opal4000', 'Opal8000', 'OrcaFl40', 'Epix', 'Epix10k', 'Epix100a', 'Fccd960', 'Andor', 'Acqiris', 'Imp', 'Quartz4A150', 'Rayonix', 'Evr', 'Fccd', 'Timepix', 'Fli', 'Pimax', 'Andor3d', 'Jungfrau', 'Zyla')

List of enumetated detector names

GlobalUtils.list_of_det_type = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)

List of enumetated detector types

GlobalUtils.load_textfile(path)[source]

Returns text file as a str object

GlobalUtils.log_rec_on_start()[source]

Returns (str) record containing timestamp, login, host, cwd, and command line

GlobalUtils.mask_edges(mask, mrows=1, mcols=1, dtype=<type 'numpy.uint8'>)[source]

Return mask with a requested number of row and column pixels masked - set to 0. mask : int - n-dimensional (n>1) array with input mask mrows : int - number of edge rows to mask mcols : int - number of edge columns to mask

GlobalUtils.mask_neighbors(mask, allnbrs=True, dtype=<type 'numpy.uint8'>)[source]

Return mask with masked eight neighbor pixels around each 0-bad pixel in input mask.

mask : int - n-dimensional (n>1) array with input mask allnbrs : bool - False/True - masks 4/8 neighbor pixels.

GlobalUtils.merge_masks(mask1=None, mask2=None, dtype=<type 'numpy.uint8'>)[source]

Merging masks using np.logical_and rule: (0,1,0,1)^(0,0,1,1) = (0,0,0,1)

GlobalUtils.path_to_calib_file(ctypedir, ctype, ofname)[source]

Returns path to file wirh calibration constants in the calib store. e.g. /some-path/calib/Jungfrau::CalibV1/CxiEndstation.0:Jungfrau.0/pedestals/9-end.data See parameters description in history_record().

GlobalUtils.path_to_history_file(ctypedir, ctype)[source]

Returns path to HISTORY file in the calib store. e.g. /some-path/calib/Jungfrau::CalibV1/CxiEndstation.0:Jungfrau.0/pedestals/HYSTORY See parameters description in history_record().

GlobalUtils.replace(template, pattern, subst)[source]

If pattern in the template replaces it with subst. Returns str object template with replaced patterns.

GlobalUtils.reshape_nda_to_2d(arr)[source]

Reshape np.array to 2-d

GlobalUtils.reshape_nda_to_3d(arr)[source]

Reshape np.array to 3-d

GlobalUtils.save_textfile(text, path, mode='w')[source]

Saves text in file specified by path. mode: ‘w’-write, ‘a’-append

GlobalUtils.shape_nda_to_2d(arr)[source]

Return shape of np.array to reshape to 2-d

GlobalUtils.shape_nda_to_3d(arr)[source]

Return shape of np.array to reshape to 3-d

GlobalUtils.str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None)[source]

Returns string timestamp for specified format and time in sec or current time by default

GlobalUtils.string_from_source(source)[source]

Returns string like “CxiDs2.0:Cspad.0” from “Source(‘DetInfo(CxiDs2.0:Cspad.0)’)” or “Source(‘DsaCsPad’)”

RunProcUtils.append_log_file(exp='xpptut15', procname='pixel_status', runs=[], verb=0)[source]

Appends records in the log file for list of (str) runs for specified experiment and process name.

RunProcUtils.arc_file(exp='xpptut15', procname='pixel_status')[source]

Returns (str) arcive log file name, e.g. ‘/reg/g/psdm/logs/run_proc/pixel_status/CXI/xpptut15-proc-arch.txt’

RunProcUtils.control_file(procname='pixel_status')[source]

Returns (str) control file name, e.g. ‘/reg/g/psdm/logs/run_proc/pixel_status/proc_control.txt’

RunProcUtils.dict_exp_run_old(ins='CXI', procname='pixel_status')[source]

Returns dict {exp:list_of_runs} for specified instrument (=None for all) and procname, e.g. {‘mfx13016’:[‘0005’,‘0006’], ‘mfx15070’:[‘0003’,‘0004’,‘0005’],…]

RunProcUtils.exp_run_new(ins='CXI', procname='pixel_status')[source]

Returns new list of tuples (exp,run) for specified instrument (=None for all) and procname, e.g. [(‘mfx13016’,‘0005’), (‘mfx15070’,‘0008’),…]

RunProcUtils.exp_run_new_under_control(procname='pixel_status')[source]

Returns new list of tuples (exp,run) for specified procname for experiments from control file, e.g. [(‘mfx13016’,‘0005’), (‘mfx15070’,‘0008’),…]

RunProcUtils.exp_run_old(ins='CXI', procname='pixel_status')[source]

Returns old list of tuples (exp,run) for specified instrument (=None for all) and procname, e.g. [(‘mfx13016’,‘0005’), (‘mfx15070’,‘0008’),…]

RunProcUtils.experiments(ins='CXI')[source]

Returns list of (8,9-char-str) experiment names for specified 3-char (str) instrument name, or all experiments is ins=None, e.g. [‘mfxo1916’, ‘mfxn8416’, ‘mfxlq3915’,…]

RunProcUtils.experiments_under_control(procname='pixel_status')[source]

Returns list of (str) experiment names from control file.

RunProcUtils.log_file(exp='xpptut15', procname='pixel_status')[source]

Returns (str) log file name, e.g. ‘/reg/g/psdm/logs/run_proc/pixel_status/CXI/xpptut15-proc-runs.txt’

RunProcUtils.move_recs_to_archive(procname, exp, runs)[source]

Move expired run records from log file to archive file.

RunProcUtils.msg_to_log(runs=[])[source]

Returns (str) message to the log file for list of (str) runs.

RunProcUtils.recs_in_log_file(exp='xpptut15', procname='pixel_status', verb=0)[source]

Returns list of (str) records in the log file for specified experiment and process name. E.g. of one record: ‘0151 2017-10-05T15:19:21’

RunProcUtils.runs_in_log_file(exp='xpptut15', procname='pixel_status')[source]

Returns list of (4-char str) runs in the log file for specified experiment and process name. E.g. [‘0059’, ‘0060’,…]

RunProcUtils.runs_in_xtc_dir(exp='xpptut15', verb=0)[source]

Returns sorted list of (str) runs in xtc directory name, e.g. [‘0059’, ‘0060’,…]

RunProcUtils.runs_new_in_exp(exp='xpptut15', procname='pixel_status', verb=0)[source]

Returns list of (4-char str) runs which are found in xtc directory and not yet listed in the log file, e.g. [‘0059’, ‘0060’,…]

RunProcUtils.runs_old_in_exp(exp='xpptut15', procname='pixel_status', verb=0)[source]

Returns list of (4-char str) runs which are found in the log file and are not listed in xtc directory, e.g. [‘0059’, ‘0060’,…]

RunProcUtils.xtc_dir(exp='xpptut15')[source]

Returns (str) xtc directory name, e.g. ‘/reg/d/psdm/XPP/xpptut15/xtc’

SubprocUtils.subproc(cmd, env=None, shell=False)[source]

e.g., command=’bsub -q psananehq -o log-ls.txt ls -l] command_seq=[‘bsub’, ‘-q’, cp.batch_queue, ‘-o’, ‘log-ls.txt’, ‘ls -l’]

Indices and tables