From 3d1ff9ae4de133c38495ffd053b242516020bb3a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:08:19 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- romancal/assign_wcs/assign_wcs_step.py | 11 ++--- romancal/assign_wcs/tests/test_wcs.py | 7 +--- romancal/dark_current/dark_current_step.py | 8 ++-- romancal/dark_current/tests/test_dark.py | 7 ++-- romancal/dq_init/dq_init_step.py | 2 +- romancal/dq_init/tests/test_dq_init.py | 9 ++-- romancal/flatfield/tests/test_flatfield.py | 9 ++-- romancal/jump/tests/test_jump_step.py | 1 - romancal/linearity/tests/test_linearity.py | 41 +++++++++---------- .../tests/test_outlier_detection.py | 2 - romancal/photom/photom_step.py | 2 +- romancal/photom/tests/test_photom.py | 10 ++--- .../ramp_fitting/tests/test_ramp_fit_cas22.py | 1 - .../ramp_fitting/tests/test_ramp_fit_ols.py | 2 - romancal/refpix/refpix_step.py | 3 +- romancal/refpix/tests/test_step.py | 9 ++-- romancal/saturation/saturation_step.py | 2 +- romancal/saturation/tests/test_saturation.py | 16 ++++---- romancal/stpipe/tests/test_core.py | 2 - 19 files changed, 61 insertions(+), 83 deletions(-) diff --git a/romancal/assign_wcs/assign_wcs_step.py b/romancal/assign_wcs/assign_wcs_step.py index 704c206f2..c4b79e449 100644 --- a/romancal/assign_wcs/assign_wcs_step.py +++ b/romancal/assign_wcs/assign_wcs_step.py @@ -39,12 +39,14 @@ def process(self, input): result = input_model result.meta.cal_step.assign_wcs = "SKIPPED" return result - + reference_file_names[reftype] = reffile if reffile else "" log.info("Using reference files: %s for assign_wcs", reference_file_names) - #result = load_wcs(input_model, reference_file_names) - # Frames - detector = cf.Frame2D(name="detector", axes_order=(0, 1), unit=(u.pix, u.pix)) + # result = load_wcs(input_model, reference_file_names) + # Frames + detector = cf.Frame2D( + name="detector", axes_order=(0, 1), unit=(u.pix, u.pix) + ) v2v3 = cf.Frame2D( name="v2v3", axes_order=(0, 1), @@ -74,7 +76,6 @@ def process(self, input): output_model.meta.cal_step["assign_wcs"] = "COMPLETE" - if self.save_results: try: self.suffix = "assignwcs" diff --git a/romancal/assign_wcs/tests/test_wcs.py b/romancal/assign_wcs/tests/test_wcs.py index aaa80758d..e9126c964 100644 --- a/romancal/assign_wcs/tests/test_wcs.py +++ b/romancal/assign_wcs/tests/test_wcs.py @@ -1,5 +1,3 @@ -import os - import numpy as np import pytest from gwcs.wcstools import grid_from_bounding_box @@ -95,7 +93,6 @@ def test_wcs(tmpdir, distortion, step): @pytest.mark.parametrize("step", create_step()) def test_crds_getbestref(step): l2im = create_image() - l2_wcs = AssignWcsStep.call(l2im, override_distortion='N/A') + l2_wcs = AssignWcsStep.call(l2im, override_distortion="N/A") - assert l2_wcs.meta.cal_step.assign_wcs == 'SKIPPED' - + assert l2_wcs.meta.cal_step.assign_wcs == "SKIPPED" diff --git a/romancal/dark_current/dark_current_step.py b/romancal/dark_current/dark_current_step.py index b652c7161..034913e5f 100755 --- a/romancal/dark_current/dark_current_step.py +++ b/romancal/dark_current/dark_current_step.py @@ -25,11 +25,11 @@ def process(self, input): # Get the name of the dark reference file to use self.dark_name = self.get_reference_file(input_model, "dark") # Check for a valid reference file - if self.dark_name == 'N/A': - self.log.warning('No DARK reference file found') - self.log.warning('Dark current step will be skipped') + if self.dark_name == "N/A": + self.log.warning("No DARK reference file found") + self.log.warning("Dark current step will be skipped") result = input_model - result.meta.cal_step.dark = 'SKIPPED' + result.meta.cal_step.dark = "SKIPPED" return result self.log.info("Using DARK reference file: %s", self.dark_name) diff --git a/romancal/dark_current/tests/test_dark.py b/romancal/dark_current/tests/test_dark.py index c267edf78..fe0def0ca 100755 --- a/romancal/dark_current/tests/test_dark.py +++ b/romancal/dark_current/tests/test_dark.py @@ -2,7 +2,6 @@ Unit tests for dark current correction """ -import os import numpy as np import pytest @@ -107,6 +106,7 @@ def test_dark_step_output_dark_file(tmpdir, instrument, exptype): assert dark_out_file_model.data.shape == shape assert dark_out_file_model.dq.shape == shape[1:] + @pytest.mark.parametrize( "instrument, exptype", [ @@ -124,9 +124,8 @@ def test_dark_step_getbestrefs(tmpdir, instrument, exptype): ramp_model, darkref_model = create_ramp_and_dark(shape, instrument, exptype) # Perform Dark Current subtraction step with override = N/A - result = DarkCurrentStep.call(ramp_model, override_dark='N/A') - assert result.meta.cal_step.dark == 'SKIPPED' - + result = DarkCurrentStep.call(ramp_model, override_dark="N/A") + assert result.meta.cal_step.dark == "SKIPPED" # Perform Dark Current subtraction step DarkCurrentStep.call(ramp_model, override_dark=darkref_model, dark_output=path) diff --git a/romancal/dq_init/dq_init_step.py b/romancal/dq_init/dq_init_step.py index 88e46e16d..db1e1786d 100644 --- a/romancal/dq_init/dq_init_step.py +++ b/romancal/dq_init/dq_init_step.py @@ -80,7 +80,7 @@ def process(self, input): reference_file_name = self.get_reference_file(output_model, "mask") # Test for reference file - if reference_file_name != 'N/A' and reference_file_name is not None: + if reference_file_name != "N/A" and reference_file_name is not None: # If there are mask files, perform dq step # Open the relevant reference files as datamodels reference_file_model = rdm.open(reference_file_name) diff --git a/romancal/dq_init/tests/test_dq_init.py b/romancal/dq_init/tests/test_dq_init.py index 52baa14c3..4bea3e8da 100644 --- a/romancal/dq_init/tests/test_dq_init.py +++ b/romancal/dq_init/tests/test_dq_init.py @@ -1,5 +1,3 @@ -import os - import numpy as np import pytest from astropy import units as u @@ -240,7 +238,6 @@ def test_dqinit_step_interface(instrument, exptype): ("WFI", "WFI_IMAGE"), ], ) - def test_dqinit_refpix(instrument, exptype): """Test that the basic inferface works for data requiring a DQ reffile""" @@ -292,7 +289,7 @@ def test_dqinit_refpix(instrument, exptype): [ ("WFI", "WFI_IMAGE"), ], -) +) def test_dqinit_getbestref(instrument, exptype): """Test that the step is skipped if the CRDS reffile is N/A""" @@ -313,5 +310,5 @@ def test_dqinit_getbestref(instrument, exptype): wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw) # Perform Data Quality application step - result = DQInitStep.call(wfi_sci_raw_model, override_mask='N/A') - assert result.meta.cal_step.dq_init == 'SKIPPED' + result = DQInitStep.call(wfi_sci_raw_model, override_mask="N/A") + assert result.meta.cal_step.dq_init == "SKIPPED" diff --git a/romancal/flatfield/tests/test_flatfield.py b/romancal/flatfield/tests/test_flatfield.py index 6909110a9..106538dd4 100644 --- a/romancal/flatfield/tests/test_flatfield.py +++ b/romancal/flatfield/tests/test_flatfield.py @@ -1,5 +1,3 @@ -import os - import numpy as np import pytest from astropy import units as u @@ -62,13 +60,12 @@ def test_flatfield_step_interface(instrument, exptype): assert result.var_flat.shape == shape assert result.meta.cal_step.flat_field == "COMPLETE" - # test that the step is skipped if the reference file is N/A - result = FlatFieldStep.call(wfi_image_model, override_flat='N/A') + result = FlatFieldStep.call(wfi_image_model, override_flat="N/A") + + assert result.meta.cal_step.flat_field == "SKIPPED" - assert result.meta.cal_step.flat_field == 'SKIPPED' - @pytest.mark.parametrize( "instrument, exptype", [ diff --git a/romancal/jump/tests/test_jump_step.py b/romancal/jump/tests/test_jump_step.py index 3abf584d1..0ebb28e4b 100644 --- a/romancal/jump/tests/test_jump_step.py +++ b/romancal/jump/tests/test_jump_step.py @@ -1,7 +1,6 @@ """ Unit tests for the Roman jump step code """ -import os from itertools import cycle import numpy as np diff --git a/romancal/linearity/tests/test_linearity.py b/romancal/linearity/tests/test_linearity.py index 900ebed66..feb35ea06 100644 --- a/romancal/linearity/tests/test_linearity.py +++ b/romancal/linearity/tests/test_linearity.py @@ -7,10 +7,10 @@ import pytest from astropy import units as u from roman_datamodels import maker_utils -from roman_datamodels.datamodels import ScienceRawModel, LinearityRefModel +from roman_datamodels.datamodels import LinearityRefModel, ScienceRawModel -from romancal.lib import dqflags from romancal.dq_init import DQInitStep +from romancal.lib import dqflags from romancal.linearity import LinearityStep @@ -40,9 +40,9 @@ def test_linearity_coeff(instrument, exptype): wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw) result = DQInitStep.call(wfi_sci_raw_model) - result = LinearityStep.call(result, override_linearity='N/A') + result = LinearityStep.call(result, override_linearity="N/A") - assert result.meta.cal_step.linearity == 'SKIPPED' + assert result.meta.cal_step.linearity == "SKIPPED" # Set coefficient values in reference file to check the algorithm # Equation is DNcorr = L0 + L1*DN(i) + L2*DN(i)^2 + L3*DN(i)^3 + L4*DN(i)^4 @@ -50,29 +50,26 @@ def test_linearity_coeff(instrument, exptype): # L0 = 0 for all pixels for CDP6 coeffs = np.zeros(shape, dtype=np.float32) - coeffs[1,:,:].fill(0.85) - coeffs[2,:,:].fill(4.62e-06) - coeffs[3,:,:].fill(-6.16e-11) - coeffs[4,:,:].fill(7.23e-16) - #coeffs = np.tile(coeffs,(5,20,4)) + coeffs[1, :, :].fill(0.85) + coeffs[2, :, :].fill(4.62e-06) + coeffs[3, :, :].fill(-6.16e-11) + coeffs[4, :, :].fill(7.23e-16) + # coeffs = np.tile(coeffs,(5,20,4)) # set one set of coeffs to 0 to check that the data values are not altered. # and that the DQ flag is set to NO_LIN_CORR - coeffs[0:,5,5] = 0.0 + coeffs[0:, 5, 5] = 0.0 # set one of the coeffs to NaN and check that the DQ flag is set to NO_LIN_CORR - coeffs[0:,6,5] = np.nan + coeffs[0:, 6, 5] = np.nan # save the pixel values to make sure they are not altered - pixels_55 = result.data[0:,5,5] - pixels_65 = result.data[0:,6,5] - linref = maker_utils.mk_linearity(shape=shape,coeffs=coeffs) + pixels_55 = result.data[0:, 5, 5] + pixels_65 = result.data[0:, 6, 5] + linref = maker_utils.mk_linearity(shape=shape, coeffs=coeffs) linref_model = LinearityRefModel(linref) LinearityStep.call(result, override_linearity=linref_model) - assert result.meta.cal_step.linearity == 'COMPLETE' - assert result.pixeldq[5,5] == dqflags.pixel["NO_LIN_CORR"] - assert result.pixeldq[6,5] == dqflags.pixel["NO_LIN_CORR"] - np.testing.assert_array_equal(result.data[0:,5,5],pixels_55) - np.testing.assert_array_equal(result.data[0:,6,5],pixels_65) - - - + assert result.meta.cal_step.linearity == "COMPLETE" + assert result.pixeldq[5, 5] == dqflags.pixel["NO_LIN_CORR"] + assert result.pixeldq[6, 5] == dqflags.pixel["NO_LIN_CORR"] + np.testing.assert_array_equal(result.data[0:, 5, 5], pixels_55) + np.testing.assert_array_equal(result.data[0:, 6, 5], pixels_65) diff --git a/romancal/outlier_detection/tests/test_outlier_detection.py b/romancal/outlier_detection/tests/test_outlier_detection.py index b6a564a77..821cdf4af 100644 --- a/romancal/outlier_detection/tests/test_outlier_detection.py +++ b/romancal/outlier_detection/tests/test_outlier_detection.py @@ -1,5 +1,3 @@ -import os - import pytest from astropy import units as u from roman_datamodels import maker_utils diff --git a/romancal/photom/photom_step.py b/romancal/photom/photom_step.py index d09a45b0f..4f2a92bf6 100644 --- a/romancal/photom/photom_step.py +++ b/romancal/photom/photom_step.py @@ -36,7 +36,7 @@ def process(self, input): reffile = self.get_reference_file(input_model, "photom") # Open the relevant photom reference file as a datamodel - if reffile is not None and reffile != 'N/A': + if reffile is not None and reffile != "N/A": # If there is a reference file, perform photom application photom_model = rdm.open(reffile) self.log.debug(f"Using PHOTOM ref file: {reffile}") diff --git a/romancal/photom/tests/test_photom.py b/romancal/photom/tests/test_photom.py index 91b46a866..044a3737a 100644 --- a/romancal/photom/tests/test_photom.py +++ b/romancal/photom/tests/test_photom.py @@ -1,4 +1,3 @@ -import os import warnings import numpy as np @@ -260,11 +259,12 @@ def test_photom_step_interface(instrument, exptype): else: assert result.meta.cal_step.photom == "SKIPPED" - # Run photom correction step with reffile as N/A - result = PhotomStep.call(wfi_image_model, override_photom='N/A') + # Run photom correction step with reffile as N/A + result = PhotomStep.call(wfi_image_model, override_photom="N/A") + + assert result.meta.cal_step.photom == "SKIPPED" + - assert result.meta.cal_step.photom == 'SKIPPED' - @pytest.mark.parametrize( "instrument, exptype", [ diff --git a/romancal/ramp_fitting/tests/test_ramp_fit_cas22.py b/romancal/ramp_fitting/tests/test_ramp_fit_cas22.py index b44629d13..20be54999 100644 --- a/romancal/ramp_fitting/tests/test_ramp_fit_cas22.py +++ b/romancal/ramp_fitting/tests/test_ramp_fit_cas22.py @@ -1,5 +1,4 @@ """Ramp Fitting tests involving MultiAccum Tables""" -import os import numpy as np import pytest diff --git a/romancal/ramp_fitting/tests/test_ramp_fit_ols.py b/romancal/ramp_fitting/tests/test_ramp_fit_ols.py index 64ea2481a..2e26d978b 100644 --- a/romancal/ramp_fitting/tests/test_ramp_fit_ols.py +++ b/romancal/ramp_fitting/tests/test_ramp_fit_ols.py @@ -1,5 +1,3 @@ -import os - import numpy as np import pytest from astropy import units as u diff --git a/romancal/refpix/refpix_step.py b/romancal/refpix/refpix_step.py index 742af3b17..3f70d972d 100644 --- a/romancal/refpix/refpix_step.py +++ b/romancal/refpix/refpix_step.py @@ -42,7 +42,7 @@ def process(self, input): # Get the reference file ref_file = self.get_reference_file(datamodel, "refpix") - # Check for a valid reference file + # Check for a valid reference file if ref_file == "N/A": self.log.warning("No REFPIX reference file found") self.log.warning("Reference pixel correction step will be skipped") @@ -50,7 +50,6 @@ def process(self, input): result.meta.cal_step.refpix = "SKIPPED" return result - log.debug(f"Opening the reference file: {ref_file}") with rdm.open(ref_file) as refs: # Run the correction diff --git a/romancal/refpix/tests/test_step.py b/romancal/refpix/tests/test_step.py index 457551eaf..2bd95e49b 100644 --- a/romancal/refpix/tests/test_step.py +++ b/romancal/refpix/tests/test_step.py @@ -1,5 +1,3 @@ -import os - import pytest from romancal.refpix import RefPixStep @@ -60,15 +58,14 @@ def test_refpix_step( result.border_ref_pix_right.value == regression.border_ref_pix_right.value ).all() assert result.border_ref_pix_right.unit == regression.border_ref_pix_right.unit -# + # # Run the step with reffile = N/A result = RefPixStep.call( datamodel, - override_refpix='N/A', + override_refpix="N/A", remove_offset=remove_offset, remove_trends=remove_trends, cosine_interpolate=cosine_interpolate, fft_interpolate=fft_interpolate, ) - assert result.meta.cal_step.refpix == 'SKIPPED' - + assert result.meta.cal_step.refpix == "SKIPPED" diff --git a/romancal/saturation/saturation_step.py b/romancal/saturation/saturation_step.py index 93b8f7a5f..440738cff 100755 --- a/romancal/saturation/saturation_step.py +++ b/romancal/saturation/saturation_step.py @@ -31,7 +31,7 @@ def process(self, input): return result # Open the reference file data model - # Test for reference file + # Test for reference file self.log.info("Using SATURATION reference file: %s", self.ref_name) ref_model = SaturationRefModel(self.ref_name) diff --git a/romancal/saturation/tests/test_saturation.py b/romancal/saturation/tests/test_saturation.py index 3e0c5cd8d..eea134a3d 100644 --- a/romancal/saturation/tests/test_saturation.py +++ b/romancal/saturation/tests/test_saturation.py @@ -11,8 +11,9 @@ from roman_datamodels.datamodels import ScienceRawModel from romancal.lib import dqflags -from romancal.saturation.saturation import flag_saturation from romancal.saturation import SaturationStep +from romancal.saturation.saturation import flag_saturation + def test_basic_saturation_flagging(setup_wfi_datamodels): """Check that the saturation flag is set when a pixel value is above the @@ -316,29 +317,30 @@ def test_nans_in_mask(setup_wfi_datamodels): # Check that output PIXELDQ is set to NO_SAT_CHECK assert output.pixeldq[5, 5] == dqflags.pixel["NO_SAT_CHECK"] + def test_saturation_getbestref(setup_wfi_datamodels): """Check that when CRDS returns N/A for the reference file the step is skipped""" - # Set test size + # Set test size shape = (2, 20, 20) # Create test science raw model wfi_sci_raw = maker_utils.mk_level1_science_raw(shape=shape) - wfi_sci_raw.meta.instrument.name = 'WFI' + wfi_sci_raw.meta.instrument.name = "WFI" wfi_sci_raw.meta.instrument.detector = "WFI01" wfi_sci_raw.meta.instrument.optical_element = "F158" wfi_sci_raw.meta["guidestar"]["gw_window_xstart"] = 1012 wfi_sci_raw.meta["guidestar"]["gw_window_xsize"] = 16 - wfi_sci_raw.meta.exposure.type = 'WFI_IMAGE' + wfi_sci_raw.meta.exposure.type = "WFI_IMAGE" wfi_sci_raw.data = u.Quantity( np.ones(shape, dtype=np.uint16), u.DN, dtype=np.uint16 ) wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw, dq=True) - + # Run the pipeline - result = SaturationStep.call(wfi_sci_raw_model, override_saturation='N/A') - assert result.meta.cal_step.saturation == 'SKIPPED' + result = SaturationStep.call(wfi_sci_raw_model, override_saturation="N/A") + assert result.meta.cal_step.saturation == "SKIPPED" @pytest.fixture(scope="function") diff --git a/romancal/stpipe/tests/test_core.py b/romancal/stpipe/tests/test_core.py index da4a4dcdd..09a046ab0 100644 --- a/romancal/stpipe/tests/test_core.py +++ b/romancal/stpipe/tests/test_core.py @@ -1,5 +1,3 @@ -import os - import asdf import pytest from astropy.time import Time