From 48e8e6c0ab65b88c8a305cf8c2c218c08ae9a1f6 Mon Sep 17 00:00:00 2001 From: 36000 Date: Tue, 19 Jul 2022 17:23:07 -0700 Subject: [PATCH 1/5] [DOC] add interactive bundle viz to OR example --- examples/plot_optic_radiations.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/plot_optic_radiations.py b/examples/plot_optic_radiations.py index c7913e110..dee136cc5 100644 --- a/examples/plot_optic_radiations.py +++ b/examples/plot_optic_radiations.py @@ -13,12 +13,15 @@ """ import os.path as op + from AFQ.api.group import GroupAFQ import AFQ.api.bundle_dict as abd import AFQ.data.fetch as afd from AFQ.definitions.image import LabelledImageFile, RoiImage import AFQ.utils.streamlines as aus +import plotly + afd.organize_stanford_data(clear_previous_afq=True) or_rois = afd.read_or_templates() @@ -80,3 +83,7 @@ my_afq.combine_bundle("L_OR") else: raise ValueError("No L_OR found") + +# open interactive bundle visualization +bundle_html = my_afq.export("all_bundles_figure") +plotly.io.show(bundle_html["01"][0]) From b339be5702b249c8e935590512d5f9cbe0493cdf Mon Sep 17 00:00:00 2001 From: 36000 Date: Tue, 2 Aug 2022 10:56:07 -0700 Subject: [PATCH 2/5] use reduced endpoint ROI; only show L OR --- AFQ/data/fetch.py | 8 ++++---- AFQ/tasks/viz.py | 7 +++---- examples/plot_optic_radiations.py | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) 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 dee136cc5..253c201d8 100644 --- a/examples/plot_optic_radiations.py +++ b/examples/plot_optic_radiations.py @@ -85,5 +85,5 @@ raise ValueError("No L_OR found") # open interactive bundle visualization -bundle_html = my_afq.export("all_bundles_figure") -plotly.io.show(bundle_html["01"][0]) +bundle_html = my_afq.export("indiv_bundles_figures") +plotly.io.show(bundle_html["01"]["L_OR"]) From be57beae5c18c103d21c761e2ce0249360be8515 Mon Sep 17 00:00:00 2001 From: 36000 Date: Tue, 16 Aug 2022 13:56:11 -0700 Subject: [PATCH 3/5] display montages --- AFQ/api/group.py | 12 ++++++++++-- examples/plot_optic_radiations.py | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) 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/examples/plot_optic_radiations.py b/examples/plot_optic_radiations.py index 253c201d8..a82cefe35 100644 --- a/examples/plot_optic_radiations.py +++ b/examples/plot_optic_radiations.py @@ -13,6 +13,7 @@ """ import os.path as op +from IPython.display import display, Image from AFQ.api.group import GroupAFQ import AFQ.api.bundle_dict as abd @@ -79,8 +80,9 @@ "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") + display(Image(filename=montages[0])) else: raise ValueError("No L_OR found") From a8a12a14469cd9f6e0170d3bfbe0d96339a7f327 Mon Sep 17 00:00:00 2001 From: 36000 Date: Wed, 2 Nov 2022 11:54:16 -0700 Subject: [PATCH 4/5] get sphinx to encode the figure --- examples/plot_optic_radiations.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/plot_optic_radiations.py b/examples/plot_optic_radiations.py index a82cefe35..8a06e0b38 100644 --- a/examples/plot_optic_radiations.py +++ b/examples/plot_optic_radiations.py @@ -13,7 +13,7 @@ """ import os.path as op -from IPython.display import display, Image +from IPython.display import Image from AFQ.api.group import GroupAFQ import AFQ.api.bundle_dict as abd @@ -21,8 +21,6 @@ from AFQ.definitions.image import LabelledImageFile, RoiImage import AFQ.utils.streamlines as aus -import plotly - afd.organize_stanford_data(clear_previous_afq=True) or_rois = afd.read_or_templates() @@ -82,10 +80,18 @@ # across subject/session in MNI montages = my_afq.montage("L_OR", (1, 1), "Axial") my_afq.combine_bundle("L_OR") - display(Image(filename=montages[0])) + montage_img = Image(filename=montages[0]) else: raise ValueError("No L_OR found") +########################################################################## +# .. figure:: {{ montage_img }} +# + # open interactive bundle visualization bundle_html = my_afq.export("indiv_bundles_figures") -plotly.io.show(bundle_html["01"]["L_OR"]) +bundle_figure = bundle_html["01"]["L_OR"] + +########################################################################## +# .. figure:: {{ bundle_figure }} +# From a74899935e831757b162bb03aa671be658d640fe Mon Sep 17 00:00:00 2001 From: 36000 Date: Tue, 8 Nov 2022 15:07:55 -0800 Subject: [PATCH 5/5] try new setup for viz --- examples/plot_optic_radiations.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/examples/plot_optic_radiations.py b/examples/plot_optic_radiations.py index 8a06e0b38..1c911366c 100644 --- a/examples/plot_optic_radiations.py +++ b/examples/plot_optic_radiations.py @@ -14,6 +14,7 @@ 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 @@ -84,14 +85,7 @@ else: raise ValueError("No L_OR found") -########################################################################## -# .. figure:: {{ montage_img }} -# - # open interactive bundle visualization bundle_html = my_afq.export("indiv_bundles_figures") bundle_figure = bundle_html["01"]["L_OR"] - -########################################################################## -# .. figure:: {{ bundle_figure }} -# +plotly.io.show(bundle_figure)