Repository navigation
Closed
Labels
Description
Description
Assume I have the pointing position of my telescope in AltAz frame and I know that it did not track (i.e. the coordinates stay constant in AltAz) and I want to know the ICRS coordinates of my pointing position as time evolves:
import numpy as np
from astropy.coordinates import SkyCoord, AltAz, EarthLocation
from astropy.time import Time
import astropy.units as u
obstime = Time.now()
location = EarthLocation.of_site('Roque de Los Muchachos')
frame1 = AltAz(location=location, obstime=obstime)
coord1 = SkyCoord(alt=80 * u.deg, az=0 * u.deg, frame=frame1)
print(coord1.icrs)
frame2 = AltAz(location=location, obstime=obstime + np.linspace(0, 15, 50) * u.min)
coord2 = SkyCoord(alt=coord1.alt, az=coord1.az, frame=frame2)
print(coord2.icrs)This raises the following error:
<SkyCoord (ICRS): (ra, dec) in deg
(68.09412325, 38.71031085)>
Traceback (most recent call last):
File "/home/maxnoe/Projects/astropy/astropy/coordinates/attributes.py", line 112, in __get__
out = out._apply(np.broadcast_to, shape=instance_shape,
File "/home/maxnoe/Projects/astropy/astropy/time/core.py", line 1070, in _apply
jd1 = apply_method(jd1)
File "/home/maxnoe/Projects/astropy/astropy/time/core.py", line 1060, in <lambda>
apply_method = lambda array: method(array, *args, **kwargs)
File "<__array_function__ internals>", line 180, in broadcast_to
File "/home/maxnoe/.local/anaconda/envs/astropy-dev/lib/python3.9/site-packages/numpy/lib/stride_tricks.py", line 412, in broadcast_to
return _broadcast_to(array, shape, subok=subok, readonly=True)
File "/home/maxnoe/.local/anaconda/envs/astropy-dev/lib/python3.9/site-packages/numpy/lib/stride_tricks.py", line 343, in _broadcast_to
raise ValueError('cannot broadcast a non-scalar to a scalar array')
ValueError: cannot broadcast a non-scalar to a scalar array
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/maxnoe/Projects/gammapy/gammapy/test_altaz.py", line 15, in <module>
coord2 = SkyCoord(alt=coord1.alt, az=coord1.az, frame=frame2)
File "/home/maxnoe/Projects/astropy/astropy/coordinates/sky_coordinate.py", line 347, in __init__
self._sky_coord_frame = frame_cls(copy=copy, **frame_kwargs)
File "/home/maxnoe/Projects/astropy/astropy/coordinates/builtin_frames/altaz.py", line 109, in __init__
super().__init__(*args, **kwargs)
File "/home/maxnoe/Projects/astropy/astropy/coordinates/baseframe.py", line 314, in __init__
values[fnm] = getattr(self, fnm)
File "/home/maxnoe/Projects/astropy/astropy/coordinates/attributes.py", line 118, in __get__
raise ValueError(
ValueError: attribute obstime should be scalar or have shape (), but is has shape (50,) and could not be broadcast.
Expected behavior
Getting the ICRS coordinates at the specified timestamps
Actual behavior
The Error above
Steps to Reproduce
Run the above snippet.
System Details
Tested using astropy 4.3 and a recent development version
Activity
maxnoe commentedon Mar 18, 2022
Replacing the creation of the second coordinate with the somewhat cumbersome:
works
ayshih commentedon Mar 19, 2022
I'll note that this issue is essentially a duplicate of #11184 and strongly related to #5982, and I suspect that #12968 is likely too brute force of a solution.
mhvk commentedon Mar 20, 2022
Hmm, yes, similar to #11184, though I like the explicitness of this example. I think we've been moving to the idea that it should be possible for the attributes to have more dimensions than the actual data, but the question remains how best to deal with it. The real question is whether the shape of the frame should always equal the shape of the underlying data. If so, then the data should be broadcast as needed in
BaseFrame.__init__. But perhaps one can get away with the frame's shape being the broadcast shape of the data and all the attributes (as the PR does)? Overall, I think that will add too much complication, e.g., in dealing with slices, etc. (where currently data is always just slices, while attributes are either passed on if they are scalar, or sliced as well; the attribute shapes are also either the frame shape or scalar).So, bottom line is that I think one should internally do broadcasting of the data if needed.
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes
Broadcast frames over both data and attributes (#15121)
maxnoe commentedon Oct 3, 2023
Oh wow, thanks so much!