Skip to content

Commit

Permalink
prototype edit and check panel
Browse files Browse the repository at this point in the history
  • Loading branch information
j-brady committed Feb 27, 2024
1 parent 1c4bafc commit 933810c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
12 changes: 9 additions & 3 deletions peakipy/cli/check_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ def create_plotly_pane(cluster, plane):


@app.command()
def check_panel(
fits_path: Path, data_path: Path, config_path: Path = Path("./peakipy.config")
def create_check_panel(
fits_path: Path,
data_path: Path,
config_path: Path = Path("./peakipy.config"),
edit_panel: bool = False,
):
data = data_singleton()
data.fits_path = fits_path
Expand Down Expand Up @@ -106,7 +109,10 @@ def check_panel(
pn.Row(interactive_plotly_pane, interactive_cluster_pane),
title="Peakipy check",
)
check_pane.show()
if edit_panel:
return check_pane
else:
check_pane.show()


if __name__ == "__main__":
Expand Down
17 changes: 14 additions & 3 deletions peakipy/cli/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from skimage.filters import threshold_otsu
from rich import print


import panel as pn

from bokeh.io import curdoc
from bokeh.events import ButtonClick, DoubleTap
from bokeh.layouts import row, column, grid
Expand All @@ -39,6 +42,7 @@
from bokeh.palettes import PuBuGn9, Category20, Viridis256, RdGy11, Reds256, YlOrRd9

from peakipy.core import LoadData, read_config, StrucEl
from check_panel import create_check_panel

log_style = "overflow:scroll;"
log_div = """<div style=%s>%s</div>"""
Expand Down Expand Up @@ -69,6 +73,7 @@ def __init__(self, peaklist_path: Path, data_path: Path):
self.setup_initial_fit_threshold()
self.setup_quit_button()
self.setup_plot()
self.check_pane = ""

def init(self, doc):
"""initialise the bokeh app"""
Expand Down Expand Up @@ -714,13 +719,19 @@ def fit_selected(self, event):
if self.checkbox_group.active == []:
fit_command = f"peakipy fit {self.TEMP_INPUT_CSV} {self.data_path} {self.TEMP_OUT_CSV} --lineshape {lineshape}{fix_command}{reference_planes_command}{initial_fit_threshold_command}{xy_bounds_command}"
# plot_command = f"peakipy check {self.TEMP_OUT_CSV} {self.data_path} --label --individual --show --outname {self.TEMP_OUT_PLOT / Path('tmp.pdf')}"
plot_command = f"peakipy-check {self.TEMP_OUT_CSV} {self.data_path}"
self.check_pane = create_check_panel(
self.TEMP_OUT_CSV, self.data_path, edit_panel=True
)
# plot_command = f"peakipy-check {self.TEMP_OUT_CSV} {self.data_path}"
else:
plane_index = self.select_plane.value
print(f"[yellow]Only fitting plane {plane_index}[/yellow]")
fit_command = f"peakipy fit {self.TEMP_INPUT_CSV} {self.data_path} {self.TEMP_OUT_CSV} --lineshape {lineshape} --plane {plane_index}{fix_command}{reference_planes_command}{initial_fit_threshold_command}{xy_bounds_command}"
self.check_pane = create_check_panel(
self.TEMP_OUT_CSV, self.data_path, edit_panel=True
)
# plot_command = f"peakipy check {self.TEMP_OUT_CSV} {self.data_path} --label --individual --outname {self.TEMP_OUT_PLOT / Path('tmp.pdf')} --plane {plane_index} --show"
plot_command = f"peakipy-check {self.TEMP_OUT_CSV} {self.data_path}"
# plot_command = f"peakipy-check {self.TEMP_OUT_CSV} {self.data_path}"

print(f"[blue]{fit_command}[/blue]")
self.fit_reports += fit_command + "<br>"
Expand All @@ -730,7 +741,7 @@ def fit_selected(self, event):
self.fit_reports = self.fit_reports.replace("\n", "<br>")
self.fit_reports_div.text = log_div % (log_style, self.fit_reports)
# plot data
os.system(plot_command)
# os.system(plot_command)

def save_peaks(self, event):
if self.savefilename.value:
Expand Down
38 changes: 38 additions & 0 deletions peakipy/cli/edit_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path
import panel as pn

from edit import BokehScript
from check_panel import create_check_panel

pn.extension("plotly")
pn.config.theme = "dark"

bs = BokehScript(
peaklist_path=Path("./edited_peaks.csv"), data_path=Path("./test1.ft2")
)
bokeh_pane = pn.pane.Bokeh(bs.p)
table_pane = pn.pane.Bokeh(bs.data_table)
spectrum_view_settings = pn.WidgetBox(
"# View settings", bs.pos_neg_contour_radiobutton, bs.contour_start
)
button = pn.widgets.Button(name="Click me", button_type="primary")
fit_controls = pn.WidgetBox(
"# Fit controls", bs.select_lineshape_radiobuttons, bs.fit_button, button
)


def b(event):
check_app.loading = True
check_panel = create_check_panel(bs.TEMP_OUT_CSV, bs.data_path, edit_panel=True)
check_app.objects = check_panel.objects
check_app.loading = False


button.on_click(b)
fit_app = pn.Card(
pn.Column(bokeh_pane, fit_controls, spectrum_view_settings, table_pane),
title="Peakipy fit",
)
check_app = pn.Card(title="Peakipy check")
app = pn.Column(fit_app, check_app)
server = app.show(threaded=True)
12 changes: 6 additions & 6 deletions peakipy/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
FitPeaksInput,
FitPeaksArgs,
)
from .edit import BokehScript
from .spec import yaml_file

app = typer.Typer()
Expand Down Expand Up @@ -1475,15 +1474,15 @@ def check(

if ccpn_flag:
plt = PlotterWidget()
else:
plt = matplotlib.pyplot
create_matplotlib_figure(
plot_data, pdf, individual, label, ccpn_flag, show
)
# fig = create_plotly_figure(plot_data)
if plotly:
fig = create_plotly_figure(plot_data)
return fig
else:
plt = matplotlib.pyplot
create_matplotlib_figure(
plot_data, pdf, individual, label, ccpn_flag, show
)
# surf = pn.pane.plotly.Plotly(fig)
# app = pn.Column(surf)
# app.show(threaded=True)
Expand All @@ -1501,6 +1500,7 @@ def edit(
):
from bokeh.util.browser import view
from bokeh.server.server import Server
from .edit import BokehScript

run_log()
bs = BokehScript(peaklist_path=peaklist_path, data_path=data_path)
Expand Down

0 comments on commit 933810c

Please sign in to comment.