From bae96ca27c38d360378cc79e4603bbd1acfbc6eb Mon Sep 17 00:00:00 2001 From: Juan Escudero Date: Sat, 8 Feb 2025 22:37:40 +0000 Subject: [PATCH] Refactor automatic flagging --- iop4lib/db/photopolresult.py | 12 ++++++++++++ iop4lib/iop4.py | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/iop4lib/db/photopolresult.py b/iop4lib/db/photopolresult.py index c92fbcb9..1b640bbe 100644 --- a/iop4lib/db/photopolresult.py +++ b/iop4lib/db/photopolresult.py @@ -296,6 +296,18 @@ def save(self, *args, **kwargs): """ Overriden to enforce clean() before saving. See PhotoPolResult.__docstring__ for more info.""" self.clean() super().save(*args, **kwargs) + + # Auto-flagging + + def auto_flag(self): + + if self.p is not None and not (0 <= self.p <= 1): + self.set_flag(PhotoPolResult.FLAGS.BAD_POLARIMETRY) + + if self.mag is not None and self.mag_err is not None and self.mag_err > 0.3: + self.set_flag(PhotoPolResult.FLAGS.BAD_PHOTOMETRY) + + self.save() # Host galaxy correction diff --git a/iop4lib/iop4.py b/iop4lib/iop4.py index 46f8b541..89559ca1 100644 --- a/iop4lib/iop4.py +++ b/iop4lib/iop4.py @@ -82,9 +82,7 @@ def process_epochs(epochname_list: Iterable[str], args): logger.info("Auto-flagging points.") for result in PhotoPolResult.objects.filter(epoch__in=epoch_L).all(): - if result.p is not None and not (0 <= result.p <= 1): - result.set_flag(PhotoPolResult.FLAGS.BAD_POLARIMETRY) - result.save() + result.auto_flag() logger.info("Applying corrections.") @@ -162,9 +160,7 @@ def process_astrosource(args): logger.info("Auto-flagging points.") for result in PhotoPolResult.objects.filter(epoch__in=epoch_L).all(): - if result.p is not None and not (0 <= result.p <= 1): - result.set_flag(PhotoPolResult.FLAGS.BAD_POLARIMETRY) - result.save() + result.auto_flag() logger.info("Applying corrections.")