derotation.simulate.synthetic_data#

This module contains the SyntheticData class that generates synthetic data for testing and developing the derotation pipeline.

Classes

SyntheticData([center_of_bright_cell, ...])

Class to generate synthetic data for testing and developing the derotation pipeline.

class derotation.simulate.synthetic_data.SyntheticData(center_of_bright_cell=(50, 10), center_of_dimmer_cell=(60, 60), pad=0, background_value=80, lines_per_frame=100, second_cell=True, radius=5, num_frames=100, center_of_rotation_offset=(0, 0), rotation_plane_angle=0, rotation_plane_orientation=0, plots=False)[source]#

Class to generate synthetic data for testing and developing the derotation pipeline.

The synthetic data consists of:
  • a 2D image with two circles, one bright and one dim (optional), by default in the top center and bottom right, respectively. Use the center_of_bright_cell and center_of_dimmer_cell parameters to change the location of the circles. If padding and background value are provided, the image will be padded and the background value will be set to the background_value. Padding helps increasing the field of view in order to accommodate for larger rotations and have more data to derotate. The background value is useful to distinguish pixels from the original image from those that are never evaluated, which will remain 0. NB: padding will alter the number of lines per frame.

  • two angle arrays for incremental and sinusoidal rotation

  • one 3D image stack with the 2D image repeated for a given number of frames (this is going to be the input for the Rotator)

  • two rotated movies made with incremental and sinusoidal rotations

  • two derotated movies:
    • one made with a mock of the IncrementalPipeline, used then to estimate the center of rotation and the ellipse fits

    • one made just with derotate_an_image_array_line_by_line with the sinusoidal rotation angles

Why mocking the IncrementalPipeline? The IncrementalPipeline has the responsibility to find the center of rotation but with mock data we cannot use it off the shelf because it is too bound to signals coming from a real motor in the calculate_mean_images method and in the constructor.

See the integration_pipeline method for the full pipeline.

Parameters:
  • center_of_bright_cell (tuple, optional) – The location of the brightest cell, by default (50, 10)

  • center_of_dimmer_cell (tuple, optional) – The location of the dimmer cell, by default (60, 60)

  • pad (int, optional) – Padding around the image, by default 0

  • background_value (int, optional) – Background value, by default 80

  • lines_per_frame (int, optional) – Number of lines per frame, by default 100

  • second_cell (bool, optional) – Add an extra dimmer cell, by default True

  • radius (int, optional) – Radius of the circles, by default 5

  • num_frames (int, optional) – Number of frames in the 3D image stack, by default 100

  • center_of_rotation_offset (tuple, optional) – The offset of the center of rotation, by default (0, 0)

  • rotation_plane_angle (int, optional) – The angle of the rotation plane, by default 0

  • rotation_plane_orientation (int, optional) – The orientation of the rotation plane, by default 0

  • plots (bool, optional) – Whether to plot debugging plots, by default False

Methods

create_image_stack()

Create a 3D image stack by repeating the 2D image for a given number of frames.

create_rotation_angles(image_stack_shape)

Create rotation angles for incremental and sinusoidal rotation for a given 3D image stack.

create_sample_image_with_cells()

Create a 2D image with two circles, one bright and one dim (optional) by default in the top center and bottom right, respectively.

get_center_of_rotation(...)

Get the center of rotation by using the IncrementalPipeline.

integration_pipeline()

Integration pipeline that combines the incremental and sinusoidal rotation pipelines to derotate a 3D image stack.

plot_a_few_rotated_frames(...)

Plot a few frames from the rotated stacks.

plot_angles(incremental_angles, ...)

Plot the incremental and sinusoidal rotation angles.

plot_derotated_frames(derotated_sinusoidal)

Plot a few frames from the derotated stack.

plot_each_frame()

Plot each frame of the rotated and derotated stacks as an image.

plot_mean_projection()

Plot the mean projection of the derotated sinusoidal stack.

plot_original_image()

Plot the original image with the two circles.

integration_pipeline()[source]#

Integration pipeline that combines the incremental and sinusoidal rotation pipelines to derotate a 3D image stack.

The pipeline rotates the image stack incrementally and sinusoidally and then derotates the sinusoidal stack using the center of rotation estimated by the incremental pipeline.

The pipeline also plots debugging plots if the plots parameter is set to True.

Return type:

ndarray

create_sample_image_with_cells()[source]#

Create a 2D image with two circles, one bright and one dim (optional) by default in the top center and bottom right, respectively.

Location of the circles can be changed by providing the center_of_bright_cell and center_of_dimmer_cell parameters.

If specified, the image will be padded and the background value will be set to the background_value.

Parameters:
  • center_of_bright_cell (Tuple[int, int], optional) – Location of brightest cell, by default (50, 10)

  • center_of_dimmer_cell (Tuple[int, int], optional) – Location of dimmer cell, by default (60, 60)

  • lines_per_frame (int, optional) – Number of lines per frame, by default 100

  • second_cell (bool, optional) – Add an extra dimmer cell, by default True

  • radius (int, optional) – Radius of the circles, by default 5

Returns:

2D image with two circles, one bright and one dim

Return type:

np.ndarray

create_image_stack()[source]#

Create a 3D image stack by repeating the 2D image for a given number of frames.

Returns:

3D image stack

Return type:

np.ndarray

static create_rotation_angles(image_stack_shape)[source]#

Create rotation angles for incremental and sinusoidal rotation for a given 3D image stack.

Parameters:

image_stack_shape (Tuple[int, int]) – Shape of the 3D image stack

Returns:

Tuple of incremental and sinusoidal rotation angles

Return type:

Tuple[np.ndarray, np.ndarray]

get_center_of_rotation(rotated_stack_incremental, incremental_angles)[source]#

Get the center of rotation by using the IncrementalPipeline.

The Incremental pipeline has the responsibility to find the center of rotation but with mock data we cannot use it off the shelf because it is too bound to signals coming from a real motor in the calculate_mean_images method and in the constructor. We will create a mock class that inherits from the IncrementalPipeline and overwrite the calculate_mean_images method to work with our mock data.

Parameters:
  • rotated_stack_incremental (np.ndarray) – The 3D image stack rotated incrementally

  • incremental_angles (np.ndarray) – The rotation angles for incremental rotation

Returns:

The center of rotation

Return type:

Tuple[int, int]

plot_angles(incremental_angles, sinusoidal_angles)[source]#

Plot the incremental and sinusoidal rotation angles.

Parameters:
  • incremental_angles (np.ndarray) – Incremental rotation angles

  • sinusoidal_angles (np.ndarray) – Sinusoidal rotation angles

plot_a_few_rotated_frames(rotated_stack_incremental, rotated_stack_sinusoidal)[source]#

Plot a few frames from the rotated stacks.

Parameters:
  • rotated_stack_incremental (np.ndarray) – The 3D image stack rotated incrementally

  • rotated_stack_sinusoidal (np.ndarray) – The 3D image stack rotated sinusoidally

plot_derotated_frames(derotated_sinusoidal)[source]#

Plot a few frames from the derotated stack.

Parameters:

derotated_sinusoidal (np.ndarray) – The 3D image stack derotated sinusoidally

plot_original_image()[source]#

Plot the original image with the two circles.

plot_each_frame()[source]#

Plot each frame of the rotated and derotated stacks as an image.

plot_mean_projection()[source]#

Plot the mean projection of the derotated sinusoidal stack.