@@ -234,53 +234,57 @@ def run(self,
234234 finalVisitSummaryIdDict = prepareCatalogDict (finalVisitSummaryRefs , useVisitDetector = False )
235235
236236 diaSourceHistory , ssSourceHistory , unassociatedSsObjectHistory = [], [], []
237- for visit , detector in diaIdDict :
238- diaCatRef = diaIdDict [(visit , detector )]
239- diaCat = diaCatRef .get ()
240- nDiaSrcIn = len (diaCat )
241- # Always false if ! self.config.doSolarSystemAssociation
242- if (visit in ssObjectIdDict ) and (visit in finalVisitSummaryIdDict ):
243- visitSummary = finalVisitSummaryIdDict [visit ].get ()
244- ssoAssocResult = self .runSolarSystemAssociation (diaCat ,
245- ssObjectIdDict [visit ].get (),
246- visitSummary = visitSummary ,
247- patchBbox = innerPatchBox ,
248- patchWcs = skyInfo .wcs ,
249- innerTractSkyRegion = innerTractSkyRegion ,
250- detector = detector ,
251- visit = visit ,
252- )
253-
254- nSsSrc = len (ssoAssocResult .associatedSsSources )
255- nSsObj = len (ssoAssocResult .unassociatedSsObjects )
256- # If diaSources were associated with Solar System objects,
257- # remove them from the catalog so they won't create new
258- # diaObjects or be associated with other diaObjects.
259- diaCat = ssoAssocResult .unassociatedDiaSources
260- else :
261- nSsSrc , nSsObj = 0 , 0
262-
263- # Only trim diaSources to the outer bbox of the patch, so that
264- # diaSources near the patch boundary can be associated.
265- # DiaObjects will be trimmed to the inner patch bbox, and any
266- # diaSources associated with dropped diaObjects will also be dropped
267- diaInPatch = self ._trimToPatch (diaCat .to_pandas (), outerPatchBox , skyInfo .wcs )
268-
269- nDiaSrc = diaInPatch .sum ()
270-
271- self .log .info (
272- "Read DiaSource catalog of length %i from visit %i, "
273- "detector %i. Found %i sources within the patch/tract "
274- "footprint, including %i associated with SSOs." ,
275- nDiaSrcIn , diaCatRef .dataId ["visit" ],
276- diaCatRef .dataId ["detector" ], nDiaSrc + nSsSrc , nSsSrc )
277-
278- if nDiaSrc > 0 :
279- diaSourceHistory .append (diaCat [diaInPatch ])
280- if nSsSrc > 0 :
281- ssSourceHistory .append (ssoAssocResult .associatedSsSources )
282- if nSsObj > 0 :
283- unassociatedSsObjectHistory .append (ssoAssocResult .unassociatedSsObjects )
237+ nSsSrc , nSsObj = 0 , 0
238+ visits = set ([v for v , _ in diaIdDict .keys ()])
239+ for visit in visits :
240+ # visit summaries and Solar System catalogs are per-visit, so only
241+ # load them once for all detectors with that visit
242+ visitSummary = finalVisitSummaryIdDict [visit ].get () if visit in finalVisitSummaryIdDict else None
243+ ssCat = ssObjectIdDict [visit ].get () if visit in ssObjectIdDict else None
244+ detectors = [det for (v , det ) in diaIdDict .keys () if v == visit ]
245+ for detector in detectors :
246+ diaCat = diaIdDict [(visit , detector )].get ()
247+ nDiaSrcIn = len (diaCat )
248+ if (ssCat is not None ) and (visitSummary is not None ):
249+ ssoAssocResult = self .runSolarSystemAssociation (diaCat ,
250+ ssCat ,
251+ visitSummary = visitSummary ,
252+ patchBbox = innerPatchBox ,
253+ patchWcs = skyInfo .wcs ,
254+ innerTractSkyRegion = innerTractSkyRegion ,
255+ detector = detector ,
256+ visit = visit ,
257+ )
258+
259+ nSsSrc = len (ssoAssocResult .associatedSsSources )
260+ nSsObj = len (ssoAssocResult .unassociatedSsObjects )
261+ # If diaSources were associated with Solar System objects,
262+ # remove them from the catalog so they won't create new
263+ # diaObjects or be associated with other diaObjects.
264+ diaCat = ssoAssocResult .unassociatedDiaSources
265+ else :
266+ nSsSrc , nSsObj = 0 , 0
267+
268+ # Only trim diaSources to the outer bbox of the patch, so that
269+ # diaSources near the patch boundary can be associated.
270+ # DiaObjects will be trimmed to the inner patch bbox, and any
271+ # diaSources associated with dropped diaObjects will also be dropped
272+ diaInPatch = self ._trimToPatch (diaCat .to_pandas (), outerPatchBox , skyInfo .wcs )
273+
274+ nDiaSrc = diaInPatch .sum ()
275+
276+ self .log .info (
277+ "Read DiaSource catalog of length %i from visit %i, "
278+ "detector %i. Found %i sources within the patch/tract "
279+ "footprint, including %i associated with SSOs." ,
280+ nDiaSrcIn , visit , detector , nDiaSrc + nSsSrc , nSsSrc )
281+
282+ if nDiaSrc > 0 :
283+ diaSourceHistory .append (diaCat [diaInPatch ])
284+ if nSsSrc > 0 :
285+ ssSourceHistory .append (ssoAssocResult .associatedSsSources )
286+ if nSsObj > 0 :
287+ unassociatedSsObjectHistory .append (ssoAssocResult .unassociatedSsObjects )
284288
285289 # After looping over all of the detector-level catalogs that overlap the
286290 # patch, combine them into patch-level catalogs
@@ -296,7 +300,7 @@ def run(self,
296300 ssSourceHistoryCat = None
297301 unassociatedSsObjectHistoryCat = None
298302
299- if (not diaSourceHistory ) and not ( self . config . doSolarSystemAssociation and ssSourceHistory ):
303+ if (not diaSourceHistory ) and ( not ssSourceHistory ):
300304 if not self .config .doWriteEmptyTables :
301305 raise pipeBase .NoWorkFound ("Found no overlapping DIASources to associate." )
302306
0 commit comments