-
Notifications
You must be signed in to change notification settings - Fork 29
[Draft] Dashboard: add plotly lattice visualizer #1098
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
Open
proy30
wants to merge
36
commits into
BLAST-ImpactX:development
Choose a base branch
from
proy30:dashboard/add_lattice_visualizer
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
bf5ddea
add initial visualization
proy30 2f846fc
add colors based off of element name
proy30 ee49d10
add settings and dialogs
proy30 b39b58e
fix __main__.py
proy30 e6b69b7
add: statistics
proy30 62e8455
statistics: modify
proy30 79a7000
update state.periods
proy30 e4d0ac2
rename classes
proy30 8fa965f
rename utils -> statistic_utils.py
proy30 6b09e8c
move statistic updates to own helper function
proy30 17c61a5
change colors
proy30 2b0eff9
draft - lattice visualizer
proy30 f658acd
add legend for each unique element
proy30 b7a82ef
group up indexes in legend
proy30 7f963c5
get element parameters name
proy30 a2eec42
do not display labels past 20 elements
proy30 90d5a72
fix hover annotations
proy30 5e24953
refactor: element hover text
proy30 0987884
display the element index on hover
proy30 e055af2
simplify: remove call to 'classify_elements'
proy30 027f443
add back removed annotation method
proy30 d712fca
fix unique elements showing on legend
proy30 1fce53c
add more defaults to _add_trace
proy30 2bab9aa
move visualization files to own folder
proy30 d1a9b27
create utilities file for the visualizer
proy30 c2045eb
update: dialogs.py
proy30 db34eb4
update ui.py
proy30 88b789e
rename statistics_utils -> statistics
proy30 b186001
update ui.py
proy30 af5dd22
use helper function to retrieve lattice values
proy30 4ffcf1f
add: calculation.py for the visualizer
proy30 44fc940
store quad colors in global dict
proy30 473e348
create elements folder inside of lattice/visualization
proy30 d69d664
fix import and state.periods for stats
proy30 68d9ea2
Merge branch 'development' into dashboard/rebase_lattice_visualizer
proy30 d35d9f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
src/python/impactx/dashboard/Input/visualization/lattice/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| from .dialogs import LatticeVisualizerDialogs as Dialogs | ||
| from .statistics import LatticeVisualizerStatisticComponents as StatComponents | ||
| from .statistics import LatticeVisualizerStatisticUtils as StatUtils | ||
|
|
||
| __all__ = [ | ||
| "Dialogs", | ||
| "StatComponents", | ||
| "StatUtils", | ||
| ] |
50 changes: 50 additions & 0 deletions
50
src/python/impactx/dashboard/Input/visualization/lattice/dialogs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """ | ||
| This file is part of ImpactX | ||
|
|
||
| Copyright 2025 ImpactX contributors | ||
| Authors: Parthib Roy | ||
| License: BSD-3-Clause-LBNL | ||
| """ | ||
|
|
||
| from .... import vuetify | ||
| from ....Input.components.card import CardComponents | ||
|
|
||
|
|
||
| class LatticeVisualizerDialogs: | ||
| @staticmethod | ||
| def settings(): | ||
| """ | ||
| A button to open the settings dialog for the lattice visualizer. | ||
| """ | ||
| CardComponents.card_button( | ||
| "mdi-cog", | ||
| color="white", | ||
| click="lattice_visualizer_dialog_settings = true", | ||
| description="Settings", | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def element_colors_tab(): | ||
| """ | ||
| A tab inside of the settings dialog to manage element colors. | ||
| """ | ||
|
|
||
| with vuetify.VCardText(): | ||
| with vuetify.VRow(): | ||
| with vuetify.VCol(cols=12): | ||
| vuetify.VCardSubtitle( | ||
| "Element Color Mapping", | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def general_settings_tab(): | ||
| """ | ||
| A tab inside of the settings dialog for general settings. | ||
| """ | ||
|
|
||
| with vuetify.VCardText(): | ||
| with vuetify.VRow(): | ||
| with vuetify.VCol(cols=12): | ||
| vuetify.VCardSubtitle( | ||
| "Settings", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/python/impactx/dashboard/Input/visualization/lattice/visualization/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from .elements.elements import LatticeVisualizerElements | ||
| from .utils import LatticeVisualizerUtils | ||
|
|
||
| __all__ = [ | ||
| "LatticeVisualizerElements", | ||
| "LatticeVisualizerUtils", | ||
| ] |
Empty file.
58 changes: 58 additions & 0 deletions
58
...thon/impactx/dashboard/Input/visualization/lattice/visualization/elements/calculations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """ | ||
| This file is part of ImpactX | ||
|
|
||
| Copyright 2025 ImpactX contributors | ||
| Authors: Parthib Roy | ||
| License: BSD-3-Clause-LBNL | ||
|
|
||
| Mathematical calculations for lattice element positioning and transformations. | ||
| """ | ||
|
|
||
| import numpy as np | ||
|
|
||
|
|
||
| def transform(x, y, rotation_deg, dx): | ||
| """ | ||
| Transform coordinates based on angle and displacement. | ||
| """ | ||
| rotation_rad = np.radians(rotation_deg) | ||
| x_new = x + dx * np.cos(rotation_rad) | ||
| y_new = y + dx * np.sin(rotation_rad) | ||
| return x_new, y_new | ||
|
|
||
|
|
||
| def rotate_corners( | ||
| x: float, y: float, rotation_deg: float, ds: float = 1.0, width: float = 0.1 | ||
| ) -> np.ndarray: | ||
| """ | ||
| Generates rectangle's corners after applying rotation matrix. | ||
| This is utilized to properly visualize a rotated lattice element in Plotly. | ||
|
|
||
| :param x: starting x-coordinate before the rotation | ||
| :param y: starting y-coordinate before the rotation | ||
| :param rotation_deg: Rotation angle in degrees, counterclockwise. | ||
| :param ds: Length of the rectangle along the local X-axis (default is 1.0). | ||
| :param width: Half of the rectangle's height (default is 0.1). | ||
| :return: A NumPy array of shape (5, 2) with rotated (x, y) corner coordinates, closed for polygon plotting. | ||
| """ | ||
| rotation_rad = np.radians(rotation_deg) | ||
|
|
||
| corners = np.array( | ||
| [ | ||
| [0, -width], | ||
| [ds, -width], | ||
| [ds, width], | ||
| [0, width], | ||
| [0, -width], # close polygon | ||
| ] | ||
| ) | ||
|
|
||
| R = np.array( | ||
| [ | ||
| [np.cos(rotation_rad), -np.sin(rotation_rad)], | ||
| [np.sin(rotation_rad), np.cos(rotation_rad)], | ||
| ] | ||
| ) | ||
|
|
||
| rotated = corners @ R.T + [x, y] | ||
| return rotated |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Unreachable code Warning