Skip to content

Commit

Permalink
Merge pull request #114 from ttngu207/dev_prairieview_multipagetif
Browse files Browse the repository at this point in the history
update: deprecate "caiman_compatible" argument
  • Loading branch information
kushalbakshi authored Jun 26, 2024
2 parents c189c48 + dbec434 commit eff0d7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 45 deletions.
56 changes: 20 additions & 36 deletions element_interface/prairie_view_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from datetime import datetime
import numpy as np
import tifffile
import logging

logger = logging.getLogger(__name__)


class PrairieViewMeta:
Expand Down Expand Up @@ -102,14 +105,16 @@ 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
)
if output_prefix is None:
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
Expand Down Expand Up @@ -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


Expand Down
14 changes: 5 additions & 9 deletions element_interface/suite2p_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit eff0d7b

Please sign in to comment.