lsst.afw  13.0-92-g8ecf155+1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pickleFits.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 
3 from lsst.afw.fits.fitsLib import MemFileManager # , cdata, memmove
4 
5 
6 def reduceToFits(obj):
7  """Pickle to FITS
8 
9  Intended to be used by the __reduce__ method of a class.
10 
11  Assumes the existence of a "writeFits" method on the object.
12  """
13  manager = MemFileManager()
14  obj.writeFits(manager)
15  size = manager.getLength()
16  data = manager.getData()
17  return (unreduceFromFits, (obj.__class__, data, size))
18 
19 
20 def unreduceFromFits(cls, data, size):
21  """Unpickle from FITS
22 
23  Unpacks data produced by reduceToFits.
24 
25  Assumes the existence of a "readFits" method on the object.
26  """
27  manager = MemFileManager(size)
28  manager.setData(data, size)
29  return cls.readFits(manager)