From 4b87313df02d8dd3806c58ea99a68779c0decb3c Mon Sep 17 00:00:00 2001 From: TheSkyentist Date: Wed, 28 Feb 2024 12:21:50 +0100 Subject: [PATCH 1/5] Added option to not do 1/f when doing set_jwst_to_hst_keywords --- grizli/jwst_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grizli/jwst_utils.py b/grizli/jwst_utils.py index ff1effa5..dfdd0b86 100644 --- a/grizli/jwst_utils.py +++ b/grizli/jwst_utils.py @@ -1456,7 +1456,7 @@ def initialize_jwst_image(filename, verbose=True, max_dq_bit=14, orig_keys=ORIG_ # 'F480M': [1.879639e-21, 1.453752e-30, 4.8152]} # -def set_jwst_to_hst_keywords(input, reset=False, verbose=True, orig_keys=ORIG_KEYS): +def set_jwst_to_hst_keywords(input, reset=False, verbose=True, orig_keys=ORIG_KEYS, oneoverf_correction=True): """ Make primary header look like an HST instrument """ @@ -1476,7 +1476,7 @@ def set_jwst_to_hst_keywords(input, reset=False, verbose=True, orig_keys=ORIG_KE 'DETECTOR':'IR'} if 'OTELESCO' not in img[0].header: - _status = initialize_jwst_image(input, verbose=verbose) + _status = initialize_jwst_image(input, oneoverf_correction=oneoverf_correction, verbose=verbose) # Reopen if isinstance(input, str): From d600292e326ab28eb941dd64dc0ad78a79c3562a Mon Sep 17 00:00:00 2001 From: TheSkyentist Date: Fri, 1 Mar 2024 17:58:26 +0100 Subject: [PATCH 2/5] Check if 1/f already applied, also added force option --- grizli/jwst_utils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/grizli/jwst_utils.py b/grizli/jwst_utils.py index dfdd0b86..c155c2bd 100644 --- a/grizli/jwst_utils.py +++ b/grizli/jwst_utils.py @@ -923,7 +923,7 @@ def copy_jwst_keywords(header, orig_keys=ORIG_KEYS, verbose=True): utils.log_comment(utils.LOGFILE, msg, verbose=verbose) -def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask=None, dilate_iterations=3, deg_pix=64, make_plot=True, init_model=0, in_place=False, skip_miri=True, verbose=True, **kwargs): +def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask=None, dilate_iterations=3, deg_pix=64, make_plot=True, init_model=0, in_place=False, skip_miri=True, force_oneoverf=False, verbose=True, **kwargs): """ 1/f correction for individual exposure @@ -971,6 +971,9 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask skip_miri : bool Don't run on MIRI exposures + force_oneoverf : bool + Force the correction even if the `ONEFEXP` keyword is already set + verbose : bool Print status messages @@ -997,6 +1000,14 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask utils.log_comment(utils.LOGFILE, msg, verbose=verbose) return None, 0 + + if (ONEFEXP in im[0].header) & im[0].header['ONEFEXP'] & (not force): + im.close() + + msg = 'exposure_oneoverf_correction: Skip, already corrected' + utils.log_comment(utils.LOGFILE, msg, verbose=verbose) + + return None, 0 if axis is None: if im[0].header['INSTRUME'] in ('NIRISS', 'NIRSPEC'): From 59c405862e07ef6b091eff7453cfe18ab9c58288 Mon Sep 17 00:00:00 2001 From: TheSkyentist Date: Fri, 1 Mar 2024 18:00:11 +0100 Subject: [PATCH 3/5] Fixed bug --- grizli/jwst_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grizli/jwst_utils.py b/grizli/jwst_utils.py index c155c2bd..88268f90 100644 --- a/grizli/jwst_utils.py +++ b/grizli/jwst_utils.py @@ -1001,7 +1001,7 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask return None, 0 - if (ONEFEXP in im[0].header) & im[0].header['ONEFEXP'] & (not force): + if ('ONEFEXP' in im[0].header) & im[0].header['ONEFEXP'] & (not force): im.close() msg = 'exposure_oneoverf_correction: Skip, already corrected' From 0343a24eed941d1db602d83e7c8b4fcafcc0635c Mon Sep 17 00:00:00 2001 From: TheSkyentist Date: Fri, 1 Mar 2024 18:02:28 +0100 Subject: [PATCH 4/5] Fixed bug --- grizli/jwst_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grizli/jwst_utils.py b/grizli/jwst_utils.py index 88268f90..33463c6b 100644 --- a/grizli/jwst_utils.py +++ b/grizli/jwst_utils.py @@ -1001,7 +1001,7 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask return None, 0 - if ('ONEFEXP' in im[0].header) & im[0].header['ONEFEXP'] & (not force): + if ('ONEFEXP' in im[0].header) & im[0].header['ONEFEXP'] & (not force_oneoverf): im.close() msg = 'exposure_oneoverf_correction: Skip, already corrected' From 8e0c6292ca60b60b916bc71c1b602ee52ba0a318 Mon Sep 17 00:00:00 2001 From: TheSkyentist Date: Mon, 4 Mar 2024 10:20:57 +0100 Subject: [PATCH 5/5] Using and instead of & to get correct behaviour --- grizli/jwst_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grizli/jwst_utils.py b/grizli/jwst_utils.py index 33463c6b..799ee5c1 100644 --- a/grizli/jwst_utils.py +++ b/grizli/jwst_utils.py @@ -1001,7 +1001,7 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask return None, 0 - if ('ONEFEXP' in im[0].header) & im[0].header['ONEFEXP'] & (not force_oneoverf): + if ('ONEFEXP' in im[0].header) and im[0].header['ONEFEXP'] and (not force_oneoverf): im.close() msg = 'exposure_oneoverf_correction: Skip, already corrected'