Skip to content

API Reference

Coordinates

__init__(coordinates)

Wrapper to hold set of particle coordinates

Parameters:

Name Type Description Default
coordinates list or ndarray

List of coordinates

required

get_coordinates(unit='µm')

Get the array containing the particle coordinates

Parameters:

Name Type Description Default
unit str

Unit to give the coordinates in. One of [nm, µm], by default "µm"

'µm'

Returns:

Type Description
ndarray

Array of coordinates (N,3) shape

scale(factor=1.0)

Update the list of coordinates by multiplication with factor

Parameters:

Name Type Description Default
factor float

Factor to scale the coordinates by, by default 1.

1.0

Returns:

Type Description
ndarray

Numpy array containing the scaled coordinates

Cube

Bases: BaseParticle

__init__(pixel_sizes, width, *args, **kwargs)

Generate cubic particle

Parameters:

Name Type Description Default
pixel_sizes list[float]

List of pixel sizes in meters in zyx order.

required
width float

Edge length of the cube in meters.

required

GaussianPSF

Bases: Image

__init__(sigmas, pixel_sizes=[1e-07, 1e-08, 1e-08])

Generate a 3D Gaussian with given sigmas to use as PSF

Parameters:

Name Type Description Default
sigmas list[float]

List of sigmas (in zyx order) to use for the Gaussian distribution, given in nanometers. Please note that this is given in nanometers, while the pixel size is given in meters.

required
pixel_sizes Optional[list[float]]

List of pixel sizes (in zyx order) in meters, by default [1e-7, 1e-8, 1e-8].

[1e-07, 1e-08, 1e-08]

HuygensImage

Bases: Image

__init__(filename)

Wrapper for Huygens-generated .h5 images Extends the Image class.

Parameters:

Name Type Description Default
filename str

Name of the Huygens-generated .h5 file

required

HuygensPSF

Bases: HuygensImage

__init__(filename)

Generate PSF from Huygens .h5 file

Parameters:

Name Type Description Default
filename Union[str, Path]

Filename/path to the .h5 file

required

Image

has_read_noise = False class-attribute instance-attribute

Whether the image has undergone read noise addition

has_shot_noise = False class-attribute instance-attribute

Whether the image has undergone shot noise addition

is_convolved = False class-attribute instance-attribute

Whether the image has undergone convolution

is_downsampled = False class-attribute instance-attribute

Whether the image has undergone downsampling

pixel_coordinates = None class-attribute instance-attribute

Pixel coordinates (z,y,x) where particles are positioned

__init__(image, pixel_sizes=None, metadata=None)

Initialize an image, used as a wrapper to hold both an N-dimensional image and its pixel sizes

Parameters:

Name Type Description Default
image ndarray

2D or 3D numpy array containing pixel values, order should be (z,)y,x

required
pixel_sizes list[float]

List/array of pixel sizes in meters, same length as number of image dimensions. Order: (z,)y,x. By default 1.0 m/px for all dimensions.

None
metadata dict

Place to store custom metadata about an image, will also be stored in .h5 file.

None

add_read_noise(SNR=50.0, background=0.0)

Add read noise to the image, realised by adding noise sampled from a normal distribution. The standard deviation of the distribution is constant across the entire image and determined by the SNR parameter, it is therefore signal-independent.

Parameters:

Name Type Description Default
SNR float

The signal-to-noise ratio of the resulting image, by default 50.0

50.0
background float

Optional offset of the background, this will be the mean of the normal distribution, by default 0.0

0.0

Returns:

Type Description
type[Image]

The image with read noise

add_shot_noise(SNR=30.0)

Add shot noise to the image, realised by sampling the intensities of the image from a Poisson distribution. At each pixel, the current value (after rescaling) dictates the mean value of the Poisson distribution, yielding signal-dependent noise.

Parameters:

Name Type Description Default
SNR float

The signal-to-noise ratio of the resulting image, by default 30.0.

30.0

Returns:

Type Description
type[Image]

The image with shot noise

convolve(other)

Convolve this image with another image (a PSF). The image is overwritten by the result of the convolution.

Parameters:

Name Type Description Default
other type[Image]

The image to convolve this image with

required

Returns:

Type Description
type[Image]

The convolved image

create_particle_image(coordinates, particle, edge_pixel_margin=0, *args, **kwargs) classmethod

Create image in which every point from the set of coordinates is represented by a given particle

Parameters:

Name Type Description Default
coordinates type[CoordinateSet]

Set of coordinates

required
particle list[BaseParticle]

Particle to use for image, will also use its pixel size for the final image

required
edge_pixel_margin Union[int, list[int]]

Number of extra empty pixels to apply as a margin around the edges of the image. Either single int for all directions or one int for every dimension (in z,y,x order).

0

Returns:

Type Description
type[Image]

Genereated image

create_point_image(coordinates, pixel_sizes, *args, **kwargs) classmethod

Create point source image in which every point from the set of coordinates is represented by a single white pixel

Parameters:

Name Type Description Default
coordinates type[CoordinateSet]

Set of coordinates

required
pixel_sizes list[float]

List of pixel sizes in meters, in zyx order.

required

Returns:

Type Description
type[Image]

Genereated image

downsample(downsample_factor)

Downsample the image, decrease the pixel sizes by given factors. Overwrites current image and pixel sizes.

Parameters:

Name Type Description Default
downsample_factor list[int]

Factors to downsample each dimension by, in zyx order.

required

Returns:

Type Description
type[Image]

Resulting image, original image and pixelsizes are also overwritten

get_particle_image(particle_id=0, box_size=(5, 5, 5))

Get 3D box around the coordinates of particle with index particle_id

Parameters:

Name Type Description Default
particle_id int

Index of the particle, by default 0

0
box_size tuple[int]

Size of the surrounding box in pixels, by default (5, 5, 5)

(5, 5, 5)

Returns:

Type Description
ndarray

Image containing the particle with shape determined by box_size. Box will be clipped to the the limits of the images and can therefore be smaller than box_size.

get_pixel_coordinates()

Get list of pixel indices containing particles

Returns:

Type Description
ndarray

Numpy (N,3) array in zyx order with indices of pixels containing particles

get_pixel_sizes(dimensions=None, unit='m')

Get pixel sizes for given dimensions in given unit

Parameters:

Name Type Description Default
dimensions List of str

Dimensions to get, one or more of (x, y, z), by default ["z","y","x"]

None
unit str

Unit to give the pixel size in. One of [m, cm, mm, µm, um, nm], by default "m".

'm'

Returns:

Type Description
list[float]

List of pixel sizes in given unit, in order of requested dimensions.

load_h5file(filename) classmethod

Load data from h5 file (custom format or HuygensImage)

Parameters:

Name Type Description Default
filename str

Name of the file to load from

required

Returns:

Type Description
Image

Resulting image with correct pixel sizes

noisify(lam=1.0)

Add Poisson noise to the image [DEPRECATED]

Parameters:

Name Type Description Default
lam float

lambda parameter to pass onto the Poisson distribution. Expected number of events occurring in a fixed-time interval, by default 1.0

1.0

Returns:

Type Description
type[Image]

The image with noise added

save_h5file(filename, description=None)

Save image as h5 file (custom format, not compatible with Huygens)

Parameters:

Name Type Description Default
filename str

Filename to save the file.

required
description Optional[str]

Description to include in the file, by default None

None

Returns:

Type Description
bool

Whether the saving is successfull

Shell

Bases: Sphere

__init__(pixel_sizes, radius, shell_thickness, *args, **kwargs)

Shell with given inner radius and shell thickness. Shell has constant intensity of 1., everything else is 0.

Parameters:

Name Type Description Default
pixel_sizes list[float]

List of pixel sizes in meters, zyx order

required
radius float

Inner radius of the shell in meters, one float for all directions.

required
shell_thickness float

Thickness of the shell in meters, one float for all directions.

required

Sphere

Bases: BaseParticle

__init__(pixel_sizes, radius, *args, **kwargs)

Sphere with given radius with constant intensity of 1.

Parameters:

Name Type Description Default
pixel_sizes list[float]

List of pixel sizes in meters, zyx order

required
radius float

Radius of the sphere in meters, one float for all directions.

required

Spherocylinder

Bases: BaseParticle

__init__(pixel_sizes, width, length, *args, **kwargs)

Generation of a spherocylinder with given length and width, oriented along the z axis of the image. Note: the length is excluding the caps. No support for alternative orientation yet.

Parameters:

Name Type Description Default
pixel_sizes list[float]

List of pixel sizes in zyx order in meters.

required
width float

Width of the spherocylinder in meters

required
length float

Length of the spherocylinder (excluding caps)

required