1) In a stage/pipeline, use an OutputStage?. The stage policy should look like:
OutputItems: {
{kernelKey}: {
StoragePolicy: {
Storage: "XmlStorage"
Location: "%(output){relative path}"
}
}
}
2) In a test script, use an OutputStage? created with SimpleStageTester.
from lsst.pex.harness import SimpleStageTester
from lsst.pex.policy import Policy
pol = Policy()
pol.set("OutputItems.d.StoragePolicy.Storage", "XmlStorage")
pol.set("OutputItems.d.StoragePolicy.Location", path)
stage = SimpleStageTester.create("lsst.pex.harness.IOStage.OutputStage", pol)
clip = stage.run({"d": object}, 0)
3) In a test script, you could also use lsst.daf.persistence directly:
from lsst.daf.base import PropertySet
import lsst.daf.persistence as dafPersist
from lsst.pex.policy import Policy
pol = Policy()
persistence = dafPersist.Persistence.getPersistence(pol)
storageList = dafPersist.StorageList()
loc = dafPersist.LogicalLocation(path)
storage = persistence.getPersistStorage("XmlStorage", loc)
storageList.append(storage)
persistence.persist(object, storageList, PropertySet())
To recover this thing from disk for e.g. a pcaPsf
becker127: more psfModel.xml ... <psf class_id="0" class_name="lsst::meas::algorithms::pcaPsf" tracking_level="1" version="0" object_id="_0"> ...
I need to say
import sys
import lsst.daf.persistence as dafPersist
import lsst.daf.base as dafBase
import lsst.pex.policy as pexPolicy
import lsst.meas.algorithms as algorithms
import pdb
xmlFile = sys.argv[1]
# Set up persistence object
pol = pexPolicy.Policy()
persistence = dafPersist.Persistence.getPersistence(pol)
# Where is the file on disk? Make a storage object
loc = dafPersist.LogicalLocation(xmlFile)
storageList = dafPersist.StorageList()
storage = persistence.getRetrieveStorage('XmlStorage', loc)
storageList.append(storage)
# Capture any associated metadata
metadata = dafBase.PropertySet()
# Unpersist the object; you need to say which object in storage to grab
persistable = persistence.retrieve('PSF', storageList, metadata)
# Cast to a PSF model
psf = algorithms.PSF.swigConvert(persistable)
NOTE : without this line
import lsst.meas.algorithms as algorithms
I get the error
0: Message: No Formatter registered for Persistable name: PSF
because the formatter is only registered when the Persistable subclass is imported.
