Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: Relocate plot functionality #857

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/python/impactx/dashboard/Analyze/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .analyzeFunctions import AnalyzeFunctions
from .plot_ParameterEvolutionOverS.overS import line_plot_1d
from .plot_PhaseSpaceProjections.phaseSpaceSettings import adjusted_settings_plot

__all__ = [
"adjusted_settings_plot",
"AnalyzeFunctions",
"line_plot_1d",
]
25 changes: 24 additions & 1 deletion src/python/impactx/dashboard/Analyze/plotsMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
License: BSD-3-Clause-LBNL
"""

import base64
import glob
import io
import os

from trame.widgets import matplotlib, plotly

from .. import setup_server, vuetify
from . import AnalyzeFunctions, line_plot_1d
from . import AnalyzeFunctions, adjusted_settings_plot, line_plot_1d

server, state, ctrl = setup_server()

Expand All @@ -21,6 +23,16 @@
# -----------------------------------------------------------------------------


def fig_to_base64(fig):
"""
Puts png in trame-compatible form
"""
buf = io.BytesIO()
fig.savefig(buf, format="png")
buf.seek(0)
return base64.b64encode(buf.read()).decode("utf-8")


# Call plot_over_s
def plot_over_s():
"""
Expand All @@ -31,6 +43,17 @@ def plot_over_s():
ctrl.plotly_figure_update(fig)


def generate_phase_space(pc):
fig = adjusted_settings_plot(pc)
ctrl.matplotlib_figure_update(fig)

fig_original = pc.plot_phasespace()

if fig_original is not None:
image_base64 = fig_to_base64(fig_original)
state.phase_space_png = f"data:image/png;base64, {image_base64}"


PLOTS = {
"Plot Over S": plot_over_s,
"Phase Space Plots": None,
Expand Down
28 changes: 2 additions & 26 deletions src/python/impactx/dashboard/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@

server, state, ctrl = setup_server()

import base64
import io

from impactx import Config, ImpactX

from .Analyze.plot_PhaseSpaceProjections.phaseSpaceSettings import (
adjusted_settings_plot,
)
from .Analyze.plotsMain import generate_phase_space
from .Input.distributionParameters.distributionMain import distribution_parameters
from .Input.latticeConfiguration.latticeMain import lattice_elements

Expand All @@ -26,16 +21,6 @@
from mpi4py import MPI # noqa


def fig_to_base64(fig):
"""
Puts png in trame-compatible form
"""
buf = io.BytesIO()
fig.savefig(buf, format="png")
buf.seek(0)
return base64.b64encode(buf.read()).decode("utf-8")


def run_simulation():
"""
This tests runs a simulation on ImpactX
Expand Down Expand Up @@ -92,15 +77,6 @@ def run_simulation():
# simulate
sim.evolve()

fig = adjusted_settings_plot(pc)
ctrl.matplotlib_figure_update(fig)

fig_original = pc.plot_phasespace()

if fig_original is not None:
image_base64 = fig_to_base64(fig_original)
state.phase_space_png = f"data:image/png;base64, {image_base64}"
generate_phase_space(pc)

sim.finalize()

return fig
Loading