@@ -68,6 +68,8 @@ class BrightStarStamp(AbstractStamp):
68
68
archive_element : Persistable | None = None
69
69
annularFlux : float | None = None
70
70
minValidAnnulusFraction : float = 0.0
71
+ optimalInnerRadius : int | None = None
72
+ optimalOuterRadius : int | None = None
71
73
72
74
@classmethod
73
75
def factory (cls , stamp_im , metadata , idx , archive_element = None , minValidAnnulusFraction = 0.0 ):
@@ -267,6 +269,7 @@ def initAndNormalize(
267
269
use_archive = False ,
268
270
imCenter = None ,
269
271
discardNanFluxObjects = True ,
272
+ forceFindFlux = False ,
270
273
statsControl = StatisticsControl (),
271
274
statsFlag = stringToStatisticsProperty ("MEAN" ),
272
275
badMaskPlanes = ("BAD" , "SAT" , "NO_DATA" ),
@@ -331,12 +334,13 @@ def initAndNormalize(
331
334
stamps, stamps normalized with different annulus definitions, or if
332
335
stamps are to be normalized but annular radii were not provided.
333
336
"""
337
+ stampSize = starStamps [0 ].stamp_im .getDimensions ()
334
338
if imCenter is None :
335
- stampSize = starStamps [0 ].stamp_im .getDimensions ()
336
339
imCenter = stampSize [0 ] // 2 , stampSize [1 ] // 2
337
340
# Create SpanSet of annulus
338
341
outerCircle = SpanSet .fromShape (outerRadius , Stencil .CIRCLE , offset = imCenter )
339
342
innerCircle = SpanSet .fromShape (innerRadius , Stencil .CIRCLE , offset = imCenter )
343
+ annulusWidth = outerRadius - innerRadius
340
344
annulus = outerCircle .intersectNot (innerCircle )
341
345
# Initialize (unnormalized) brightStarStamps instance
342
346
bss = cls (
@@ -354,6 +358,7 @@ def initAndNormalize(
354
358
bss ._innerRadius , bss ._outerRadius = innerRadius , outerRadius
355
359
# Create a list to contain rejected stamps.
356
360
rejects = []
361
+ badStamps = []
357
362
# Apply normalization
358
363
for stamp in bss ._stamps :
359
364
try :
@@ -367,13 +372,60 @@ def initAndNormalize(
367
372
# steps needed before bright stars can be subtracted.
368
373
if discardNanFluxObjects :
369
374
rejects .append (stamp )
375
+ elif forceFindFlux :
376
+ newInnerRadius = innerRadius
377
+ newOuterRadius = outerRadius
378
+ while True :
379
+ newOuterRadius += annulusWidth
380
+ newInnerRadius += annulusWidth
381
+ if newOuterRadius > min (imCenter ):
382
+ logger .info (f"No flux found for the star with Gaia ID of { stamp .gaiaId } " )
383
+ stamp .annularFlux = None
384
+ badStamps .append (stamp )
385
+ break
386
+ newOuterCircle = SpanSet .fromShape (newOuterRadius , Stencil .CIRCLE , offset = imCenter )
387
+ newInnerCircle = SpanSet .fromShape (newInnerRadius , Stencil .CIRCLE , offset = imCenter )
388
+ newAnnulus = newOuterCircle .intersectNot (newInnerCircle )
389
+ try :
390
+ stamp .measureAndNormalize (
391
+ newAnnulus ,
392
+ statsControl = statsControl ,
393
+ statsFlag = statsFlag ,
394
+ badMaskPlanes = badMaskPlanes ,
395
+ )
396
+
397
+ except RuntimeError as err :
398
+ stamp .annularFlux = np .nan
399
+ logger .error (
400
+ "The annulux flux was not found for radii {} and {}" .format (
401
+ newInnerRadius , newOuterRadius
402
+ )
403
+ )
404
+ if stamp .annularFlux and stamp .annularFlux > 0 :
405
+ logger .info ("The flux is found within an optimized annulus." )
406
+ logger .info (
407
+ "The optimized annulus raddi are {} and {} and the flux is {}" .format (
408
+ newInnerRadius , newOuterRadius , stamp .annularFlux
409
+ )
410
+ )
411
+ stamp .optimalOuterRadius = newOuterRadius
412
+ stamp .optimalInnerRadius = newInnerRadius
413
+ break
414
+ # elif newInnerRadius > maxInnerRadius:
415
+ # logger.info("The star with gaiaId of {} is impossible to normalize!".format(stamp.gaiaId))
416
+ # break
370
417
else :
371
418
stamp .annularFlux = np .nan
372
419
# Remove rejected stamps.
420
+ bss .normalized = True
373
421
if discardNanFluxObjects :
374
422
for reject in rejects :
375
423
bss ._stamps .remove (reject )
376
- bss .normalized = True
424
+ elif forceFindFlux :
425
+ for badStamp in badStamps :
426
+ bss ._stamps .remove (badStamp )
427
+ bss ._innerRadius , bss ._outerRadius = None , None
428
+ return bss , badStamps
377
429
return bss
378
430
379
431
def _refresh_metadata (self ):
0 commit comments