batoolset 0.1.0__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 (162) hide show
  1. batoolset/GUI/__init__.py +0 -0
  2. batoolset/GUI/list_gui.py +513 -0
  3. batoolset/GUI/multi_image_display.py +989 -0
  4. batoolset/GUI/open.py +325 -0
  5. batoolset/GUI/overlay_hints.py +45 -0
  6. batoolset/GUI/paint2.py +1345 -0
  7. batoolset/GUI/scrollablepaint.py +1152 -0
  8. batoolset/IJ_ROIs/__init__.py +0 -0
  9. batoolset/IJ_ROIs/tools.py +40 -0
  10. batoolset/PATH/__init__.py +0 -0
  11. batoolset/PATH/tools.py +79 -0
  12. batoolset/SQLite_tools/__init__.py +0 -0
  13. batoolset/SQLite_tools/tools.py +840 -0
  14. batoolset/__init__.py +0 -0
  15. batoolset/binary/__init__.py +0 -0
  16. batoolset/binary/tools.py +123 -0
  17. batoolset/binarytools/__init__.py +0 -0
  18. batoolset/binarytools/cell_center_detector.py +290 -0
  19. batoolset/clipboard_tools/__init__.py +0 -0
  20. batoolset/clipboard_tools/tools.py +7 -0
  21. batoolset/colors/__init__.py +0 -0
  22. batoolset/colors/colorgen.py +193 -0
  23. batoolset/colors/tools.py +22 -0
  24. batoolset/command_line/__init__.py +0 -0
  25. batoolset/command_line/tools.py +18 -0
  26. batoolset/dialogs/__init__.py +0 -0
  27. batoolset/dialogs/opensave.py +228 -0
  28. batoolset/dicts/__init__.py +0 -0
  29. batoolset/dicts/tools.py +299 -0
  30. batoolset/dims/__init__.py +0 -0
  31. batoolset/dims/tools.py +83 -0
  32. batoolset/draw/__init__.py +0 -0
  33. batoolset/draw/shapes/Position.py +183 -0
  34. batoolset/draw/shapes/__init__.py +0 -0
  35. batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
  36. batoolset/draw/shapes/circle2d.py +99 -0
  37. batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
  38. batoolset/draw/shapes/ellipse2d.py +336 -0
  39. batoolset/draw/shapes/freehand2d.py +235 -0
  40. batoolset/draw/shapes/group.py +1830 -0
  41. batoolset/draw/shapes/image2d.py +2469 -0
  42. batoolset/draw/shapes/line2d.py +575 -0
  43. batoolset/draw/shapes/point2d.py +257 -0
  44. batoolset/draw/shapes/polygon2d.py +357 -0
  45. batoolset/draw/shapes/polyline2d.py +235 -0
  46. batoolset/draw/shapes/rect2d.py +388 -0
  47. batoolset/draw/shapes/rectangle2d.py +601 -0
  48. batoolset/draw/shapes/scalebar.py +304 -0
  49. batoolset/draw/shapes/serializablefont.py +126 -0
  50. batoolset/draw/shapes/serializableguiparams.py +10 -0
  51. batoolset/draw/shapes/square2d.py +103 -0
  52. batoolset/draw/shapes/textorientation.py +45 -0
  53. batoolset/draw/shapes/tools.py +467 -0
  54. batoolset/draw/shapes/transform2D.py +350 -0
  55. batoolset/draw/shapes/txt2d.py +550 -0
  56. batoolset/draw/widgets/__init__.py +0 -0
  57. batoolset/draw/widgets/col.py +343 -0
  58. batoolset/draw/widgets/image_group.py +248 -0
  59. batoolset/draw/widgets/image_organizer.py +96 -0
  60. batoolset/draw/widgets/paint.py +184 -0
  61. batoolset/draw/widgets/vectorial.py +257 -0
  62. batoolset/figure/__init__.py +0 -0
  63. batoolset/figure/alignment.py +814 -0
  64. batoolset/figure/column.py +1117 -0
  65. batoolset/figure/fig_tools.py +285 -0
  66. batoolset/figure/minimal_debugger_scale_etc.py +139 -0
  67. batoolset/figure/panel.py +697 -0
  68. batoolset/figure/row.py +852 -0
  69. batoolset/figure/user_selection.py +287 -0
  70. batoolset/files/__init__.py +0 -0
  71. batoolset/files/tools.py +1321 -0
  72. batoolset/images/__init__.py +0 -0
  73. batoolset/images/tools.py +81 -0
  74. batoolset/img.py +5216 -0
  75. batoolset/linux/__init__.py +0 -0
  76. batoolset/linux/tools.py +72 -0
  77. batoolset/lists/__init__.py +0 -0
  78. batoolset/lists/tools.py +436 -0
  79. batoolset/luts/__init__.py +0 -0
  80. batoolset/luts/lut_minimal_test.py +1207 -0
  81. batoolset/matplolib/__init__.py +0 -0
  82. batoolset/matplolib/tools.py +44 -0
  83. batoolset/np_tools/__init__.py +0 -0
  84. batoolset/np_tools/tools.py +252 -0
  85. batoolset/np_tools/trash.py +15 -0
  86. batoolset/pandas_tools/__init__.py +0 -0
  87. batoolset/pandas_tools/tools.py +880 -0
  88. batoolset/partials/__init__.py +0 -0
  89. batoolset/partials/tools.py +83 -0
  90. batoolset/plot_tools/__init__.py +0 -0
  91. batoolset/plot_tools/tools.py +70 -0
  92. batoolset/pyqt/__init__.py +0 -0
  93. batoolset/pyqt/tools.py +691 -0
  94. batoolset/re_tools/__init__.py +0 -0
  95. batoolset/re_tools/tools.py +35 -0
  96. batoolset/serialization/__init__.py +0 -0
  97. batoolset/serialization/tools.py +1192 -0
  98. batoolset/sets/__init__.py +0 -0
  99. batoolset/sets/tools.py +109 -0
  100. batoolset/settings/__init__.py +0 -0
  101. batoolset/settings/global_settings.py +134 -0
  102. batoolset/strings/__init__.py +0 -0
  103. batoolset/strings/tools.py +225 -0
  104. batoolset/ta/__init__.py +0 -0
  105. batoolset/ta/database/__init__.py +0 -0
  106. batoolset/ta/database/advanced_sql_plotter.py +1170 -0
  107. batoolset/ta/database/my_qt_table.py +79 -0
  108. batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
  109. batoolset/ta/database/sql.py +2141 -0
  110. batoolset/ta/database/sql_column_name_dialog.py +122 -0
  111. batoolset/ta/measurements/TAmeasures.py +2226 -0
  112. batoolset/ta/measurements/__init__.py +0 -0
  113. batoolset/ta/measurements/measurements3D/__init__.py +0 -0
  114. batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
  115. batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
  116. batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
  117. batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
  118. batoolset/ta/measurements/nematic.py +562 -0
  119. batoolset/ta/measurements/nematic_measurements.py +107 -0
  120. batoolset/ta/segmentation/__init__.py +0 -0
  121. batoolset/ta/segmentation/neo_wshed.py +314 -0
  122. batoolset/ta/selections/__init__.py +0 -0
  123. batoolset/ta/selections/selection.py +329 -0
  124. batoolset/ta/tracking/__init__.py +0 -0
  125. batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
  126. batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
  127. batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
  128. batoolset/ta/tracking/registration.py +108 -0
  129. batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
  130. batoolset/ta/tracking/track_correction.py +238 -0
  131. batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
  132. batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
  133. batoolset/ta/utils/TA_tools.py +43 -0
  134. batoolset/ta/utils/__init__.py +0 -0
  135. batoolset/ta/utils/rps_tools.py +1783 -0
  136. batoolset/tests/__init__.py +0 -0
  137. batoolset/tests/rps_tools.py +51 -0
  138. batoolset/tests/tools.py +10 -0
  139. batoolset/tools/__init__.py +0 -0
  140. batoolset/tools/early_stopper_class.py +9 -0
  141. batoolset/tools/guided_data_recoverer.py +110 -0
  142. batoolset/tools/logger.py +100 -0
  143. batoolset/tools/mytimer.py +31 -0
  144. batoolset/tools/prompt_color.py +160 -0
  145. batoolset/tools/qthandler.py +118 -0
  146. batoolset/uitools/__init__.py +0 -0
  147. batoolset/uitools/blinker.py +56 -0
  148. batoolset/unsafe/__init__.py +0 -0
  149. batoolset/unsafe/tools.py +115 -0
  150. batoolset/utils/__init__.py +0 -0
  151. batoolset/utils/commontools.py +158 -0
  152. batoolset/utils/loadlist.py +728 -0
  153. batoolset/version.py +10 -0
  154. batoolset/xml/__init__.py +0 -0
  155. batoolset/xml/tools.py +65 -0
  156. batoolset/zip_tools/__init__.py +0 -0
  157. batoolset/zip_tools/tools.py +76 -0
  158. batoolset-0.1.0.dist-info/LICENSE +24 -0
  159. batoolset-0.1.0.dist-info/METADATA +45 -0
  160. batoolset-0.1.0.dist-info/RECORD +162 -0
  161. batoolset-0.1.0.dist-info/WHEEL +5 -0
  162. batoolset-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1170 @@
1
+ # TODO ADD PLOT AS VARIOUS SHAPES --> TODO SUCH AS POINTS OR DOTS OR CIRCLE OR SQUARES OR RECTANGLES OR ALIKE !!!
2
+ # TODO --> add this at some point ADD PLOT AS POINT OR ANY SHAPE!!!!
3
+
4
+
5
+ # for points I would need to have two columns and maybe a radius or something alike --> THINK OF THAT
6
+ # maybe also extend that to 3D as I more and more need that !!!!
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ # can I add plot as CIRCLE OR PLOT AS DOT ???? --> check what plot as vertices do...
18
+ # NB I DO HAVE PLOT AS POINTS AND THAT SHOULD DO THE JOB !!!
19
+
20
+
21
+
22
+
23
+
24
+ # not bad --> almost there --> see what is really missing and add it for the MS --> TODO
25
+
26
+
27
+ # TODO I have a big bug in the polarity --> need fix it but maybe not very urgent in fact !!!
28
+ # do a small test on a small image --> easy to debug
29
+ # test of all
30
+
31
+ # examples of SQLite commands I'd like to reimplement rapidly
32
+ # PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, area_cells FROM cells + LUT DNA
33
+ # PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells WHERE is_border_cell=='false' + LUT DNA + OPACITY 35% + DILATATION 1
34
+ # PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells NATURAL JOIN tracked_clone_022 + LUT DNA MIN=GLOBAL_MIN MAX=GLOBAL_MAX + OPACITY 35% + DILATATION 1
35
+ # PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10 + LUT DNA MIN=GLOBAL_MIN MAX=GLOBAL_MAX
36
+ # PLOT AS ARROWS SELECT first_pixel_x_cells,first_pixel_y_cells , center_x_cells,center_y_cells, area_cells AS COLOR, '1' AS STROKE_SIZE, 'DEFAULT_ARROW' AS ARROWHEAD_TYPE, '5' AS ARROWHEAD_HEIGHT,'3' AS ARROWHEAD_HEIGHT, '0.3' AS STROKE_OPACITY FROM cells + LUT DNA
37
+ # PLOT AS BONDS SELECT first_pixel_x_bonds, first_pixel_y_bonds, bond_orientation FROM bonds WHERE first_pixel_y_bonds != 'null' + LUT DNA
38
+
39
+
40
+ # some columns would require specific plots
41
+ # implement plot as nematic
42
+ # implement plot as cells
43
+
44
+
45
+ # offer exclude border cells
46
+ # support quantiles
47
+ #
48
+
49
+
50
+ # https://matplotlib.org/2.0.2/faq/usage_faq.html --> check backends beacuse that is most likely what I need for my figure editor
51
+
52
+
53
+ # plots stuff as cell, bonds or vertices ideally from a db
54
+ # should not be too hard --> need load the image duplicate it and do the plots through conversions maybe need enable numba otherwise it will be too slow!!!
55
+ # from PIL.ImageDraw import ImageDraw
56
+ import traceback
57
+
58
+ from PIL import ImageDraw, Image
59
+
60
+ from batoolset.draw.shapes.image2d import Image2D
61
+ from batoolset.img import Img, PIL_to_numpy, invert
62
+ from skimage.measure import regionprops
63
+ import numpy as np
64
+ import matplotlib
65
+ from scipy.ndimage import grey_erosion, grey_dilation, generate_binary_structure
66
+ import os
67
+ from batoolset.ta.database.sql import TAsql, createMasterDB, sort_col_numpy
68
+ from batoolset.luts.lut_minimal_test import PaletteCreator, apply_lut
69
+ from batoolset.ta.measurements.nematic import Nematic
70
+ from batoolset.files.tools import smart_name_parser
71
+
72
+
73
+ # matplotlib.use('Qt5Agg') #, Qt5Cairo,
74
+ # matplotlib.use('Qt5Cairo') #, Qt5Cairo,
75
+ # matplotlib.use('WXAgg') #, Qt5Cairo,
76
+ # matplotlib.use('agg') #, Qt5Cairo,
77
+ # matplotlib.use('TkCairo') #, Qt5Cairo,
78
+ # supported values are['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
79
+ # matplotlib.rcParams['backend'] = 'cairo'
80
+
81
+ # - interactive
82
+ # backends:
83
+ # GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
84
+ # Qt4Agg, Qt4Cairo, Qt5Agg, Qt5Cairo,
85
+ # TkAgg, TkCairo, WebAgg, WX, WXAgg, WXCairo
86
+ #
87
+ # - non - interactive
88
+ # backends:
89
+ # agg, cairo, pdf, pgf, ps, svg, template
90
+
91
+ # print(matplotlib.use)
92
+
93
+ import matplotlib.pyplot as plt
94
+ from batoolset.tools.logger import TA_logger # logging
95
+ from batoolset.utils.loadlist import loadlist
96
+ import re
97
+
98
+ logger = TA_logger()
99
+
100
+ # TODO finalize that
101
+ # need a type of plot and need data to be plotted that is associated to the id of the relevant table --> TODO
102
+ # whole data can also be obtained from a SQL command --> such as PLOT AS CELLS ...
103
+ # can I do blending directly at the qimage level ??? if so --> quite simple in a way!!!
104
+
105
+
106
+ # then need get a mapping of the colors --> TODO
107
+ # for the SQL plots see how I can do that --> need convert to number and do stuff with it
108
+ # faire un importeur de csv
109
+ # plus simple de matcher la cell ID avec une valeur que les coordonnées en fait dans cette nouvelle version et en plus il y a moins de données ce qui sera plus simple à gérer -> juste besoin de la local ID des cellules ou des vertex ou des bonds --> vraiment du gateau
110
+
111
+
112
+ '''
113
+ TODO to be ok with TA
114
+
115
+ //PLOT AS BONDS SQL
116
+ //PLOT AS RECTANGLE
117
+ //PLOT AS LINE
118
+ //PLOT AS NEMATIC
119
+ //PLOT AS VECTOR same as plot as line
120
+ //PLOT AS SQUARE
121
+ //PLOT AS POINTS
122
+ PLOT AS STRINGS
123
+ '''
124
+
125
+ # check a set of TA commands to see how I can parse them
126
+ # in a way the SQL command is anything between select and the end of the line or a plus --> it is anything before the first encountered extra keyword --> should not be too hard to do!!!
127
+ # especially now that the command is cleaned
128
+ # if unknown keyword --> then return an error
129
+
130
+
131
+ extra_plot_commands_for_images = ['LUT', 'EROSION', 'DILATATION', 'DILATION', 'OPACITY', 'TRANSPARENCY']
132
+
133
+ def plot_SQL(SQL_command):
134
+ """
135
+ Plot SQL data based on the given SQL command.
136
+
137
+ Args:
138
+ SQL_command (str): The SQL command to plot.
139
+
140
+ Examples:
141
+ >>> plot_SQL("PLOT AS CELLS SELECT * FROM table")
142
+ cleaned_SQL_command "PLOT AS CELLS SELECT * FROM table"
143
+ plot_type "CELLS"
144
+ SQL_command "SELECT * FROM table"
145
+ extra_commands_to_parse "None"
146
+
147
+ """
148
+ if SQL_command is None:
149
+ logger.error('Empty SQL command --> nothing to do')
150
+ return
151
+
152
+ if not isinstance(SQL_command, str):
153
+ logger.error('SQL command must be a string, instead a ' + str(type(SQL_command)) + ' was passed...')
154
+ return
155
+
156
+ if SQL_command.strip().startswith('#') or SQL_command.strip().startswith('//'):
157
+ return
158
+
159
+ cleaned_SQL_command = _clean_string(SQL_command)
160
+
161
+ print('cleaned_SQL_command "' + cleaned_SQL_command + '"')
162
+
163
+ plot_type = None
164
+ if cleaned_SQL_command.upper().startswith('PLOT AS CELLS'):
165
+ plot_type = 'CELLS'
166
+ cleaned_SQL_command = _strip_from_command(cleaned_SQL_command, 'PLOT AS CELLS')
167
+ elif cleaned_SQL_command.upper().startswith('PLOT AS BONDS'):
168
+ plot_type = 'BONDS'
169
+ cleaned_SQL_command = _strip_from_command(cleaned_SQL_command, 'PLOT AS BONDS')
170
+ elif cleaned_SQL_command.upper().startswith('PLOT AS VERTICES'):
171
+ plot_type = 'VERTICES'
172
+ cleaned_SQL_command = _strip_from_command(cleaned_SQL_command, 'PLOT AS VERTICES')
173
+ else:
174
+ logger.error('unsupported plot command: ' + str(cleaned_SQL_command))
175
+ return
176
+
177
+ print('plot_type "' + str(plot_type) + '"')
178
+
179
+ first_idx = None
180
+ for extra in extra_plot_commands_for_images:
181
+ try:
182
+ idx = cleaned_SQL_command.upper().index(extra)
183
+ if first_idx is None:
184
+ first_idx = idx
185
+ else:
186
+ first_idx = min(first_idx, idx)
187
+ except:
188
+ continue
189
+
190
+ extra_commands_to_parse = None
191
+ if first_idx is not None:
192
+ SQL_command = cleaned_SQL_command[0:first_idx].strip()
193
+ if SQL_command.endswith('+'):
194
+ SQL_command = SQL_command[:-1].strip()
195
+ extra_commands_to_parse = cleaned_SQL_command[first_idx:].strip()
196
+ else:
197
+ SQL_command = cleaned_SQL_command
198
+
199
+ print('SQL_command "' + str(SQL_command) + '"')
200
+ print('extra_commands_to_parse "' + str(extra_commands_to_parse) + '"')
201
+
202
+ if extra_commands_to_parse:
203
+ individual_extras = extra_commands_to_parse.split('+')
204
+
205
+ for individual_extra in individual_extras:
206
+ print('individual_extra "' + individual_extra.strip() + '"')
207
+
208
+ extra_type = individual_extra.strip().split()
209
+
210
+ if extra_type[0].strip().upper() not in extra_plot_commands_for_images:
211
+ logger.error('unknown image extra ' + str(extra_type[0]) + ' --> ignoring')
212
+ else:
213
+ if extra_type[0].strip().upper() == extra_plot_commands_for_images[0]:
214
+ print('LUT to parse')
215
+ print('param', parse_lut(extra_type))
216
+ elif extra_type[0].strip().upper() == extra_plot_commands_for_images[1]:
217
+ print('EROSION to parse')
218
+ print('param', parse_erosion_dilation(extra_type))
219
+ elif extra_type[0].strip().upper() == extra_plot_commands_for_images[2] or extra_type[0].strip().upper() == extra_plot_commands_for_images[3]:
220
+ print('DILATION to parse')
221
+ print('param', parse_erosion_dilation(extra_type))
222
+ elif extra_type[0].strip().upper() == extra_plot_commands_for_images[4]:
223
+ print('OPACITY to parse')
224
+ print('param', parse_opacity(extra_type))
225
+ elif extra_type[0].strip().upper() == extra_plot_commands_for_images[5]:
226
+ print('TRANSPARENCY to parse')
227
+ print('param', 1. - parse_opacity(extra_type))
228
+
229
+ def parse_lut(extra_type):
230
+ """
231
+ Parse the LUT extra command.
232
+
233
+ Args:
234
+ extra_type (list): List of strings representing the LUT extra command.
235
+
236
+ Returns:
237
+ dict or str: The parsed LUT mapping as a dictionary or the name of the LUT.
238
+
239
+ Examples:
240
+ >>> parse_lut(['LUT', 'DNA'])
241
+ 'DNA'
242
+
243
+ """
244
+
245
+ if len(extra_type) == 2 and (not ':' in extra_type[1]):
246
+ try:
247
+ return extra_type[1] # returns the name of the LUT
248
+ except:
249
+ pass
250
+ else:
251
+ if ':' in extra_type[1]:
252
+ lut_mapping = {}
253
+ for mapping in extra_type[1:]:
254
+ split_mappings = mapping.split(':')
255
+ split_mappings = [split_mapping.strip() for split_mapping in split_mappings]
256
+ key = int(split_mappings[0])
257
+ value = split_mappings[1]
258
+ if '#' in value:
259
+ value = int(value.replace('#', ''), 16)
260
+ else:
261
+ value = int(value)
262
+ lut_mapping[key] = value
263
+ else:
264
+ logger.warning('LUT bounds not implemented yet')
265
+ return parse_lut(extra_type=extra_type[0:2])
266
+ return lut_mapping
267
+
268
+ return None
269
+
270
+
271
+ def parse_opacity(extra_type):
272
+ """
273
+ Parse the opacity extra command.
274
+
275
+ Args:
276
+ extra_type (list): List of strings representing the opacity extra command.
277
+
278
+ Returns:
279
+ float or None: The parsed opacity value as a float or None if parsing fails.
280
+
281
+ Examples:
282
+ >>> parse_opacity(['OPACITY', '50'])
283
+ 50.0
284
+
285
+ >>> parse_opacity(['OPACITY', '25%'])
286
+ 0.25
287
+
288
+ """
289
+
290
+ if len(extra_type) == 2:
291
+ try:
292
+ ispercent = '%' in extra_type[1]
293
+ if ispercent:
294
+ extra_type[1] = extra_type[1].replace('%', '')
295
+ value = float(extra_type[1])
296
+ if ispercent:
297
+ value /= 100.
298
+ return value
299
+ except:
300
+ pass
301
+ return None
302
+
303
+
304
+ def parse_erosion_dilation(extra_type):
305
+ """
306
+ Parse the erosion or dilation extra command.
307
+
308
+ Args:
309
+ extra_type (list): List of strings representing the erosion or dilation extra command.
310
+
311
+ Returns:
312
+ int or None: The parsed erosion or dilation value as an integer or None if parsing fails.
313
+
314
+ Examples:
315
+ >>> parse_erosion_dilation(['EROSION', '2'])
316
+ 2
317
+
318
+ """
319
+
320
+ if len(extra_type) == 2:
321
+ try:
322
+ return int(extra_type[1])
323
+ except:
324
+ pass
325
+ return None
326
+
327
+
328
+ def _clean_string(string):
329
+ """
330
+ Clean the string by removing leading/trailing whitespaces and extra whitespaces between words.
331
+
332
+ Args:
333
+ string (str): The input string.
334
+
335
+ Returns:
336
+ str: The cleaned string.
337
+
338
+ Examples:
339
+ >>> _clean_string(' Hello world! ')
340
+ 'Hello world!'
341
+
342
+ """
343
+
344
+ parsed_commands = string.split()
345
+ parsed_commands = [command.strip() for command in parsed_commands]
346
+ cleaned_string = ' '.join(parsed_commands)
347
+ return cleaned_string
348
+
349
+
350
+ def _strip_from_command(command, things_to_strip):
351
+ """
352
+ Strip the specified things from the command.
353
+
354
+ Args:
355
+ command (str): The command string.
356
+ things_to_strip (str): The things to strip from the command.
357
+
358
+ Returns:
359
+ str: The stripped command.
360
+
361
+ Examples:
362
+ >>> _strip_from_command('SELECT * FROM table', 'SELECT')
363
+ '* FROM table'
364
+
365
+ >>> _strip_from_command('HELLO world', 'hello')
366
+ 'world'
367
+
368
+ """
369
+
370
+ import re
371
+ case_insensitive_replace = re.compile(re.escape(things_to_strip), re.IGNORECASE)
372
+ stripped = case_insensitive_replace.sub('', command).strip()
373
+
374
+ return stripped
375
+
376
+
377
+
378
+
379
+
380
+ # NB THERE IS A BUG THAT FORCES THE PLOT TWICE --> PROBABLY SOME ADJUSTMENT STUFF --> NEED CHANGE THIS
381
+ def plot_as_any(parent_image, SQL_command, plot_type='cells', return_mask=False, invert_mask=True, db=None,current_frame=None, **kwargs):
382
+ """
383
+ Plot image based on SQL command results.
384
+
385
+ Args:
386
+ parent_image (str): Path to the parent image.
387
+ SQL_command (str): SQL command to run and get the results for plotting.
388
+ plot_type (str, optional): Type of plot to generate. Defaults to 'cells'.
389
+ return_mask (bool, optional): Whether to return the mask image. Defaults to False.
390
+ invert_mask (bool, optional): Whether to invert the mask image. Defaults to True.
391
+ db (TAsql, optional): TAsql object representing the database. Defaults to None.
392
+ current_frame (int, optional): Current frame number. Defaults to None.
393
+ **kwargs: Additional keyword arguments for extra parameters.
394
+
395
+ Returns:
396
+ None
397
+
398
+ # Examples:
399
+ # # Example 1: Plotting as cells with default parameters
400
+ # plot_as_any('path/to/parent_image.tif', 'SELECT * FROM table')
401
+ #
402
+ # # Example 2: Plotting as bonds with additional parameters
403
+ # plot_as_any('path/to/parent_image.tif', 'SELECT * FROM table', plot_type='bonds', return_mask=True, LUT='rainbow', opacity=0.5)
404
+ #
405
+ # # Example 3: Plotting as vertices with database object
406
+ # db = TAsql('path/to/database.db')
407
+ # plot_as_any('path/to/parent_image.tif', 'SELECT * FROM table', plot_type='vertices', db=db, current_frame=1)
408
+
409
+ """
410
+ if parent_image is None:
411
+ logger.error('No input image specified, cannot plot image!')
412
+ return
413
+
414
+ # print('current_frame inside', current_frame)
415
+
416
+ TA_path = smart_name_parser(parent_image, ordered_output='TA')
417
+ erosion_dilation = None
418
+ lut = None
419
+ opacity = None
420
+ freq = None
421
+
422
+ if kwargs:
423
+ # parse extra parameters such as dilation...
424
+ # ['LUT', 'EROSION', 'DILATATION','DILATION', 'OPACITY', 'TRANSPARENCY']
425
+ if extra_plot_commands_for_images[0] in kwargs:
426
+ lut = kwargs[extra_plot_commands_for_images[0]]
427
+ if extra_plot_commands_for_images[1] in kwargs:
428
+ erosion_dilation = -kwargs[extra_plot_commands_for_images[1]]
429
+ if extra_plot_commands_for_images[
430
+ 3] in kwargs: # elif extra_type[0].strip().upper() == extra_plot_commands_for_images[2]
431
+ erosion_dilation = kwargs[extra_plot_commands_for_images[3]]
432
+ if extra_plot_commands_for_images[4] in kwargs:
433
+ opacity = kwargs[extra_plot_commands_for_images[4]]
434
+ if extra_plot_commands_for_images[5] in kwargs:
435
+ opacity = 1. - kwargs[extra_plot_commands_for_images[5]]
436
+ if 'freq' in kwargs:
437
+ freq = kwargs['freq']
438
+
439
+ # those guys require the cell db
440
+ if plot_type in ['cells', 'nematic', 'nematics']:
441
+ # by default plot as cells
442
+ logger.debug('plot as cells')
443
+ image_plot = Img(os.path.join(TA_path,'cells.tif')).astype(np.uint64)
444
+ elif plot_type == 'bonds':
445
+ logger.debug('plot as bonds')
446
+ image_plot = Img(os.path.join(TA_path,'bonds.tif')).astype(np.uint64)
447
+ elif plot_type == 'vertices':
448
+ logger.debug('plot as vertices')
449
+ image_plot = Img(os.path.join(TA_path,'vertices.tif')).astype(np.uint64)
450
+ elif plot_type == 'packing':
451
+ logger.debug('plot as packing')
452
+ image_plot = Img(os.path.join(TA_path, 'cells.tif')).astype(np.uint64)
453
+ else:
454
+ logger.error('Plot type unknonw: \'' + str(plot_type) + '\'')
455
+ return
456
+
457
+ if erosion_dilation and plot_type in ['packing', 'cells', 'bonds', 'vertices']:
458
+ s = generate_binary_structure(2, 1)
459
+ if erosion_dilation > 0:
460
+ # do gray dilation on image
461
+ for _ in range(abs(erosion_dilation)):
462
+ image_plot = grey_dilation(image_plot, footprint=s)
463
+ elif erosion_dilation < 0:
464
+ # do gray erosion on image
465
+ for _ in range(abs(erosion_dilation)):
466
+ image_plot = grey_erosion(image_plot, footprint=s)
467
+
468
+ # then run sql command and see what TODO exactly
469
+ # map all to the first
470
+ # if full then find image in full list by its index maybe -> do that at some point
471
+
472
+ database_path = os.path.join(TA_path, 'pyTA.db')
473
+ # database_path = os.path.join(TA_path, 'TA.db')
474
+ if not os.path.isfile(database_path):
475
+ logger.error('pyTA db not found, nothing to plot ' + str(database_path))
476
+ return
477
+
478
+ query_results = None
479
+ # db = None
480
+ if db is None:
481
+ try:
482
+ db = TAsql(database_path)
483
+ headers, query_results = db.run_SQL_command_and_get_results(SQL_command, return_header=True)
484
+
485
+ # need get the max and min too of that command --> see how I can do that
486
+
487
+ except:
488
+ pass
489
+ finally:
490
+ if db is not None:
491
+ db.close()
492
+ db=None
493
+ else:
494
+ try:
495
+ # use and query the master db but do not close it --> need query it twice to get the max and min of the values
496
+ # db = TAsql(database_path)
497
+ if SQL_command.strip().endswith(';'):
498
+ SQL_command.replace(';','')
499
+
500
+ # print('new sql command for masted db', SQL_command + ' WHERE frame_nb == '+str(current_frame))
501
+ headers, query_results = db.run_SQL_command_and_get_results(SQL_command + ' WHERE frame_nb == '+str(current_frame), return_header=True)
502
+ except:
503
+ pass
504
+
505
+ if query_results is None:
506
+ logger.error('Plot failed because of an erroneous SQL command: ' + str(SQL_command))
507
+ return
508
+
509
+ # faut que je reparse le truc
510
+ # ça marche mais voir comment faire ça de maniere portable en fait
511
+ # print(query_results, headers)
512
+
513
+ # TODO replace by panda dataframe to handle many more things or do smart loopings to read as if it were cols from the data --> in a way that is also not that hard
514
+ method1 = False
515
+ method2 = False
516
+ if method1:
517
+ # add a 0,0 mapping for cells --> TODO
518
+ # in case of clones I may miss so many cells !!! --> think about the fastest way to add them !!!
519
+ query_results.insert(0, (0, 0))
520
+
521
+ # is there anything more secure ???
522
+ # maybe yes with a loop but will be much less efficient --> think about it
523
+
524
+ # ça marche mais si il manque plein de cellules il faut que je les ajoute --> si differe de continu --> soit ajouter des valeurs
525
+
526
+ # j'en suis pas loin mais faut reflechir à la facon la plus facile de faire ça
527
+ # need get the max of the image
528
+
529
+ # convert this to a mapping array
530
+ # should not be too hard to do
531
+ formatted = np.asarray(query_results)
532
+ # print(formatted.shape, formatted.dtype) # 337 2
533
+
534
+ # In[153]: keyarray = np.array(['S', 'M', 'L', 'XL'])
535
+ # In[158]: data = np.array([[0, 2, 1], [1, 3, 2]])
536
+ # In[159]: keyarray[data]
537
+ # Out[159]:
538
+
539
+ keyarray = formatted[:, 1]
540
+
541
+ # output = np.zeros_like(image_plot)
542
+ output = keyarray[image_plot]
543
+
544
+ # print('output', output.shape, output.dtype)
545
+
546
+ # convert left values to that in right --> indexing
547
+
548
+ # no do some magic plotting
549
+ # and somehow apply a lut ???
550
+
551
+ # do stuff for the cells --> such as a plot of the area, etc...
552
+ # need get global max and min --> a good idea and very easy todo with sqlite
553
+
554
+ # create an empty image that we can then fill
555
+
556
+ # can easily replace that by values from a database
557
+
558
+ # for plot in rps:
559
+ # # do stuff
560
+ # # cell_output[cell.coords[:, 0], cell.coords[:, 1]] = 255
561
+ # output[plot.coords[:, 0], plot.coords[:, 1]] = plot.area # easy area plot in fact
562
+
563
+ # if opacity ... do stuff
564
+ # if Lut do further stuff
565
+
566
+ # todo --> DO A SECOND MAPPING FOR LUT --> TODO -->
567
+
568
+ # maybe could use negative values to get excluded cells
569
+ # the color coding would be better with me !!! in fact
570
+
571
+ # plt.imshow(output, cmap='Pastel1')
572
+ # # plt.imshow(output, cmap='rainbow')
573
+ # # plt.imshow(output, cmap='viridis')
574
+ # # plt.imshow(output, cmap='gray')
575
+ # plt.show()
576
+ elif method2:
577
+ # marche pas car l'erosion peut faire perdre des IDs de cellules --> need a fix
578
+ rps = regionprops(image_plot)
579
+ formatted = np.asarray(query_results, dtype=object)
580
+ output = np.zeros_like(image_plot)
581
+
582
+ # can easily replace that by values from a database
583
+ # another way of doing, it might ultimately be simpler
584
+
585
+ for iii, id in enumerate(formatted[:, 0]):
586
+ # for plot in rps:
587
+ plot = rps[int(id) - 1]
588
+ # do stuff
589
+ # cell_output[cell.coords[:, 0], cell.coords[:, 1]] = 255
590
+
591
+
592
+
593
+ output[plot.coords[:, 0], plot.coords[:, 1]] = formatted[iii, 1] # easy area plot in fact
594
+
595
+ # # plt.imshow(output, cmap='Pastel1')
596
+ # # plt.imshow(output, cmap='rainbow')
597
+ # plt.imshow(output, cmap='viridis')
598
+ # # plt.imshow(output, cmap='gray')
599
+ # plt.show()
600
+ else:
601
+ # ça marche aussi même avec l'erosion --> pas le plus propre ni le plus efficace mais super robuste --> donc probablement utiliser ça !!!
602
+ # rps = regionprops(image_plot)
603
+ # in fact that still does not work great --> cannot handle None
604
+ formatted = np.asarray(query_results, dtype=object) # required for handling complex outputs that contain string Nones and ints and floats
605
+
606
+ # print(formatted) # all ok here --> why not plotting properly
607
+
608
+ # print('formatted.shape', formatted.shape)
609
+
610
+
611
+ # print(formatted, '\n test sqdqdsq', db==None, SQL_command)
612
+
613
+ # do an autoscale for polarity based on the value of polarity for the max Q1 and Q2 values and at some point offer a rescaling factor maybe
614
+ # print formatted
615
+ # plot as cells
616
+ if plot_type in ['packing', 'cells', 'bonds', 'vertices']:
617
+ output = np.zeros_like(image_plot, dtype=float) # super important to have float here otherwise loses data !!!
618
+ if return_mask:
619
+ mask = np.zeros_like(image_plot)
620
+ # can easily replace that by values from a database
621
+ # another way of doing, it might ultimately be simpler
622
+
623
+ # print(formatted[:, 0])
624
+ # if not formatted:
625
+ # return
626
+
627
+
628
+
629
+
630
+ for iii, id in enumerate(formatted[:, 0]):
631
+ # for plot in rps:
632
+ # plot = rps[int(id) - 1]
633
+ # do stuff
634
+ # cell_output[cell.coords[:, 0], cell.coords[:, 1]] = 255
635
+ # output[plot.coords[:, 0], plot.coords[:, 1]] = formatted[iii, 1] # easy area plot in fact
636
+
637
+ # print(id, formatted[iii, 1], type(id)) # numpy.str_ --> for id --> why is that ??????
638
+ idx = image_plot == id
639
+ output[idx] = formatted[iii, 1] # easy area plot in fact
640
+
641
+
642
+
643
+
644
+ # print(formatted[iii, 1])
645
+
646
+ if return_mask:
647
+ mask[idx] = 255
648
+ # FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
649
+ # output[image_plot == id] = formatted[iii, 1] # easy area plot in fact
650
+
651
+ # print(formatted[iii, 1]) # --> values are ok but I have a bug of conversion somewhere --> if values are very small --> less than 1 they are rounded
652
+ # plt.imshow(output)
653
+ # plt.show()
654
+ # up until here all is ok --> bug is in color coding
655
+ elif plot_type.startswith('nematic'):
656
+ # if return_mask:
657
+ # mask = np.zeros_like(image_plot)
658
+
659
+ rps = regionprops(image_plot)
660
+ # output = np.zeros_like(image_plot.shape, dtype=np.uint8)
661
+ # im = numpy_to_PIL(output)
662
+
663
+ # nb image is defined by with then height --> opposite of numpy!!!!
664
+ # create a black image of the size of the image
665
+
666
+ im = np.zeros_like(image_plot)
667
+ # im = Image.new('RGB', (image_plot.shape[1],image_plot.shape[0]), (0,0,0))
668
+ # draw = ImageDraw.Draw(im)
669
+
670
+ has_scaling_factor = 'SCALING_FACTOR' in headers
671
+ scaling_factor_idx = -1
672
+ if has_scaling_factor:
673
+ scaling_factor_idx = headers.index('SCALING_FACTOR')
674
+ # print('scaling_factor_idx',scaling_factor_idx)
675
+ has_colors = 'COLOR' in headers
676
+ colors_idx = -1
677
+ if has_colors:
678
+ colors_idx= headers.index('COLOR')
679
+ has_stroke_size = 'STROKE_SIZE' in headers
680
+ stroke_idx = -1
681
+ if has_stroke_size:
682
+ stroke_idx = headers.index('STROKE_SIZE')
683
+
684
+ lines2ds = []
685
+ # TODO --> implement nematic plot maybe with autoscaling depending on magnitude --> should not be too hard to do!!!
686
+ for iii, id in enumerate(formatted[:, 0]):
687
+ # need draw a line over the cell centroid
688
+ # I need the rps corresponding to the cell to get its centroid
689
+ # if
690
+ plot = rps[int(id) - 1]
691
+ # do stuff
692
+ # cell_output[cell.coords[:, 0], cell.coords[:, 1]] = 255
693
+ # output[plot.coords[:, 0], plot.coords[:, 1]] = formatted[iii, 1] # easy area plot in fact
694
+ centroid = plot.centroid
695
+
696
+
697
+ # print(plot.centroid)
698
+ # draw a nematic at this level
699
+ # need
700
+
701
+ # print('formatted[iii,1],formatted[iii,2]', formatted[iii,1],formatted[iii,2], formatted[iii,1]+1)
702
+
703
+
704
+
705
+ nemat = Nematic(S1=formatted[iii, 1],S2=formatted[iii, 2], center = centroid)
706
+ # nemat.draw(output)
707
+ # nemat.draw(draw, stroke=2 if not has_stroke_size else formatted[iii, stroke_idx], rescaling_factor=None if not has_scaling_factor else formatted[iii, scaling_factor_idx], color= 0xFFFF00 if not has_colors else formatted[iii, colors_idx]) # todo scale it -> try that
708
+
709
+
710
+ # TODO FINALIZE THE PLOTS WITH THE COLORS AND STUFF ALIKE
711
+
712
+
713
+
714
+
715
+ l2d = nemat.toLine2D(rescaling_factor=1 if not has_scaling_factor else formatted[iii, scaling_factor_idx])
716
+ # TODO add rescaling and line stroke
717
+ if l2d is not None:
718
+ l2d.stroke = 2 if not has_stroke_size else formatted[iii, stroke_idx]
719
+ l2d.color =0xFFFF00 if not has_colors else formatted[iii, colors_idx]
720
+ lines2ds.append(l2d)
721
+
722
+ # print(l2d)
723
+
724
+
725
+ # print(nemat)
726
+
727
+ # would need to draw it as a line at some point but ok for now!!!
728
+ # nemat
729
+
730
+ im2d = Image2D(im)
731
+ im2d.annotation.extend(lines2ds)
732
+
733
+ im = im2d.save(None)
734
+ im = im2d.convert_qimage_to_numpy(im)
735
+ output = im
736
+
737
+ # print('lines2ds', lines2ds)
738
+ # output = PIL_to_numpy(im)
739
+
740
+
741
+
742
+ if return_mask:
743
+ mask = np.zeros_like(output)
744
+ mask[output!=0]=255
745
+
746
+ # print(output.shape)
747
+ #
748
+ # plt.imshow(output)
749
+ # plt.show()
750
+
751
+ # random_lut=random.choice(list(luts.keys()))
752
+ # print('random.lut',random_lut)
753
+ # plot.imshow(output)
754
+ # plt.show()
755
+
756
+ # print(output)
757
+
758
+
759
+ # just get data normally and it is only for min and max that I will need the masterdb max and min
760
+ # only for the LUT that I need that the rest can stay as such in fact
761
+ if plot_type not in ['nematic','nematics']:
762
+ # all seems ok --> just compare to TA to avoid issues
763
+ # random_lut = 'HI_LO'
764
+ lutcreator = PaletteCreator()
765
+ luts = lutcreator.list
766
+ # lut = lutcreator.create3(luts[lut])
767
+ try:
768
+ palette = lutcreator.create3(luts[lut])
769
+ except:
770
+ if lut is not None:
771
+ logger.error('could not load the specified lut (' +str(lut)+') a gray lut is loaded instead') # --> ignoring or shall I default to gray
772
+ # palette = None
773
+ # default to grey palette
774
+ palette = lutcreator.create3(luts['GRAY'])
775
+
776
+
777
+ # maybe in the end also only get the modified pixels and plot only those --> especially for overlay or use transparency value to hide what should not be plotted --> set to fully transparent --> TODO!!!
778
+
779
+ # lut = lutcreator.create3(luts['HI_LO'])
780
+
781
+ # vraiment j'en suis pas loin --> juste voir comment finaliser les trucs
782
+ # peut etre convertir l'output du truc de maniere simple
783
+ # --> est-ce slow --> probablement pas
784
+ # see how I can do that
785
+
786
+
787
+
788
+ # ça marche presque --> juste tt finaliser maintenant !!!
789
+ # output = apply_lut(output, lut, True, max=1000, min=900)
790
+ # output = apply_lut(output, lut, True, max=6000, min=0) # max = 3*+ que le real max --> should all appear weak
791
+ # output = apply_lut(output, lut, True, max=6000, min=100) # max = 3*+ que le real max --> should all appear weak # it seems to work but compare to TA
792
+ # output = apply_lut(output, lut, True, max=3000, min=0) # 2*plus
793
+ # is the bottom incorrect --> maybe
794
+ # output = apply_lut(output, lut, True, max=1600, min=400) # 2*plus #a bit below real max # does it create a bug ???? --> maybe --> check it --> it looks weird to me
795
+ # output = apply_lut(output, lut, True, max=0.9*output.max(), min=output.min()+(10.*(output.max()-output.min())/100.)) # 2*plus #a bit below real max # does it create a bug ???? --> maybe --> check it --> it looks weird to me
796
+
797
+
798
+ # print(output) # no it's not rescaled
799
+ # plt.imshow(output)
800
+ # plt.show()
801
+
802
+ # print(output.max())
803
+
804
+ if plot_type == 'packing':
805
+ # the trick to plot as packing is to maintain the data as it normally is and just bound it between 0 and 255 --> ignore all possible min and max
806
+ # TODO see if I should not also add another value or other plots for example for bonds
807
+ # or maybe plot as cell_id or alike and same stuff for bonds --> in such case apply no rescale whatever the data is... --> keep the raw values
808
+
809
+ output = apply_lut(output, palette, True, min=0, max=255)
810
+ else:
811
+
812
+ # here I should get the max and min of the stuff to plot --> assumes there is a single value --> will that always be true????
813
+
814
+
815
+ # need get real max and min here to apply a real global color code --> TODO
816
+
817
+
818
+ # need get local or global max and min
819
+ #
820
+ # if SQL_command.strip().endswith(';'):
821
+ # SQL_command.replace(';', '')
822
+ #
823
+ # print(SQL_command + ' WHERE frame_nb == ' + str(current_frame))
824
+ # headers, query_results = db.run_SQL_command_and_get_results(
825
+ # SQL_command + ' WHERE frame_nb == ' + str(current_frame), return_header=True)
826
+ # probably need rerun the query
827
+
828
+ # rerun the query
829
+
830
+ min = None
831
+ max = None
832
+ # if db is
833
+ if db is None:
834
+ # print('getting local max and min TODO')
835
+ try:
836
+ min, max = sort_col_numpy(formatted[:, -1], freq=freq)
837
+ logger.info('min is set to '+str(min)+ ' max is set to '+str(max))
838
+ # min is set to 1 max is set to 1 --> why
839
+ except:
840
+ traceback.print_exc()
841
+ logger.error('local min/max would not be retrieved')
842
+
843
+ # print()
844
+ else:
845
+ # print('getting global max and min TODO')
846
+ # db.get_min_max()
847
+
848
+ # print(formatted[:,-1]) # these are just the last values I would like to sort
849
+ # seems ok now try to sort them
850
+
851
+ # marche mais faut voir comment faire
852
+ # if freq is not None:
853
+ # is there any case where I should not do that ???
854
+
855
+ headers, query_results = db.run_SQL_command_and_get_results(SQL_command, return_header=True)
856
+ formatted = np.asarray(query_results, dtype=object)
857
+
858
+
859
+ # need rerun the query without the frame nb
860
+
861
+ # print(db.sort_col_numpy(formatted[:,-1]))
862
+
863
+ # print(db.sort_col_numpy(formatted[:,-1], freq=(0.05, 0.05))) # ça marche pas mal enb fait
864
+ try:
865
+ min, max = sort_col_numpy(formatted[:,-1], freq=freq)
866
+ logger.info('min is set to ' + str(min) + ' max is set to ' + str(max))
867
+ except:
868
+ traceback.print_exc()
869
+ logger.error('global min/max would not be retrieved')
870
+
871
+ # print(formatted.shape)
872
+
873
+
874
+ output = apply_lut(output, palette, True, min=min, max=max) # 2*plus #a bit below real max # does it create a bug ???? --> maybe --> check it --> it looks weird to me
875
+
876
+ # is that faster to get global max and min once for all
877
+
878
+ # need check
879
+
880
+
881
+
882
+ # je crois que tt marche mais faudrait vraiment tester en grandeur reelle
883
+ # voir comment recuperer que les regions à vraiment plotter --> doit pas etre trop dur --> ignorer les trucs qui n'existent pas
884
+
885
+
886
+ # if len(output.shape)==2:
887
+ # # plt.imshow(output, cmap='Pastel1')
888
+ # # plt.imshow(output, cmap='rainbow')
889
+ # plt.imshow(output, cmap='viridis')
890
+ # # plt.imshow(output, cmap='gray')
891
+ # else:
892
+ # plt.imshow(output)
893
+ # plt.show()
894
+ if return_mask:
895
+ if invert_mask:
896
+ mask=invert(mask)
897
+ # also we apply the mask to the output
898
+ output[mask!=0]=0
899
+ return mask, output
900
+ return output
901
+
902
+
903
+ def plot_as_image_old(plot_type='cells'):
904
+ if plot_type == 'cells':
905
+ # by default plot as cells
906
+ logger.debug('plot as cells')
907
+ image_plot = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/cells.tif').astype(
908
+ np.uint64)
909
+
910
+ elif plot_type == 'bonds':
911
+ logger.debug('plot as bonds')
912
+ image_plot = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/bonds.tif').astype(
913
+ np.uint64)
914
+ elif plot_type == 'vertices':
915
+ logger.debug('plot as vertices')
916
+ image_plot = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/vertices.tif').astype(
917
+ np.uint64)
918
+ else:
919
+ logger.error('Plot type unknown: \'' + str(plot_type) + '\'')
920
+ return
921
+
922
+ rps = regionprops(image_plot)
923
+
924
+ # do stuff for the cells --> such as a plot of the area, etc...
925
+ # need get global max and min --> a good idea and very easy todo with sqlite
926
+
927
+ # create an empty image that we can then fill
928
+ output = np.zeros_like(image_plot)
929
+
930
+ # can easily replace that by values from a database
931
+
932
+ for plot in rps:
933
+ # do stuff
934
+ # cell_output[cell.coords[:, 0], cell.coords[:, 1]] = 255
935
+ output[plot.coords[:, 0], plot.coords[:, 1]] = plot.area # easy area plot in fact
936
+
937
+ plt.imshow(output)
938
+ plt.show()
939
+ # plt.show(block=True)
940
+
941
+
942
+ # --> this is all very good and simple
943
+ # could also make graphs easily now --> TODO too
944
+
945
+
946
+ # TO plot a cell I need a command that generate a local id as first col then the value to plot as second col then various parameters that can be used for plotting -> try finalize that!!!!
947
+
948
+
949
+ if __name__ == '__main__':
950
+
951
+ print(matplotlib.get_backend())
952
+ matplotlib.validate_backend(matplotlib.get_backend())
953
+ matplotlib.use('TkAgg') # dirty fix for erroneous display with Qt5Agg
954
+
955
+
956
+ if True:
957
+ file = '/E/Sample_images/trash/complete/focused_Series010.png'
958
+ # file = '/E/Sample_images/sample_images_pyta/surface_projection/210219.lif_t000.tif'
959
+ # SQL_command = "SELECT local_id_cells,P1_polarity_ch2, P2_polarity_ch2, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells" #for TA db
960
+ # SQL_command = "SELECT local_id,nb_of_vertices_or_neighbours FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
961
+ SQL_command = "SELECT local_id,S1, S2, 10 AS SCALING_FACTOR FROM cells_2D" # a bit more complex just to see which method to choose --> very easy
962
+ # extras = {'LUT': 'DNA'}
963
+ # extras = {'LUT': 'None'}
964
+ # mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True, **extras)
965
+ # mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True, **extras)
966
+ # pb cannot plot is border --> somehow cannot plot booleans --> need a special treatment to avoid issues ??? assume min is 0 then and max is another thing ??? --> shall I implement that or a plot as boolean
967
+ mask, output = plot_as_any(file, SQL_command, plot_type='nematics', return_mask=True)
968
+ # --> bug
969
+ if len(output.shape) == 2:
970
+ # plt.imshow(output, cmap='Pastel1')
971
+ # plt.imshow(output, cmap='rainbow')
972
+ plt.imshow(output, cmap='viridis')
973
+ # plt.imshow(output, cmap='gray')
974
+ else:
975
+ plt.imshow(output)
976
+ # plt.imshow(mask)
977
+ plt.show()
978
+
979
+ if False:
980
+ # master db plot
981
+ master_db = createMasterDB(loadlist('/E/Sample_images/sample_images_pyta/surface_projection/list.lst'))
982
+
983
+
984
+ SQL_command = "SELECT local_id, area FROM cells_2D" # a bit more complex just to see which method to choose --> very easy
985
+ extras = {'LUT': 'DNA'}
986
+ file = '/E/Sample_images/sample_images_pyta/surface_projection/210219.lif_t000.tif'
987
+ mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True, db=master_db, current_frame=0, **extras)
988
+ if len(output.shape) == 2:
989
+ # plt.imshow(output, cmap='Pastel1')
990
+ # plt.imshow(output, cmap='rainbow')
991
+ plt.imshow(output, cmap='viridis')
992
+ # plt.imshow(output, cmap='gray')
993
+ else:
994
+ plt.imshow(output)
995
+ # plt.imshow(mask)
996
+ plt.show()
997
+ master_db.close()
998
+
999
+
1000
+
1001
+ if False:
1002
+ file = '/E/Sample_images/sample_images_PA/mini_different_nb_of_channels/focused_Series012.png'
1003
+ # file = '/E/Sample_images/sample_images_pyta/surface_projection/210219.lif_t000.tif'
1004
+ # SQL_command = "SELECT local_id_cells,P1_polarity_ch2, P2_polarity_ch2, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells" #for TA db
1005
+ # SQL_command = "SELECT local_id,nb_of_vertices_or_neighbours FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1006
+ SQL_command = "SELECT local_id, is_border FROM cells_2D" # a bit more complex just to see which method to choose --> very easy
1007
+ # extras = {'LUT': 'DNA'}
1008
+ # extras = {'LUT': 'None'}
1009
+ # mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True, **extras)
1010
+ # mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True, **extras)
1011
+ # pb cannot plot is border --> somehow cannot plot booleans --> need a special treatment to avoid issues ??? assume min is 0 then and max is another thing ??? --> shall I implement that or a plot as boolean
1012
+ mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True)
1013
+ # --> bug
1014
+ if len(output.shape) == 2:
1015
+ # plt.imshow(output, cmap='Pastel1')
1016
+ # plt.imshow(output, cmap='rainbow')
1017
+ plt.imshow(output, cmap='viridis')
1018
+ # plt.imshow(output, cmap='gray')
1019
+ else:
1020
+ plt.imshow(output)
1021
+ # plt.imshow(mask)
1022
+ plt.show()
1023
+
1024
+ if False:
1025
+ file = '/E/Sample_images/sample_images_PA/mini_different_nb_of_channels/focused_Series012.png'
1026
+ file = '/E/Sample_images/sample_images_pyta/surface_projection/210219.lif_t000.tif'
1027
+ # SQL_command = "SELECT local_id_cells,P1_polarity_ch2, P2_polarity_ch2, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells" #for TA db
1028
+ # SQL_command = "SELECT local_id,nb_of_vertices_or_neighbours FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1029
+ SQL_command = "SELECT local_id, nb_of_vertices_or_neighbours FROM cells_2D" # a bit more complex just to see which method to choose --> very easy
1030
+ extras = {'LUT': 'PACKING'}
1031
+ # mask, output = plot_as_any(file, SQL_command, plot_type='cells', return_mask=True, **extras)
1032
+ mask, output = plot_as_any(file, SQL_command, plot_type='packing', return_mask=True, **extras)
1033
+ if len(output.shape) == 2:
1034
+ # plt.imshow(output, cmap='Pastel1')
1035
+ # plt.imshow(output, cmap='rainbow')
1036
+ plt.imshow(output, cmap='viridis')
1037
+ # plt.imshow(output, cmap='gray')
1038
+ else:
1039
+ plt.imshow(output)
1040
+ # plt.imshow(mask)
1041
+ plt.show()
1042
+
1043
+ if True:
1044
+
1045
+ # file = '/E/Sample_images/sample_images_PA/mini_different_nb_of_channels/focused_Series014.png' # to see if the nematic bug is linked to too many channels --> maybe the case
1046
+ # SQL_command = "SELECT local_id,Q1_polarity_ch0, Q2_polarity_ch0, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1047
+
1048
+ file = '/E/Sample_images/sample_images_PA/mini_different_nb_of_channels/focused_Series012.png'
1049
+ # SQL_command = "SELECT local_id_cells,P1_polarity_ch2, P2_polarity_ch2, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells" #for TA db
1050
+ SQL_command = "SELECT local_id,Q1_polarity_ch1, Q2_polarity_ch1, '#FF0000' AS COLOR, 2 AS STROKE_SIZE, 0.1 AS SCALING_FACTOR FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1051
+
1052
+
1053
+ # file = '/E/Sample_images/sample_images_PA/mini/focused_Series012.png'
1054
+ # SQL_command = "PLOT AS CELLS SELECT local_id, area FROM cells_2D + LUT DNA + OPACITY 35% + DILATATION 1"
1055
+ # SQL_command = "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch1, P2_polarity_ch1, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border=='false'"
1056
+ # SQL_command = "SELECT local_id, area FROM cells_2D"
1057
+ # SQL_command = "SELECT local_id, area FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1058
+ # try plot a command that has a
1059
+ # SQL_command = "SELECT local_id, area FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1060
+ # SQL_command = "SELECT local_id,Q1_polarity_ch1, Q2_polarity_ch1, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells_2D WHERE is_border == FALSE" # a bit more complex just to see which method to choose --> very easy
1061
+
1062
+
1063
+ # extras = {} # see how I can apply LUTS
1064
+ # extras = {'DILATION':1} # ça marche
1065
+ # extras = {'EROSION': 1} # ça marche pas avec methode2 # seems to give me a bug --> why ??? --> shifts ids --> yes makes sense because some cells may be lost
1066
+ # extras = {'EROSION': 3} # ça marche # seems to give me a bug --> why ??? --> shifts ids --> yes makes sense because some cells may be lost
1067
+ # extras = {'EROSION': 5} # ça marche meme avec une strong erosion # seems to give me a bug --> why ??? --> shifts ids --> yes makes sense because some cells may be lost
1068
+ # extras = {'EROSION': 10} # ça marche meme avec une strong erosion # seems to give me a bug --> why ??? --> shifts ids --> yes makes sense because some cells may be lost
1069
+ # extras = {'DILATION':22} # ça marche # dilation gives crappy results --> dialtion should be 1 not really more, just to fill the holes
1070
+ extras = {'LUT':'DNA'} # ça marche # dilation gives crappy results --> dialtion should be 1 not really more, just to fill the holes
1071
+ # extras = {'LUT':'copper'} # a cmap lut just to try # ça marche # dilation gives crappy results --> dialtion should be 1 not really more, just to fill the holes
1072
+ # output = plot_as_any(file, SQL_command, **extras)
1073
+ # output = plot_as_any(file, SQL_command, plot_type='cells',**extras)
1074
+ mask, output = plot_as_any(file, SQL_command, plot_type='nematics', return_mask=True,**extras)
1075
+ if len(output.shape)==2:
1076
+ # plt.imshow(output, cmap='Pastel1')
1077
+ # plt.imshow(output, cmap='rainbow')
1078
+ plt.imshow(output, cmap='viridis')
1079
+ # plt.imshow(output, cmap='gray')
1080
+ else:
1081
+ plt.imshow(output)
1082
+ # plt.imshow(mask)
1083
+ plt.show()
1084
+
1085
+ # test all the stuff
1086
+ # TODO
1087
+
1088
+ '''
1089
+
1090
+ here are plenty of command line examples just to see how I can handle that
1091
+ titleNCommands.put("SQL command to select the 10 biggest cells (biggest area) (this will not generate a plot)", "SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10");
1092
+ titleNCommands.put("plots 10 biggest cells (biggest area)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10");
1093
+ titleNCommands.put("plots 10 biggest cells (biggest area) and color code them by area (color code only applies to the current image, it is local not global)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10 + LUT DNA");
1094
+ titleNCommands.put("plots 10 biggest cells (biggest area) and color code them by area (use same color code/scaling parameters for all images)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10 + LUT DNA MIN=GLOBAL_MIN MAX=GLOBAL_MAX");
1095
+ titleNCommands.put("plots 10 biggest cells (biggest area) and color them in red", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells, '#FF0000' AS COLOR FROM cells ORDER BY area_cells DESC LIMIT 10");
1096
+ titleNCommands.put("plots 10 biggest cells (biggest area) and color them in red and plot them transparently (please select a background image)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells, '#FF0000' AS COLOR FROM cells ORDER BY area_cells DESC LIMIT 10 + OPACITY 35%");
1097
+ titleNCommands.put("plots 10 biggest cells (biggest area) and color them in red, dilate them by one pixel and plot them transparently (please select a background image)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells, '#FF0000' AS COLOR FROM cells ORDER BY area_cells DESC LIMIT 10 + DILATATION 1 + OPACITY 35%");
1098
+ titleNCommands.put("plots in red the elongation/stretch nematic scaled by a factor = 60, border cells are excluded", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,S1_stretch_cells, S2_stretch_cells, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 60 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1099
+ titleNCommands.put("plots in red the polarity nematic of the image channel 1 scaled by a factor = 0.06, border cells are excluded, NB: will not display anything if the channel is empty", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch1, P2_polarity_ch1, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1100
+ titleNCommands.put("plots in green the polarity nematic of the image channel 2 scaled by a factor = 0.06, border cells are excluded, NB: will not display anything if the channel is empty", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch2, P2_polarity_ch2, '#00FF00' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1101
+ titleNCommands.put("plots in blue the polarity nematic of the image channel 3 scaled by a factor = 0.06, border cells are excluded, NB: will not display anything if the channel is empty", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch3, P2_polarity_ch3, '#0000FF' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1102
+ titleNCommands.put("plots in purple the polarity nematic of the 16 bits (single channel) image scaled by a factor = 0.0006, border cells are excluded", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_12bits, P2_polarity_12bits, '#FF00FF' AS COLOR, '2' AS STROKE_SIZE, 0.0006 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1103
+ titleNCommands.put("plots in red the intensity normalized polarity nematic of the image channel 1 scaled by a factor = 0.06, border cells are excluded, NB: will not display anything if the channel is empty", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch1_normalized, P2_polarity_ch1_normalized, '#FF0000' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1104
+ titleNCommands.put("plots in green the intensity normalized polarity nematic of the image channel 2 scaled by a factor = 0.06, border cells are excluded, NB: will not display anything if the channel is empty", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch2_normalized, P2_polarity_ch2_normalized, '#00FF00' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1105
+ titleNCommands.put("plots in blue the intensity normalized polarity nematic of the image channel 3 scaled by a factor = 0.06, border cells are excluded, NB: will not display anything if the channel is empty", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_ch3_normalized, P2_polarity_ch3_normalized, '#0000FF' AS COLOR, '2' AS STROKE_SIZE, 0.06 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1106
+ titleNCommands.put("plots in purple the intensity normalized polarity nematic of the 16 bits (single channel) image scaled by a factor = 0.0006, border cells are excluded", "PLOT AS NEMATICS SELECT center_x_cells,center_y_cells,P1_polarity_12bits_normalized, P2_polarity_12bits_normalized, '#FF00FF' AS COLOR, '2' AS STROKE_SIZE, 0.0006 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1107
+ titleNCommands.put("plots (-10, -5) yellow vectors centered on cells with a scaling factor 2, border cells are excluded", "PLOT AS VECTORS SELECT center_x_cells,center_y_cells, -10, -5, '#FFFF00' AS COLOR, '2' AS STROKE_SIZE, 2 AS SCALING_FACTOR FROM cells WHERE is_border_cell=='false'");
1108
+ //do the same for polarity for one channel in particular
1109
+ //maybe put all three channels separately
1110
+ titleNCommands.put("plots a line joining the centroid of cells and their first encountered pixel", "PLOT AS LINES SELECT first_pixel_x_cells,first_pixel_y_cells , center_x_cells,center_y_cells, '#0000FF' AS COLOR, '12' AS STROKE_SIZE, '0.3' AS STROKE_OPACITY FROM cells");
1111
+ titleNCommands.put("Plot cell geometry, triangles are in cyan, 4-sided green, 5-sided yellow, hexagons gray, 7-sided blue, cells 8 or 9 neighbours are red", "PLOT AS CELLS SELECT first_pixel_x_cells, first_pixel_y_cells, nb_of_vertices_cut_off FROM cells + LUT 3:#00FFFF 4:#00FF00 5:#FFFF00 6:#AAAAAA 7:#0000FF 8:#FF0000 9:#FF0000");
1112
+ titleNCommands.put("plots an arrow joining the centroid of cells and the first encountered cell pixel", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells FROM cells");
1113
+ titleNCommands.put("plots an arrow joining the centroid of cells and the first encountered cell pixel, the arrow width is defined to 20 pixels and the arrowheight to 10", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells, 20 AS ARROWHEAD_WIDTH, 10 AS ARROWHEAD_HEIGHT FROM cells");
1114
+ titleNCommands.put("plots an half headed arrow (up) joining the centroid of cells and the first encountered cell pixel", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells, 'HALF_HEAD_UP_ARROW' AS ARROWHEAD_TYPE FROM cells");
1115
+ titleNCommands.put("plots an half headed arrow (down) joining the centroid of cells and the first encountered cell pixel", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells, 'HALF_HEAD_DOWN_ARROW' AS ARROWHEAD_TYPE FROM cells");
1116
+ titleNCommands.put("plots an double headed arrow joining the centroid of cells and the first encountered cell pixel", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells, 'DOUBLE_HEAD_ARROW' AS ARROWHEAD_TYPE FROM cells");
1117
+ titleNCommands.put("plots an inhibition arrow joining the centroid of cells and the first encountered cell pixel", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells, 'INIBITION_ARROW' AS ARROWHEAD_TYPE FROM cells");
1118
+ titleNCommands.put("plots a double headed inhibition arrow joining the centroid of cells and the first encountered cell pixel", "PLOT AS ARROWS SELECT center_x_cells,center_y_cells,first_pixel_x_cells , first_pixel_y_cells, 'DOUBLE_HEADED_INIBITION' AS ARROWHEAD_TYPE FROM cells");
1119
+
1120
+ titleNCommands.put("plots a text containing the 'local id of cells' (i.e. their cell nb) centered over the cell centroid", "PLOT AS STRINGS SELECT center_x_cells, center_y_cells , local_id_cells, '#00FF00' AS COLOR, '#FF0000' AS BG_COLOR, '22' AS FONT_SIZE, 'ITALIC' AS FONT_STYLE FROM cells");
1121
+ titleNCommands.put("plots a square the width of which is proportional to the cell area/100 where the top left corner of the square is the centroid", "PLOT AS SQUARES SELECT center_x_cells, center_y_cells , area_cells/100, '8016' AS COLOR,'30000' AS FILL_COLOR,'0.3' AS FILL_OPACITY FROM cells");
1122
+ //titleNCommands.put("plots a vector joining the first encountered pixel of the cell to its cenroid", "PLOT AS VECTORS SELECT first_pixel_x_cells,first_pixel_y_cells , center_x_cells,center_y_cells, '#00FF00' AS COLOR, '1' AS STROKE_SIZE, 'DEFAULT_ARROW' AS ARROWHEAD_TYPE, '5' AS ARROWHEAD_HEIGHT,'3' AS ARROWHEAD_HEIGHT, '0.3' AS STROKE_OPACITY FROM cells;");
1123
+ titleNCommands.put("plots all cells with an area between 1000 and 1200 pixels. NB may not show anything depending on your cell area", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, '#FFFF00' AS COLOR FROM cells WHERE area_cells > 1000 AND area_cells <1200 + OPACITY 35% + DILATATION 1");
1124
+ titleNCommands.put("color codes all cells according to their area", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, area_cells FROM cells + LUT DNA");
1125
+ titleNCommands.put("color codes (according to cell area) a vector joining the first encountered pixel of the cell to its cenroid", "PLOT AS ARROWS SELECT first_pixel_x_cells,first_pixel_y_cells , center_x_cells,center_y_cells, area_cells AS COLOR, '1' AS STROKE_SIZE, 'DEFAULT_ARROW' AS ARROWHEAD_TYPE, '5' AS ARROWHEAD_HEIGHT,'3' AS ARROWHEAD_HEIGHT, '0.3' AS STROKE_OPACITY FROM cells + LUT DNA");
1126
+ titleNCommands.put("color codes bonds according to their orientation (ignores bonds consisting only of two vertices)", "PLOT AS BONDS SELECT first_pixel_x_bonds, first_pixel_y_bonds, bond_orientation FROM bonds WHERE first_pixel_y_bonds != 'null' + LUT DNA");
1127
+ titleNCommands.put("draws cells as polygons (using vertex coordinates)", "PLOT AS POLYGONS SELECT vx_coords_cells, area_cells AS COLOR,area_cells AS FILL_COLOR, '0.65' AS STROKE_SIZE FROM cells + LUT DNA + OPACITY 35%");
1128
+ titleNCommands.put("Test a SQL command (i.e. preview table output)", "SELECT * FROM CELLS");
1129
+ titleNCommands.put("color code cells accoding to their elongation", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells + LUT DNA + OPACITY 35% + DILATATION 1");
1130
+ titleNCommands.put("color code cells, except border cells, accoding to their elongation", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells WHERE is_border_cell=='false' + LUT DNA + OPACITY 35% + DILATATION 1");
1131
+ titleNCommands.put("color code cells, except border cells and cells immediately adjacent to border cells, accoding to their elongation", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells WHERE is_border_cell_plus_one=='false' + LUT DNA + OPACITY 35% + DILATATION 1");
1132
+
1133
+ titleNCommands.put("(Global) color code cells belonging to clone #22 according to their amount of stretch (NB: virtual clone #22 must exist for the command to work)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells NATURAL JOIN tracked_clone_022 + LUT DNA MIN=GLOBAL_MIN MAX=GLOBAL_MAX + OPACITY 35% + DILATATION 1");
1134
+ titleNCommands.put("(Global) color code cells belonging to clone #0 according to their amount of stretch (NB: virtual clone #0 must exist for the command to work)", "PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells NATURAL JOIN tracked_clone + LUT DNA MIN=GLOBAL_MIN MAX=GLOBAL_MAX + OPACITY 35% + DILATATION 1");
1135
+ '''
1136
+
1137
+
1138
+ if False:
1139
+ plot_SQL('PLOT AS CELLS SELECT * FROM CELLS;')
1140
+ plot_SQL('PLOT AS BONDS SELECT * FROM CELLS;')
1141
+ plot_SQL('PLOT AS VERTices SELECT * FROM CELLS;')
1142
+ plot_SQL('PLOT AS TEST SELECT * FROM CELLS;')
1143
+ plot_SQL('PLOT AS POLYGON SELECT * FROM CELLS;')
1144
+
1145
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10") # --> see how I can do that
1146
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10 + LUT DNA") # --> see how I can do that
1147
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells, '#FF0000' AS COLOR FROM cells ORDER BY area_cells DESC LIMIT 10 + DILATATION 1 + OPACITY 35%") # in fact each extra is starting with a + --> quite easy to get
1148
+ # --> ignore pluses in extras
1149
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10 + LUT DNA MIN=GLOBAL_MIN MAX=GLOBAL_MAX") # --> maybe not that hard because the values if complex are connected to MIn and MAX --> if all are like that then I can parse all extras as keys and values and all is gonna be a piece of cake and easy to detect and report errors --> TODO
1150
+
1151
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells + LUT DNA + OPACITY 35% + DILATATION 1") # --> maybe not that hard because the values if complex are connected to MIn and MAX --> if all are like that then I can parse all extras as keys and values and all is gonna be a piece of cake and easy to detect and report errors --> TODO
1152
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells + LUT DNA + OPACITY 35% + DILATATION 1+BOUGA BOUU") # --> maybe not that hard because the values if complex are connected to MIn and MAX --> if all are like that then I can parse all extras as keys and values and all is gonna be a piece of cake and easy to detect and report errors --> TODO
1153
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells + LUT DNA + OPACITY 35% + DILATATION 1+BOUGA") # --> maybe not that hard because the values if complex are connected to MIn and MAX --> if all are like that then I can parse all extras as keys and values and all is gonna be a piece of cake and easy to detect and report errors --> TODO
1154
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells, S0_stretch_cells FROM cells + LUT DNA + TRANSPARENCY 35% + DILATATION 1+BOUGA") # --> maybe not that hard because the values if complex are connected to MIn and MAX --> if all are like that then I can parse all extras as keys and values and all is gonna be a piece of cake and easy to detect and report errors --> TODO
1155
+ plot_SQL("PLOT AS CELLS SELECT first_pixel_x_cells, first_pixel_y_cells, nb_of_vertices_cut_off FROM cells + LUT 3:#00FFFF 4:#00FF00 5:#FFFF00 6:#AAAAAA 7:#0000FF 8:#FF0000 9:#FF0000") # --> maybe not that hard because the values if complex are connected to MIn and MAX --> if all are like that then I can parse all extras as keys and values and all is gonna be a piece of cake and easy to detect and report errors --> TODO
1156
+
1157
+ # value and how to do that
1158
+
1159
+ # or parse the extras between the pluses and accept all the data in between is data connected to the first keyword --> TODO
1160
+ # _strip_from_command("PLOT AS CELLS SELECT first_pixel_x_cells,first_pixel_y_cells , area_cells FROM cells ORDER BY area_cells DESC LIMIT 10", "PLOT AS CELLS")
1161
+ # --> ok that seems to work
1162
+
1163
+ print(parse_opacity("OPACITY 35%".split()))
1164
+
1165
+ # for _ in range(abs(0)):
1166
+ # print('hello')
1167
+
1168
+ if False:
1169
+ plot_as_image_old(plot_type=None)
1170
+ plot_as_image_old()