Repository navigation
Closed
Labels
Description
There is a test failure in coordinates in the 32bits job:
'NoneType' object has no attribute 'to_geodetic'
https://github.com/astropy/astropy/pull/11274/checks?check_run_id=1772534200
_______________ test_skyoffset[inradec0-expectedlatlon0-tolsep0] _______________
inradec = <Quantity [45., 45.] deg>, expectedlatlon = <Quantity [0., 0.] deg>
tolsep = <Quantity 0.001 arcsec>, originradec = <Quantity [45., 45.] deg>
@pytest.mark.parametrize("inradec,expectedlatlon, tolsep", [
((45, 45)*u.deg, (0, 0)*u.deg, .001*u.arcsec),
((45, 0)*u.deg, (0, -45)*u.deg, .001*u.arcsec),
((45, 90)*u.deg, (0, 45)*u.deg, .001*u.arcsec),
((46, 45)*u.deg, (1*np.cos(45*u.deg), 0)*u.deg, 16*u.arcsec),
])
def test_skyoffset(inradec, expectedlatlon, tolsep, originradec=(45, 45)*u.deg):
origin = ICRS(*originradec)
skyoffset_frame = SkyOffsetFrame(origin=origin)
skycoord = SkyCoord(*inradec, frame=ICRS)
skycoord_inaf = skycoord.transform_to(skyoffset_frame)
assert hasattr(skycoord_inaf, 'lon')
assert hasattr(skycoord_inaf, 'lat')
expected = SkyCoord(*expectedlatlon, frame=skyoffset_frame)
assert skycoord_inaf.separation(expected) < tolsep
# Check we can also transform back (regression test for gh-11254).
> roundtrip = skycoord_inaf.transform_to(ICRS())
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/tests/test_skyoffset_transformations.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py:627: in transform_to
return self.__class__(new_coord, **frame_kwargs)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py:323: in __init__
setattr(self, attr, skycoord_kwargs[attr])
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py:811: in __setattr__
frame_transform_graph.frame_attributes[attr].__get__(self)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/attributes.py:104: in __get__
out, converted = self.convert_input(out)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/attributes.py:451: in convert_input
transformedobj = value.transform_to(self._frame)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py:619: in transform_to
new_coord = trans(self.frame, generic_frame)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/transformations.py:1422: in __call__
curr_coord = t(curr_coord, curr_toframe)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/transformations.py:1025: in __call__
return supcall(fromcoord, toframe)
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/builtin_frames/icrs_observed_transforms.py:29: in icrs_to_altaz
astrom = erfa_astrom.get().apco(altaz_frame)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
frame_or_coord = <AltAz Frame (obstime=None, location=None, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0.0, obswl=1.0 micron)>
@staticmethod
def apco(frame_or_coord):
'''
Wrapper for ``erfa.apco``, used in conversions AltAz <-> ICRS and CIRS <-> ICRS
Arguments
---------
frame_or_coord: ``astropy.coordinates.BaseCoordinateFrame`` or ``astropy.coordinates.SkyCoord``
Frame or coordinate instance in the corresponding frame
for which to calculate the calculate the astrom values.
For this function, an AltAz or CIRS frame is expected.
'''
> lon, lat, height = frame_or_coord.location.to_geodetic('WGS84')
E AttributeError: 'NoneType' object has no attribute 'to_geodetic'
../../.tox/py38-test-double/lib/python3.8/site-packages/astropy/coordinates/erfa_astrom.py:45: AttributeError
Activity
pllim commentedon Jan 27, 2021
That's weird. It had been passing on
masterand I don't see any newerfaorpyerfarelease. Any idea, @mhvk or @adrn ?[-]Test failure with coordinates[/-][+]Test failure with coordinates: 'NoneType' object has no attribute 'to_geodetic'[/+]saimn commentedon Jan 27, 2021
It passed on master after the merge, and on most of the builds I have looked at, but sometimes it's failing. Another example: https://github.com/astropy/astropy/runs/1754950817?check_suite_focus=true
Probably a transient with a remote service, but it's weird that it happens each time on the 32bits job ?
pllim commentedon Jan 27, 2021
Keep in mind that the 32-bit job also runs parallel and "run the suite twice" jobs, and it is failing in
py38-test-double, so probably some state that is kept dirty after the first run, but not always?mhvk commentedon Jan 28, 2021
Hmm, I'd guess this might be related to #11255. There definitely was something tricky going on with frame attributes for
SkyOffsetFrame, and maybe I messed up in a way that neither I nor @embray noticed. I do vaguely recall getting similar error messages while working on that...pllim commentedon Feb 1, 2021
I can reproduce locally but only if I do this. It doesn't show when I run
pytest <filename>twice on the terminal.So maybe the test runner is "polluting" the test somehow.
mhvk commentedon Feb 1, 2021
Nice sleuthing! As noted in the PR, I'll try to have a quick check if there isn't a real problem underlying this failure... A possibility might be that the coordinate relative to which the
SkyOffsetFrameis defined is deleted, but the frame still hangs around, which would not be right.mhvk commentedon Feb 2, 2021
Yikes, this is tricky: I cannot consistently reproduce getting the error on the 2nd run with your one-liner calling
astropy.testtwice. The first time I tried, it worked, but now tried a few times again and both calls just pass. Well, at least perhaps that is what happened to your cache clearing too?!mhvk commentedon Feb 2, 2021
Well, at least it is consistent with not always failing on CI...
mhvk commentedon Feb 2, 2021
Ha, got another failure! But only once every 10 calls or so.
Looking at the trace, I now notice that somehow it is trying to get a location, because it thinks it is dealing with some sort of
AltAzframe, even though in reality it is all in ICRS.Hah, at least some progress: if I move the AltAz tests before the ICRS tests, the first trial of the test file much more consistently gives errors (not always, but mostly; and any subsequent trial is fine); and now
pytestalso regularly fails.So, it is not due to the test runner at least, but something semi-persistent, likely not being cleaned up fast enough.
mhvk commentedon Feb 2, 2021
So, at least it is clear where the problem lies:
astropy/astropy/coordinates/sky_coordinate.py
Lines 810 to 811 in 63f90ef
Here, when transforming back from the offset frame to the base frame, the 'origin' attribute is stored on the
SkyCoord(because ICRS does not have 'origin'). But the validation is done by theoriginattribute of whatever SkyOffsetFrame happens to be last in asetof all frames in the frame transform graph, which, if multiple sky offset frames have been defined, may be an altaz coordinate attribute (somewhat randomly, just if thesethappens to be like that). If so, for an ICRS sky offset, it tries to convert the icrs origin to altaz (which is impossible, because it does not have a location).Now how to solve this is less obvious... I tried simply disabling input verification here, but that gives lots of errors. Perhaps those
SkyOffsetFrameattributes should simply never be kept... Though I think the main problem is having an attribute for which the behaviour depends on some internal state.pllim commentedon Feb 2, 2021
Wow, even better sleuthing, @mhvk ! Sorry to send you down the wrong rabbit hole.
Is this an acceptable workaround?
xfail.mhvk commentedon Feb 2, 2021
The problem is that the error is actually wrong: it is using the
origininstance for a different OffsetFrame than the one that is passed in. It could happen in user code too (if they have offset frames in different coordinate systems).p.s. I do think we could have a relatively hacky work-around, but need to have some time to think it through.
3 remaining items
TST: Temporarily xfail until astropy#11277 is solved
TST: Temporarily xfail until astropy#11277 is solved
TST: Temporarily xfail until astropy#11277 is solved
TST: Temporarily xfail until astropy#11277 is solved
TST: Temporarily xfail until astropy#11277 is solved
bmerry commentedon Apr 23, 2021
I have indeed just run into this while trying to convert AltAz offsets to ICRS offsets. Any suggestions for a workaround, or is trying to use offset frames from different coordinates systems currently unworkable?
bmerry commentedon Apr 23, 2021
In case having a MWE will help with testing, here's what I was preparing for a bug report before I discovered this bug. It fails most of the time:
adrn commentedon Apr 23, 2021
Hm, totally confused about how to solve this, but as a workaround for your use case, would it work to replace the last line with
?
bmerry commentedon Apr 26, 2021
Thanks, that does appear to work (although it means I end up with a SkyOffsetICRS instead of a SkyCoord).
adrn commentedon Apr 26, 2021
In that case
😄
bmerry commentedon Apr 27, 2021
Thanks, that does seem to work reliably (slightly to my surprise, but I don't really understand the cause of the bug).
Simplify workaround for astropy bug
kbwestfall commentedon May 7, 2021
In the interest of providing more examples, I also just ran into this. Here's the code:
As noted in the comments, this line suggested by @adrn:
seems to work consistently. But it always issues this warning:
The other two lines:
and
fail with differing regularity, but the failure always occurs at the line:
Based on the Traceback below, is there some instability in which object is used to specify
location, or howlocationis pass/copied between objects? In the code above, e.g.,keck_frameconsistently has a definedlocation, butsky_crossdoes not.Thanks for any help on this!
mhvk commentedon May 11, 2021
OK, I think I have a fix in #11730.
@bmerry - thanks very much for your minimal example - it is now part of the test suite! And it was especially helpful as it turns out it actually had a slightly different cause, more properly a bug and with a clean fix (unlike the special-casing I ended up having to do to get rid of the test failures that started this).