Detector Module

The detector module provides classes for handling detector geometry and pixel information.

Module containing detector class

class dragonfly.detector.CDetector(fname=None, **kwargs)

Bases: object

Dragonfly detector cython class.

The detector file format is specified in github.com/duaneloh/Dragonfly/wiki. This class reads the file and provides numpy arrays for further processing.

Parameters:
  • fname (str) – Path to detector file to populate attributes.

  • norm (bool) – Whether to normalize correction factors, default: True

  • rtype (str) – Reconstruction type (2d or 3d), default: 3d

background

Background value for each pixel, if present, shape (num_pix,).

corr

Correction factors.

detd

Detector distance.

ewald_rad

Ewald sphere radius in voxels.

fname

Path to detector file.

free(self)

Free memory

num_pix

Number of pixels.

parse(self, fname, norm=True, rtype='3d')

Parse Dragonfly detector from file

Parameters:
  • fname (str) – Path to detector file to populate attributes.

  • norm (bool) – Whether to normalize correction factors, default: True

  • rtype (str) – Reconstruction type (2d or 3d), default: 3d

Note: The old ASCII format is no longer supported

parse_background(self, fname)
qmax(self)

Get maximum voxel-space radius

qvals

3D voxel space coordinates for each pixel, shape (num_pix, 3).

raw_mask

Unassembled mask as stored in file (0=good, 1=ignore, 2=bad).

class dragonfly.detector.Detector(fname=None, **kwargs)

Bases: CDetector

Detector class with assembly and coordinate methods.

Extends CDetector with additional functionality for frame assembly, coordinate calculations, and file I/O.

Parameters:
  • fname (str) – Path to detector file to populate attributes.

  • mask_flag (bool) – Whether to read the mask column. Default True.

  • keep_mask_1 (bool) – Whether to consider mask=1 pixels as good. Default True.

cx, cy

Floating point 2D coordinates (origin at (0,0)).

Type:

numpy.ndarray

x, y

Integer shifted 2D coordinates (corner at (0,0)).

Type:

numpy.ndarray

mask

Unassembled mask (1=good, 0=bad).

Type:

numpy.ndarray

mask_assem

Assembled mask (1-good, 0=bad).

Type:

numpy.ndarray

frame_shape

Shape of assembled frame.

Type:

tuple

zoom_bounds

Bounds of zoomed region (xmin, xmax, ymin, ymax).

Type:

tuple

assemble_frame(self, data, zoomed=False, sym=False, avg=False)

Assemble given raw image.

Parameters:
  • data (numpy.ndarray) – Array of num_pix values.

  • zoomed (bool) – Restrict assembled image to non-masked pixels. Default False.

  • sym (bool) – Centro-symmetrize image. Default False.

  • avg (bool) – Average assembled image. Default False.

Returns:

Assembled image.

Return type:

numpy.ma.MaskedArray

calc_from_coords(self, pol='x')

Calculate essential detector attributes from pixel coordinates

Needs:

cx, cy, detd, ewald_rad

Calculates:

qvals and corr

property coords_xy

Return 2D pixel coordinates

get_assembled_cen(self, zoomed=False, sym=False)
property indices_xy

Return 2D integer coordinates (for assembly) Corner of the detector at (0,0)

parse(self, fname, mask_flag=True, keep_mask_1=True)
remask(self, qradius)

Remask detector with given q-radius

Sets mask value of all good pixels (mask==0) with q-radius greater than specified to be irrelevant (mask==1). This is useful when doing coarse orientational alignment

write(self, fname)

Write Dragonfly detector to file

If h5py is available and the file name as a ‘.h5’ extension, an HDF5 detector will be written, otherwise an ASCII file will be generated.

Note that the background array can only be stored in an HDF5 detector