Skip to content

Commit

Permalink
update: deprecate "caiman_compatible" argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ttngu207 committed Jun 26, 2024
1 parent bc548de commit dbec434
Showing 1 changed file with 20 additions and 36 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

0 comments on commit dbec434

Please sign in to comment.