Skip to content

More poloidal selectors#28

Merged
dschwoerer merged 31 commits into
mainfrom
more-poloidal-selectors
Jun 10, 2026
Merged

More poloidal selectors#28
dschwoerer merged 31 commits into
mainfrom
more-poloidal-selectors

Conversation

@mikekryjak

@mikekryjak mikekryjak commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

This PR adds more poloidal selectors, adds 2D selection and improves plot_region.

New selection system

Selectors

The workflow starts with selectors.

selector_poloidal returns a poloidal index or slice, e.g.
xhermes.selector_poloidal("sol")

selector_radial returns a radial index or slice, e.g.
xhermes.selector_radial("domain")

xhermes.selector_2d returns a tuple of indices/slices and takes both a radial and poloidal selection. It has handling of incompatible combinations and can automatically parse a boundary radial selection into a radial boundary appropriate to the poloidal region. e.g.
xhermes.selector_2d("boundary", "sol")

Dataset selection

The selectors can be used to select a region of the dataset using the same syntax as selector_2d, e.g.
ds.hermes.select_region("domain", "outer_lower_target")

This can be plotted to visually check what is being selected:
xhermes.plot_selection("domain", "outer_lower_target")

Conventions

It is assumed that the midplane is always at a cell boundary. A poloidal index is provided for the cell centre above the midplane (e.g. outer_upper_midplane) and below (e.g. outer_lower_midplane). In double null topologies, they are calculated from the branch cuts. In single null topologies, they are calculated based on the R gradient changing sign.

X-point poloidal indices are provided for each target, e.g. outer_lower_xpoint for double null, or outer_xpoint for single null. The convention is that this point always corresponds to the first point in the divertor region. This is because it is assumed that the main use of this feature is to mark the X-point on plots along the field line.

Misc improvements

  • extract_2d_tokamak_data and its 1D equivalent is now automatically run on load
  • Fixed species lists and other similar metadata not being correctly written on load
  • Rename dl to dpol and add dtor

Docs

Docs are provided in the form of a tutorial notebook in xhermes/examples/.

Next steps / sdtools:

This PR lays the groundwork for the implementation of two key functions from sdtools:
get_1d_poloidal_data and get_1d_radial_data.

sdtools itself has been updated to use this system here:
mikekryjak/sdtools#6

dschwoerer and others added 24 commits May 19, 2026 23:32
Need the flexibility to plot an arbitrary selection, not just a named region. This also makes nomenclature consistent with sdtools.
It can plot either the RZ or poloidal grid
Now no longer relies on try/except for selections which are unavailable in a particular topology, which was bad design. Also correctly saves and retrieves the reference data.
Now RZ plot doesn't have the pink shading which can hide region boundaries. Also reduced font size in legend.
The guards can be either guard replaced or removed by the user. This is much easier than adding guards to the selection later.
Update for fix in yguards, add image generation
This has many advantages, especially because it allows you to easily see if a region is missing (due to wrong topology or not being implemented).
They were in the metadata, so Xarray had to compare them for many operations, and slices are not comparable as it turns out
- Add more poloidal selections and finish test
- Now radial selections are explicit instead of bundled into combined regions "e.g. SOL boundary"

# Conflicts:
#	tests/test_slice_poloidal.py
Now there is a separate radial and poloidal selector. The combined 2D selection always needs the radial, then the poloidal region.
select_2d now has the function of ensuring the radial and poloidal choices make sense and handle special cases.
Also added an example notebook and tests.

Co-authored-by: Copilot <copilot@github.com>
This resolves a big confusor - the select_... tools return selectors, while ds.select_region returns an actual selected region. Now that the names are different, it should be clearer.

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Previously ixseps1 was used instead of ixseps1g etc, breaking radial indexing when guards were removed - something that is handled properly for datasets already.
I added a grid with guards removed to both the DN and SN tests in both poloidal and radial selector tests.

Co-authored-by: Copilot <copilot@github.com>
@mikekryjak mikekryjak force-pushed the more-poloidal-selectors branch from b50128e to a134dea Compare June 10, 2026 09:06
@mikekryjak mikekryjak force-pushed the more-poloidal-selectors branch from a134dea to dd8ad52 Compare June 10, 2026 09:50

@dschwoerer dschwoerer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dschwoerer dschwoerer merged commit cf59f47 into main Jun 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants