deepcinac.utils.utils
¶
Module Contents¶
Functions¶
|
smooth the data using a window with requested size. |
|
take a binary array and return a list of tuples representing the first and last position(included) of continuous |
Get all potential onsets and peaks from a fluorescence signal |
|
|
Check if for each identifier in idenfifiers, a dir with this name exists |
|
Normalize an array so that values are ranging between 0 and 1 |
|
Consider a dict representing a tree (the tree leaves are string), it returns list of all paths from |
|
Split a calcium imaging movie so that each frame will be saved as a npy file. |
|
Split a calcium imaging movie so that each frame will be saved as a tiff image. |
|
Take an instance of shapely.geometry.Polygon or shapely.geometry.LineString and scale it, so that each of |
|
Load a movie in memory. So far only tiff format is valid |
|
Build a raster_dur, a 2d binary array indicating when the cell is active (rise time). |
|
For given cell, get the binary mask representing this cell with the possibility to get the binary masks |
|
implementation of welsh_powell algorithm |
|
movie is a 3D numpy array |
|
movie is a 3D numpy array |
|
movie is a 3D numpy array |
|
movie is a 3D numpy array |
|
movie is a 3D numpy array |
- deepcinac.utils.utils.smooth_convolve(x, window_len=11, window='hanning')¶
smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.
- input:
x: the input signal window_len: the dimension of the smoothing window; should be an odd integer window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’
flat window will produce a moving average smoothing.
- output:
the smoothed signal
example:
t=linspace(-2,2,0.1) x=sin(t)+randn(len(t))*0.1 y=smooth(x)
Source: https://scipy-cookbook.readthedocs.io/items/SignalSmooth.html
NOTE: length(output) != length(input), to correct this: return y[(window_len/2-1):-(window_len/2)] instead of just y.
- deepcinac.utils.utils.get_continous_time_periods(binary_array)¶
take a binary array and return a list of tuples representing the first and last position(included) of continuous positive period This code was copied from another project or from a forum, but i’ve lost the reference. :param binary_array: :return:
- deepcinac.utils.utils.find_all_onsets_and_peaks_on_fluorescence_signal(smooth_trace, threshold_factor=0.5, identifier=None)¶
Get all potential onsets and peaks from a fluorescence signal :param smooth_trace: fluorescence signal of cell, should be smooth :param threshold_factor: use to define a threshold over which to keep peaks. :param The threshold used is: :type The threshold used is: threshold_factor * std(smooth_trace) + min(smooth_trace :param identifier: :type identifier: str
Returns: a 1d array of integers (binary) representing the time when the cell is active
- deepcinac.utils.utils.check_one_dir_by_id_exists(identifiers, results_path, dir_in_id_name=False)¶
Check if for each identifier in idenfifiers, a dir with this name exists in results_path. If they all exists, then True is return, otherwise False Useful to check if a CI_movie has been separated in multiple tiff files. However, doesn’t check in all the files are present, we assume that they are :param identifiers: list of string :param results_path: a path where to check for existing dir :param dir_in_id_name: if True, means the dir name should be in the identifier, no need for the directory to be :param exactly named as identifier:
Returns: boolean
- deepcinac.utils.utils.norm01(data)¶
Normalize an array so that values are ranging between 0 and 1 :param data: numpy array
Returns:
- deepcinac.utils.utils.get_tree_dict_as_a_list(tree_dict)¶
Consider a dict representing a tree (the tree leaves are string), it returns list of all paths from root node to all leaves :param tree_dict:
Returns:
- deepcinac.utils.utils.create_one_npy_file_by_frame(movies_to_split, results_path, without_mean_std_files=False, verbose=0)¶
Split a calcium imaging movie so that each frame will be saved as a npy file. If the directory for results already contains a directory of the name of the movie identifier, the data won’t be erased. :param movies_to_split: a dictionary with as a key an identifier for the movie that will be used to name :param the directory in which the tiff will be put: :type the directory in which the tiff will be put: using lower case :param of the tiff or an numpy float: :param ndarray representing the calcium imaging data: :type ndarray representing the calcium imaging data: should n_frames * n_pixels_x * n_pixels_y :param results_path: String. The directory in which will be created the directories containing the tiff files. :param verbose: Integer. 0, 1, or 2. Verbosity mode. 0 = silent, 1 = times for main operation, 2 = various prints. :param without_mean_std_files: if True, mean and std are not recorded, useful if the movie is already normalized
Returns: None
- deepcinac.utils.utils.create_one_tiff_file_by_frame(movies_to_split, results_path, without_mean_std_files=False, verbose=0)¶
Split a calcium imaging movie so that each frame will be saved as a tiff image. If the directory for results already contains a directory of the name of the movie identifier, the data won’t be erased. :param movies_to_split: a dictionary with as a key an identifier for the movie that will be used to name :param the directory in which the tiff will be put: :type the directory in which the tiff will be put: using lower case :param of the tiff or an numpy float: :param ndarray representing the calcium imaging data: :type ndarray representing the calcium imaging data: should n_frames * n_pixels_x * n_pixels_y :param results_path: String. The directory in which will be created the directories containing the tiff files. :param verbose: Integer. 0, 1, or 2. Verbosity mode. 0 = silent, 1 = times for main operation, 2 = various prints. :param without_mean_std_files: if True, mean and std are not recorded, useful if the movie is already normalized
Returns: None
- deepcinac.utils.utils.scale_polygon_to_source(polygon, minx, miny)¶
- Take an instance of shapely.geometry.Polygon or shapely.geometry.LineString and scale it, so that each of
it coordinates are substracted by minx and miny on the x and y axis respectively
coordinates to match minx and miny :param polygon: Polygon instance from shapely package. Could also be a LineString :param minx: integer :param miny: integer
Returns: a new shapely.geometry.Polygon or shapely.geometry.LineString
- deepcinac.utils.utils.load_movie(file_name, with_normalization, both_instances=False, verbose=True)¶
Load a movie in memory. So far only tiff format is valid :param file_name: str for a file_name, or array representing the movie :param with_normalization: if True, normalize the movie using z-score formula :param both_instances: if with_normalization is True and both_instances is True, then :param the function return both movie: :param the normal and the normalized one in that order:
Returns:
- deepcinac.utils.utils.build_raster_dur_from_onsets_peaks(onsets, peaks)¶
Build a raster_dur, a 2d binary array indicating when the cell is active (rise time). n_cells * n_frames :param onsets: 2d binary array, n_cells * n_frames, 1 if onset at this frame :param peaks: 2d binary array, n_cells * n_frames
Returns:
- deepcinac.utils.utils.get_source_profile_param(cell, movie_dimensions, coord_obj, max_width, max_height, pixels_around=0, buffer=None, with_all_masks=False, get_only_polygon_contour=False)¶
For given cell, get the binary mask representing this cell with the possibility to get the binary masks of the cells it intersects with.
- Parameters
cell –
movie_dimensions – tuple of integers, width and height of the movie
coord_obj – instance of
max_width – Max width of the frame returned. Might cropped some overlaping cell if necessary
max_height – Max height of the frame returned. Might cropped some overlaping cell if necessary
pixels_around – how many pixels to add around the frame containing the cell and the overlapping one,
mask (doesn't change the) –
buffer – How much pixels to scale the cell contour in the mask. If buffer is 0 or None, then size of the cell
change. (won't) –
with_all_masks –
Return a dict with all overlaps cells masks + the main cell mask. The key is an int.
- The mask consist on a binary array of with 0 for all pixels in the cell, 1 otherwise
get_only_polygon_contour: the mask represents then only the pixels that makes the contour of the cells
- Returns: A mask (numpy 2d binary array), with 0 for all pixels in the cell, 1 otherwise.
A tuple with four integers representing the corner coordinates (minx, maxx, miny, maxy)
- deepcinac.utils.utils.welsh_powell(graph)¶
implementation of welsh_powell algorithm https://github.com/MUSoC/Visualization-of-popular-algorithms-in-Python/blob/master/Graph%20Coloring/graph_coloring.py :param graph: instance of networkx graph
Returns:
- deepcinac.utils.utils.horizontal_flip(movie)¶
movie is a 3D numpy array :param movie: :return:
- deepcinac.utils.utils.vertical_flip(movie)¶
movie is a 3D numpy array :param movie: :return:
- deepcinac.utils.utils.v_h_flip(movie)¶
movie is a 3D numpy array :param movie: :return:
- deepcinac.utils.utils.rotate_movie(movie, angle)¶
movie is a 3D numpy array :param movie: :return:
- deepcinac.utils.utils.shift_movie(movie, x_shift, y_shift)¶
movie is a 3D numpy array :param movie: :param x_shift: :param y_shift: :return: