LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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)