SchmollerLab / Cell_ACDC

A Python GUI-based framework for segmentation, tracking and cell cycle annotations of microscopy data
BSD 3-Clause "New" or "Revised" License
127 stars 21 forks source link

Analysis/Plotting script raises error when loading data #41

Open jacobmhkim opened 2 years ago

jacobmhkim commented 2 years ago

Describe the bug I get the error when I run the cell to load the data. I think it doesn't like having the pixel size set to a float in the metadata. But the pixel size is 0.109524 microns so I can't have it as an int.

0.109524 --

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context error:

`Load files for good_positions, Position_2... Number of cells in position: 40 Number of annotated frames in position: 121 Calculate regionprops on each frame based on Segmentation... 0%| | 0/121 [00:00<?, ?it/s]

TypeError Traceback (most recent call last) File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\ops\array_ops.py:163, in _na_arithmetic_op(left, right, op, is_cmp) 162 try: --> 163 result = func(left, right) 164 except TypeError:

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\computation\expressions.py:239, in evaluate(op, a, b, use_numexpr) 237 if use_numexpr: 238 # error: "None" not callable --> 239 return _evaluate(op, op_str, a, b) # type: ignore[misc] 240 return _evaluate_standard(op, op_str, a, b)

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\computation\expressions.py:69, in _evaluate_standard(op, op_str, a, b) 68 _store_test_result(False) ---> 69 return op(a, b)

TypeError: can't multiply sequence by non-int of type 'float'

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) Input In [12], in <cell line: 1>() ----> 1 overall_df, is_timelapse_data, is_zstack_data = cca_functions.calculate_downstream_data( 2 file_names, 3 image_folders, 4 positions, 5 channels, 6 force_recalculation=True # if True, recalculates overall_df; use this if anything upstream is changed 7 )

File ~\miniconda3\envs\acdc\lib\site-packages\cellacdc\cca_functions.py:127, in calculate_downstream_data(file_names, image_folders, positions, channels, force_recalculation) 125 else: 126 print(f'Calculate regionprops on each frame based on Segmentation...') --> 127 rp_df = _calculate_rp_df(seg_mask, is_timelapse_data, is_zstack_data, metadata, max_frame=cc_data.frame_i.max()+1) 128 print(f'Calculate signal metrics for every channel and cell...') 129 flu_signal_df = _calculate_flu_signal( 130 seg_mask, 131 channel_data, (...) 135 is_zstack_data 136 )

File ~\miniconda3\envs\acdc\lib\site-packages\cellacdc\cca_functions.py:434, in _calculate_rp_df(seg_mask, is_timelapse_data, is_zstack_data, metadata, max_frame, label_input) 432 else: 433 t_rp = regionprops(img.astype(int)) --> 434 vol_vox = [_calc_rot_vol(obj, metadata.loc["PhysicalSizeY"], metadata.loc["PhysicalSizeX"])[0] for obj in t_rp] 435 vol_fl = [_calc_rot_vol(obj, metadata.loc["PhysicalSizeY"], metadata.loc["PhysicalSizeX"])[1] for obj in t_rp] 436 assert len(t_rp_df) == len(vol_vox)

File ~\miniconda3\envs\acdc\lib\site-packages\cellacdc\cca_functions.py:434, in (.0) 432 else: 433 t_rp = regionprops(img.astype(int)) --> 434 vol_vox = [_calc_rot_vol(obj, metadata.loc["PhysicalSizeY"], metadata.loc["PhysicalSizeX"])[0] for obj in t_rp] 435 vol_fl = [_calc_rot_vol(obj, metadata.loc["PhysicalSizeY"], metadata.loc["PhysicalSizeX"])[1] for obj in t_rp] 436 assert len(t_rp_df) == len(vol_vox)

File ~\miniconda3\envs\acdc\lib\site-packages\cellacdc\cca_functions.py:467, in _calc_rot_vol(obj, PhysicalSizeY, PhysicalSizeX) 466 def _calc_rot_vol(obj, PhysicalSizeY=1, PhysicalSizeX=1): --> 467 vox_to_fl = PhysicalSizeYpow(PhysicalSizeX, 2) 468 rotate_ID_img = skimage.transform.rotate( 469 obj.image.astype(np.single), -(obj.orientation180/np.pi), 470 resize=True, order=3 471 ) 472 radii = np.sum(rotate_ID_img, axis=1)/2

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\ops\common.py:70, in _unpack_zerodim_and_defer..new_method(self, other) 66 return NotImplemented 68 other = item_from_zerodim(other) ---> 70 return method(self, other)

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\arraylike.py:116, in OpsMixin.mul(self, other) 114 @unpack_zerodim_and_defer("mul") 115 def mul(self, other): --> 116 return self._arith_method(other, operator.mul)

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\series.py:5639, in Series._arith_method(self, other, op) 5637 def _arith_method(self, other, op): 5638 self, other = ops.align_method_SERIES(self, other) -> 5639 return base.IndexOpsMixin._arith_method(self, other, op)

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\base.py:1295, in IndexOpsMixin._arith_method(self, other, op) 1292 rvalues = ensure_wrapped_if_datetimelike(rvalues) 1294 with np.errstate(all="ignore"): -> 1295 result = ops.arithmetic_op(lvalues, rvalues, op) 1297 return self._construct_result(result, name=res_name)

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\ops\array_ops.py:222, in arithmetic_op(left, right, op) 217 else: 218 # TODO we should handle EAs consistently and move this check before the if/else 219 # (https://github.com/pandas-dev/pandas/issues/41165) 220 _bool_arith_check(op, left, right) --> 222 res_values = _na_arithmetic_op(left, right, op) 224 return res_values

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\ops\array_ops.py:170, in _na_arithmetic_op(left, right, op, is_cmp) 164 except TypeError: 165 if not is_cmp and (is_object_dtype(left.dtype) or is_object_dtype(right)): 166 # For object dtype, fallback to a masked operation (only operating 167 # on the non-missing values) 168 # Don't do this for comparisons, as that will handle complex numbers 169 # incorrectly, see GH#32047 --> 170 result = _masked_arith_op(left, right, op) 171 else: 172 raise

File ~\miniconda3\envs\acdc\lib\site-packages\pandas\core\ops\array_ops.py:127, in _masked_arith_op(x, y, op) 124 mask = np.where(y == 1, False, mask) 126 if mask.any(): --> 127 result[mask] = op(xrav[mask], y) 129 np.putmask(result, ~mask, np.nan) 130 result = result.reshape(x.shape) # 2D compat

TypeError: can't multiply sequence by non-int of type 'float'`

jacobmhkim commented 2 years ago

it seems that its an issue with version 17. Jordan has 16, and it works fine for him

ElpadoCan commented 2 years ago

Hi Jacob, I released a new version v1.2.4rc18 where I fixed this issue. Let me know if it works, thanks!

jacobmhkim commented 2 years ago

Thanks. It loads now, but now I get the problem where the pixel area, volume, etc measurements are missing from overall_df.

This is what I see when I upload a movie:

"Volume is missing in acdc output, NaNs inserted in concentration columns of channel Phase Volume is missing in acdc output, NaNs inserted in concentration columns of channel mCitrine Volume is missing in acdc output, NaNs inserted in concentration columns of channel mKate2 Saving calculated data for next time... Done!"

Most of the measurements are there, but I think somehow the area measurement is excluded or renamed, and it leads to problems with calculating the volume, concentration, etc.

ElpadoCan commented 2 years ago

Ok that warning is when it calculates concentration and it wants to divide the amount by the cell volume.

Can you please check if in the acdc_output.csv file you have a column called cell_vol_fl? If you have that column I think the fastest is that you zip the entire position folder and you send it to me for testing.

If you don't want to make a public google drive link you can share a folder with my email padovaf@tcd.ie thanks!

ElpadoCan commented 2 years ago

If you don't have the cell_vol_fl column you first have to calculate the metrics in the GUI. Currently the cell volume is computed only in the GUI metrics, we will add it to the notebook in the next release.

jacobmhkim commented 2 years ago

This happens even after I re-save the additional measurements in the GUI. The "cell_vol_fl" column isn't there. Also, I only have the option to close with comment on this thread. But it's definitely not closed. I'll send you the folder to your email.

ElpadoCan commented 2 years ago

The closing is weird, let me try to re-open.

I will test with your positions thanks!

jacobmhkim commented 2 years ago

just reopened

ElpadoCan commented 2 years ago

Ok I received the position, I will test first thing in the morning (here is 9pm unfortunately). The issue is reopened now. I will keep you updated, thanks!

jacobmhkim commented 2 years ago

thank you!

ElpadoCan commented 2 years ago

Hi Jacob, I released a new version v1.2.4rc19 with the fix to this issue.

It was my fault, when I refactored the code to remove possible sources of crashes I moved the calculation of the volume in the main thread (since in a separate thread it was a possible source of crashes), but then I forgot to add the result to the final table.

So even if you saved the metrics, the columns cell_vol_fland cell_area were not saved. Sorry about that!

Let me know if it works now, thanks.