Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug that prevents RotatedSunFrame instances from being pickled #6342

Merged
merged 1 commit into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/6342.bugfix.rst
@@ -0,0 +1 @@
Fixed bug that prevented `~sunpy.coordinates.metaframes.RotatedSunFrame` instances from being pickled.
7 changes: 7 additions & 0 deletions sunpy/coordinates/metaframes.py
Expand Up @@ -216,6 +216,13 @@ def rotated_time(self):
"""
return self.base.obstime + self.duration

def __reduce__(self):
return (_rotatedsunframe_reducer, (self.base,), self.__dict__)


def _rotatedsunframe_reducer(base):
return RotatedSunFrame.__new__(RotatedSunFrame, base=base)


# For Astropy 4.3+, we need to manually remove the `obstime` frame attribute from RotatedSunFrame
if 'obstime' in RotatedSunFrame.frame_attributes:
Expand Down
10 changes: 10 additions & 0 deletions sunpy/coordinates/tests/test_metaframes.py
@@ -1,3 +1,5 @@
import pickle

import pytest
from hypothesis import given, settings

Expand Down Expand Up @@ -276,3 +278,11 @@ def test_tranformation_to_nonobserver_frame(indirect_fixture):
hgs_coord = rot_frame.transform_to(hgs_frame)

assert hgs_coord.obstime == hgs_frame.obstime


def test_pickle_rotatedsunframe():
base_coord = SkyCoord(1*u.deg, 2*u.deg, obstime="2003-04-05", rsun=600*u.Mm,
frame='heliographic_stonyhurst')
rotated_coord = RotatedSunFrame(base=base_coord, duration=7*u.day)
pickled_coord = pickle.loads(pickle.dumps(rotated_coord))
assert pickled_coord == rotated_coord