From dbec43425fa908df35b4381bf0d7b10036df6db4 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 26 Jun 2024 13:31:30 -0500 Subject: [PATCH] update: deprecate "caiman_compatible" argument --- element_interface/prairie_view_loader.py | 56 +++++++++--------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/element_interface/prairie_view_loader.py b/element_interface/prairie_view_loader.py index f43f7ca..97a0efa 100644 --- a/element_interface/prairie_view_loader.py +++ b/element_interface/prairie_view_loader.py @@ -5,6 +5,9 @@ from datetime import datetime import numpy as np import tifffile +import logging + +logger = logging.getLogger(__name__) class PrairieViewMeta: @@ -102,6 +105,8 @@ def write_single_bigtiff( caiman_compatible=False, # if True, save the movie as a single page (frame x height x width) overwrite=False, ): + logger.warning("Deprecation warning: `caiman_compatible` argument will no longer have any effect and will be removed in the future. `write_single_bigtiff` will return multi-page tiff, which is compatible with CaImAn.") + tiff_names, plane_idx, channel = self.get_prairieview_filenames( plane_idx=plane_idx, channel=channel, return_pln_chn=True ) @@ -109,7 +114,7 @@ def write_single_bigtiff( output_prefix = os.path.commonprefix(tiff_names) output_tiff_fullpath = ( Path(output_dir) - / f"{output_prefix}_pln{plane_idx}_chn{channel}{'.ome' if not caiman_compatible else ''}.tif" + / f"{output_prefix}_pln{plane_idx}_chn{channel}.tif" ) if output_tiff_fullpath.exists() and not overwrite: return output_tiff_fullpath @@ -158,47 +163,26 @@ def write_single_bigtiff( bigtiff=True, ) else: - if not caiman_compatible: - with tifffile.TiffWriter( - output_tiff_fullpath, - bigtiff=True, - ) as tiff_writer: - try: - for input_file in tiff_names: - with tifffile.TiffFile( - self.prairieview_dir / input_file - ) as tffl: - assert len(tffl.pages) == 1 - tiff_writer.write( - tffl.pages[0].asarray(), - metadata={ - "axes": "YX", - "'fps'": self.meta["frame_rate"], - }, - ) - except Exception as e: - raise Exception(f"Error in processing tiff file {input_file}: {e}") - else: - combined_data = [] + with tifffile.TiffWriter( + output_tiff_fullpath, + bigtiff=True, + ) as tiff_writer: try: for input_file in tiff_names: - with tifffile.TiffFile(self.prairieview_dir / input_file) as tffl: + with tifffile.TiffFile( + self.prairieview_dir / input_file + ) as tffl: assert len(tffl.pages) == 1 - combined_data.append(tffl.pages[0].asarray()) + tiff_writer.write( + tffl.pages[0].asarray(), + metadata={ + "axes": "YX", + "'fps'": self.meta["frame_rate"], + }, + ) except Exception as e: raise Exception(f"Error in processing tiff file {input_file}: {e}") - combined_data = np.dstack(combined_data).transpose( - 2, 0, 1 - ) # (frame x height x width) - - tifffile.imwrite( - output_tiff_fullpath, - combined_data, - metadata={"axes": "TYX", "'fps'": self.meta["frame_rate"]}, - bigtiff=True, - ) - return output_tiff_fullpath