labsyspharm / quantification

Quantification module for mcmicro
https://github.com/labsyspharm/mcmicro
9 stars 13 forks source link

Update skimage.measure._regionprops.PROP_VALS when upgrading scikit-image #46

Closed josenimo closed 4 months ago

josenimo commented 11 months ago

Hey all,

I am trying to run mcquant locally with some masks, and I am not able to troubleshoot. I am cloning the repo, creating a conda/mamba environment with the quantification.yml. Then running my command:

Command 1, running cloned quantification repo ``` python CommandSingleCellExtraction.py \ --image '/Volumes/ag_coscia-1/Jose/P09_E02_Lung_Glass/background_job2/P09_E02_Lung_Glass_backsub.ome.tif' \ --masks '/Users/jnimoca/Jose_BI/Tancredi/output/P09_E02_Lung_Glass_backsub_segprep.ome_cp_masks.tif' \ --channel_names '/Volumes/ag_coscia-1/Jose/P09_E02_Lung_Glass/background_job2/markers_bs.csv' \ --output '/Users/jnimoca/Jose_BI/Tancredi/mcquant_output/' ```
Traceback from running cloned quantification ``` Traceback (most recent call last): File "/Users/jnimoca/Jose_BI/Repositories/quantification/CommandSingleCellExtraction.py", line 11, in SingleCellDataExtraction.MultiExtractSingleCells(**args) File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 270, in MultiExtractSingleCells ExtractSingleCells(masks,image,channel_names,output, mask_props=mask_props, intensity_props=intensity_props) File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 243, in ExtractSingleCells scdata_z = MaskZstack(masks_loaded,image,channel_names_loaded_checked, mask_props=mask_props, intensity_props=intensity_props) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 152, in MaskZstack MaskChannel(masks_loaded[mask_names[nm]],image_loaded_z, intensity_props=intensity_props) File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 39, in MaskChannel builtin_props = set(intensity_props).intersection(measure._regionprops.PROP_VALS) ^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/mambaforge/base/envs/quantification-env/lib/python3.12/site-packages/lazy_loader/init.py", line 89, in getattr raise AttributeError(f"No {package_name} attribute {name}") AttributeError: No skimage.measure attribute _regionprops. Did you mean: 'regionprops'? ```

I thought that this was a simple typo, so I corrected the "_regionprops" to "regionprops", and reran the same command

Traceback from running cloned quantification ``` (quantification-env) CMP06623:JN_P12_E13_mcquant jnimoca$ python /Users/jnimoca/Jose_BI/Repositories/quantification/CommandSingleCellExtraction.py --image ./input/P09_E02_Lung_Glass_backsub.ome.tif --masks ./mask/cell.tif --channel_names ./markers/markers_bs.csv --output ./output/ {'masks': ['./mask/cell.tif'], 'image': './input/P09_E02_Lung_Glass_backsub.ome.tif', 'channel_names': './markers/markers_bs.csv', 'output': './output/', 'intensity_props': {'intensity_mean'}, 'mask_props': None} Extracting single-cell data for ./input/P09_E02_Lung_Glass_backsub.ome.tif... Traceback (most recent call last): File "/Users/jnimoca/Jose_BI/Repositories/quantification/CommandSingleCellExtraction.py", line 11, in SingleCellDataExtraction.MultiExtractSingleCells(**args) File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 270, in MultiExtractSingleCells ExtractSingleCells(masks,image,channel_names,output, mask_props=mask_props, intensity_props=intensity_props) File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 243, in ExtractSingleCells scdata_z = MaskZstack(masks_loaded,image,channel_names_loaded_checked, mask_props=mask_props, intensity_props=intensity_props) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 152, in MaskZstack MaskChannel(masks_loaded[mask_names[nm]],image_loaded_z, intensity_props=intensity_props) File "/Users/jnimoca/Jose_BI/Repositories/quantification/SingleCellDataExtraction.py", line 39, in MaskChannel builtin_props = set(intensity_props).intersection(measure.regionprops.PROP_VALS) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'function' object has no attribute 'PROP_VALS' ```

I tried deleting this part of the code, since I am not running any extra variables, I just want mean intensity, but it does not seem to work. I also tried running the docker container (code below), but the command runs, and nothing happens. Any help is very welcome.

Computer details ``` Model Name: MacBook Pro Model Identifier: Mac14,9 Model Number: MPHF3D/A Chip: Apple M2 Pro Total Number of Cores: 12 (8 performance and 4 efficiency) Memory: 16 GB System Firmware Version: 10151.1.1 OS Loader Version: 10151.1.1 Serial Number (system): Q33PC9H9J1 Hardware UUID: 1F72CEC3-C0FB-5451-9A09-83418EFF5717 Provisioning UDID: 00006020-0018702936C0C01E Activation Lock Status: Disabled ```
Conda environment ``` # packages in environment at /opt/homebrew/Caskroom/mambaforge/base/envs/quantification-env: # # Name Version Build Channel aom 3.6.1 hb765f3a_0 conda-forge blosc 1.21.5 hc338f07_0 conda-forge brotli 1.1.0 hb547adb_1 conda-forge brotli-bin 1.1.0 hb547adb_1 conda-forge brunsli 0.1 h9f76cd9_0 conda-forge bzip2 1.0.8 h3422bc3_4 conda-forge c-ares 1.20.1 h93a5062_1 conda-forge c-blosc2 2.10.5 h8eb3132_0 conda-forge ca-certificates 2023.7.22 hf0a4a13_0 conda-forge cached-property 1.5.2 hd8ed1ab_1 conda-forge cached_property 1.5.2 pyha770c72_1 conda-forge charls 2.4.2 h13dd4ca_0 conda-forge dav1d 1.2.1 hb547adb_0 conda-forge freetype 2.12.1 hadb7bae_2 conda-forge giflib 5.2.1 h1a8c8d9_3 conda-forge h5py 3.10.0 nompi_py312h3cf556f_100 conda-forge hdf5 1.14.2 nompi_h3aba7b3_100 conda-forge imagecodecs 2023.9.18 py312hbe4d967_2 conda-forge imageio 2.31.5 pyh8c1a49c_0 conda-forge jxrlib 1.1 h27ca646_2 conda-forge krb5 1.21.2 h92f50d5_0 conda-forge lazy_loader 0.3 pyhd8ed1ab_0 conda-forge lcms2 2.15 hf2736f0_3 conda-forge lerc 4.0.0 h9a09cb3_0 conda-forge libaec 1.1.2 h13dd4ca_1 conda-forge libavif16 1.0.1 h18c541d_2 conda-forge libblas 3.9.0 19_osxarm64_openblas conda-forge libbrotlicommon 1.1.0 hb547adb_1 conda-forge libbrotlidec 1.1.0 hb547adb_1 conda-forge libbrotlienc 1.1.0 hb547adb_1 conda-forge libcblas 3.9.0 19_osxarm64_openblas conda-forge libcurl 8.4.0 h2d989ff_0 conda-forge libcxx 16.0.6 h4653b0c_0 conda-forge libdeflate 1.19 hb547adb_0 conda-forge libedit 3.1.20191231 hc8eb9b7_2 conda-forge libev 4.33 h642e427_1 conda-forge libexpat 2.5.0 hb7217d7_1 conda-forge libffi 3.4.2 h3422bc3_5 conda-forge libgfortran 5.0.0 13_2_0_hd922786_1 conda-forge libgfortran5 13.2.0 hf226fd6_1 conda-forge libjpeg-turbo 3.0.0 hb547adb_1 conda-forge liblapack 3.9.0 19_osxarm64_openblas conda-forge libnghttp2 1.55.1 h2b02ca0_0 conda-forge libopenblas 0.3.24 openmp_hd76b1f2_0 conda-forge libpng 1.6.39 h76d750c_0 conda-forge libsqlite 3.43.2 h091b4b1_0 conda-forge libssh2 1.11.0 h7a5bd25_0 conda-forge libtiff 4.6.0 ha8a6c65_2 conda-forge libwebp-base 1.3.2 hb547adb_0 conda-forge libxcb 1.15 hf346824_0 conda-forge libzlib 1.2.13 h53f4e23_5 conda-forge libzopfli 1.0.3 h9f76cd9_0 conda-forge llvm-openmp 17.0.3 hcd81f8e_0 conda-forge lz4-c 1.9.4 hb7217d7_0 conda-forge ncurses 6.4 h463b476_2 conda-forge networkx 3.2.1 pyhd8ed1ab_0 conda-forge numpy 1.26.0 py312h696b312_0 conda-forge openjpeg 2.5.0 h4c1507b_3 conda-forge openssl 3.1.4 h0d3ecfb_0 conda-forge packaging 23.2 pyhd8ed1ab_0 conda-forge pandas 2.1.2 py312h9e53831_0 conda-forge pathlib 1.0.1 py_1 conda-forge pillow 10.1.0 py312hac22aec_0 conda-forge pip 23.3.1 pyhd8ed1ab_0 conda-forge pthread-stubs 0.4 h27ca646_1001 conda-forge python 3.12.0 h47c9636_0_cpython conda-forge python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge python-tzdata 2023.3 pyhd8ed1ab_0 conda-forge python_abi 3.12 4_cp312 conda-forge pytz 2023.3.post1 pyhd8ed1ab_0 conda-forge pywavelets 1.4.1 py312h3339331_1 conda-forge rav1e 0.6.6 h69fbcac_2 conda-forge readline 8.2 h92ec313_1 conda-forge scikit-image 0.22.0 py312h9e53831_2 conda-forge scipy 1.11.3 py312h44883eb_1 conda-forge setuptools 68.2.2 pyhd8ed1ab_0 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge snappy 1.1.10 h17c5cce_0 conda-forge svt-av1 1.7.0 hb765f3a_0 conda-forge tifffile 2023.9.26 pyhd8ed1ab_0 conda-forge tk 8.6.13 hb31c410_0 conda-forge tzdata 2023c h71feb2d_0 conda-forge wheel 0.41.3 pyhd8ed1ab_0 conda-forge xorg-libxau 1.0.11 hb547adb_0 conda-forge xorg-libxdmcp 1.1.3 h27ca646_0 conda-forge xz 5.2.6 h57fd34a_0 conda-forge zfp 1.0.0 h82938aa_4 conda-forge zlib-ng 2.0.7 h1a8c8d9_0 conda-forge zstd 1.5.5 h4f39d0f_0 conda-forge ```
ArtemSokolov commented 11 months ago

Hi @josenimo,

Can you try downgrading your scikit-image to 0.19.3 and let me know if the problem persists?

That's the version currently in the container:

$ docker run -it --rm labsyspharm/quantification:1.5.3 /bin/bash

root@2e495c32195e:/# pip show scikit-image

Name: scikit-image
Version: 0.19.3
Summary: Image processing in Python
Home-page: https://scikit-image.org
Author: 
Author-email: 
License: Modified BSD
Location: /usr/local/lib/python3.9/site-packages
Requires: imageio, networkx, numpy, packaging, pillow, PyWavelets, scipy, tifffile
Required-by: 

root@2e495c32195e:/# python

Python 3.9.15 (main, Oct 26 2022, 03:47:43) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import skimage.measure as measure
>>> measure._regionprops.PROP_VALS
{'inertia_tensor_eigvals', 'eccentricity', 'equivalent_diameter_area', 'label', 'coords', 'moments_normalized', 'extent', 'slice', 'image', 'image_intensity', 'moments_weighted_normalized', 'area_convex', 'centroid_weighted_local', 'axis_major_length', 'moments_weighted_hu', 'bbox', 'intensity_min', 'moments_weighted', 'perimeter', 'feret_diameter_max', 'area_filled', 'centroid', 'centroid_weighted', 'moments_central', 'intensity_mean', 'centroid_local', 'axis_minor_length', 'moments', 'inertia_tensor', 'intensity_max', 'moments_weighted_central', 'moments_hu', 'area', 'area_bbox', 'image_convex', 'perimeter_crofton', 'euler_number', 'orientation', 'solidity', 'image_filled'}

I think we probably just need to update how we access available properties in regionprops.

josenimo commented 11 months ago

Hey @ArtemSokolov,

I can confirm that creating a environment with scikit-image 0.19.3 works.

Thank you for the quick help.

ArtemSokolov commented 11 months ago

Great to hear it! I'll rename the issue to give us a reminder to update PROP_VALS code once we update to a newer version of scikit-image.