cellects 0.1.2__py3-none-any.whl → 0.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. cellects/__main__.py +65 -25
  2. cellects/config/all_vars_dict.py +18 -17
  3. cellects/core/cellects_threads.py +1034 -396
  4. cellects/core/motion_analysis.py +1664 -2010
  5. cellects/core/one_image_analysis.py +1082 -1061
  6. cellects/core/program_organizer.py +1687 -1316
  7. cellects/core/script_based_run.py +80 -76
  8. cellects/gui/advanced_parameters.py +390 -330
  9. cellects/gui/cellects.py +102 -91
  10. cellects/gui/custom_widgets.py +16 -33
  11. cellects/gui/first_window.py +226 -104
  12. cellects/gui/if_several_folders_window.py +117 -68
  13. cellects/gui/image_analysis_window.py +866 -454
  14. cellects/gui/required_output.py +104 -57
  15. cellects/gui/ui_strings.py +840 -0
  16. cellects/gui/video_analysis_window.py +333 -155
  17. cellects/image_analysis/cell_leaving_detection.py +64 -4
  18. cellects/image_analysis/image_segmentation.py +451 -22
  19. cellects/image_analysis/morphological_operations.py +2166 -1635
  20. cellects/image_analysis/network_functions.py +616 -253
  21. cellects/image_analysis/one_image_analysis_threads.py +94 -153
  22. cellects/image_analysis/oscillations_functions.py +131 -0
  23. cellects/image_analysis/progressively_add_distant_shapes.py +2 -3
  24. cellects/image_analysis/shape_descriptors.py +517 -466
  25. cellects/utils/formulas.py +169 -6
  26. cellects/utils/load_display_save.py +362 -109
  27. cellects/utils/utilitarian.py +86 -9
  28. cellects-0.2.6.dist-info/LICENSE +675 -0
  29. cellects-0.2.6.dist-info/METADATA +829 -0
  30. cellects-0.2.6.dist-info/RECORD +44 -0
  31. cellects/core/one_video_per_blob.py +0 -540
  32. cellects/image_analysis/cluster_flux_study.py +0 -102
  33. cellects-0.1.2.dist-info/LICENSE.odt +0 -0
  34. cellects-0.1.2.dist-info/METADATA +0 -132
  35. cellects-0.1.2.dist-info/RECORD +0 -44
  36. {cellects-0.1.2.dist-info → cellects-0.2.6.dist-info}/WHEEL +0 -0
  37. {cellects-0.1.2.dist-info → cellects-0.2.6.dist-info}/entry_points.txt +0 -0
  38. {cellects-0.1.2.dist-info → cellects-0.2.6.dist-info}/top_level.txt +0 -0
@@ -4,57 +4,90 @@
4
4
  import logging
5
5
  import os
6
6
  from pathlib import Path
7
+ from numpy.typing import NDArray
7
8
  import numpy as np
8
9
  import pandas as pd
9
10
  import cv2
10
11
  from cellects.core.program_organizer import ProgramOrganizer
11
12
  from cellects.utils.utilitarian import insensitive_glob
12
- from cellects.core.one_video_per_blob import OneVideoPerBlob
13
13
  from cellects.core.motion_analysis import MotionAnalysis
14
- from cellects.config.all_vars_dict import DefaultDicts
15
- from cellects.utils.load_display_save import show
16
-
17
-
18
- def load_one_folder(pathway, sample_number):
14
+ from cellects.image_analysis.morphological_operations import create_ellipse
15
+ from cellects.image_analysis.image_segmentation import convert_subtract_and_filter_video
16
+ from cellects.utils.load_display_save import write_video_sets, readim, display_network_methods
17
+ from cellects.image_analysis.network_functions import NetworkDetection
18
+
19
+ def generate_colony_like_video():
20
+ ellipse = create_ellipse(7, 7).astype(np.uint8)
21
+ binary_video = np.zeros((20, 1000, 1000), dtype=np.uint8)
22
+ binary_video[0, np.random.randint(100, 900, 20), np.random.randint(100, 900, 20)] = 1
23
+ binary_video[0, ...] = cv2.dilate(binary_video[0, ...], ellipse)
24
+ for t in range(1, binary_video.shape[0]):
25
+ binary_video[t, ...] = cv2.dilate(binary_video[t - 1, ...], ellipse, iterations=1)
26
+ rgb_video = np.zeros((binary_video.shape[0], binary_video.shape[1], binary_video.shape[2], 3), dtype=np.uint8)
27
+ for c_ in range(3):
28
+ rgb_video[:, :, :, c_][binary_video > 0] = np.random.randint(150 + c_ * 20, 250 - c_ * 20, binary_video.sum())
29
+ rgb_video[:, :, :, c_][binary_video == 0] = np.random.randint(5 ,20 ,
30
+ binary_video.size - binary_video.sum())
31
+ return rgb_video
32
+
33
+ def load_data(rgb_video: NDArray=None, pathway: str='', sample_number:int=None, radical: str='', extension: str='', im_or_vid: int=0):
19
34
  po = ProgramOrganizer()
20
- po.load_variable_dict()
21
- # dd = DefaultDicts()
22
- # po.all = dd.all
23
- # po.vars = dd.vars
24
- po.all['global_pathway'] = pathway
25
- po.all['first_folder_sample_number'] = sample_number
26
- # po.all['first_folder_sample_number'] = 6
27
- # po.all['radical'] = "IMG"
28
- # po.all['extension'] = ".jpg"
29
- # po.all['im_or_vid'] = 0
30
- po.look_for_data()
31
- po.load_data_to_run_cellects_quickly()
35
+ if rgb_video is None:
36
+ if len(pathway) == 0:
37
+ pathway = Path(os.getcwd() + "/data/experiment")
38
+ po.all['global_pathway'] = pathway
39
+ po.all['first_folder_sample_number'] = sample_number
40
+ po.all['radical'] = radical
41
+ po.all['extension'] = extension
42
+ po.all['im_or_vid'] = im_or_vid
43
+ po.look_for_data()
44
+ po.load_data_to_run_cellects_quickly()
45
+ po.get_first_image()
46
+ else:
47
+ po.get_first_image(rgb_video[0,...])
48
+ po.analysis_instance = rgb_video
49
+ po.all['im_or_vid'] = 1
32
50
  return po
33
51
 
34
- def run_image_analysis(po):
52
+ def run_image_analysis(po, PCA: bool=True, last_im:NDArray=None):
35
53
  if not po.first_exp_ready_to_run:
36
- po.get_first_image()
37
- po.fast_image_segmentation(True)
38
- # po.first_image.find_first_im_csc(sample_number=po.sample_number,
39
- # several_blob_per_arena=None,
40
- # spot_shape=None, spot_size=None,
41
- # kmeans_clust_nb=2,
42
- # biomask=None, backmask=None,
43
- # color_space_dictionaries=None,
44
- # carefully=True)
54
+ if PCA:
55
+ po.fast_first_image_segmentation()
56
+ else:
57
+ po.first_image.find_first_im_csc()
45
58
  po.cropping(is_first_image=True)
46
59
  po.get_average_pixel_size()
47
60
  po.delineate_each_arena()
48
61
  po.get_background_to_subtract()
49
62
  po.get_origins_and_backgrounds_lists()
50
- po.get_last_image()
51
- po.fast_image_segmentation(is_first_image=False)
63
+ po.get_last_image(last_im)
64
+ po.fast_last_image_segmentation()
52
65
  po.find_if_lighter_background()
53
66
  po.extract_exif()
54
67
  else:
55
68
  print('Image analysis already done, run video analysis')
56
69
  return po
57
70
 
71
+ def run_one_video_analysis(po, with_video_in_ram: bool=False):
72
+ i=0
73
+ show_seg= False
74
+ po.vars['frame_by_frame_segmentation'] = True
75
+ po.vars['do_threshold_segmentation'] = False
76
+ po.vars['do_slope_segmentation'] = False
77
+ if po.vars['convert_for_motion'] is None:
78
+ po.vars['convert_for_motion'] = po.vars['convert_for_origin']
79
+ videos_already_in_ram = None
80
+ if with_video_in_ram:
81
+ converted_video, _ = convert_subtract_and_filter_video(po.analysis_instance, po.vars['convert_for_motion'])
82
+ videos_already_in_ram = [po.analysis_instance, converted_video]
83
+ segment: bool = True
84
+ l = [i, i + 1, po.vars, segment, False, show_seg, videos_already_in_ram]
85
+ MA = MotionAnalysis(l)
86
+ MA.get_descriptors_from_binary()
87
+ # MA.detect_growth_transitions()
88
+ # MA.networks_analysis(show_seg)
89
+ # MA.study_cytoscillations(show_seg)
90
+ return MA
58
91
 
59
92
  def write_videos(po):
60
93
  po.update_output_list()
@@ -65,37 +98,17 @@ def write_videos(po):
65
98
  do_write_videos = not there_already_are_videos or (
66
99
  there_already_are_videos and po.all['overwrite_unaltered_videos'])
67
100
  if do_write_videos:
68
- po.videos = OneVideoPerBlob(po.first_image, po.starting_blob_hsize_in_pixels, po.all['raw_images'])
69
- po.videos.left = po.left
70
- po.videos.right = po.right
71
- po.videos.top = po.top
72
- po.videos.bot = po.bot
73
- po.videos.first_image.shape_number = po.sample_number
74
- po.videos.write_videos_as_np_arrays(
75
- po.data_list, po.vars['min_ram_free'], not po.vars['already_greyscale'], po.reduce_image_dim)
101
+ po.first_image.shape_number = po.sample_number
102
+ in_colors = not po.vars['already_greyscale']
103
+ bunch_nb, video_nb_per_bunch, sizes, video_bunch, vid_names, rom_memory_required, analysis_status, remaining, use_list_of_vid, is_landscape = po.prepare_video_writing(
104
+ po.data_list, po.vars['min_ram_free'], in_colors)
105
+ write_video_sets(po.data_list, sizes, vid_names, po.first_image.crop_coord,
106
+ (po.top, po.bot, po.left, po.right), bunch_nb, video_nb_per_bunch,
107
+ remaining, po.all["raw_images"], is_landscape, use_list_of_vid, in_colors, po.reduce_image_dim,
108
+ pathway="")
76
109
  po.instantiate_tables()
77
110
  return po
78
111
 
79
-
80
- def run_one_video_analysis(po):
81
- i=0
82
- show_seg= False
83
- # if os.path.isfile(f"coord_specimen{i + 1}_t720_y1475_x1477.npy"):
84
- # binary_coord = np.load(f"coord_specimen{i + 1}_t720_y1475_x1477.npy")
85
- # l = [i, i + 1, po.vars, False, False, show_seg, None]
86
- # MA = MotionAnalysis(l)
87
- # MA.binary = np.zeros((720, 1475, 1477), dtype=np.uint8)
88
- # MA.binary[binary_coord[0, :], binary_coord[1, :], binary_coord[2, :]] = 1
89
- # else:
90
- l = [i, i + 1, po.vars, True, False, show_seg, None]
91
- MA = MotionAnalysis(l)
92
- MA.get_descriptors_from_binary()
93
- MA.detect_growth_transitions()
94
- MA.networks_detection(show_seg)
95
- MA.study_cytoscillations(show_seg)
96
- return MA
97
-
98
-
99
112
  def run_all_arenas(po):
100
113
  po.instantiate_tables()
101
114
  for i, arena in enumerate(po.vars['analyzed_individuals']):
@@ -128,27 +141,18 @@ def run_all_arenas(po):
128
141
  cv2.imwrite(f"Analysis efficiency, {np.ceil(po.vars['img_number'] / 10).astype(np.uint64)}th image.jpg",
129
142
  po.first_image.bgr)
130
143
 
144
+ def detect_network_in_one_image(im_path, save_path):
145
+ im = readim(im_path)
146
+ im = im[100:870, 200:1000]
147
+ greyscale_image = im.mean(axis=2)
148
+ net = NetworkDetection(greyscale_image, add_rolling_window=True)
149
+ net.get_best_network_detection_method()
150
+ display_network_methods(net, save_path)
151
+
131
152
 
132
153
 
133
154
  if __name__ == "__main__":
134
- po = load_one_folder(Path("/data/experiment"), 1)
155
+ po = load_data(pathway=os.getcwd() + "/data/experiment", sample_number=1, extension='tif')
135
156
  po = run_image_analysis(po)
136
157
  po = write_videos(po)
137
- # MA = run_one_video_analysis(po)
138
158
  run_all_arenas(po)
139
-
140
- # MA.one_row_per_frame.to_csv(
141
- # "/Users/Directory/Scripts/python/Cellects/tests/data/experiment/motion_analysis_thresh.csv")
142
-
143
- # path = Path("/Users/Directory/Scripts/python/Cellects/tests/data/experiment")
144
- # po.load_variable_dict()
145
- # run_image_analysis(po)
146
- # os.chdir(path)
147
- # from glob import glob
148
- # from cellects.utils.load_display_save import readim
149
- # im_names = np.sort(glob("*.JPG"))
150
- # for i, im_name in enumerate(im_names): # im_name = im_names[-1]
151
- # im = readim(im_name)
152
- # cv2.imwrite(f"image{i + 1}.tif", im[2925:3170, 1200:1500, :])
153
- #
154
- # show(im[2925:3170,1200:1500, :])