Skip to content

Commit

Permalink
Merge pull request #16 from beckermr/pickling
Browse files Browse the repository at this point in the history
ENH enable pickling
  • Loading branch information
esheldon authored Dec 13, 2019
2 parents 2364a71 + f4192cf commit 75fcc25
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
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 75fcc25

Please sign in to comment.