Skip to content

conform7 VCV propagation raises ValueError with NumPy ≥ 2.x #181

Open

Description

@BatchelorJ

When a vcv is passed to conform7 and the transformation has a tf_sd, the call fails while building the Jacobian. Every function that calls conform7 with a vcv fails too: conform14, plate_motion_transformation, transform_atrf2014_to_gda2020 and transform_gda2020_to_atrf2014, and both MGA94↔MGA2020 functions.

To reproduce

import numpy as np
from geodepy.transform import conform7
from geodepy.constants import gda94_to_gda2020

conform7(-4052051.7643, 4212836.2017, -2545106.0245,
         gda94_to_gda2020, vcv=np.diag([1e-4, 1e-4, 1e-4]))
TypeError: only 0-dimensional arrays can be converted to Python scalars
...
  File "geodepy/transform.py", line 98, in conform7
    j_mat[0, 3] = rot_xyz[0]
ValueError: setting an array element with a sequence.

Environment: NumPy 2.4.2, Python 3.14.

Cause

xyz_before and rot_xyz are 3×1 column vectors, so rot_xyz[0] and xyz_before[2] return 1-element arrays of shape (1,) rather than scalars. Assigning them to single cells of j_mat (transform.py:98-108) depended on NumPy converting size-1 arrays to scalars implicitly. NumPy deprecated that in 1.25 and now raises an error. The transformed coordinates are unaffected because lines 59–61 already index with [i][0].

The existing tests didn't catch this because none of them passes a vcv.

Proposed fix

Index the scalars explicitly (rot_xyz[i, 0], xyz_before[i, 0]), or work with 1-D vectors throughout:

xyz_before = np.array([x, y, z])
rot_xyz = rotation @ xyz_before
...
j_mat[:, 0:3] = scale * rotation
j_mat[:, 3] = rot_xyz
j_mat[0, 5], j_mat[0, 6] = -scale * z, scale * y
j_mat[1, 4], j_mat[1, 6] = scale * z, -scale * x
j_mat[2, 4], j_mat[2, 5] = -scale * y, scale * x
j_mat[:, 7:10] = np.eye(3)

After the fix, the Jacobian matches a finite-difference check to within about 5×10⁻⁷ per column, so only the indexing needs to change.

Suggested regression test (ALIC, GDA2020 Tech Manual §3.1.1, input VCV = diag(1e-4) m²)

Expected vcv_out (m²):

[[ 1.007199e-04  -1.221569e-07   7.888910e-08]
 [-1.221569e-07   1.006026e-04  -7.672700e-08]
 [ 7.888910e-08  -7.672700e-08   1.006438e-04]]

The transformation adds about 0.85, 0.78 and 0.80 mm (1σ) in X, Y and Z.


Bug Report Created with Claude 🤖

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions