From 20cf21ea86b00b9b7e31aeca0469e2ff26e37dce Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 22 May 2024 14:07:55 -0500 Subject: [PATCH 1/2] fix(suite2p_loader): allow loading suite2p results without ROI detection or trace extraction --- element_interface/suite2p_loader.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/element_interface/suite2p_loader.py b/element_interface/suite2p_loader.py index 07dbff1..2e6884b 100644 --- a/element_interface/suite2p_loader.py +++ b/element_interface/suite2p_loader.py @@ -138,15 +138,6 @@ def __init__(self, suite2p_plane_dir: str): ) self.creation_time = datetime.fromtimestamp(ops_fp.stat().st_ctime) - iscell_fp = self.fpath / "iscell.npy" - if not iscell_fp.exists(): - raise FileNotFoundError( - 'No "iscell.npy" found. Invalid suite2p plane folder: {}'.format( - self.fpath - ) - ) - self.curation_time = datetime.fromtimestamp(iscell_fp.stat().st_ctime) - # -- Initialize attributes -- for s2p_type in _suite2p_ftypes: setattr(self, "_{}".format(s2p_type), None) @@ -160,6 +151,11 @@ def __init__(self, suite2p_plane_dir: str): # -- load core files -- + @property + def curation_time(self): + print("DeprecationWarning: 'curation_time' is deprecated, set to be the same as 'creation time', no longer reliable.") + return self.creation_time + @property def ops(self): if self._ops is None: From dbec43425fa908df35b4381bf0d7b10036df6db4 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 26 Jun 2024 13:31:30 -0500 Subject: [PATCH 2/2] 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