Coverage for examples/rerun.py: 0%
41 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-20 12:26 +0000
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-20 12:26 +0000
1from lsst.pex.config import Config, ConfigurableField
2from lsst.pipe.base import CmdLineTask
3from lsst.meas.deblender import SourceDeblendTask
4import lsst.afw.table as afwTable
6'''
7This script allows one to quickly load an image and run just the
8deblender on it, without any of the calibration steps before that.
10That is, it reads the calexp and pre-deblending sources, then runs the
11deblender and writes the outputs to self-contained FITS files.
12'''
15class MyConfig(Config):
16 deblend = ConfigurableField(target=SourceDeblendTask, doc="Deblender")
19class MyTask(CmdLineTask):
20 _DefaultName = "my"
21 ConfigClass = MyConfig
23 def _getConfigName(self):
24 return None
26 def __init__(self, *args, **kwargs):
27 super(MyTask, self).__init__(*args, **kwargs)
28 # self.makeSubtask("deblend", schema=self.schema)
30 def run(self, dataRef):
31 calexp = dataRef.get("calexp")
32 psf = calexp.getPsf()
33 sources = dataRef.get("src")
35 mapper = afwTable.SchemaMapper(sources.getSchema())
36 # map all the existing fields
37 mapper.addMinimalSchema(sources.getSchema(), True)
38 schema = mapper.getOutputSchema()
40 # It would be better for the schema-populating code to not be in
41 # the SourceDeblendTask constructor!
42 self.makeSubtask("deblend", schema=schema)
44 outsources = afwTable.SourceCatalog(schema)
45 outsources.reserve(2 * len(sources))
46 outsources.extend(sources, mapper=mapper)
47 sources = outsources
48 print(len(sources), 'sources before deblending')
50 self.deblend.run(calexp, sources)
51 print(len(sources), 'sources after deblending')
53 fn = 'deblended.fits'
54 print('Writing sources...')
55 sources.writeFits(fn)
56 print('Wrote sources to', fn)
58 fn = 'calexp.fits'
59 calexp.writeFits(fn)
60 print('Wrote calexp to', fn)
62 fn = 'psf.fits'
63 psf.writeFits(fn)
64 print('Wrote PSF to', fn)
67if __name__ == "__main__":
68 MyTask.parseAndRun()