diff --git a/AFQ/api/group.py b/AFQ/api/group.py index 6ba04a303..160877d75 100644 --- a/AFQ/api/group.py +++ b/AFQ/api/group.py @@ -533,6 +533,10 @@ def montage(self, bundle_name, size, view, slice_pos=None): If float, indicates the fractional position along the perpendicular axis to the slice. Currently only works with plotly. If None, no slice is displayed. + + Returns + ------- + list of filenames of montage images """ if view not in ["Sagittal", "Coronal", "Axial"]: raise ValueError( @@ -551,6 +555,7 @@ def montage(self, bundle_name, size, view, slice_pos=None): clean_bundles_dict = self.export("clean_bundles", collapse=False) best_scalar_dict = self.export(best_scalar, collapse=False) + all_fnames = [] self.logger.info("Generating Montage...") for ii in tqdm(range(len(self.valid_ses_list))): this_sub = self.valid_sub_list[ii] @@ -648,10 +653,12 @@ def montage(self, bundle_name, size, view, slice_pos=None): window.snapshot(figure, fname=this_fname, size=(600, 600)) def _save_file(curr_img, curr_file_num): - curr_img.save(op.abspath(op.join( + save_path = op.abspath(op.join( self.afq_path, (f"bundle-{bundle_name}_view-{view}" - f"_idx-{curr_file_num}_montage.png")))) + f"_idx-{curr_file_num}_montage.png"))) + curr_img.save(save_path) + all_fnames.append(save_path) this_img_trimmed = {} max_height = 0 @@ -692,6 +699,7 @@ def _save_file(curr_img, curr_file_num): (x_pos * max_width, y_pos * max_height)) _save_file(curr_img, curr_file_num) + return all_fnames def combine_bundle(self, bundle_name): """ diff --git a/AFQ/data/fetch.py b/AFQ/data/fetch.py index d9fef8047..383cf5030 100644 --- a/AFQ/data/fetch.py +++ b/AFQ/data/fetch.py @@ -588,9 +588,9 @@ def read_templates(as_img=True, resample_to=False): ] or_remote_fnames = [ - "26831630", + "36514170", "26831633", - "26831636", + "36514173", "26831639", "26831642", "26831645", @@ -605,9 +605,9 @@ def read_templates(as_img=True, resample_to=False): ] or_md5_hashes = [ - "c18f3f82c26f334dc26b96d21f026dd1", + "a45126a727c4b5d843b2f7aae181825f", "ad996c67bf5cc59fc3a7b60255873b67", - "786fb4ba915599f746950acd980e5b03", + "7a75c3ddd25335277a099626dbc946ac", "cc88fb4671311404eb9dfa8fa11a59e0", "9cff03af586d9dd880750cef3e0bf63f", "ff728ba3ffa5d1600bcd19fdef8182c4", diff --git a/AFQ/tasks/viz.py b/AFQ/tasks/viz.py index 5a21d6469..be0f04726 100644 --- a/AFQ/tasks/viz.py +++ b/AFQ/tasks/viz.py @@ -198,6 +198,7 @@ def viz_indivBundle(base_fname, bundle_names = bundle_dict.keys() + figures = {} for bundle_name in bundle_names: logger.info(f"Generating {bundle_name} visualization...") figure = viz_backend.visualize_volume( @@ -261,7 +262,7 @@ def viz_indivBundle(base_fname, roi_dir = op.join(results_dir, 'viz_bundles') os.makedirs(roi_dir, exist_ok=True) - fnames = [] + figures[bundle_name] = figure if "no_gif" not in viz_backend.backend: fname = op.split( get_fname( @@ -273,7 +274,6 @@ def viz_indivBundle(base_fname, fname = op.join(roi_dir, fname[1]) viz_backend.create_gif(figure, fname) - fnames.append(fname) if "plotly" in viz_backend.backend: roi_dir = op.join(results_dir, 'viz_bundles') os.makedirs(roi_dir, exist_ok=True) @@ -287,7 +287,6 @@ def viz_indivBundle(base_fname, fname = op.join(roi_dir, fname[1]) figure.write_html(fname) - fnames.append(fname) # also do the core visualizations when using the plotly backend core_dir = op.join(results_dir, 'viz_core_bundles') @@ -341,7 +340,7 @@ def viz_indivBundle(base_fname, segmentation_params=segmentation_params) meta = dict(Timing=time() - start_time) write_json(meta_fname, meta) - return fnames + return {"indiv_bundles_figures": figures} @pimms.calc("tract_profile_plots") diff --git a/examples/plot_optic_radiations.py b/examples/plot_optic_radiations.py index c7913e110..1c911366c 100644 --- a/examples/plot_optic_radiations.py +++ b/examples/plot_optic_radiations.py @@ -13,6 +13,9 @@ """ import os.path as op +from IPython.display import Image +import plotly + from AFQ.api.group import GroupAFQ import AFQ.api.bundle_dict as abd import AFQ.data.fetch as afd @@ -76,7 +79,13 @@ "01"]).get_bundle("L_OR").streamlines) > 1: # create bundle montage and bundle combination # across subject/session in MNI - my_afq.montage("L_OR", (1, 1), "Axial") + montages = my_afq.montage("L_OR", (1, 1), "Axial") my_afq.combine_bundle("L_OR") + montage_img = Image(filename=montages[0]) else: raise ValueError("No L_OR found") + +# open interactive bundle visualization +bundle_html = my_afq.export("indiv_bundles_figures") +bundle_figure = bundle_html["01"]["L_OR"] +plotly.io.show(bundle_figure)