24 from lsst.pipe.base import (CmdLineTask, Struct, ArgumentParser, ButlerInitializedTaskRunner,
25 PipelineTask, InitOutputDatasetField, InputDatasetField, OutputDatasetField,
29 from lsst.meas.base import SingleFrameMeasurementTask, ApplyApCorrTask, CatalogCalculationTask
42 from .mergeDetections
import MergeDetectionsConfig, MergeDetectionsTask
43 from .mergeMeasurements
import MergeMeasurementsConfig, MergeMeasurementsTask
44 from .multiBandUtils
import MergeSourcesRunner, CullPeaksConfig, _makeGetSchemaCatalogs
45 from .multiBandUtils
import getInputSchema, getShortFilterName, readCatalog, _makeMakeIdFactory
46 from .deblendCoaddSourcesPipeline
import DeblendCoaddSourcesSingleConfig
47 from .deblendCoaddSourcesPipeline
import DeblendCoaddSourcesSingleTask
48 from .deblendCoaddSourcesPipeline
import DeblendCoaddSourcesMultiConfig
49 from .deblendCoaddSourcesPipeline
import DeblendCoaddSourcesMultiTask
54 * deepCoadd_det: detections from what used to be processCoadd (tract, patch, filter) 55 * deepCoadd_mergeDet: merged detections (tract, patch) 56 * deepCoadd_meas: measurements of merged detections (tract, patch, filter) 57 * deepCoadd_ref: reference sources (tract, patch) 58 All of these have associated *_schema catalogs that require no data ID and hold no records. 60 In addition, we have a schema-only dataset, which saves the schema for the PeakRecords in 61 the mergeDet, meas, and ref dataset Footprints: 62 * deepCoadd_peak_schema 70 @anchor DetectCoaddSourcesConfig_ 72 @brief Configuration parameters for the DetectCoaddSourcesTask 74 doScaleVariance =
Field(dtype=bool, default=
True, doc=
"Scale variance plane using empirical noise?")
77 coaddName =
Field(dtype=str, default=
"deep", doc=
"Name of coadd")
78 doInsertFakes =
Field(dtype=bool, default=
False,
79 doc=
"Run fake sources injection task")
81 doc=
"Injection of fake sources for testing " 82 "purposes (must be retargeted)")
84 doc=
"Schema of the detection catalog",
85 name=
"{}Coadd_det_schema",
86 storageClass=
"SourceCatalog",
89 doc=
"Exposure on which detections are to be performed",
92 storageClass=
"ExposureF",
93 dimensions=(
"Tract",
"Patch",
"AbstractFilter",
"SkyMap")
96 doc=
"Output Backgrounds used in detection",
97 name=
"{}Coadd_calexp_background",
99 storageClass=
"Background",
100 dimensions=(
"Tract",
"Patch",
"AbstractFilter",
"SkyMap")
103 doc=
"Detected sources catalog",
106 storageClass=
"SourceCatalog",
107 dimensions=(
"Tract",
"Patch",
"AbstractFilter",
"SkyMap")
110 doc=
"Exposure post detection",
111 name=
"{}Coadd_calexp",
113 storageClass=
"ExposureF",
114 dimensions=(
"Tract",
"Patch",
"AbstractFilter",
"SkyMap")
116 quantum = QuantumConfig(
117 dimensions=(
"Tract",
"Patch",
"AbstractFilter",
"SkyMap")
121 Config.setDefaults(self)
122 self.
detection.thresholdType =
"pixel_stdev" 125 self.
detection.reEstimateBackground =
False 126 self.
detection.background.useApprox =
False 128 self.
detection.background.undersampleStyle =
'REDUCE_INTERP_ORDER' 129 self.
detection.doTempWideBackground =
True 141 @anchor DetectCoaddSourcesTask_ 143 @brief Detect sources on a coadd 145 @section pipe_tasks_multiBand_Contents Contents 147 - @ref pipe_tasks_multiBand_DetectCoaddSourcesTask_Purpose 148 - @ref pipe_tasks_multiBand_DetectCoaddSourcesTask_Initialize 149 - @ref pipe_tasks_multiBand_DetectCoaddSourcesTask_Run 150 - @ref pipe_tasks_multiBand_DetectCoaddSourcesTask_Config 151 - @ref pipe_tasks_multiBand_DetectCoaddSourcesTask_Debug 152 - @ref pipe_tasks_multiband_DetectCoaddSourcesTask_Example 154 @section pipe_tasks_multiBand_DetectCoaddSourcesTask_Purpose Description 156 Command-line task that detects sources on a coadd of exposures obtained with a single filter. 158 Coadding individual visits requires each exposure to be warped. This introduces covariance in the noise 159 properties across pixels. Before detection, we correct the coadd variance by scaling the variance plane 160 in the coadd to match the observed variance. This is an approximate approach -- strictly, we should 161 propagate the full covariance matrix -- but it is simple and works well in practice. 163 After scaling the variance plane, we detect sources and generate footprints by delegating to the @ref 164 SourceDetectionTask_ "detection" subtask. 167 deepCoadd{tract,patch,filter}: ExposureF 169 deepCoadd_det{tract,patch,filter}: SourceCatalog (only parent Footprints) 170 @n deepCoadd_calexp{tract,patch,filter}: Variance scaled, background-subtracted input 172 @n deepCoadd_calexp_background{tract,patch,filter}: BackgroundList 176 DetectCoaddSourcesTask delegates most of its work to the @ref SourceDetectionTask_ "detection" subtask. 177 You can retarget this subtask if you wish. 179 @section pipe_tasks_multiBand_DetectCoaddSourcesTask_Initialize Task initialization 181 @copydoc \_\_init\_\_ 183 @section pipe_tasks_multiBand_DetectCoaddSourcesTask_Run Invoking the Task 187 @section pipe_tasks_multiBand_DetectCoaddSourcesTask_Config Configuration parameters 189 See @ref DetectCoaddSourcesConfig_ "DetectSourcesConfig" 191 @section pipe_tasks_multiBand_DetectCoaddSourcesTask_Debug Debug variables 193 The @link lsst.pipe.base.cmdLineTask.CmdLineTask command line task@endlink interface supports a 194 flag @c -d to import @b debug.py from your @c PYTHONPATH; see @ref baseDebug for more about @b debug.py 197 DetectCoaddSourcesTask has no debug variables of its own because it relegates all the work to 198 @ref SourceDetectionTask_ "SourceDetectionTask"; see the documetation for 199 @ref SourceDetectionTask_ "SourceDetectionTask" for further information. 201 @section pipe_tasks_multiband_DetectCoaddSourcesTask_Example A complete example 202 of using DetectCoaddSourcesTask 204 DetectCoaddSourcesTask is meant to be run after assembling a coadded image in a given band. The purpose of 205 the task is to update the background, detect all sources in a single band and generate a set of parent 206 footprints. Subsequent tasks in the multi-band processing procedure will merge sources across bands and, 207 eventually, perform forced photometry. Command-line usage of DetectCoaddSourcesTask expects a data 208 reference to the coadd to be processed. A list of the available optional arguments can be obtained by 209 calling detectCoaddSources.py with the `--help` command line argument: 211 detectCoaddSources.py --help 214 To demonstrate usage of the DetectCoaddSourcesTask in the larger context of multi-band processing, we 215 will process HSC data in the [ci_hsc](https://github.com/lsst/ci_hsc) package. Assuming one has followed 216 steps 1 - 4 at @ref pipeTasks_multiBand, one may detect all the sources in each coadd as follows: 218 detectCoaddSources.py $CI_HSC_DIR/DATA --id patch=5,4 tract=0 filter=HSC-I 220 that will process the HSC-I band data. The results are written to 221 `$CI_HSC_DIR/DATA/deepCoadd-results/HSC-I`. 223 It is also necessary to run: 225 detectCoaddSources.py $CI_HSC_DIR/DATA --id patch=5,4 tract=0 filter=HSC-R 227 to generate the sources catalogs for the HSC-R band required by the next step in the multi-band 228 processing procedure: @ref MergeDetectionsTask_ "MergeDetectionsTask". 230 _DefaultName =
"detectCoaddSources" 231 ConfigClass = DetectCoaddSourcesConfig
232 getSchemaCatalogs = _makeGetSchemaCatalogs(
"det")
233 makeIdFactory = _makeMakeIdFactory(
"CoaddId")
236 def _makeArgumentParser(cls):
238 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2 filter=r",
239 ContainerClass=ExistingCoaddDataIdContainer)
244 coaddName = config.coaddName
245 for name
in (
"outputBackgrounds",
"outputSources",
"outputExposure"):
246 attr = getattr(config, name)
247 setattr(attr,
"name", attr.name.format(coaddName))
249 return outputTypeDict
253 coaddName = config.coaddName
254 attr = config.detectionSchema
255 setattr(attr,
"name", attr.name.format(coaddName))
261 @brief Initialize the task. Create the @ref SourceDetectionTask_ "detection" subtask. 263 Keyword arguments (in addition to those forwarded to CmdLineTask.__init__): 265 @param[in] schema: initial schema for the output catalog, modified-in place to include all 266 fields set by this task. If None, the source minimal schema will be used. 267 @param[in] **kwargs: keyword arguments to be passed to lsst.pipe.base.task.Task.__init__ 273 schema = afwTable.SourceTable.makeMinimalSchema()
274 if self.config.doInsertFakes:
275 self.makeSubtask(
"insertFakes")
277 self.makeSubtask(
"detection", schema=self.
schema)
278 if self.config.doScaleVariance:
279 self.makeSubtask(
"scaleVariance")
286 @brief Run detection on a coadd. 288 Invokes @ref run and then uses @ref write to output the 291 @param[in] patchRef: data reference for patch 293 exposure = patchRef.get(self.config.coaddName +
"Coadd", immediate=
True)
294 expId =
int(patchRef.get(self.config.coaddName +
"CoaddId"))
296 self.
write(results, patchRef)
301 inputData[
"idFactory"] = afwTable.IdFactory.makeSimple()
302 inputData[
"expId"] = 0
303 return self.
run(**inputData)
305 def run(self, exposure, idFactory, expId):
307 @brief Run detection on an exposure. 309 First scale the variance plane to match the observed variance 310 using @ref ScaleVarianceTask. Then invoke the @ref SourceDetectionTask_ "detection" subtask to 313 @param[in,out] exposure: Exposure on which to detect (may be backround-subtracted and scaled, 314 depending on configuration). 315 @param[in] idFactory: IdFactory to set source identifiers 316 @param[in] expId: Exposure identifier (integer) for RNG seed 318 @return a pipe.base.Struct with fields 319 - sources: catalog of detections 320 - backgrounds: list of backgrounds 322 if self.config.doScaleVariance:
323 varScale = self.scaleVariance.
run(exposure.maskedImage)
324 exposure.getMetadata().add(
"variance_scale", varScale)
326 if self.config.doInsertFakes:
327 self.insertFakes.
run(exposure, background=backgrounds)
328 table = afwTable.SourceTable.make(self.
schema, idFactory)
329 detections = self.detection.makeSourceCatalog(table, exposure, expId=expId)
330 sources = detections.sources
331 fpSets = detections.fpSets
332 if hasattr(fpSets,
"background")
and fpSets.background:
333 for bg
in fpSets.background:
334 backgrounds.append(bg)
335 return Struct(outputSources=sources, outputBackgrounds=backgrounds, outputExposure=exposure)
339 @brief Write out results from runDetection. 341 @param[in] exposure: Exposure to write out 342 @param[in] results: Struct returned from runDetection 343 @param[in] patchRef: data reference for patch 345 coaddName = self.config.coaddName +
"Coadd" 346 patchRef.put(results.outputBackgrounds, coaddName +
"_calexp_background")
347 patchRef.put(results.outputSources, coaddName +
"_det")
348 patchRef.put(results.outputExposure, coaddName +
"_calexp")
354 """DeblendCoaddSourcesConfig 356 Configuration parameters for the `DeblendCoaddSourcesTask`. 359 doc=
"Deblend sources separately in each band")
361 doc=
"Deblend sources simultaneously across bands")
362 simultaneous =
Field(dtype=bool, default=
False, doc=
"Simultaneously deblend all bands?")
363 coaddName =
Field(dtype=str, default=
"deep", doc=
"Name of coadd")
366 Config.setDefaults(self)
371 """Task runner for the `MergeSourcesTask` 373 Required because the run method requires a list of 374 dataRefs rather than a single dataRef. 378 """Provide a list of patch references for each patch, tract, filter combo. 385 Keyword arguments passed to the task 390 List of tuples, where each tuple is a (dataRef, kwargs) pair. 392 refDict = MergeSourcesRunner.buildRefDict(parsedCmd)
393 kwargs[
"psfCache"] = parsedCmd.psfCache
394 return [(
list(p.values()), kwargs)
for t
in refDict.values()
for p
in t.values()]
398 """Deblend the sources in a merged catalog 400 Deblend sources from master catalog in each coadd. 401 This can either be done separately in each band using the HSC-SDSS deblender 402 (`DeblendCoaddSourcesTask.config.simultaneous==False`) 403 or use SCARLET to simultaneously fit the blend in all bands 404 (`DeblendCoaddSourcesTask.config.simultaneous==True`). 405 The task will set its own `self.schema` atribute to the `Schema` of the 406 output deblended catalog. 407 This will include all fields from the input `Schema`, as well as additional fields 410 `pipe.tasks.multiband.DeblendCoaddSourcesTask Description 411 --------------------------------------------------------- 417 Butler used to read the input schemas from disk or 418 construct the reference catalog loader, if `schema` or `peakSchema` or 420 The schema of the merged detection catalog as an input to this task. 422 The schema of the `PeakRecord`s in the `Footprint`s in the merged detection catalog 424 ConfigClass = DeblendCoaddSourcesConfig
425 RunnerClass = DeblendCoaddSourcesRunner
426 _DefaultName =
"deblendCoaddSources" 427 makeIdFactory = _makeMakeIdFactory(
"MergedCoaddId")
430 def _makeArgumentParser(cls):
432 parser.add_id_argument(
"--id",
"deepCoadd_calexp",
433 help=
"data ID, e.g. --id tract=12345 patch=1,2 filter=g^r^i",
434 ContainerClass=ExistingCoaddDataIdContainer)
435 parser.add_argument(
"--psfCache", type=int, default=100, help=
"Size of CoaddPsf cache")
438 def __init__(self, butler=None, schema=None, peakSchema=None, **kwargs):
439 CmdLineTask.__init__(self, **kwargs)
441 assert butler
is not None,
"Neither butler nor schema is defined" 442 schema = butler.get(self.config.coaddName +
"Coadd_mergeDet_schema", immediate=
True).schema
446 if peakSchema
is None:
447 assert butler
is not None,
"Neither butler nor peakSchema is defined" 448 peakSchema = butler.get(self.config.coaddName +
"Coadd_peak_schema", immediate=
True).schema
450 if self.config.simultaneous:
451 self.makeSubtask(
"multiBandDeblend", schema=self.
schema, peakSchema=peakSchema)
453 self.makeSubtask(
"singleBandDeblend", schema=self.
schema, peakSchema=peakSchema)
456 """Return a dict of empty catalogs for each catalog dataset produced by this task. 461 Dictionary of empty catalogs, with catalog names as keys. 464 return {self.config.coaddName +
"Coadd_deblendedFlux": catalog,
465 self.config.coaddName +
"Coadd_deblendedModel": catalog}
470 Deblend each source simultaneously or separately 471 (depending on `DeblendCoaddSourcesTask.config.simultaneous`). 472 Set `is-primary` and related flags. 473 Propagate flags from individual visits. 474 Write the deblended sources out. 479 List of data references for each filter 481 if self.config.simultaneous:
485 for patchRef
in patchRefList:
486 exposure = patchRef.get(self.config.coaddName +
"Coadd_calexp", immediate=
True)
487 filters.append(patchRef.dataId[
"filter"])
488 exposures.append(exposure)
491 exposure = afwImage.MultibandExposure.fromExposures(filters, exposures)
492 fluxCatalogs, templateCatalogs = self.multiBandDeblend.
run(exposure, sources)
493 for n
in range(len(patchRefList)):
494 self.
write(patchRefList[n], fluxCatalogs[filters[n]], templateCatalogs[filters[n]])
497 for patchRef
in patchRefList:
498 exposure = patchRef.get(self.config.coaddName +
"Coadd_calexp", immediate=
True)
499 exposure.getPsf().setCacheCapacity(psfCache)
501 self.singleBandDeblend.
run(exposure, sources)
502 self.
write(patchRef, sources)
505 """Read merged catalog 507 Read the catalog of merged detections and create a catalog 512 dataRef: data reference 513 Data reference for catalog of merged detections 517 sources: `SourceCatalog` 518 List of sources in merged catalog 520 We also need to add columns to hold the measurements we're about to make 521 so we can measure in-place. 523 merged = dataRef.get(self.config.coaddName +
"Coadd_mergeDet", immediate=
True)
524 self.log.
info(
"Read %d detections: %s" % (len(merged), dataRef.dataId))
527 idFactory.notify(s.getId())
528 table = afwTable.SourceTable.make(self.
schema, idFactory)
533 def write(self, dataRef, flux_sources, template_sources=None):
534 """Write the source catalog(s) 538 dataRef: Data Reference 539 Reference to the output catalog. 540 flux_sources: `SourceCatalog` 541 Flux conserved sources to write to file. 542 If using the single band deblender, this is the catalog 544 template_sources: `SourceCatalog` 545 Source catalog using the multiband template models 550 if flux_sources
is not None:
551 assert not self.config.simultaneous
or self.config.multiBandDeblend.conserveFlux
552 dataRef.put(flux_sources, self.config.coaddName +
"Coadd_deblendedFlux")
556 if template_sources
is not None:
557 assert self.config.multiBandDeblend.saveTemplates
558 dataRef.put(template_sources, self.config.coaddName +
"Coadd_deblendedModel")
559 self.log.
info(
"Wrote %d sources: %s" % (len(flux_sources), dataRef.dataId))
562 """Write the metadata produced from processing the data. 566 List of Butler data references used to write the metadata. 567 The metadata is written to dataset type `CmdLineTask._getMetadataName`. 569 for dataRef
in dataRefList:
571 metadataName = self._getMetadataName()
572 if metadataName
is not None:
573 dataRef.put(self.getFullMetadata(), metadataName)
574 except Exception
as e:
575 self.log.
warn(
"Could not persist metadata for dataId=%s: %s", dataRef.dataId, e)
578 """Get the ExposureId from a data reference 580 return int(dataRef.get(self.config.coaddName +
"CoaddId"))
585 @anchor MeasureMergedCoaddSourcesConfig_ 587 @brief Configuration parameters for the MeasureMergedCoaddSourcesTask 589 inputCatalog =
Field(dtype=str, default=
"deblendedFlux",
590 doc=(
"Name of the input catalog to use." 591 "If the single band deblender was used this should be 'deblendedFlux." 592 "If the multi-band deblender was used this should be 'deblendedModel." 593 "If no deblending was performed this should be 'mergeDet'"))
595 setPrimaryFlags =
ConfigurableField(target=SetPrimaryFlagsTask, doc=
"Set flags for primary tract/patch")
597 dtype=bool, default=
True,
598 doc=
"Whether to match sources to CCD catalogs to propagate flags (to e.g. identify PSF stars)" 600 propagateFlags =
ConfigurableField(target=PropagateVisitFlagsTask, doc=
"Propagate visit flags to coadd")
601 doMatchSources =
Field(dtype=bool, default=
True, doc=
"Match sources to reference catalog?")
606 doc=(
"Write reference matches in denormalized format? " 607 "This format uses more disk space, but is more convenient to read."),
609 coaddName =
Field(dtype=str, default=
"deep", doc=
"Name of coadd")
611 doc=
"Strictness of Astropy unit compatibility check, can be 'raise', 'warn' or 'silent'",
618 doc=
"Apply aperture corrections" 621 target=ApplyApCorrTask,
622 doc=
"Subtask to apply aperture corrections" 627 doc=
'Run catalogCalculation task' 630 target=CatalogCalculationTask,
631 doc=
"Subtask to run catalogCalculation plugins on catalog" 635 Config.setDefaults(self)
636 self.
measurement.plugins.names |= [
'base_InputCount',
'base_Variance']
637 self.
measurement.plugins[
'base_PixelFlags'].masksFpAnywhere = [
'CLIPPED',
'SENSOR_EDGE',
639 self.
measurement.plugins[
'base_PixelFlags'].masksFpCenter = [
'CLIPPED',
'SENSOR_EDGE',
651 """Get the psfCache setting into MeasureMergedCoaddSourcesTask""" 654 return ButlerInitializedTaskRunner.getTargetList(parsedCmd, psfCache=parsedCmd.psfCache)
659 @anchor MeasureMergedCoaddSourcesTask_ 661 @brief Deblend sources from master catalog in each coadd seperately and measure. 663 @section pipe_tasks_multiBand_Contents Contents 665 - @ref pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Purpose 666 - @ref pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Initialize 667 - @ref pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Run 668 - @ref pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Config 669 - @ref pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Debug 670 - @ref pipe_tasks_multiband_MeasureMergedCoaddSourcesTask_Example 672 @section pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Purpose Description 674 Command-line task that uses peaks and footprints from a master catalog to perform deblending and 675 measurement in each coadd. 677 Given a master input catalog of sources (peaks and footprints) or deblender outputs 678 (including a HeavyFootprint in each band), measure each source on the 679 coadd. Repeating this procedure with the same master catalog across multiple coadds will generate a 680 consistent set of child sources. 682 The deblender retains all peaks and deblends any missing peaks (dropouts in that band) as PSFs. Source 683 properties are measured and the @c is-primary flag (indicating sources with no children) is set. Visit 684 flags are propagated to the coadd sources. 686 Optionally, we can match the coadd sources to an external reference catalog. 689 deepCoadd_mergeDet{tract,patch} or deepCoadd_deblend{tract,patch}: SourceCatalog 690 @n deepCoadd_calexp{tract,patch,filter}: ExposureF 692 deepCoadd_meas{tract,patch,filter}: SourceCatalog 696 MeasureMergedCoaddSourcesTask delegates most of its work to a set of sub-tasks: 699 <DT> @ref SingleFrameMeasurementTask_ "measurement" 700 <DD> Measure source properties of deblended sources.</DD> 701 <DT> @ref SetPrimaryFlagsTask_ "setPrimaryFlags" 702 <DD> Set flag 'is-primary' as well as related flags on sources. 'is-primary' is set for sources that are 703 not at the edge of the field and that have either not been deblended or are the children of deblended 705 <DT> @ref PropagateVisitFlagsTask_ "propagateFlags" 706 <DD> Propagate flags set in individual visits to the coadd.</DD> 707 <DT> @ref DirectMatchTask_ "match" 708 <DD> Match input sources to a reference catalog (optional). 711 These subtasks may be retargeted as required. 713 @section pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Initialize Task initialization 715 @copydoc \_\_init\_\_ 717 @section pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Run Invoking the Task 721 @section pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Config Configuration parameters 723 See @ref MeasureMergedCoaddSourcesConfig_ 725 @section pipe_tasks_multiBand_MeasureMergedCoaddSourcesTask_Debug Debug variables 727 The @link lsst.pipe.base.cmdLineTask.CmdLineTask command line task@endlink interface supports a 728 flag @c -d to import @b debug.py from your @c PYTHONPATH; see @ref baseDebug for more about @b debug.py 731 MeasureMergedCoaddSourcesTask has no debug variables of its own because it delegates all the work to 732 the various sub-tasks. See the documetation for individual sub-tasks for more information. 734 @section pipe_tasks_multiband_MeasureMergedCoaddSourcesTask_Example A complete example of using 735 MeasureMergedCoaddSourcesTask 737 After MeasureMergedCoaddSourcesTask has been run on multiple coadds, we have a set of per-band catalogs. 738 The next stage in the multi-band processing procedure will merge these measurements into a suitable 739 catalog for driving forced photometry. 741 Command-line usage of MeasureMergedCoaddSourcesTask expects a data reference to the coadds 743 A list of the available optional arguments can be obtained by calling measureCoaddSources.py with the 744 `--help` command line argument: 746 measureCoaddSources.py --help 749 To demonstrate usage of the DetectCoaddSourcesTask in the larger context of multi-band processing, we 750 will process HSC data in the [ci_hsc](https://github.com/lsst/ci_hsc) package. Assuming one has finished 751 step 6 at @ref pipeTasks_multiBand, one may perform deblending and measure sources in the HSC-I band 754 measureCoaddSources.py $CI_HSC_DIR/DATA --id patch=5,4 tract=0 filter=HSC-I 756 This will process the HSC-I band data. The results are written in 757 `$CI_HSC_DIR/DATA/deepCoadd-results/HSC-I/0/5,4/meas-HSC-I-0-5,4.fits 759 It is also necessary to run 761 measureCoaddSources.py $CI_HSC_DIR/DATA --id patch=5,4 tract=0 filter=HSC-R 763 to generate the sources catalogs for the HSC-R band required by the next step in the multi-band 764 procedure: @ref MergeMeasurementsTask_ "MergeMeasurementsTask". 766 _DefaultName =
"measureCoaddSources" 767 ConfigClass = MeasureMergedCoaddSourcesConfig
768 RunnerClass = MeasureMergedCoaddSourcesRunner
769 getSchemaCatalogs = _makeGetSchemaCatalogs(
"meas")
770 makeIdFactory = _makeMakeIdFactory(
"MergedCoaddId")
773 def _makeArgumentParser(cls):
775 parser.add_id_argument(
"--id",
"deepCoadd_calexp",
776 help=
"data ID, e.g. --id tract=12345 patch=1,2 filter=r",
777 ContainerClass=ExistingCoaddDataIdContainer)
778 parser.add_argument(
"--psfCache", type=int, default=100, help=
"Size of CoaddPsf cache")
781 def __init__(self, butler=None, schema=None, peakSchema=None, refObjLoader=None, **kwargs):
783 @brief Initialize the task. 785 Keyword arguments (in addition to those forwarded to CmdLineTask.__init__): 786 @param[in] schema: the schema of the merged detection catalog used as input to this one 787 @param[in] peakSchema: the schema of the PeakRecords in the Footprints in the merged detection catalog 788 @param[in] refObjLoader: an instance of LoadReferenceObjectsTasks that supplies an external reference 789 catalog. May be None if the loader can be constructed from the butler argument or all steps 790 requiring a reference catalog are disabled. 791 @param[in] butler: a butler used to read the input schemas from disk or construct the reference 792 catalog loader, if schema or peakSchema or refObjLoader is None 794 The task will set its own self.schema attribute to the schema of the output measurement catalog. 795 This will include all fields from the input schema, as well as additional fields for all the 798 CmdLineTask.__init__(self, **kwargs)
799 self.
deblended = self.config.inputCatalog.startswith(
"deblended")
802 assert butler
is not None,
"Neither butler nor schema is defined" 803 schema = butler.get(self.config.coaddName + self.
inputCatalog +
"_schema", immediate=
True).schema
808 self.makeSubtask(
"measurement", schema=self.
schema, algMetadata=self.
algMetadata)
809 self.makeSubtask(
"setPrimaryFlags", schema=self.
schema)
810 if self.config.doMatchSources:
811 if refObjLoader
is None:
812 assert butler
is not None,
"Neither butler nor refObjLoader is defined" 813 self.makeSubtask(
"match", butler=butler, refObjLoader=refObjLoader)
814 if self.config.doPropagateFlags:
815 self.makeSubtask(
"propagateFlags", schema=self.
schema)
816 self.
schema.checkUnits(parse_strict=self.config.checkUnitsParseStrict)
817 if self.config.doApCorr:
818 self.makeSubtask(
"applyApCorr", schema=self.
schema)
819 if self.config.doRunCatalogCalculation:
820 self.makeSubtask(
"catalogCalculation", schema=self.
schema)
824 @brief Deblend and measure. 826 @param[in] patchRef: Patch reference. 828 Set 'is-primary' and related flags. Propagate flags 829 from individual visits. Optionally match the sources to a reference catalog and write the matches. 830 Finally, write the deblended sources and measurements out. 832 exposure = patchRef.get(self.config.coaddName +
"Coadd_calexp", immediate=
True)
833 exposure.getPsf().setCacheCapacity(psfCache)
835 table = sources.getTable()
838 self.measurement.
run(sources, exposure, exposureId=self.
getExposureId(patchRef))
840 if self.config.doApCorr:
841 self.applyApCorr.
run(
843 apCorrMap=exposure.getInfo().getApCorrMap()
850 if not sources.isContiguous():
851 sources = sources.copy(deep=
True)
853 if self.config.doRunCatalogCalculation:
854 self.catalogCalculation.
run(sources)
856 skyInfo =
getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
857 self.setPrimaryFlags.
run(sources, skyInfo.skyMap, skyInfo.tractInfo, skyInfo.patchInfo,
859 if self.config.doPropagateFlags:
860 self.propagateFlags.
run(patchRef.getButler(), sources, self.propagateFlags.getCcdInputs(exposure),
862 if self.config.doMatchSources:
864 self.
write(patchRef, sources)
868 @brief Read input sources. 870 @param[in] dataRef: Data reference for catalog of merged detections 871 @return List of sources in merged catalog 873 We also need to add columns to hold the measurements we're about to make 874 so we can measure in-place. 876 merged = dataRef.get(self.config.coaddName + self.
inputCatalog, immediate=
True)
877 self.log.
info(
"Read %d detections: %s" % (len(merged), dataRef.dataId))
880 idFactory.notify(s.getId())
881 table = afwTable.SourceTable.make(self.
schema, idFactory)
888 @brief Write matches of the sources to the astrometric reference catalog. 890 We use the Wcs in the exposure to match sources. 892 @param[in] dataRef: data reference 893 @param[in] exposure: exposure with Wcs 894 @param[in] sources: source catalog 896 result = self.match.
run(sources, exposure.getInfo().getFilter().getName())
899 matches.table.setMetadata(result.matchMeta)
900 dataRef.put(matches, self.config.coaddName +
"Coadd_measMatch")
901 if self.config.doWriteMatchesDenormalized:
903 dataRef.put(denormMatches, self.config.coaddName +
"Coadd_measMatchFull")
907 @brief Write the source catalog. 909 @param[in] dataRef: data reference 910 @param[in] sources: source catalog 912 dataRef.put(sources, self.config.coaddName +
"Coadd_meas")
913 self.log.
info(
"Wrote %d sources: %s" % (len(sources), dataRef.dataId))
916 return int(dataRef.get(self.config.coaddName +
"CoaddId"))
def InitOutputDatasetField
def readSources(self, dataRef)
def getTargetList(parsedCmd, kwargs)
def runDataRef(self, patchRef)
Run detection on a coadd.
Class for storing ordered metadata with comments.
A mapping between the keys of two Schemas, used to copy data between them.
Configuration parameters for the DetectCoaddSourcesTask.
def denormalizeMatches(matches, matchMeta=None)
def runDataRef(self, patchRefList, psfCache=100)
def __init__(self, schema=None, kwargs)
Initialize the task.
def adaptArgsAndRun(self, inputData, inputDataIds, outputDataIds, butler)
Deblend sources from master catalog in each coadd seperately and measure.
def writeMatches(self, dataRef, exposure, sources)
Write matches of the sources to the astrometric reference catalog.
def getInitOutputDatasetTypes(cls, config)
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
def __init__(self, butler=None, schema=None, peakSchema=None, kwargs)
def getInitOutputDatasets(self)
def getExposureId(self, dataRef)
def readSources(self, dataRef)
Read input sources.
def getSchemaCatalogs(self)
def write(self, results, patchRef)
Write out results from runDetection.
template BaseCatalog packMatches(SourceMatchVector const &)
def getExposureId(self, dataRef)
def write(self, dataRef, flux_sources, template_sources=None)
def write(self, dataRef, sources)
Write the source catalog.
def getTargetList(parsedCmd, kwargs)
Configuration parameters for the MeasureMergedCoaddSourcesTask.
def getSkyInfo(coaddName, patchRef)
Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded...
def __init__(self, butler=None, schema=None, peakSchema=None, refObjLoader=None, kwargs)
Initialize the task.
def run(self, exposure, idFactory, expId)
Run detection on an exposure.
Detect sources on a coadd.
daf::base::PropertyList * list
def runDataRef(self, patchRef, psfCache=100)
Deblend and measure.
def writeMetadata(self, dataRefList)
def getOutputDatasetTypes(cls, config)