Skip to content

Commit

Permalink
Backport PR sunpy#6342: Fixed bug that prevents RotatedSunFrame insta…
Browse files Browse the repository at this point in the history
…nces from being pickled
  • Loading branch information
nabobalis authored and meeseeksmachine committed Nov 4, 2022
1 parent 429d3ce commit a035841
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit a035841

Please sign in to comment.