LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
pickleFits.py
Go to the documentation of this file.
1 from lsst.afw.fits.fitsLib import MemFileManager, cdata, memmove
2 
3 def reduceToFits(obj):
4  """Pickle to FITS
5 
6  Intended to be used by the __reduce__ method of a class.
7 
8  Assumes the existence of a "writeFits" method on the object.
9  """
10  manager = MemFileManager()
11  obj.writeFits(manager)
12  size = manager.getLength()
13  data = cdata(manager.getData(), size);
14  return (unreduceFromFits, (obj.__class__, data, size))
15 
16 def unreduceFromFits(cls, data, size):
17  """Unpickle from FITS
18 
19  Unpacks data produced by reduceToFits.
20 
21  Assumes the existence of a "readFits" method on the object.
22  """
23  manager = MemFileManager(size + 1) # Allow an extra char for nul
24  memmove(manager.getData(), data)
25  return cls.readFits(manager)