Skip to content

2.0 extract image metadata DEMO

In the code, s_sceneposition_round = 'R1_' but the file is'r1_'

Made the change and get:

Attempted file (C:/Users/smith6jt/cmIF_2021-01-07_demo/CziImages/HER2B-K185/original/r1_phh3.ck14.ki67.ck19_her2b-k185_2021_01_11__10_41__4318.czi) load with reader: aicsimageio.readers.czi_reader.CziReader failed with error: aicspylibczi is required for this reader. Install with pip install 'aicspylibczi>=3.1.1' 'fsspec>=2022.7.1' Attempted file (C:/Users/smith6jt/cmIF_2021-01-07_demo/CziImages/HER2B-K185/original/r1_phh3.ck14.ki67.ck19_her2b-k185_2021_01_11__10_41__4318.czi) load with reader: aicsimageio.readers.bioformats_reader.BioformatsReader failed with error: bioformats_jar is required for this reader. Install with pip install bioformats_jar or conda install bioformats_jar run: mplexable.imgmeta.fetch_meta_batch for slide ['HER2B-K185', 'JE-TMA-66'] ... <class 'pandas.core.frame.DataFrame'> Index: 0 entries Data columns (total 10 columns):

Column Non-Null Count Dtype


0 filetype 0 non-null object 1 markers 0 non-null object 2 mscene 0 non-null object 3 round 0 non-null object 4 scanid 0 non-null object 5 slide 0 non-null object 6 slide_mscene 0 non-null object 7 round_int 0 non-null float64 8 round_real 0 non-null float64 9 round_order 0 non-null object dtypes: float64(2), object(8) memory usage: 0.0+ bytes None

fetch_meta_slide_sceneposition: HER2B-K185 CziImages/HER2B-K185/original/ ... process file: r1_phh3.ck14.ki67.ck19_her2b-k185_2021_01_11__10_41__4318.czi ...

UnsupportedFileFormatError Traceback (most recent call last) Cell In[16], line 9 1 # 2.0 extract image metadata 2 3 # the metadata is by default extracted from the original czi files. (...) 6 # and the splitscenes czi files are expected to be under {s_czidir}/{s_slide_id}/splitscenes/ 7 # Additionaly, the czi images filenames them self have to follow the correct naming convention. ----> 9 imgmeta.fetch_meta_batch( 10 es_slide = ls_slide, 11 s_czidir = config.d_nconv['s_czidir'], # 'CziImages/', 12 s_format_czidir_original = config.d_nconv['s_format_czidir_original'], #'{}{}/original/', # s_czidir, s_slide 13 s_format_czidir_splitscene = config.d_nconv['s_format_czidir_splitscene'], #'{}{}/splitscenes/', # s_czidir, s_slide 14 s_sceneposition_round = 'r1_', # file matching pattern, can but does not have to be round.
15 b_exposuretime_original = False, 16 b_exposuretime_splitscene = True, 17 b_sceneposition_original = True, 18 s_metadir = config.d_nconv['s_metadir'], #'MetaImages/', 19 )

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\mplexable\imgmeta.py:365, in fetch_meta_batch(es_slide, s_czidir, s_format_czidir_original, s_format_czidir_splitscene, s_sceneposition_round, b_sceneposition_original, b_exposuretime_original, b_exposuretime_splitscene, s_metadir) 362 # fetch scene position 363 if b_sceneposition_original: 364 # slide with one or many scenes --> 365 fetch_meta_slide_sceneposition( 366 s_slide = s_slide, 367 s_czidir_original = s_wd_original, 368 s_sceneposition_round = s_sceneposition_round, 369 s_metadir = s_metadir, 370 )

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\mplexable\imgmeta.py:249, in fetch_meta_slide_sceneposition(s_slide, s_czidir_original, s_sceneposition_round, b_omexml, s_metadir) 243 print(f'detected slide id: {s_slide} ...') 245 # load metadata 246 # bue 20211115: in future, maybe o_img.ome_metadata can be used to become czi metadata format independent. 247 # the problem at the moment is that o_img.ome_metadata xlst is not transforming scene position 248 # into o_img.ome_metadata.images[*].pixels.planes.{position_y, position_y_unit, position_x, position_x_unit} object. --> 249 o_img = AICSImage(s_ipathfile) 250 x_root = o_img.metadata 251 #print(x_root.tag) 252 253 # for each scene get scene position 254 # bue 20211115: this is czi metadata format dependent code.

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\aicsimageio\aics_image.py:277, in AICSImage.init(self, image, reader, reconstruct_mosaic, fs_kwargs, **kwargs) 267 def init( 268 self, 269 image: types.ImageLike, (...) 273 **kwargs: Any, 274 ): 275 if reader is None: 276 # Determine reader class and create dask delayed array --> 277 ReaderClass = self.determine_reader(image, fs_kwargs=fs_kwargs, **kwargs) 278 else: 279 # Init reader 280 ReaderClass = reader

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\aicsimageio\aics_image.py:231, in AICSImage.determine_reader(image, fs_kwargs, **kwargs) 229 if readers[0] in READER_TO_INSTALL: 230 installer = READER_TO_INSTALL[readers[0]] --> 231 raise exceptions.UnsupportedFileFormatError( 232 "AICSImage", 233 path, 234 msg_extra=( 235 f"File extension suggests format: '{format_ext}'. " 236 f"Install extra format dependency with: " 237 f"pip install {installer}. " 238 f"See all known format extensions and their " 239 f"extra install name with " 240 f"aicsimageio.formats.FORMAT_IMPLEMENTATIONS. " 241 f"If the extra dependency is already installed this " 242 f"error may have raised because the file is " 243 f"corrupt or similar issue. For potentially more " 244 f"information and to help debug, try loading the file " 245 f"directly with the desired file format reader " 246 f"instead of with the AICSImage object." 247 ), 248 ) 249 else: 250 raise exceptions.UnsupportedFileFormatError( 251 "AICSImage", 252 path, 253 )

UnsupportedFileFormatError: AICSImage does not support the image: 'C:/Users/smith6jt/cmIF_2021-01-07_demo/CziImages/HER2B-K185/original/r1_phh3.ck14.ki67.ck19_her2b-k185_2021_01_11__10_41__4318.czi'. File extension suggests format: 'czi'. Install extra format dependency with: pip install aicspylibczi>=3.1.1. See all known format extensions and their extra install name with aicsimageio.formats.FORMAT_IMPLEMENTATIONS. If the extra dependency is already installed this error may have raised because the file is corrupt or similar issue. For potentially more information and to help debug, try loading the file directly with the desired file format reader instead of with the AICSImage object.

The image opens properly with FIJI so it is not corrupt. Did conda install -c channel-forge bioformats_jar and reran cell:

Attempted file (C:/Users/smith6jt/cmIF_2021-01-07_demo/CziImages/HER2B-K185/original/r1_phh3.ck14.ki67.ck19_her2b-k185_2021_01_11__10_41__4318.czi) load with reader: aicsimageio.readers.czi_reader.CziReader failed with error: aicspylibczi is required for this reader. Install with pip install 'aicspylibczi>=3.1.1' 'fsspec>=2022.7.1' run: mplexable.imgmeta.fetch_meta_batch for slide ['HER2B-K185', 'JE-TMA-66'] ... <class 'pandas.core.frame.DataFrame'> Index: 0 entries Data columns (total 10 columns):

Column Non-Null Count Dtype


0 filetype 0 non-null object 1 markers 0 non-null object 2 mscene 0 non-null object 3 round 0 non-null object 4 scanid 0 non-null object 5 slide 0 non-null object 6 slide_mscene 0 non-null object 7 round_int 0 non-null float64 8 round_real 0 non-null float64 9 round_order 0 non-null object dtypes: float64(2), object(8) memory usage: 0.0+ bytes None

fetch_meta_slide_sceneposition: HER2B-K185 CziImages/HER2B-K185/original/ ... process file: r1_phh3.ck14.ki67.ck19_her2b-k185_2021_01_11__10_41__4318.czi ...

AttributeError Traceback (most recent call last) Cell In[19], line 9 1 # 2.0 extract image metadata 2 3 # the metadata is by default extracted from the original czi files. (...) 6 # and the splitscenes czi files are expected to be under {s_czidir}/{s_slide_id}/splitscenes/ 7 # Additionaly, the czi images filenames them self have to follow the correct naming convention. ----> 9 imgmeta.fetch_meta_batch( 10 es_slide = ls_slide, 11 s_czidir = config.d_nconv['s_czidir'], # 'CziImages/', 12 s_format_czidir_original = config.d_nconv['s_format_czidir_original'], #'{}{}/original/', # s_czidir, s_slide 13 s_format_czidir_splitscene = config.d_nconv['s_format_czidir_splitscene'], #'{}{}/splitscenes/', # s_czidir, s_slide 14 s_sceneposition_round = 'r1_', # file matching pattern, can but does not have to be round.
15 b_exposuretime_original = False, 16 b_exposuretime_splitscene = True, 17 b_sceneposition_original = True, 18 s_metadir = config.d_nconv['s_metadir'], #'MetaImages/', 19 )

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\mplexable\imgmeta.py:365, in fetch_meta_batch(es_slide, s_czidir, s_format_czidir_original, s_format_czidir_splitscene, s_sceneposition_round, b_sceneposition_original, b_exposuretime_original, b_exposuretime_splitscene, s_metadir) 362 # fetch scene position 363 if b_sceneposition_original: 364 # slide with one or many scenes --> 365 fetch_meta_slide_sceneposition( 366 s_slide = s_slide, 367 s_czidir_original = s_wd_original, 368 s_sceneposition_round = s_sceneposition_round, 369 s_metadir = s_metadir, 370 )

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\mplexable\imgmeta.py:256, in fetch_meta_slide_sceneposition(s_slide, s_czidir_original, s_sceneposition_round, b_omexml, s_metadir) 251 #print(x_root.tag) 252 253 # for each scene get scene position 254 # bue 20211115: this is czi metadata format dependent code. 255 dlr_sceneposition_xy = {} --> 256 for x_scene in x_root.findall('./Metadata/Information/Image/Dimensions/S/Scenes/Scene'): 257 x_centerposition = x_scene.find('./CenterPosition') 258 #print(x_scene.attrib) 259 #print(x_centerposition.text)

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\ome_types_mixins_base_type.py:160, in OMEType.getattr(self, key) 153 warnings.warn( 154 f"Attribute '{cls_name}.{key}' is deprecated, use {new_key!r} instead", 155 DeprecationWarning, 156 stacklevel=2, 157 ) 158 return getattr(self, new_key) --> 160 return super().getattr(key)

File ~\AppData\Local\anaconda3\envs\mplexable\lib\site-packages\pydantic\main.py:761, in BaseModel.getattr(self, item) 758 return super().getattribute(item) # Raises AttributeError if appropriate 759 else: 760 # this is the current error --> 761 raise AttributeError(f'{type(self).name!r} object has no attribute {item!r}')

AttributeError: 'OME' object has no attribute 'findall'

Then did pip install aicspylibczi>=3.1.1 fsspec>=2022.7.1 and everything was super great!