Skip to content

Commit

Permalink
Merge pull request #243 from arayabrain/feature/image-index
Browse files Browse the repository at this point in the history
[#242] outputの動画のrange指定機能修正
  • Loading branch information
ReiHashimoto authored Dec 15, 2023
2 parents a46a2a6 + 4deb550 commit e8ed81a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
29 changes: 21 additions & 8 deletions studio/app/common/dataclass/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,27 @@ def data(self):
return np.array(imageio.volread(self.path))

def save_json(self, json_dir):
self.json_path = join_filepath([json_dir, f"{self.file_name}.json"])
JsonWriter.write_as_split(self.json_path, create_images_list(self.data))
JsonWriter.write_plot_meta(json_dir, self.file_name, self.meta)
if self.data.ndim < 3:
self.json_path = join_filepath([json_dir, f"{self.file_name}.json"])
JsonWriter.write_as_split(self.json_path, create_images_list(self.data))
JsonWriter.write_plot_meta(json_dir, self.file_name, self.meta)

@property
def output_path(self) -> OutputPath:
return OutputPath(
path=self.json_path,
type=OutputType.IMAGE,
max_index=len(self.data) if self.data.ndim == 3 else 1,
)
if self.data.ndim == 3:
# self.path will be a list if self.data got into else statement on __init__
if isinstance(self.path, list) and isinstance(self.path[0], str):
_path = self.path[0]
else:
_path = self.path
return OutputPath(
path=_path,
type=OutputType.IMAGE,
max_index=len(self.data),
)
else:
return OutputPath(
path=self.json_path,
type=OutputType.IMAGE,
max_index=1,
)
13 changes: 4 additions & 9 deletions studio/app/common/dataclass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@


def create_images_list(data):
if len(data.shape) == 2:
save_data = copy.deepcopy(data)
elif len(data.shape) == 3:
save_data = copy.deepcopy(data[:10])
else:
assert False, "data is error"
assert len(data.shape) == 2, "data is error"

if len(data.shape) == 2:
data = data[np.newaxis, :, :]
save_data = save_data[np.newaxis, :, :]
save_data = copy.deepcopy(data)
data = data[np.newaxis, :, :]
save_data = save_data[np.newaxis, :, :]

images = []
for _img in save_data:
Expand Down
6 changes: 4 additions & 2 deletions studio/app/common/routers/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ async def get_image(
filepath: str,
workspace_id: str,
start_index: Optional[int] = 0,
end_index: Optional[int] = 1,
end_index: Optional[int] = 10,
):
filename, ext = os.path.splitext(os.path.basename(filepath))
if ext in ACCEPT_TIFF_EXT:
filepath = join_filepath([DIRPATH.INPUT_DIR, workspace_id, filepath])
if not filepath.startswith(join_filepath([DIRPATH.OUTPUT_DIR, workspace_id])):
filepath = join_filepath([DIRPATH.INPUT_DIR, workspace_id, filepath])

save_dirpath = join_filepath(
[
os.path.dirname(filepath),
Expand Down
2 changes: 1 addition & 1 deletion studio/app/optinist/wrappers/suite2p/spike_deconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def suite2p_spike_deconv(
).T
roi_list.append(kargs)

nwbfile[NWBDATASET.ROI] = {function_id: {"roi_list": roi_list}}
nwbfile[NWBDATASET.ROI] = {function_id: roi_list}

# Fluorenceを追加
nwbfile[NWBDATASET.FLUORESCENCE] = {
Expand Down

0 comments on commit e8ed81a

Please sign in to comment.