Skip to content

Commit

Permalink
Merge pull request #226 from arayabrain/feature/fix-nwbfile
Browse files Browse the repository at this point in the history
fix nwbfile data inheritance
  • Loading branch information
ReiHashimoto authored Dec 7, 2023
2 parents 40ae189 + 12ae917 commit 86a47c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions studio/app/common/core/rules/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ def run(cls, __rule: Rule, last_output):
gc.collect()

except Exception as e:
PickleWriter.write(
__rule.output,
list(traceback.TracebackException.from_exception(e).format())[-2:],
)
err_msg = list(traceback.TracebackException.from_exception(e).format())
# show full trace to console
print(*err_msg, sep="\n")
# save msg for GUI
PickleWriter.write(__rule.output, err_msg)

@classmethod
def set_func_start_timestamp(cls, output_dirpath):
Expand Down Expand Up @@ -142,9 +143,25 @@ def read_input_info(cls, input_files):
input_info = {}
for filepath in input_files:
load_data = PickleReader.read(filepath)
merged_nwb = cls.deep_merge(
load_data.pop("nwbfile", {}), input_info.pop("nwbfile", {})
)
input_info = dict(list(load_data.items()) + list(input_info.items()))
input_info["nwbfile"] = merged_nwb
return input_info

@classmethod
def deep_merge(cls, dict1, dict2):
if not isinstance(dict1, dict) or not isinstance(dict2, dict):
return dict2
merged = dict1.copy()
for k, v in dict2.items():
if k in merged and isinstance(merged[k], dict):
merged[k] = cls.deep_merge(merged[k], v)
else:
merged[k] = v
return merged

@classmethod
def dict2leaf(cls, root_dict: dict, path_list):
path = path_list.pop(0)
Expand Down
2 changes: 1 addition & 1 deletion studio/app/optinist/core/nwb/nwb_creater.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def motion_correction(cls, nwbfile, function_id, mc_data, xy_trans_data):

@classmethod
def roi(cls, nwbfile, function_id, roi_list):
image_seg = nwbfile.processing["ophys"].data_interfaces["ImageSegmentation"]
nwbfile = cls.add_plane_segmentation(nwbfile, function_id)
image_seg = nwbfile.processing["ophys"].data_interfaces["ImageSegmentation"]
plane_seg = image_seg.plane_segmentations[function_id]

if roi_list:
Expand Down

0 comments on commit 86a47c6

Please sign in to comment.