Skip to content

Commit

Permalink
Add stars missing from BS stamps to BSS pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
bazkiaei authored and leeskelvin committed Jul 27, 2023
1 parent 81e08b0 commit 5bb47dd
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions python/lsst/meas/algorithms/brightStarStamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class BrightStarStamp(AbstractStamp):
archive_element: Persistable | None = None
annularFlux: float | None = None
minValidAnnulusFraction: float = 0.0
optimalInnerRadius: int | None = None
optimalOuterRadius: int | None = None

@classmethod
def factory(cls, stamp_im, metadata, idx, archive_element=None, minValidAnnulusFraction=0.0):
Expand Down Expand Up @@ -267,6 +269,7 @@ def initAndNormalize(
use_archive=False,
imCenter=None,
discardNanFluxObjects=True,
forceFindFlux=False,
statsControl=StatisticsControl(),
statsFlag=stringToStatisticsProperty("MEAN"),
badMaskPlanes=("BAD", "SAT", "NO_DATA"),
Expand Down Expand Up @@ -331,12 +334,13 @@ def initAndNormalize(
stamps, stamps normalized with different annulus definitions, or if
stamps are to be normalized but annular radii were not provided.
"""
stampSize = starStamps[0].stamp_im.getDimensions()
if imCenter is None:
stampSize = starStamps[0].stamp_im.getDimensions()
imCenter = stampSize[0] // 2, stampSize[1] // 2
# Create SpanSet of annulus
outerCircle = SpanSet.fromShape(outerRadius, Stencil.CIRCLE, offset=imCenter)
innerCircle = SpanSet.fromShape(innerRadius, Stencil.CIRCLE, offset=imCenter)
annulusWidth = outerRadius - innerRadius
annulus = outerCircle.intersectNot(innerCircle)
# Initialize (unnormalized) brightStarStamps instance
bss = cls(
Expand All @@ -354,6 +358,7 @@ def initAndNormalize(
bss._innerRadius, bss._outerRadius = innerRadius, outerRadius
# Create a list to contain rejected stamps.
rejects = []
badStamps = []
# Apply normalization
for stamp in bss._stamps:
try:
Expand All @@ -367,13 +372,58 @@ def initAndNormalize(
# steps needed before bright stars can be subtracted.
if discardNanFluxObjects:
rejects.append(stamp)
elif forceFindFlux:
newInnerRadius = innerRadius
newOuterRadius = outerRadius
while True:
newOuterRadius += annulusWidth
newInnerRadius += annulusWidth
if newOuterRadius > min(imCenter):
logger.info("No flux found for the star with Gaia ID of %s", stamp.gaiaId)
stamp.annularFlux = None
badStamps.append(stamp)
break
newOuterCircle = SpanSet.fromShape(newOuterRadius, Stencil.CIRCLE, offset=imCenter)
newInnerCircle = SpanSet.fromShape(newInnerRadius, Stencil.CIRCLE, offset=imCenter)
newAnnulus = newOuterCircle.intersectNot(newInnerCircle)
try:
stamp.measureAndNormalize(
newAnnulus,
statsControl=statsControl,
statsFlag=statsFlag,
badMaskPlanes=badMaskPlanes,
)

except RuntimeError:
stamp.annularFlux = np.nan
logger.error(
"The annular flux was not found for radii {} and {}",
newInnerRadius,
newOuterRadius,
)
if stamp.annularFlux and stamp.annularFlux > 0:
logger.info("The flux is found within an optimized annulus.")
logger.info(
"The optimized annulus radii are %d and %d and the flux is %f",
newInnerRadius,
newOuterRadius,
stamp.annularFlux,
)
stamp.optimalOuterRadius = newOuterRadius
stamp.optimalInnerRadius = newInnerRadius
break
else:
stamp.annularFlux = np.nan
# Remove rejected stamps.
bss.normalized = True
if discardNanFluxObjects:
for reject in rejects:
bss._stamps.remove(reject)
bss.normalized = True
elif forceFindFlux:
for badStamp in badStamps:
bss._stamps.remove(badStamp)
bss._innerRadius, bss._outerRadius = None, None
return bss, badStamps
return bss

def _refresh_metadata(self):
Expand Down

0 comments on commit 5bb47dd

Please sign in to comment.