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

fix Transform.from_points for scalar spatial points #1184

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/1184.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :meth:`geovista.bridge.Transform.from_points` to create a mesh from
scalar spatial points. (:user:`bjlittle`)
4 changes: 2 additions & 2 deletions src/geovista/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ def to_cartesian(
.. versionadded:: 0.1.0

"""
lons = np.asanyarray(lons)
lats = np.asanyarray(lats)
lons = np.atleast_1d(lons)
lats = np.atleast_1d(lats)

if (shape := lons.shape) != lats.shape:
emsg = (
Expand Down
9 changes: 9 additions & 0 deletions tests/bridge/test_from_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ def test_transform_points(lam_uk_sample, wgs84_wkt, proj):
assert result[GV_FIELD_CRS] == wgs84_wkt
expected = to_cartesian(lons, lats)
np.testing.assert_array_almost_equal(result.points, expected)


def test_scalar():
"""Test scalar and single element mixture of xs/ys."""
expected = np.array([[0.0, 0.0, 1.0]])
np.testing.assert_array_equal(Transform.from_points(0, 90).points, expected)
np.testing.assert_array_equal(Transform.from_points(0, [90]).points, expected)
np.testing.assert_array_equal(Transform.from_points([0], 90).points, expected)
np.testing.assert_array_equal(Transform.from_points([0], [90]).points, expected)
9 changes: 9 additions & 0 deletions tests/common/test_to_cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def test_zlevel_broadcast_fail():
_ = to_cartesian(lons, lats, zlevel=zlevel)


def test_scalar():
"""Test scalar and single element mixture of lons/lats."""
expected = np.array([[0.0, 0.0, 1.0]])
np.testing.assert_array_equal(to_cartesian(0, 90), expected)
np.testing.assert_array_equal(to_cartesian(0, [90]), expected)
np.testing.assert_array_equal(to_cartesian([0], 90), expected)
np.testing.assert_array_equal(to_cartesian([0], [90]), expected)


@pytest.mark.parametrize("stacked", [True, False])
def test_defaults(lam_uk_sample, stacked):
"""Test expected defaults are honoured."""
Expand Down