diff --git a/element_interface/extract_trigger.py b/element_interface/extract_trigger.py index 103e3e0..2600a93 100644 --- a/element_interface/extract_trigger.py +++ b/element_interface/extract_trigger.py @@ -43,7 +43,8 @@ def __init__( def write_matlab_run_script(self): """Compose a matlab script and save it with the name run_extract.m. - The composed script is basically the formatted version of the m_template attribute.""" + The composed script is basically the formatted version of the m_template attribute. + """ self.output_fullpath = ( self.output_dir / f"{self.scanfile.stem}_extract_output.mat" @@ -53,11 +54,15 @@ def write_matlab_run_script(self): **dict( parameters_list_string="\n".join( [ - f"config.{k} = '{v}';" - if isinstance(v, str) - else f"config.{k} = {str(v).lower()};" - if isinstance(v, bool) - else f"config.{k} = {v};" + ( + f"config.{k} = '{v}';" + if isinstance(v, str) + else ( + f"config.{k} = {str(v).lower()};" + if isinstance(v, bool) + else f"config.{k} = {v};" + ) + ) for k, v in self.parameters.items() ] ), diff --git a/element_interface/prairie_view_loader.py b/element_interface/prairie_view_loader.py index a3e9790..33fe1a9 100644 --- a/element_interface/prairie_view_loader.py +++ b/element_interface/prairie_view_loader.py @@ -106,7 +106,9 @@ def write_single_bigtiff( overwrite=False, gb_per_file=None, ): - 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.") + 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 @@ -126,7 +128,9 @@ def write_single_bigtiff( output_tiff_list = [] if self.meta["is_multipage"]: if gb_per_file is not None: - logger.warning("Ignoring `gb_per_file` argument for multi-page tiff (NotYetImplemented)") + logger.warning( + "Ignoring `gb_per_file` argument for multi-page tiff (NotYetImplemented)" + ) # For multi-page tiff - the pages are organized as: # (channel x slice x frame) - each page is (height x width) # - TODO: verify this is the case for Bruker multi-page tiff @@ -137,36 +141,45 @@ def write_single_bigtiff( slice_idx = self.meta["plane_indices"].index(plane_idx) channel_idx = self.meta["channels"].index(channel) - page_indices = [frame_idx * frame_step + slice_idx * slice_step + channel_idx - for frame_idx in range(self.meta["num_frames"])] + page_indices = [ + frame_idx * frame_step + slice_idx * slice_step + channel_idx + for frame_idx in range(self.meta["num_frames"]) + ] - combined_data = np.empty([self.meta["num_frames"], - self.meta["height_in_pixels"], - self.meta["width_in_pixels"]], - dtype=int) + combined_data = np.empty( + [ + self.meta["num_frames"], + self.meta["height_in_pixels"], + self.meta["width_in_pixels"], + ], + dtype=int, + ) start_page = 0 try: for input_file in tiff_names: with tifffile.TiffFile(self.prairieview_dir / input_file) as tffl: # Get indices in this tiff file and in output array final_page_in_file = start_page + len(tffl.pages) - is_page_in_file = lambda page: page in range(start_page, final_page_in_file) + is_page_in_file = lambda page: page in range( + start_page, final_page_in_file + ) pages_in_file = filter(is_page_in_file, page_indices) file_indices = [page - start_page for page in pages_in_file] - global_indices = [is_page_in_file(page) for page in page_indices] + global_indices = [ + is_page_in_file(page) for page in page_indices + ] # Read from this tiff file (if needed) if len(file_indices) > 0: # this line looks a bit ugly but is memory efficient. Do not separate - combined_data[global_indices] = tffl.asarray(key=file_indices) + combined_data[global_indices] = tffl.asarray( + key=file_indices + ) start_page += len(tffl.pages) except Exception as e: raise Exception(f"Error in processing tiff file {input_file}: {e}") - output_tiff_fullpath = ( - output_dir - / f"{output_tiff_stem}.tif" - ) + output_tiff_fullpath = output_dir / f"{output_tiff_stem}.tif" tifffile.imwrite( output_tiff_fullpath, combined_data, @@ -177,8 +190,7 @@ def write_single_bigtiff( else: while len(tiff_names): output_tiff_fullpath = ( - output_dir - / f"{output_tiff_stem}_{len(output_tiff_list):04}.tif" + output_dir / f"{output_tiff_stem}_{len(output_tiff_list):04}.tif" ) with tifffile.TiffWriter( output_tiff_fullpath, @@ -203,8 +215,14 @@ def write_single_bigtiff( tffl.close() del tffl except Exception as e: - raise Exception(f"Error in processing tiff file {input_file}: {e}") - if gb_per_file and output_tiff_fullpath.stat().st_size >= gb_per_file * 1024 ** 3: + raise Exception( + f"Error in processing tiff file {input_file}: {e}" + ) + if ( + gb_per_file + and output_tiff_fullpath.stat().st_size + >= gb_per_file * 1024**3 + ): break output_tiff_list.append(output_tiff_fullpath) diff --git a/element_interface/run_caiman.py b/element_interface/run_caiman.py index 7c9e514..4eefadc 100644 --- a/element_interface/run_caiman.py +++ b/element_interface/run_caiman.py @@ -12,6 +12,7 @@ try: import torch + cuda_is_available = torch.cuda.is_available() except: cuda_is_available = False diff --git a/element_interface/suite2p_loader.py b/element_interface/suite2p_loader.py index e16fd3f..646c01b 100644 --- a/element_interface/suite2p_loader.py +++ b/element_interface/suite2p_loader.py @@ -153,7 +153,9 @@ def __init__(self, suite2p_plane_dir: str): @property def curation_time(self): - print("DeprecationWarning: 'curation_time' is deprecated, set to be the same as 'creation time', no longer reliable.") + print( + "DeprecationWarning: 'curation_time' is deprecated, set to be the same as 'creation time', no longer reliable." + ) return self.creation_time @property