Skip to content
Snippets Groups Projects

Data explorer

1 file
+ 87
38
Compare changes
  • Side-by-side
  • Inline
+ 87
38
@@ -20,7 +20,15 @@ class Interface:
self.title = "Data Explorer"
self.height = 1024
self.width = 900
self.operations = [
"Data summary",
"Z Slicer",
"Y Slicer",
"X Slicer",
"Z max projection",
"Z min projection",
"Intensity histogram",
]
# CSS path
current_dir = os.path.dirname(os.path.abspath(__file__))
self.css_path = os.path.join(current_dir, "..", "css", "gradio.css")
@@ -34,6 +42,27 @@ class Interface:
return gr.update(root=new_path, label=new_path)
def set_visible(self):
return gr.update(visible=True)
def set_spinner(self):
return gr.update(
elem_classes="btn btn-spinner",
value=f"Processing...",
interactive=False,
)
def set_relaunch_button(self):
return gr.update(
elem_classes="btn btn-run",
value=f"Relaunch",
interactive=True,
)
def make_pipeline(self, session):
print(session.operations)
return session
def create_interface(self):
with gr.Blocks(css=self.css_path) as gradio_interface:
gr.Markdown("# Data Explorer")
@@ -65,8 +94,9 @@ class Interface:
elem_classes="h-256 hide-overflow",
)
with gr.Column(scale=1):
with gr.Column(scale=2):
gr.Markdown("### Parameters")
virtual_stack = gr.Checkbox(value=False, label="Virtual stack")
cmap = gr.Dropdown(
value="viridis",
@@ -75,29 +105,33 @@ class Interface:
interactive=True,
)
dataset_name = gr.Textbox(
label="Dataset name (in case of H5 files, for example)"
label="Dataset name (in case of H5 files, for example)",
value="exchange/data",
)
virtual_stack = gr.Checkbox(value=False, label="Virtual stack")
with gr.Column(scale=1):
gr.Markdown("### Pipeline")
gr.Checkbox()
gr.Checkbox()
gr.Checkbox()
gr.Checkbox()
gr.Markdown("### Operations")
operations = gr.CheckboxGroup(
choices=self.operations,
value=[self.operations[0], self.operations[1]],
label=None,
container=False,
interactive=True,
)
with gr.Row():
btn_run = gr.Button(
value="Load & Run", elem_classes="btn btn-html btn-run"
)
# Visualization adn results
with gr.Row(elem_classes="mt-64"):
data_summary = gr.Text(
label=None,
show_label=False,
elem_classes="monospace-box",
value="Data summary",
)
# Visualization and results
with gr.Row(elem_classes="mt-64", visible=False) as results:
with gr.Column():
data_summary = gr.Text(
label=None,
show_label=False,
elem_classes="monospace-box",
value="Data summary",
)
with gr.Column():
zslice_plot = gr.Plot(label="Z slice", elem_classes="rounded")
zpos = gr.Slider(
@@ -116,25 +150,34 @@ class Interface:
xpos = gr.Slider(
minimum=0, maximum=1, value=0.5, step=0.01, label="X position"
)
with gr.Row(elem_classes="h-32"):
gr.Markdown()
with gr.Row(elem_classes="h-480"):
max_projection_plot = gr.Plot(
label="Z max projection", elem_classes="rounded"
)
min_projection_plot = gr.Plot(
label="Z min projection", elem_classes="rounded"
)
with gr.Column():
max_projection_plot = gr.Plot(
label="Z max projection", elem_classes="rounded"
)
with gr.Column():
min_projection_plot = gr.Plot(
label="Z min projection", elem_classes="rounded"
)
hist_plot = gr.Plot(label="Volume intensity histogram")
with gr.Column():
hist_plot = gr.Plot(label="Volume intensity histogram")
### Gradio objects lists
pipeline = Pipeline()
session = gr.State([])
# Inputs
inputs = [explorer, zpos, ypos, xpos, cmap, dataset_name, virtual_stack]
inputs = [
operations,
explorer,
zpos,
ypos,
xpos,
cmap,
dataset_name,
virtual_stack,
]
# Outputs
outputs = [
data_summary,
@@ -152,7 +195,10 @@ class Interface:
# fmt: off
reload_base_path.click(fn=self.update_root_path,inputs=base_path, outputs=explorer)
btn_run.click(
fn=self.set_spinner, inputs=[], outputs=btn_run).success(
fn=self.start_session, inputs=inputs, outputs=session).success(
fn=self.make_pipeline, inputs=session, outputs=session).success(
fn=self.set_visible, inputs=[], outputs=results).success(
fn=pipeline.process_input, inputs=session, outputs=session).success(
fn=pipeline.show_summary_str, inputs=session, outputs=data_summary).success(
fn=pipeline.create_zslice_fig, inputs=session, outputs=zslice_plot).success(
@@ -160,7 +206,9 @@ class Interface:
fn=pipeline.create_xslice_fig, inputs=session, outputs=xslice_plot).success(
fn=pipeline.create_projections_figs, inputs=session, outputs=projection_outputs).success(
fn=pipeline.show_summary_str, inputs=session, outputs=data_summary).success(
fn=pipeline.plot_vol_histogram, inputs=session, outputs=hist_plot)
fn=pipeline.plot_vol_histogram, inputs=session, outputs=hist_plot).success(
fn=self.set_relaunch_button, inputs=[], outputs=btn_run)
zpos.release(
@@ -181,15 +229,16 @@ class Interface:
def start_session(self, *args):
# Starts a new session dictionary
session = Session()
session.root_path = os.path.expanduser("~/temp")
session.root_path = os.path.expanduser("~")
session.interface = "gradio"
session.file_path = args[0]
session.zpos = args[1]
session.ypos = args[2]
session.xpos = args[3]
session.cmap = args[4]
session.dataset_name = args[5]
session.virtual_stack = args[6]
session.operations = args[0]
session.file_path = args[1]
session.zpos = args[2]
session.ypos = args[3]
session.xpos = args[4]
session.cmap = args[5]
session.dataset_name = args[6]
session.virtual_stack = args[7]
return session
@@ -235,7 +284,7 @@ class Interface:
class Session:
def __init__(self):
self.root_path = os.path.expanduser("~/temp/")
self.root_path = os.path.expanduser("~")
self.virtual_stack = False
self.interface = None
self.file_path = None
Loading