Skip to content

Commit

Permalink
Make polygon() use standard sepx plotter
Browse files Browse the repository at this point in the history
Also modified plotter to accept style kwargs
  • Loading branch information
mikekryjak committed Mar 22, 2024
1 parent 1a38a49 commit d76febe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
28 changes: 2 additions & 26 deletions xbout/plotting/plotfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ def plot2d_polygon(
add_colorbar = True,
colorbar_label = None,
separatrix = True,
separatrix_kwargs = {"color":"white", "linestyle":"-", "linewidth":1},
targets = False,
add_limiter_hatching=True,
grid_only = False,
Expand Down Expand Up @@ -945,32 +946,7 @@ def plot2d_polygon(
ax.set_title(da.name)

if separatrix:
# plot_separatrices(da, ax, x = "R", y = "Z")
plot_separatrices(da, ax, x = "R", y = "Z", **separatrix_kwargs)

color = "white"
ls = "-"
lw = 2

m = da.attrs["metadata"]



if m["topology"] == "connected-double-null":

# TODO: test this for single null
if m["MXG"] > 0 or m["MYG"] > 0:
lhs = (m["ixseps1"] + 1 - m["MXG"], slice(0,m["ny_inner"] + m["MYG"] * int(4/2)))
rhs = (m["ixseps1"] + 1 - m["MXG"], slice(m["ny_inner"]+m["MYG"]*(4 - 1), None))
else:
lhs = (m["ixseps1"]-m["MXG"]-1, slice(0,m["ny_inner"]))
rhs = (m["ixseps1"]-m["MXG"]-1, slice(m["ny_inner"], None))
ax.plot(da["Rxy_lower_right_corners"].data[lhs], da["Zxy_lower_right_corners"].data[lhs], c = color, lw = lw, ls = ls)
ax.plot(da["Rxy_lower_right_corners"].data[rhs], da["Zxy_lower_right_corners"].data[rhs], c = color, lw = lw, ls = ls)

if m["topology"] == "single-null":
points = (m["ixseps1"]-m["MXG"]-1, slice(0,None))
ax.plot(da["Rxy_lower_right_corners"].data[points], da["Zxy_lower_right_corners"].data[points], c = color, lw = lw, ls = ls)


if targets:
plot_targets(da, ax, x = "R", y = "Z", hatching = add_limiter_hatching)
12 changes: 9 additions & 3 deletions xbout/plotting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def _is_core_only(da):
return ix1 >= nx and ix2 >= nx


def plot_separatrices(da, ax, *, x="R", y="Z"):
"""Plot separatrices"""
def plot_separatrices(da, ax, *, x="R", y="Z", **kwargs):
"""
Plot separatrices. Kwargs are passed to ax.plot().
"""

if not isinstance(da, dict):
da_regions = _decompose_regions(da)
Expand Down Expand Up @@ -116,7 +118,11 @@ def plot_separatrices(da, ax, *, x="R", y="Z"):
y_sep = 0.5 * (
da_region[y].isel(**{xcoord: 0}) + da_inner[y].isel(**{xcoord: -1})
)
ax.plot(x_sep, y_sep, "k--")
default_style = {"color": "black", "linestyle": "--"}
if any(x for x in kwargs if x in ["c", "ls"]):
raise ValueError("When passing separatrix plot style kwargs, use 'color' and 'linestyle' instead lf 'c' and 'ls'")
style = {**default_style, **kwargs}
ax.plot(x_sep, y_sep, **style)


def plot_targets(da, ax, *, x="R", y="Z", hatching=True):
Expand Down

0 comments on commit d76febe

Please sign in to comment.