PyDDM.dcimg_mod.DCIMGFile#

class DCIMGFile(file_path=None)#

Bases: object

A DCIMG file (Hamamatsu format), memory-mapped.

This class provides an interface for reading 3D Hamamatsu DCIMG files.

Usage is pretty straightforward. First of all, create a DCIMGFile object:

>>> my_file = DCIMGFile('input_file.dcimg')
>>> my_file
<DCIMGFile shape=2450x2048x2048 dtype=<class 'numpy.uint16'>file_name=input_file.dcimg>

Image data can then be accessed using NumPy’s basic indexing:

>>> my_file[-10, :5, :5]
array([[101, 104, 100,  99,  89],
       [103, 102, 103,  99, 102],
       [101, 104,  99, 108,  98],
       [102, 111,  99, 111,  95],
       [103,  98,  99, 104, 106]], dtype=uint16)

Other convenience methods for accessing image data are: zslice, zslice_idx, frame and whole.

DCIMGFile supports context managers:

>>> with DCIMGFile('input_file.dcimg') as f:
>>>     a = f[800, ...]

See also

NumPy’s basic indexing: numpy:arrays.indexing

Methods

close

compute_target_line

frame

Convenience function to retrieve a single frame (Z plane).

open

ts

Timestamp of a single frame.

whole

Convenience function to retrieve the whole stack.

zslice

Return a slice along Z, i.e. a substack of frames.

zslice_idx

Return a slice, i.e. a substack of frames, by index.

Attributes

FILE_HDR_DTYPE

FMT_NEW

FMT_OLD

NEW_CROP_INFO

NEW_FRAME_FOOTER_CAMLINK_DTYPE

NEW_FRAME_FOOTER_USB_DTYPE

NEW_SESSION_HEADER_DTYPE

SESSION_FOOTER2_DTYPE

SESSION_FOOTER_DTYPE

SESS_HDR_DTYPE

byte_depth

Number of bytes per pixel.

bytes_per_img

bytes_per_row

deep_copy_enabled

dtype

NumPy numerical dtype.

file_size

File size in bytes.

framestamps

Framestamps of all frames.

nfrms

Number of frames (Z planes), same as zsize.

shape

Shape of the whole image stack.

timestamps

Timestamps of all frames.

xsize

ysize

zsize

mm

a numpy.memmap object with the raw contents of the DCIMG file.

mma

memory-mapped numpy.ndarray of the image data, without 4px correction.

first_4px_correction_enabled

For some reason, the first 4 pixels of each frame (or the first 4 pixels of line number 1023 of each frame) are stored in a different area in the file.

property byte_depth#

Number of bytes per pixel.

property dtype#

NumPy numerical dtype.

property file_size#

File size in bytes.

first_4px_correction_enabled#

For some reason, the first 4 pixels of each frame (or the first 4 pixels of line number 1023 of each frame) are stored in a different area in the file. This switch enables retrieving those 4 pixels. If False, those pixels are set to 0. If None, they are left unchanged. Actually, when the dtype is uint8, this affects the first 8 pixels. In any case this affects 8 bytes. Defaults to True.

frame(index, dtype=None, copy=True)#

Convenience function to retrieve a single frame (Z plane).

Same as calling zslice_idx and squeezing.

Parameters:
  • index (int) – frame index

  • dtype

  • copy (see zslice)

Returns:

A numpy array of the original type or of dtype, if specified. The shape of the array is (ysize, xsize).

Return type:

numpy.ndarray

property framestamps#

Framestamps of all frames.

Returns:

A numpy array of dtype numpy.uint32 with framestamps.

Return type:

numpy.ndarray

mm#

a numpy.memmap object with the raw contents of the DCIMG file.

mma#

memory-mapped numpy.ndarray of the image data, without 4px correction.

property nfrms#

Number of frames (Z planes), same as zsize.

property shape#

Shape of the whole image stack.

Returns:

(zsize, ysize, xsize)

Return type:

tuple

property timestamps#

Timestamps of all frames.

Returns:

A numpy array of dtype numpy.datetime64 with frame timestamps.

Return type:

numpy.ndarray

ts(frame)#

Timestamp of a single frame.

Parameters:

frame (int) – Frame index

Return type:

numpy.datetime64

whole(dtype=None, copy=True)#

Convenience function to retrieve the whole stack.

Equivalent to call zslice_idx with index = 0 and frames_per_slice = nfrms

Parameters:
  • dtype

  • copy (see zslice)

Returns:

A numpy array of the original type or of dtype, if specified. The shape of the array is shape.

Return type:

numpy.ndarray

zslice(arg1, arg2=None, step=None, dtype=None, copy=True)#

Return a slice along Z, i.e. a substack of frames.

Parameters:
  • arg1 (int) – Mandatory argument, will be passed to python:slice If arg2 and step are both None, it will be passed as slice(arg1), i.e. it would act as the stop argument.

  • arg2 (int) – If not null, will be passed as slice(arg1, arg2, step)

  • step (int) – If not null, will be passed as slice(arg1, arg2, step)

  • dtype

  • copy (bool) – If True, the requested slice is copied to memory. Otherwise a memory mapped array is returned.

Returns:

A numpy array of the original type or of dtype, if specified. The shape of the array is (end_frame - start_frame, ysize, xsize).

Return type:

numpy.ndarray

zslice_idx(index, frames_per_slice=1, dtype=None, copy=True)#

Return a slice, i.e. a substack of frames, by index.

Parameters:
  • index (int) – slice index

  • frames_per_slice (int) – number of frames per slice

  • dtype

  • copy (see zslice)

Returns:

A numpy array of the original type or of dtype, if specified. The shape of the array is (frames_per_slice, ysize, xsize).

Return type:

numpy.ndarray