deepcinac.cinac_simulated_movie_generator

Module Contents

Classes

CellPiece

MovieConstructor

Used to construct the movie, will build the frames, deal with overlapping and pixels intensity

SimulatedMovieGenerator

Class that will handle the generation of simulated calcium imaging movie

Functions

produce_cell_coord_from_cnn_validated_cells(param)

shift_cell_coord_to_centroid(centroid, cell_coord[, ...])

change_polygon_centroid(new_centroid, poly_cell)

make_video(images[, outvid, fps, size, is_color, format])

Create a video from a list of images.

fig2data(fig)

http://www.icare.univ-lille1.fr/tutorials/convert_a_matplotlib_figure

fig2img(fig)

@brief Convert a Matplotlib figure to a PIL Image in RGBA format and return it

normalize_array_0_255(img_array)

noisy(noise_typ, image)

param image

Input image data. Will be converted to float.

get_mask(dimensions, poly_gon)

get_weighted_activity_mask_for_a_cell(mask, soma_mask, ...)

construct_movie_images(coord_obj, traces, dimensions, ...)

build_somas(coord_obj, dimensions)

give_values_on_linear_line_between_2_points(x_coords, ...)

exponential_decay_formula(t, a, k, c)

Exponential decay formula

finding_growth_rate(t, a, end_value)

Find the growth rate.

produce_vessels(vessels_imgs_dir[, path_results])

Produce vessels polygons based on images in vessels_imgs_dir

plot_all_cells_on_map(coord_obj, path_results[, ...])

Plot all cells contour on a map using welsh powell algorithm to color cell that intersect

deepcinac.cinac_simulated_movie_generator.produce_cell_coord_from_cnn_validated_cells(param)
deepcinac.cinac_simulated_movie_generator.shift_cell_coord_to_centroid(centroid, cell_coord, from_matlab=False)
deepcinac.cinac_simulated_movie_generator.change_polygon_centroid(new_centroid, poly_cell)
deepcinac.cinac_simulated_movie_generator.make_video(images, outvid=None, fps=5, size=None, is_color=True, format='XVID')

Create a video from a list of images.

@param outvid output video file_name @param images list of images to use in the video @param fps frame per second @param size size of each frame @param is_color color @param format see http://www.fourcc.org/codecs.php @return see http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html

The function relies on http://opencv-python-tutroals.readthedocs.org/en/latest/. By default, the video will have the size of the first image. It will resize every image to this size before adding them to the video.

deepcinac.cinac_simulated_movie_generator.fig2data(fig)

http://www.icare.univ-lille1.fr/tutorials/convert_a_matplotlib_figure @brief Convert a Matplotlib figure to a 4D numpy array with RGBA channels and return it @param fig a matplotlib figure @return a numpy 3D array of RGBA values

deepcinac.cinac_simulated_movie_generator.fig2img(fig)

@brief Convert a Matplotlib figure to a PIL Image in RGBA format and return it @param fig a matplotlib figure @return a Python Imaging Library ( PIL ) image

deepcinac.cinac_simulated_movie_generator.normalize_array_0_255(img_array)
deepcinac.cinac_simulated_movie_generator.noisy(noise_typ, image)
Parameters
  • image (ndarray) – Input image data. Will be converted to float.

  • mode (str) –

  • strings (One of the following) –

  • add (selecting the type of noise to) –

  • noise. ('gauss' Gaussian-distributed additive) –

  • data. ('poisson' Poisson-distributed noise generated from the) –

  • 1. ('s&p' Replaces random pixels with 0 or) –

  • n*image ('speckle' Multiplicative noise using out = image +) – n is uniform noise with specified mean & variance.

  • where – n is uniform noise with specified mean & variance.

:param : :type : param img_array: :param : :type : return:

class deepcinac.cinac_simulated_movie_generator.CellPiece(id, poly_gon, dimensions, activity_mask=None, frame_mode=False)
fill_movie_images(images)
set_activity_mask_from_other(other_activity_mask)
set_activity_mask_from_two_other(other_1, other_2)
get_mask()
split(other)
update_activity_mask(activity_mask=None)
__eq__(other)

Return self==value.

__hash__()

Return hash(self).

deepcinac.cinac_simulated_movie_generator.get_mask(dimensions, poly_gon)
deepcinac.cinac_simulated_movie_generator.get_weighted_activity_mask_for_a_cell(mask, soma_mask, n_pixels, n_pixels_soma)
class deepcinac.cinac_simulated_movie_generator.MovieConstructor(coord_obj, traces, dimensions, baseline, soma_geoms, vessels)

Used to construct the movie, will build the frames, deal with overlapping and pixels intensity

get_frame(frame)
Parameters

frame

Returns:

deepcinac.cinac_simulated_movie_generator.construct_movie_images(coord_obj, traces, dimensions, baseline, soma_geoms, vessels, param, n_pixels_by_cell=None)
deepcinac.cinac_simulated_movie_generator.build_somas(coord_obj, dimensions)
deepcinac.cinac_simulated_movie_generator.give_values_on_linear_line_between_2_points(x_coords, y_coords)
deepcinac.cinac_simulated_movie_generator.exponential_decay_formula(t, a, k, c)

Exponential decay formula Code probably copy from an online source. Sorry i don’t have the reference :param t: time that has passed :param a: initial value (amount before measuring growth or decay) :param k: continuous growth rate (also called constant of proportionality) (k > 0, the amount is increasing (growing); k < 0, the amount is decreasing (decaying)) :param c: lowest value :return:

deepcinac.cinac_simulated_movie_generator.finding_growth_rate(t, a, end_value)

Find the growth rate. Code probably copy from an online source. Sorry i don’t have the reference :param t: time :param a: :param end_value:

Returns:

deepcinac.cinac_simulated_movie_generator.produce_vessels(vessels_imgs_dir, path_results=None)

Produce vessels polygons based on images in vessels_imgs_dir :param vessels_imgs_dir: directory from which load the images containing the vessels :param path_results: If not None, the path where to save to vessels produced

Returns: coord_list a list of 2D array (n_coord x 2): each column represents the x and y coordinates of each point

of the polygon (vessel) dimensions_list a List of 1D array with 2 values, integer, representing the height and width of the movie

deepcinac.cinac_simulated_movie_generator.plot_all_cells_on_map(coord_obj, path_results, save_formats='pdf')

Plot all cells contour on a map using welsh powell algorithm to color cell that intersect with a different color :param coord_obj: instance of CellsCoord object :param path_results: (string), directory where to save the figure :param save_formats: string or list of string, formats in which to save the figure

Returns:

class deepcinac.cinac_simulated_movie_generator.SimulatedMovieGenerator(n_frames, path_results, dimensions=(120, 120), with_mvt=False, n_cells_of_interest=16, n_overlap_by_cell_range=(1, 4), non_overlap_by_cell_range=(2, 10), range_n_transient_cells_of_interest=(2, 4), range_n_transient_overlapping_cells=(8, 16), range_n_transient_other_cells=(2, 16), range_duration_transient=(1, 8), decay_factor=10, max_decay=12, time_str=None, use_only_valid_cells=True)

Class that will handle the generation of simulated calcium imaging movie

generate_movie()

Generate the movie by buimding first the cells map, then generate ting the raster then the traces and then the movie. Before calling this method vessels must have been created or loaded if necessary and the cells model must be loaded as well. Returns:

save_cell_coords()

Save the cell coordinate so far in the same output as CaImAn Returns:

__generate_artificial_map()

Use the cells models to generate a map of the dimensions given when instanciating SimulatedMovieGenerator. It will create a “square” for each cell of interest that will be in the center of this square, this square will be filled with a certain number of cells overlapping the cell of interest and other cell that will not overlapping it but might overlap other cells. All the parameters can be change in the __init__ of the class Returns: None

save_raster_dur_for_gui()

Save the raster dur that was generated in the path_results defined in the constructor Returns: None

__build_raster_dur()

Build the raster that will be used to produce the simulated movie Returns: a 2d-array (int8) of n_cells x n_frames

build_traces(n_pixels_by_cell, baseline, use_traces_for_amplitude=None)
__produce_movie(use_traces_for_amplitude=None, file_name=None)

Generate the movie based on the cell contour map, the raster and the traces generated previously :param use_traces_for_amplitude: :param file_name:

Returns:

save_traces(output_formats='npy')

Save traces :param output_formats: (string or list of string) npy or mat (if matlab, the traces variable name will be raw_traces

Returns:

produce_and_load_vessels(vessels_imgs_dir, n_vessels_max=None, path_results=None)
Parameters
  • path_results – indicate the directory where to save the vessels produced. If None, the vessels won’t be

  • saved.

  • vessels_imgs_dir

Returns:

load_vessels(vessels_dir, n_vessels_max)

Load vessels from data generated previously :param vessels_dir: Directory that contain the data file allowing to load vessels to the movie. :param n_vessels_max: max number of vessels that can be loaded. If None, no limit

Returns:

load_cell_coords(data_file, from_matlab)

Load cell coords based on model from the data_file path :param data_file: path and file name of the file containing model of cell contours. :param from_matlab: means the cells coordinates have been computed with matlab and starts at 1

Returns:

__add_vessels(coord_list, dimensions_list, n_vessels_max=None)

Add vessels in the movie based on the the coordinates and dimensions list given :param coord_list: List of 2D array (n_coord x 2): each column represents the x and y coordinates of each point :param of the polygon: :type of the polygon: vessel :param dimensions_list: List of 1D array with 2 values, integer, representing the height and width of the movie :param n_vessels_max: max number of vessels that can be loaded. If None, no limit

Returns: