Skip to content

Commit

Permalink
[#429] Use output_dir as file save path
Browse files Browse the repository at this point in the history
  • Loading branch information
ReiHashimoto committed Apr 24, 2023
1 parent f695ccc commit bb6b698
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
8 changes: 4 additions & 4 deletions optinist/api/dataclass/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions optinist/wrappers/caiman_wrapper/cnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions optinist/wrappers/caiman_wrapper/motion_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand All @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion optinist/wrappers/lccd_wrapper/lccd_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
Expand Down
5 changes: 2 additions & 3 deletions optinist/wrappers/suite2p_wrapper/file_convert.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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'
}

Expand All @@ -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')
}

Expand Down
4 changes: 2 additions & 2 deletions optinist/wrappers/suite2p_wrapper/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}

Expand Down
10 changes: 5 additions & 5 deletions optinist/wrappers/suite2p_wrapper/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit bb6b698

Please sign in to comment.