diff --git a/optinist/api/dataclass/image.py b/optinist/api/dataclass/image.py index 5fd4cb93f..3804b8ec5 100644 --- a/optinist/api/dataclass/image.py +++ b/optinist/api/dataclass/image.py @@ -11,7 +11,7 @@ class ImageData(BaseData): - def __init__(self, data, file_name='image'): + def __init__(self, data, output_dir=DIRPATH.OUTPUT_DIR, file_name='image'): super().__init__(file_name) self.json_path = None @@ -23,7 +23,7 @@ def __init__(self, data, file_name='image'): elif isinstance(data, list) and isinstance(data[0], str): self.path = data else: - _dir = join_filepath([DIRPATH.OUTPUT_DIR, "tiff", file_name]) + _dir = join_filepath([output_dir, "tiff", file_name]) create_directory(_dir) _path = join_filepath([_dir, f'{file_name}.tif']) @@ -49,12 +49,12 @@ def save_json(self, json_dir): class RoiData(BaseData): - def __init__(self, data, file_name='roi'): + def __init__(self, data, output_dir=DIRPATH.OUTPUT_DIR, file_name='roi'): super().__init__(file_name) images = create_images_list(data) - _dir = join_filepath([DIRPATH.OUTPUT_DIR, "tiff", file_name]) + _dir = join_filepath([output_dir, "tiff", file_name]) create_directory(_dir) self.path = join_filepath([_dir, f'{file_name}.tif']) tifffile.imsave(self.path, images) diff --git a/optinist/wrappers/caiman_wrapper/cnmf.py b/optinist/wrappers/caiman_wrapper/cnmf.py index 476d7812d..2c17ae2c9 100644 --- a/optinist/wrappers/caiman_wrapper/cnmf.py +++ b/optinist/wrappers/caiman_wrapper/cnmf.py @@ -210,12 +210,12 @@ def caiman_cnmf( ]) info = { - 'images': ImageData(np.array(Cn * 255, dtype=np.uint8), file_name='images'), + 'images': ImageData(np.array(Cn * 255, dtype=np.uint8), output_dir=output_dir, file_name='images'), 'fluorescence': FluoData(fluorescence, file_name='fluorescence'), 'iscell': IscellData(iscell, file_name='iscell'), - 'all_roi': RoiData(all_roi, file_name='all_roi'), - 'cell_roi': RoiData(cell_roi, file_name='cell_roi'), - 'non_cell_roi': RoiData(non_cell_roi, file_name='non_cell_roi'), + 'all_roi': RoiData(all_roi, output_dir=output_dir, file_name='all_roi'), + 'cell_roi': RoiData(cell_roi, output_dir=output_dir, file_name='cell_roi'), + 'non_cell_roi': RoiData(non_cell_roi, output_dir=output_dir, file_name='non_cell_roi'), 'nwbfile': nwbfile } diff --git a/optinist/wrappers/caiman_wrapper/motion_correction.py b/optinist/wrappers/caiman_wrapper/motion_correction.py index 274c48bfd..0be17d4c7 100644 --- a/optinist/wrappers/caiman_wrapper/motion_correction.py +++ b/optinist/wrappers/caiman_wrapper/motion_correction.py @@ -56,7 +56,7 @@ def caiman_mc( xy_trans_data = (np.array(mc.x_shifts_els), np.array(mc.y_shifts_els)) \ if params['pw_rigid'] else np.array(mc.shifts_rig) - mc_images = ImageData(images, file_name='mc_images') + mc_images = ImageData(images, output_dir=output_dir, file_name='mc_images') nwbfile = {} nwbfile[NWBDATASET.MOTION_CORRECTION] = { @@ -68,8 +68,8 @@ def caiman_mc( info = { 'mc_images': mc_images, - 'meanImg': ImageData(meanImg, file_name='meanImg'), - 'rois': RoiData(rois, file_name='rois'), + 'meanImg': ImageData(meanImg, output_dir=output_dir, file_name='meanImg'), + 'rois': RoiData(rois, output_dir=output_dir, file_name='rois'), 'nwbfile': nwbfile, } diff --git a/optinist/wrappers/lccd_wrapper/lccd_detection.py b/optinist/wrappers/lccd_wrapper/lccd_detection.py index 213e7144e..dbf9d59b1 100644 --- a/optinist/wrappers/lccd_wrapper/lccd_detection.py +++ b/optinist/wrappers/lccd_wrapper/lccd_detection.py @@ -42,7 +42,7 @@ def lccd_detect( timeseries_dff[i, k] = (timeseries[i, k] - f0) / f0 info = { - 'rois': RoiData(np.nanmax(roi_list, axis=0), file_name='cell_roi'), + 'rois': RoiData(np.nanmax(roi_list, axis=0), output_dir=output_dir, file_name='cell_roi'), 'fluorescence': FluoData(timeseries, file_name='fluorescence'), 'dff': FluoData(timeseries_dff, file_name='dff'), } diff --git a/optinist/wrappers/suite2p_wrapper/file_convert.py b/optinist/wrappers/suite2p_wrapper/file_convert.py index d0782196e..ecd0ab7ff 100644 --- a/optinist/wrappers/suite2p_wrapper/file_convert.py +++ b/optinist/wrappers/suite2p_wrapper/file_convert.py @@ -1,7 +1,6 @@ import os from optinist.api.dataclass.dataclass import * -from optinist.api.dir_path import DIRPATH from optinist.api.utils.filepath_creater import join_filepath @@ -25,7 +24,7 @@ def suite2p_file_convert( db = { 'data_path': data_path_list, 'tiff_list': data_name_list, - 'save_path0': DIRPATH.OUTPUT_DIR, + 'save_path0': output_dir, 'save_folder': 'suite2p' } @@ -40,7 +39,7 @@ def suite2p_file_convert( ops = io.tiff_to_binary(ops.copy()) info = { - 'meanImg': ImageData(ops['meanImg'], file_name='meanImg'), + 'meanImg': ImageData(ops['meanImg'], output_dir=output_dir, file_name='meanImg'), 'ops': Suite2pData(ops, file_name='ops') } diff --git a/optinist/wrappers/suite2p_wrapper/registration.py b/optinist/wrappers/suite2p_wrapper/registration.py index c2555d4c7..b20424551 100644 --- a/optinist/wrappers/suite2p_wrapper/registration.py +++ b/optinist/wrappers/suite2p_wrapper/registration.py @@ -25,8 +25,8 @@ def suite2p_registration( ops = registration.get_pc_metrics(ops) info = { - 'refImg': ImageData(ops['refImg'], file_name='refImg'), - 'meanImgE': ImageData(ops['meanImgE'], file_name='meanImgE'), + 'refImg': ImageData(ops['refImg'], output_dir=output_dir, file_name='refImg'), + 'meanImgE': ImageData(ops['meanImgE'], output_dir=output_dir, file_name='meanImgE'), 'ops': Suite2pData(ops, file_name='ops'), } diff --git a/optinist/wrappers/suite2p_wrapper/roi.py b/optinist/wrappers/suite2p_wrapper/roi.py index 5fb2875bb..25970ac8e 100644 --- a/optinist/wrappers/suite2p_wrapper/roi.py +++ b/optinist/wrappers/suite2p_wrapper/roi.py @@ -93,13 +93,13 @@ def suite2p_roi( info = { 'ops': Suite2pData(ops), - 'max_proj': ImageData(ops['max_proj'], file_name='max_proj'), - 'Vcorr': ImageData(ops['Vcorr'], file_name='Vcorr'), + 'max_proj': ImageData(ops['max_proj'], output_dir=output_dir, file_name='max_proj'), + 'Vcorr': ImageData(ops['Vcorr'], output_dir=output_dir, file_name='Vcorr'), 'fluorescence': FluoData(F, file_name='fluorescence'), 'iscell': IscellData(iscell, file_name='iscell'), - 'all_roi': RoiData(np.nanmax(im, axis=0), file_name='all_roi'), - 'non_cell_roi': RoiData(np.nanmax(im[~iscell], axis=0), file_name='noncell_roi'), - 'cell_roi': RoiData(np.nanmax(im[iscell], axis=0), file_name='cell_roi'), + 'all_roi': RoiData(np.nanmax(im, axis=0), output_dir=output_dir, file_name='all_roi'), + 'non_cell_roi': RoiData(np.nanmax(im[~iscell], axis=0), output_dir=output_dir, file_name='noncell_roi'), + 'cell_roi': RoiData(np.nanmax(im[iscell], axis=0), output_dir=output_dir, file_name='cell_roi'), 'nwbfile': nwbfile, }