Skip to content

When trying to plot quadrangles with a transform to VBI WCS there appears to be a unit error #424

@Cadair

Description

@Cadair
import astropy.units as u
import matplotlib.pyplot as plt

import dkist
import dkist.net
from sunpy.net import Fido, attrs as a
import sunpy.map

asdf_path = Fido.fetch(Fido.search(a.dkist.Dataset("ARVLR")), path="/data/dkist/prod/{primary_proposal_id}/{dataset_id}")

tds = dkist.load_dataset(asdf_path)

aia_context = Fido.fetch(
    Fido.search(
        a.Instrument.aia,
        a.Time(tds.inventory["startTime"], tds.inventory["endTime"], tds.inventory["startTime"]),
        a.Wavelength(19.3*u.nm)
        )
    )


aia = sunpy.map.Map(aia_context)
bounding_boxes = []
for tile in tds.flat:
    tile = tile[0]  # Use the first frame
    corners = [[0, tile.data.shape[0]], [0, tile.data.shape[1]]] * u.pix
    bounding_boxes.append(corners)

fig = plt.figure()
ax = plt.subplot(projection=aia)
aia.plot(axes=ax)
for i, tile_bb in enumerate(bounding_boxes):
    aia.draw_quadrangle(tile_bb[0], top_right=tile_bb[1], edgecolor=f"C{i}", transform=ax.get_transform(tds.flat[i][0].wcs))

plt.show()
See full traceback
ValueError: Latitude angle(s) must be within -90 deg <= angle <= 90 deg, got [332.32139296 332.32139296 332.32139296 332.32139296 332.32139296, ... ]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File <string>:33

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/units/decorators.py:313, in QuantityInput.__call__.<locals>.wrapper(*func_args, **func_kwargs)
    311 # Call the original function with any equivalencies in force.
    312 with add_enabled_equivalencies(self.equivalencies):
--> 313     return_ = wrapped_function(*func_args, **func_kwargs)
    315 # Return
    316 ra = wrapped_signature.return_annotation

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/sunpy/map/mapbase.py:2294, in GenericMap.draw_quadrangle(self, bottom_left, width, height, axes, top_right, **kwargs)
   2292 kwergs.update(kwargs)
   2293 quad = Quadrangle(anchor, width, height, **kwergs)
-> 2294 axes.add_patch(quad)
   2295 return quad

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/axes/_base.py:2384, in _AxesBase.add_patch(self, p)
   2382 if p.get_clip_path() is None:
   2383     p.set_clip_path(self.patch)
-> 2384 self._update_patch_limits(p)
   2385 self._children.append(p)
   2386 p._remove_method = self._children.remove

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/axes/_base.py:2426, in _AxesBase._update_patch_limits(self, patch)
   2424         updatey = False
   2425 trf_to_data = patch_trf - self.transData
-> 2426 xys = trf_to_data.transform(vertices)
   2427 self.update_datalim(xys, updatex=updatex, updatey=updatey)

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/transforms.py:1495, in Transform.transform(self, values)
   1492 values = values.reshape((-1, self.input_dims))
   1494 # Transform the values
-> 1495 res = self.transform_affine(self.transform_non_affine(values))
   1497 # Convert the result back to the shape of the input values.
   1498 if ndim == 0:

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/_api/deprecation.py:297, in rename_parameter.<locals>.wrapper(*args, **kwargs)
    292     warn_deprecated(
    293         since, message=f"The {old!r} parameter of {func.__name__}() "
    294         f"has been renamed {new!r} since Matplotlib {since}; support "
    295         f"for the old name will be dropped %(removal)s.")
    296     kwargs[new] = kwargs.pop(old)
--> 297 return func(*args, **kwargs)

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/transforms.py:2419, in CompositeGenericTransform.transform_non_affine(self, values)
   2417     return self._a.transform_non_affine(values)
   2418 else:
-> 2419     return self._b.transform_non_affine(self._a.transform(values))

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/_api/deprecation.py:297, in rename_parameter.<locals>.wrapper(*args, **kwargs)
    292     warn_deprecated(
    293         since, message=f"The {old!r} parameter of {func.__name__}() "
    294         f"has been renamed {new!r} since Matplotlib {since}; support "
    295         f"for the old name will be dropped %(removal)s.")
    296     kwargs[new] = kwargs.pop(old)
--> 297 return func(*args, **kwargs)

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/matplotlib/transforms.py:2419, in CompositeGenericTransform.transform_non_affine(self, values)
   2417     return self._a.transform_non_affine(values)
   2418 else:
-> 2419     return self._b.transform_non_affine(self._a.transform(values))

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/visualization/wcsaxes/transforms.py:126, in CoordinateTransform.transform(self, input_coords)
    122 input_coords = input_coords * u.deg
    123 x_in, y_in = input_coords[:, 0], input_coords[:, 1]
    125 c_in = SkyCoord(
--> 126     UnitSphericalRepresentation(x_in, y_in), frame=self.input_system
    127 )
    129 # We often need to transform arrays that contain NaN values, and filtering
    130 # out the NaN values would have a performance hit, so instead we just pass
    131 # on all values and just ignore Numpy warnings
    132 with np.errstate(all="ignore"):

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/coordinates/representation/spherical.py:55, in UnitSphericalRepresentation.__init__(self, lon, lat, differentials, copy)
     54 def __init__(self, lon, lat=None, differentials=None, copy=True):
---> 55     super().__init__(lon, lat, differentials=differentials, copy=copy)

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/coordinates/representation/base.py:643, in BaseRepresentation.__init__(self, differentials, *args, **kwargs)
    641 def __init__(self, *args, differentials=None, **kwargs):
    642     # Handle any differentials passed in.
--> 643     super().__init__(*args, **kwargs)
    644     if differentials is None and args and isinstance(args[0], self.__class__):
    645         differentials = args[0]._differentials

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/coordinates/representation/base.py:205, in BaseRepresentationOrDifferential.__init__(self, *args, **kwargs)
    201         raise TypeError(f"unexpected keyword arguments: {kwargs}")
    203 # Pass attributes through the required initializing classes.
    204 attrs = [
--> 205     self.attr_classes[component](attr, copy=copy, subok=True)
    206     for component, attr in zip(components, attrs)
    207 ]
    208 try:
    209     bc_attrs = np.broadcast_arrays(*attrs, subok=True)

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/coordinates/angles/core.py:604, in Latitude.__new__(cls, angle, unit, **kwargs)
    602     raise TypeError("A Latitude angle cannot be created from a Longitude angle")
    603 self = super().__new__(cls, angle, unit=unit, **kwargs)
--> 604 self._validate_angles()
    605 return self

File ~/.virtualenvs/dkist/lib/python3.12/site-packages/astropy/coordinates/angles/core.py:635, in Latitude._validate_angles(self, angles)
    632     angles_view = angles_view[np.newaxis]
    634 if np.any(np.abs(angles_view) > limit):
--> 635     raise ValueError(
    636         "Latitude angle(s) must be within -90 deg <= angle <= 90 deg, "
    637         f"got {angles.to(u.degree)}"
    638     )

ValueError: Latitude angle(s) must be within -90 deg <= angle <= 90 deg, got [332.32139296 332.32139296 332.32139296 332.32139296 332.32139296, ... ]

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