yt-project/yt

BUG: convert_to_cartesian from _sanitize_center fails for Geographic geometry when bbox is subset of globe

chrishavlin opened this issue · 0 comments

Bug report

Geographic data that doesn't cover the full latitude/longitude range errors when plotting.

Code for reproduction

import yt 
import numpy as np
dshp = (16,16,16)
data = {'density': np.random.random(dshp)}

bbox = np.array([[0, 1000], 
                [-150., -100.],   # longitude range 
                [-90., 90.]])

ds = yt.load_uniform_grid(data, dshp, geometry='geographic', 
                          bbox = bbox,
                          axis_order=('altitude', 'longitude', 'latitude'))

yt.SlicePlot(ds, 'altitude', 'density')

Actual outcome

>>> yt.SlicePlot(ds, 'altitude', 'density')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/chavlin/.pyenv/versions/yt_NASA_SMD/lib/python3.10/site-packages/yt/visualization/plot_window.py", line 1821, in __init__
    (bounds, center, display_center) = get_window_parameters(
  File "/Users/chavlin/.pyenv/versions/yt_NASA_SMD/lib/python3.10/site-packages/yt/visualization/plot_window.py", line 71, in get_window_parameters
    center, display_center = ds.coordinates.sanitize_center(center, axis)
  File "/Users/chavlin/.pyenv/versions/yt_NASA_SMD/lib/python3.10/site-packages/yt/geometry/coordinates/geographic_coordinates.py", line 429, in sanitize_center
    center, display_center = super().sanitize_center(center, axis)
  File "/Users/chavlin/.pyenv/versions/yt_NASA_SMD/lib/python3.10/site-packages/yt/geometry/coordinates/coordinate_handler.py", line 331, in sanitize_center
    display_center = self.convert_to_cartesian(center)
  File "/Users/chavlin/.pyenv/versions/yt_NASA_SMD/lib/python3.10/site-packages/yt/geometry/coordinates/geographic_coordinates.py", line 335, in convert_to_cartesian
    theta = (90.0 - b) * np.pi / 180
  File "/Users/chavlin/.pyenv/versions/yt_NASA_SMD/lib/python3.10/site-packages/unyt/array.py", line 1931, in __array_ufunc__
    raise UnitOperationError(ufunc, u0, u1)
unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units 'dimensionless' (dimensions '1') and 'code_length' (dimensions '(length)') is not well defined.

Expected outcome

plot!

Version Information

  • yt version: '4.4.dev0'

Bug Origin

#4839 fixed the equations in convert_to_cartesian for geographic data but didn't account for units (and introduced a subtraction where previously there was only a multiplication) and we must not have any plotting tests for geographic data with subsets of the globe...