-
Notifications
You must be signed in to change notification settings - Fork 0
Docs/visualization training #29
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
397b227
add training for visualization actor
SBlokhuizen c5e3e81
add nomachine warning
SBlokhuizen a0e4ed0
clarify docs
SBlokhuizen 4fab897
clarify docs
SBlokhuizen e1a5e98
choose random port by default
SBlokhuizen a5d5244
add test machine description training
SBlokhuizen 2582dff
fix machine description example
SBlokhuizen 4ae67be
add exercise for loading machine description
SBlokhuizen a08e043
linting
SBlokhuizen 241bcf1
fix typos
SBlokhuizen e8928ac
add gif
SBlokhuizen 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
89 changes: 89 additions & 0 deletions
89
imas_muscle3/visualization/examples/machine_description/machine_description.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,89 @@ | ||
| """ | ||
| Example that plots the following: | ||
| - First wall and divertor from machine description IDS. | ||
| - Boundary outline from an equilibrium IDS | ||
| """ | ||
|
|
||
| import holoviews as hv | ||
| import numpy as np | ||
| import panel as pn | ||
| import xarray as xr | ||
|
|
||
| from imas_muscle3.visualization.base_plotter import BasePlotter | ||
| from imas_muscle3.visualization.base_state import BaseState | ||
|
|
||
|
|
||
| class State(BaseState): | ||
| def extract(self, ids): | ||
| if ids.metadata.name == "equilibrium": | ||
| self.extract_equilibrium(ids) | ||
|
|
||
| def extract_equilibrium(self, ids): | ||
| ts = ids.time_slice[0] | ||
| outline = ts.boundary.outline | ||
|
|
||
| boundary_data = xr.Dataset( | ||
| { | ||
| "r": (("time", "point"), [outline.r]), | ||
| "z": (("time", "point"), [outline.z]), | ||
| }, | ||
| coords={ | ||
| "time": [ids.time[0]], | ||
| "point": np.arange(len(outline.r)), | ||
| }, | ||
| ) | ||
|
|
||
| current_data = self.data.get("equilibrium") | ||
| if current_data is None: | ||
| self.data["equilibrium"] = boundary_data | ||
| else: | ||
| self.data["equilibrium"] = xr.concat( | ||
| [current_data, boundary_data], dim="time", join="outer" | ||
| ) | ||
|
|
||
|
|
||
| class Plotter(BasePlotter): | ||
| DEFAULT_OPTS = hv.opts.Overlay( | ||
| xlim=(0, 13), | ||
| ylim=(-10, 10), | ||
| title="Wall and equilibrium boundary outline", | ||
| xlabel="r [m]", | ||
| ylabel="z [m]", | ||
| ) | ||
|
|
||
| def get_dashboard(self): | ||
| elements = [ | ||
| hv.DynamicMap(self._plot_boundary_outline), | ||
| hv.DynamicMap(self._plot_wall), | ||
| ] | ||
| overlay = hv.Overlay(elements).collate().opts(self.DEFAULT_OPTS) | ||
| return pn.pane.HoloViews(overlay, width=800, height=1000) | ||
|
|
||
| @pn.depends("time") | ||
| def _plot_boundary_outline(self): | ||
| state = self.active_state.data.get("equilibrium") | ||
|
|
||
| if state is not None and "r" in state and "z" in state: | ||
| selected_data = state.sel(time=self.time) | ||
| r = selected_data.r.values | ||
| z = selected_data.z.values | ||
| else: | ||
| r, z = [], [], "Waiting for data..." | ||
|
|
||
| return hv.Curve((r, z)).opts(self.DEFAULT_OPTS) | ||
|
|
||
| def _plot_wall(self): | ||
| """Generates path for limiter and divertor.""" | ||
| paths = [] | ||
| wall = self.active_state.md.get("wall") | ||
| if wall is not None: | ||
| for unit in wall.description_2d[0].limiter.unit: | ||
| name = str(unit.name) | ||
| r_vals = unit.outline.r | ||
| z_vals = unit.outline.z | ||
| paths.append((r_vals, z_vals, name)) | ||
| return hv.Path(paths, vdims=["name"]).opts( | ||
| color="black", | ||
| line_width=2, | ||
| hover_tooltips=[("", "@name")], | ||
| ) |
39 changes: 39 additions & 0 deletions
39
imas_muscle3/visualization/examples/machine_description/machine_description.ymmsl
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,39 @@ | ||
| ymmsl_version: v0.1 | ||
| model: | ||
| name: test_model | ||
| components: | ||
| source_component: | ||
| implementation: source_component | ||
| ports: | ||
| o_i: [equilibrium_out] | ||
| source_component_md: | ||
| implementation: source_component | ||
| ports: | ||
| o_i: [wall_out, pf_active_out] | ||
| visualization_component: | ||
| implementation: visualization_component | ||
| ports: | ||
| s: [equilibrium_in, pf_active_md_in, wall_md_in] | ||
| conduits: | ||
| source_component.equilibrium_out: visualization_component.equilibrium_in | ||
| source_component_md.wall_out: visualization_component.wall_md_in | ||
| source_component_md.pf_active_out: visualization_component.pf_active_md_in | ||
| settings: | ||
| source_component.source_uri: imas:hdf5?path=/home/ITER/blokhus/public/imasdb/ITER/4/666666/3/ | ||
| source_component_md.source_uri: imas:hdf5?path=/home/ITER/blokhus/public/imasdb/ITER/4/666666/3/ | ||
| visualization_component.plot_file_path: /home/ITER/blokhus/projects/IMAS-MUSCLE3/imas_muscle3/visualization/examples/machine_description/machine_description.py | ||
| visualization_component.keep_alive: true | ||
| implementations: | ||
| visualization_component: | ||
| executable: python | ||
| args: -u -m imas_muscle3.actors.visualization_component | ||
| source_component: | ||
| executable: python | ||
| args: -u -m imas_muscle3.actors.source_component | ||
| resources: | ||
| source_component: | ||
| threads: 1 | ||
| source_component_md: | ||
| threads: 1 | ||
| visualization_component: | ||
| threads: 1 |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.