From e5859642deb95ad1539efe9a7153305065967c4d Mon Sep 17 00:00:00 2001 From: Curtis McCully Date: Mon, 16 Dec 2024 09:57:52 -0500 Subject: [PATCH] Fixes to tests. Addressed some comments. --- banzai/calibrations.py | 8 ++++---- banzai/celery.py | 2 +- banzai/dbs.py | 12 ++++++------ banzai/main.py | 3 ++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/banzai/calibrations.py b/banzai/calibrations.py index 0a4fa999..2909691a 100644 --- a/banzai/calibrations.py +++ b/banzai/calibrations.py @@ -139,11 +139,11 @@ def apply_master_calibration(self, image, master_calibration_image): def get_calibration_file_info(self, image): return dbs.cal_record_to_file_info( dbs.get_master_cal_record(image, self.calibration_type, self.master_selection_criteria, - self.runtime_context.db_address, + self.runtime_context.db_address, use_only_older_calibrations=self.runtime_context.use_only_older_calibrations, - prefer_same_block=self.runtime_context.same_block_cals, - prefer_same_proposal=self.runtime_context.prefer_same_proposal, - check_public=self.runtime_context.check_public_cals) + prefer_same_block_cals=self.runtime_context.same_block_cals, + prefer_same_proposal_cals=self.runtime_context.prefer_same_proposal_cals, + check_public_cals=self.runtime_context.check_public_cals) ) diff --git a/banzai/celery.py b/banzai/celery.py index e34214e8..bdda5e06 100644 --- a/banzai/celery.py +++ b/banzai/celery.py @@ -183,7 +183,7 @@ def process_image(self, file_info: dict, runtime_context: dict): try: logger.info('Processing frame', extra_tags={'filename': file_info.get('filename')}) runtime_context = Context(runtime_context) - if realtime_utils.need_to_process_image(file_info, runtime_context): + if realtime_utils.need_to_process_image(file_info, runtime_context, self): if 'path' in file_info: filename = os.path.basename(file_info['path']) else: diff --git a/banzai/dbs.py b/banzai/dbs.py index 1c5ef66c..ca8bbacd 100755 --- a/banzai/dbs.py +++ b/banzai/dbs.py @@ -338,8 +338,8 @@ def cal_record_to_file_info(record): def get_master_cal_record(image, calibration_type, master_selection_criteria, db_address, - use_only_older_calibrations=False, prefer_same_block=False, check_public=False, - prefer_same_proposal=False): + use_only_older_calibrations=False, prefer_same_block_cals=False, check_public_cals=False, + prefer_same_proposal_cals=False): calibration_criteria = CalibrationImage.type == calibration_type.upper() calibration_criteria &= CalibrationImage.instrument_id == image.instrument.id calibration_criteria &= CalibrationImage.is_master.is_(True) @@ -361,16 +361,16 @@ def get_master_cal_record(image, calibration_type, master_selection_criteria, db calibration_image = None with get_session(db_address=db_address) as db_session: - if prefer_same_block: + if prefer_same_block_cals: block_criteria = CalibrationImage.blockid == image.blockid image_filter = db_session.query(CalibrationImage).filter(calibration_criteria & block_criteria) calibration_image = image_filter.order_by(func.abs(CalibrationImage.dateobs - image.dateobs)).first() - if calibration_image is None and prefer_same_proposal: + if calibration_image is None and prefer_same_proposal_cals: proposal_criteria = CalibrationImage.proposal == image.proposal image_filter = db_session.query(CalibrationImage).filter(calibration_criteria & proposal_criteria) calibration_image = image_filter.order_by(func.abs(CalibrationImage.dateobs - image.dateobs)).first() - if check_public: - calibration_criteria &= CalibrationImage.public_date <= datetime.datetime.utcnow() + if check_public_cals: + calibration_criteria &= CalibrationImage.public_date <= datetime.datetime.now(datetime.UTC) if calibration_image is None: image_filter = db_session.query(CalibrationImage).filter(calibration_criteria) calibration_image = image_filter.order_by(func.abs(CalibrationImage.dateobs - image.dateobs)).first() diff --git a/banzai/main.py b/banzai/main.py index 76deb975..a1e12145 100755 --- a/banzai/main.py +++ b/banzai/main.py @@ -124,7 +124,8 @@ def parse_args(settings, extra_console_arguments=None, parser_description='Proce help='Prefer calibrations taken in the same block') parser.add_argument('--check-public-cals', dest='check_public_cals', default=False, action='store_true', help='Check to see if calibration frames are public before using them?') - parser.add_argument('--prefer-same-proposal', dest='prefer_same_proposal', default=False, action='store_true', + parser.add_argument('--prefer-same-proposal-cals', dest='prefer_same_proposal_cals', + default=False, action='store_true', help='Prefer calibrations taken with the same proposal') if extra_console_arguments is None: