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

BUG: Normal vectors in SlicePlot doesn't understand non-cartesian coordinate systems #3528

Closed
neutrinoceros opened this issue Sep 26, 2021 · 1 comment · Fixed by #3489
Closed
Labels
api-consistency naming conventions, code deduplication, informative error messages, code smells... bug coordinates: non-cartesian

Comments

@neutrinoceros
Copy link
Member

Bug report

Good news, this one already has a fix waiting in #3489, but I'm reporting it independently because it wasn't my main motivation in that PR and I actually encountered this bug now.

Bug summary
because SlicePlot instantiates OffAxisSlicePlot as well as AxisAlignedSlicePlot classes based on the value of the normal argument, it implements some magic to transcribe special values of normal vectors into strings, namely:

(1, 0, 0) -> "x"
(0, 1, 0) -> "y"
(0, 0, 1) -> "z"

The problem being that this correspondence is hard coded and doesn't account for the relevant geometry, so it only works with cartesian coordinates.

Code for reproduction

import yt

ds = yt.load_sample("bw_spherical_2d")
yt.SlicePlot(ds, (0, 0, 1), "density")

Actual outcome

Traceback
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ <ipython-input-7-f6eeb60e5811>:1 in <module>                                                     │
│                                                                                                  │
│ /Users/robcleme/dev/yt-project/yt/yt/visualization/plot_window.py:2484 in SlicePlot              │
│                                                                                                  │
│   2481 │   │   │   )                                                                             │
│   2482 │   │   │   del kwargs["north_vector"]                                                    │
│   2483 │   │                                                                                     │
│ ❱ 2484 │   │   return AxisAlignedSlicePlot(ds, normal, fields, *args, **kwargs)                  │
│   2485                                                                                           │
│   2486                                                                                           │
│   2487 def plot_2d(                                                                              │
│                                                                                                  │
│ /Users/robcleme/dev/yt-project/yt/yt/visualization/plot_window.py:1584 in __init__               │
│                                                                                                  │
│   1581 │   ):                                                                                    │
│   1582 │   │   # this will handle time series data and controllers                               │
│   1583 │   │   axis = fix_axis(axis, ds)                                                         │
│ ❱ 1584 │   │   (bounds, center, display_center) = get_window_parameters(                         │
│   1585 │   │   │   axis, center, width, ds                                                       │
│   1586 │   │   )                                                                                 │
│   1587 │   │   if field_parameters is None:                                                      │
│                                                                                                  │
│ /Users/robcleme/dev/yt-project/yt/yt/visualization/plot_window.py:77 in get_window_parameters    │
│                                                                                                  │
│     74                                                                                           │
│     75                                                                                           │
│     76 def get_window_parameters(axis, center, width, ds):                                       │
│ ❱   77 │   width = ds.coordinates.sanitize_width(axis, width, None)                              │
│     78 │   center, display_center = ds.coordinates.sanitize_center(center, axis)                 │
│     79 │   xax = ds.coordinates.x_axis[axis]                                                     │
│     80 │   yax = ds.coordinates.y_axis[axis]                                                     │
│                                                                                                  │
│ /Users/robcleme/dev/yt-project/yt/yt/geometry/coordinates/spherical_coordinates.py:304 in        │
│ sanitize_width                                                                                   │
│                                                                                                  │
│   301 │   │   return center, display_center                                                      │
│   302 │                                                                                          │
│   303 │   def sanitize_width(self, axis, width, depth):                                          │
│ ❱ 304 │   │   name = self.axis_name[axis]                                                        │
│   305 │   │   if width is not None:                                                              │
│   306 │   │   │   width = super().sanitize_width(axis, width, depth)                             │
│   307 │   │   elif name == "r":                                                                  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'z'

Expected outcome

Should be equivalent to

yt.SlicePlot(ds, "phi", "density")
@neutrinoceros neutrinoceros added bug api-consistency naming conventions, code deduplication, informative error messages, code smells... labels Sep 26, 2021
@neutrinoceros neutrinoceros linked a pull request Sep 26, 2021 that will close this issue
2 tasks
@matthewturk
Copy link
Member

We have long punted on properly addressing this, but the recent changes to the API for slice plots (esp re:Normal vectors) make this much more feasible.

@neutrinoceros neutrinoceros changed the title BUG: Normal vectors in SlicePlot doens't understand non-cartesian coordinate systems BUG: Normal vectors in SlicePlot doesn't understand non-cartesian coordinate systems Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-consistency naming conventions, code deduplication, informative error messages, code smells... bug coordinates: non-cartesian
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants