Skip to content

Commit

Permalink
ENH make sure it pickls
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Dec 11, 2019
1 parent a134b60 commit f4192cf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
16 changes: 14 additions & 2 deletions psfex/psfex_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,17 @@ def _load_from_fits(self, fits, ext=DEFAULT_EXT):
self['contextscale'],
self['psf_samp'],
self._psf_mask)



def __getstate__(self):
state = self.__dict__.copy()
del state['_psfex']
return state

def __setstate__(self, state):
self.__dict__.update(state)
self._psfex = _psfex_pywrap.PSFEx(self['masksize'],
self['poldeg'],
self['contextoffset'],
self['contextscale'],
self['psf_samp'],
self._psf_mask)
Empty file added psfex/tests/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions psfex/tests/test_pickles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import io
import pickle
import numpy as np

from ..psfex_lib import PSFEx


def test_pickles():
fname = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'test_psfcat.psf'
)

psf = PSFEx(fname)
im = psf.get_rec(10, 11)

val = io.BytesIO()
pickle.dump(psf, val)
val.flush()
val.seek(0)
new_psf = pickle.load(val)
new_im = new_psf.get_rec(10, 11)

assert np.array_equal(new_im, im)

# also make sure old object still works
assert np.array_equal(im, psf.get_rec(10, 11))
Binary file added psfex/tests/test_psfcat.psf
Binary file not shown.

0 comments on commit f4192cf

Please sign in to comment.