Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-36726: Add FgcmBuildFromIsolatedStarsTask to use isolated stars as input. #98

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
804 changes: 804 additions & 0 deletions python/lsst/fgcmcal/fgcmBuildFromIsolatedStars.py

Large diffs are not rendered by default.

42 changes: 17 additions & 25 deletions python/lsst/fgcmcal/fgcmBuildStarsBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def __init__(self, initInputs=None, **kwargs):
# Only log warning and fatal errors from the sourceSelector
self.sourceSelector.log.setLevel(self.sourceSelector.log.WARN)

@abc.abstractmethod
def fgcmMakeAllStarObservations(self, groupedHandles, visitCat,
sourceSchema,
camera,
Expand Down Expand Up @@ -230,7 +229,7 @@ def fgcmMakeAllStarObservations(self, groupedHandles, visitCat,
"""
raise NotImplementedError("fgcmMakeAllStarObservations not implemented.")

def fgcmMakeVisitCatalog(self, camera, groupedHandles, bkgHandleDict=None):
def fgcmMakeVisitCatalog(self, camera, groupedHandles):
"""
Make a visit catalog with all the keys from each visit

Expand All @@ -240,8 +239,6 @@ def fgcmMakeVisitCatalog(self, camera, groupedHandles, bkgHandleDict=None):
Camera from the butler
groupedHandles: `dict` [`list` [`lsst.daf.butler.DeferredDatasetHandle`]]
Dataset handles, grouped by visit.
bkgHandleDict: `dict`, optional
Dictionary of `lsst.daf.butler.DeferredDatasetHandle` for background info.

Returns
-------
Expand All @@ -264,12 +261,11 @@ def fgcmMakeVisitCatalog(self, camera, groupedHandles, bkgHandleDict=None):

# No matter what, fill the catalog. This will check if it was
# already read.
self._fillVisitCatalog(visitCat, groupedHandles,
bkgHandleDict=bkgHandleDict)
self._fillVisitCatalog(visitCat, groupedHandles)

return visitCat

def _fillVisitCatalog(self, visitCat, groupedHandles, bkgHandleDict=None):
def _fillVisitCatalog(self, visitCat, groupedHandles):
"""
Fill the visit catalog with visit metadata

Expand All @@ -279,11 +275,10 @@ def _fillVisitCatalog(self, visitCat, groupedHandles, bkgHandleDict=None):
Visit catalog. See _makeFgcmVisitSchema() for schema definition.
groupedHandles : `dict` [`list` [`lsst.daf.butler.DeferredDatasetHandle`]]
Dataset handles, grouped by visit.
bkgHandleDict : `dict`, optional
Dictionary of `lsst.daf.butler.DeferredDatasetHandle`
for background info.
"""
for i, visit in enumerate(groupedHandles):

# Guarantee that these are sorted.
for i, visit in enumerate(sorted(groupedHandles)):
if (i % self.config.nVisitsPerCheckpoint) == 0:
self.log.info("Retrieving metadata for visit %d (%d/%d)", visit, i, len(groupedHandles))

Expand All @@ -295,18 +290,26 @@ def _fillVisitCatalog(self, visitCat, groupedHandles, bkgHandleDict=None):
# Take the first available ccd if reference isn't available
summaryRow = summary[0]

summaryDetector = summaryRow['id']
visitInfo = summaryRow.getVisitInfo()
physicalFilter = summaryRow['physical_filter']
# Compute the median psf sigma if possible
goodSigma, = np.where(summary['psfSigma'] > 0)
if goodSigma.size > 2:
psfSigma = np.median(summary['psfSigma'][goodSigma])
elif goodSigma.size > 0:
psfSigma = np.mean(summary['psfSigma'][goodSigma])
psfSigma = summary['psfSigma'][goodSigma[0]]
else:
self.log.warning("Could not find any good summary psfSigma for visit %d", visit)
psfSigma = 0.0
# Compute median background if possible
goodBackground, = np.where(np.nan_to_num(summary['skyBg']) > 0.0)
if goodBackground.size > 2:
skyBackground = np.median(summary['skyBg'][goodBackground])
elif goodBackground.size > 0:
skyBackground = summary['skyBg'][goodBackground[0]]
else:
self.log.warning('Could not find any good summary skyBg for visit %d', visit)
skyBackground = -1.0

rec = visitCat[i]
rec['visit'] = visit
Expand All @@ -329,18 +332,7 @@ def _fillVisitCatalog(self, visitCat, groupedHandles, bkgHandleDict=None):
# Median delta aperture, to be measured from stars
rec['deltaAper'] = 0.0
rec['psfSigma'] = psfSigma

if self.config.doModelErrorsWithBackground:
# Use the same detector used from the summary.
bkgHandle = bkgHandleDict[(visit, summaryDetector)]
bgList = bkgHandle.get()

bgStats = (bg[0].getStatsImage().getImage().array
for bg in bgList)
rec['skyBackground'] = sum(np.median(bg[np.isfinite(bg)]) for bg in bgStats)
else:
rec['skyBackground'] = -1.0

rec['skyBackground'] = skyBackground
rec['used'] = 1

def _makeSourceMapper(self, sourceSchema):
Expand Down
23 changes: 1 addition & 22 deletions python/lsst/fgcmcal/fgcmBuildStarsTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ class FgcmBuildStarsTableConnections(pipeBase.PipelineTaskConnections,
multiple=True,
)

background = connectionTypes.Input(
doc="Calexp background model",
name="calexpBackground",
storageClass="Background",
dimensions=("instrument", "visit", "detector"),
deferLoad=True,
multiple=True,
)

fgcmVisitCatalog = connectionTypes.Output(
doc="Catalog of visit information for fgcm",
name="fgcmVisitCatalog",
Expand Down Expand Up @@ -154,9 +145,6 @@ def __init__(self, *, config=None):
self.prerequisiteInputs.remove("refCat")
self.prerequisiteInputs.remove("fgcmLookUpTable")

if not config.doModelErrorsWithBackground:
self.inputs.remove("background")

if not config.doReferenceMatches:
self.outputs.remove("fgcmReferenceStars")

Expand Down Expand Up @@ -277,16 +265,7 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
groupedHandles = self._groupHandles(sourceTableHandleDict,
visitSummaryHandleDict)

if self.config.doModelErrorsWithBackground:
bkgHandles = inputRefDict['background']
bkgHandleDict = {(bkgHandle.dataId.byName()['visit'],
bkgHandle.dataId.byName()['detector']): bkgHandle for
bkgHandle in bkgHandles}
else:
bkgHandleDict = None

visitCat = self.fgcmMakeVisitCatalog(camera, groupedHandles,
bkgHandleDict=bkgHandleDict)
visitCat = self.fgcmMakeVisitCatalog(camera, groupedHandles)

rad = calibFluxApertureRadius
fgcmStarObservationCat = self.fgcmMakeAllStarObservations(groupedHandles,
Expand Down