Skip to content

[2.4.0] test_crop_by_extra_coords_values_all_axes_with_coord fails during build time #913

Open

Description

@olebole

Describe the bug

When running pytest during package build, I see the following failure:

_____________ test_crop_by_extra_coords_values_all_axes_with_coord _____________

ndcube_3d_ln_lt_l_ec_all_axes = <ndcube.ndcube.NDCube object at 0x7fdac83fdb30>
NDCube
------
Shape: (2, 3, 4)
Physical Types of Axes: [('custom:pos.h...ive.lat', 'custom:pos.helioprojective.lon', 'custom:PIXEL'), ('em.wl', 'custom:SPATIAL')]
Unit: None
Data Type: float64

    def test_crop_by_extra_coords_values_all_axes_with_coord(ndcube_3d_ln_lt_l_ec_all_axes):
        cube = ndcube_3d_ln_lt_l_ec_all_axes
        interval0 = [3 * 60 * 60, 8 * 60 * 60] * u.s
        interval1 = [0, 1] * u.pix
        interval2 = [1, 3] * u.m
        lower_corner = (interval0[0], interval1[0], interval2[0])
        upper_corner = (interval0[1], interval1[1], interval2[1])
>       output = cube.crop_by_values(lower_corner, upper_corner, wcs=cube.extra_coords)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

../../../ndcube/tests/test_ndcube_slice_and_crop.py:483: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../ndcube/ndcube.py:658: in crop_by_values
    item = self._get_crop_by_values_item(*points, units=units, wcs=wcs, keepdims=keepdims)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../ndcube/utils/cube.py:58: in wcs_wrapper
    return func(*params.args, **params.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../ndcube/ndcube.py:695: in _get_crop_by_values_item
    return utils.cube.get_crop_item_from_points(points, wcs, True, keepdims=keepdims,
../../../ndcube/utils/cube.py:184: in get_crop_item_from_points
    point_pixel_indices = (sliced_wcs.world_to_pixel_values(*sliced_point) if crop_by_values
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../ndcube/wcs/wrappers/compound_wcs.py:127: in world_to_pixel_values
    pixel_arrays_sub = w.world_to_pixel_values(*world_arrays_sub)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3/dist-packages/gwcs/api.py:121: in world_to_pixel_values
    result = self.invert(*world_arrays)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3/dist-packages/gwcs/wcs/_wcs.py:351: in invert
    if is_high_level(*args, low_level_wcs=self):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

low_level_wcs = <WCS(output_frame=CompositeFrame, input_frame=Frame-8546, forward_transform=Model: CompoundModel
Inputs: ('x0', 'x1', ... 2.] pix)>

    [2]: <Tabular1D(points=(<Quantity [0., 1., 2., 3.] pix>,), lookup_table=[0. 1. 2. 3.] m)>
Parameters:)>
args = (<Quantity 10800. s>, <Quantity 0. pix>, <Quantity 1. m>)

    def is_high_level(*args, low_level_wcs):
        """
        Determine if args matches the high level classes as defined by
        ``low_level_wcs``.
        """
        if len(args) != len(low_level_wcs.world_axis_object_classes):
            return False
    
        type_match = [
            (type(arg), waoc[0])
            for arg, waoc in zip(
                args, low_level_wcs.world_axis_object_classes.values(), strict=False
            )
        ]
    
        types_are_high_level = [argt is t for argt, t in type_match]
    
        if all(types_are_high_level):
            return True
    
        if any(types_are_high_level):
            msg = (
                "Invalid types were passed, got "
                f"({', '.join(tm[0].__name__ for tm in type_match)}) expected "
                f"({', '.join(tm[1].__name__ for tm in type_match)})."
            )
>           raise TypeError(msg)
E           TypeError: Invalid types were passed, got (Quantity, Quantity, Quantity) expected (Time, Quantity, Quantity).

/usr/lib/python3/dist-packages/gwcs/utils.py:508: TypeError

System Details

  • Python 3.13 and 3.14
  • asdf 5.1.0
  • asdf-standard 1.4.0
  • asdf-transform-schemas 0.6.0
  • asdf-coordinates-schemas 0.4.0
  • asdf-wcs-schemas 0.5.0
  • asdf-astropy 0.9.0

All dependencies are from Debian testing.

Installation method

From github, while building a .deb package.

Activity

  1. Cadair commented on Jan 22, 2026

    @Cadair
    SponsorMember

    Thanks for the issue as always!

    What version of gwcs are you running?

  2. olebole commented on Jan 27, 2026

    @olebole
    Author

    This is with gwcs 1.0; sorry that I forgot to mention it (was obvious that this version info is relevant).

  3. Cadair commented on Jan 27, 2026

    @Cadair
    SponsorMember

    yeah this seems to be a known bug with gwcs 1.0, I haven't had a chance to look into it yet.

  4. olebole commented on Jan 27, 2026

    @olebole
    Author

    There is gwcs 1.0.1 out, maybe that fixed it.

  5. WilliamJamieson commented on Jan 29, 2026

    @WilliamJamieson

    This issue was introduced by spacetelescope/gwcs#635.

    This issue appears to be an APE 14 issue. Basically world_to_pixel_values and pixel_to_world_values should only accept "low-level" (numerical array) inputs. Per APE 14 quantities are considered "high-level" inputs and that is what ndcube is passing the world_to_pixel_values function of the GWCS. PR spacetelescope/gwcs#635 changed stuff internally so that the "level" of the inputs to world_to_pixel_values is now being checked. Before it was simply assuming you passed numerical arrays which accidentally managed to make it through everything without breaking.

    What is interesting here is that the "high-level" inputs for the WCS in this case are (astropy.time.Time, Quantity, Quantity) but ndcube is actually passing (Quantity, Quantity, Quantity) the first quantity is a value with a time unit not an astropy.time.Time. This means that the input causing the gwcs error is actually a mix of "not-high-level" and "high-level" inputs so it fails because the inputs are not self consistent with the "level".

    In reality, the fix is that ndcube needs to only pass numerical arrays to the wcs in this case.

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

    BugProbably a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions