sunpy: Error trying to set observer to heliographic_carrington coord
I am trying to set the observer of a helioprojective coord to a coordinate in a heliographic_carrington frame, using the following code:
from astropy.coordinates import SkyCoord
import astropy.units as u
import sunpy.coordinates
observer = SkyCoord(0 * u.deg, 0 * u.deg, 1 * u.m,
frame='heliographic_carrington', obstime='now')
ref_coord = SkyCoord(0.0, 0.0, frame='helioprojective', obstime='now',
unit='deg', observer=observer)
however this gives me the error:
File "test.py", line 7, in <module>
ref_coord = SkyCoord(0.0, 0.0, frame='helioprojective', obstime='now',
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py", line 256, in __init__
frame_cls(**frame_kwargs), args, kwargs)
File "/Users/dstansby/github/sunpy/sunpy/coordinates/frames.py", line 109, in __init__
super().__init__(*args, **kwargs)
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/baseframe.py", line 601, in __init__
values[fnm] = getattr(self, fnm)
File "/Users/dstansby/github/sunpy/sunpy/coordinates/frameattributes.py", line 141, in __get__
return super().__get__(instance, frame_cls=frame_cls)
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/attributes.py", line 103, in __get__
out, converted = self.convert_input(out)
File "/Users/dstansby/github/sunpy/sunpy/coordinates/frameattributes.py", line 105, in convert_input
return super().convert_input(value)
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/attributes.py", line 445, in convert_input
transformedobj = value.transform_to(self._frame)
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py", line 443, in transform_to
new_coord = trans(self.frame, generic_frame)
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/transformations.py", line 1392, in __call__
curr_coord = t(curr_coord, curr_toframe)
File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/astropy/coordinates/transformations.py", line 995, in __call__
return supcall(fromcoord, toframe)
File "/Users/dstansby/github/sunpy/sunpy/coordinates/transformations.py", line 176, in wrapped_func
result = func(*args, **kwargs)
File "/Users/dstansby/github/sunpy/sunpy/coordinates/transformations.py", line 299, in hgc_to_hgs
_check_observer_defined(hgccoord)
File "/Users/dstansby/github/sunpy/sunpy/coordinates/transformations.py", line 220, in _check_observer_defined
raise ConvertError("This transformation cannot be performed because the "
astropy.coordinates.errors.ConvertError: This transformation cannot be performed because the HeliographicCarrington frame has observer=None.
I’m guessing this is something to do with heliographic coords becoming observer based, but I’m not sure how an observer coordinate can itself have an observer attribute? Or perhaps I’m doing something wrong here?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (16 by maintainers)
@dstansby I suggest you hold off; I’m actively trying something right now
Cool, I might have a go at attacking that issue, since I am keen to migrate my code away from sunpy 1.1.
I think this is the same issue we work around in mapbase here: https://github.com/sunpy/sunpy/blob/master/sunpy/map/mapbase.py#L860-L877
but @ayshih will have answers.
It depends on what you mean with the assertion that the two Carrington coordinates are “identical”. If you mean that the component values are the same, then no, the two coordinates will be different when transformed to a non-Carrington frame.
HeliographicCarringtonaccounts for Carrington rotation, so there’d be a heliographic-longitude difference of 0.9 AU divided by the speed of light times the Carrington rotation rate.If the coordinates are not at all close to being on the surface of the Sun, the
HeliographicCarringtonframe may not be an sensible frame to use. It’s really meant (now) for co-aligning images of the surface of the Sun (or at low solar altitudes).HGC needs an observer to be able to calculate light travel time to the Sun as of #3782 to enable it to be used for co-aligning data. See https://docs.sunpy.org/en/latest/code_ref/coordinates/carrington.html for a very detailed description.