Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 8, 2024
1 parent 4404ae1 commit 3d1ff9a
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 83 deletions.
11 changes: 6 additions & 5 deletions romancal/assign_wcs/assign_wcs_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def process(self, input):
result = input_model
result.meta.cal_step.assign_wcs = "SKIPPED"
return result

Check warning on line 41 in romancal/assign_wcs/assign_wcs_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/assign_wcs/assign_wcs_step.py#L36-L41

Added lines #L36 - L41 were not covered by tests

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(

Check warning on line 47 in romancal/assign_wcs/assign_wcs_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/assign_wcs/assign_wcs_step.py#L47

Added line #L47 was not covered by tests
name="detector", axes_order=(0, 1), unit=(u.pix, u.pix)
)
v2v3 = cf.Frame2D(

Check warning on line 50 in romancal/assign_wcs/assign_wcs_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/assign_wcs/assign_wcs_step.py#L50

Added line #L50 was not covered by tests
name="v2v3",
axes_order=(0, 1),
Expand Down Expand Up @@ -74,7 +76,6 @@ def process(self, input):

output_model.meta.cal_step["assign_wcs"] = "COMPLETE"

Check warning on line 77 in romancal/assign_wcs/assign_wcs_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/assign_wcs/assign_wcs_step.py#L77

Added line #L77 was not covered by tests


if self.save_results:
try:
self.suffix = "assignwcs"
Expand Down
7 changes: 2 additions & 5 deletions romancal/assign_wcs/tests/test_wcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import numpy as np
import pytest
from gwcs.wcstools import grid_from_bounding_box
Expand Down Expand Up @@ -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"
8 changes: 4 additions & 4 deletions romancal/dark_current/dark_current_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 33 in romancal/dark_current/dark_current_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/dark_current/dark_current_step.py#L28-L33

Added lines #L28 - L33 were not covered by tests

self.log.info("Using DARK reference file: %s", self.dark_name)
Expand Down
7 changes: 3 additions & 4 deletions romancal/dark_current/tests/test_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Unit tests for dark current correction
"""

import os

import numpy as np
import pytest
Expand Down Expand Up @@ -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",
[
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion romancal/dq_init/dq_init_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Check warning on line 83 in romancal/dq_init/dq_init_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/dq_init/dq_init_step.py#L83

Added line #L83 was not covered by tests
# If there are mask files, perform dq step
# Open the relevant reference files as datamodels
reference_file_model = rdm.open(reference_file_name)
Expand Down
9 changes: 3 additions & 6 deletions romancal/dq_init/tests/test_dq_init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import numpy as np
import pytest
from astropy import units as u
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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"""

Expand All @@ -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"
9 changes: 3 additions & 6 deletions romancal/flatfield/tests/test_flatfield.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import numpy as np
import pytest
from astropy import units as u
Expand Down Expand Up @@ -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",
[
Expand Down
1 change: 0 additions & 1 deletion romancal/jump/tests/test_jump_step.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Unit tests for the Roman jump step code
"""
import os
from itertools import cycle

import numpy as np
Expand Down
41 changes: 19 additions & 22 deletions romancal/linearity/tests/test_linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -40,39 +40,36 @@ 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
# DN(i) = signal in pixel, Ln = coefficient from ref file
# 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)
2 changes: 0 additions & 2 deletions romancal/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import pytest
from astropy import units as u
from roman_datamodels import maker_utils
Expand Down
2 changes: 1 addition & 1 deletion romancal/photom/photom_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":

Check warning on line 39 in romancal/photom/photom_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/photom/photom_step.py#L39

Added line #L39 was not covered by tests
# If there is a reference file, perform photom application
photom_model = rdm.open(reffile)
self.log.debug(f"Using PHOTOM ref file: {reffile}")
Expand Down
10 changes: 5 additions & 5 deletions romancal/photom/tests/test_photom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import warnings

import numpy as np
Expand Down Expand Up @@ -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",
[
Expand Down
1 change: 0 additions & 1 deletion romancal/ramp_fitting/tests/test_ramp_fit_cas22.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Ramp Fitting tests involving MultiAccum Tables"""
import os

import numpy as np
import pytest
Expand Down
2 changes: 0 additions & 2 deletions romancal/ramp_fitting/tests/test_ramp_fit_ols.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import numpy as np
import pytest
from astropy import units as u
Expand Down
3 changes: 1 addition & 2 deletions romancal/refpix/refpix_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ 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")
result = datamodel
result.meta.cal_step.refpix = "SKIPPED"
return result

Check warning on line 51 in romancal/refpix/refpix_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/refpix/refpix_step.py#L46-L51

Added lines #L46 - L51 were not covered by tests


log.debug(f"Opening the reference file: {ref_file}")
with rdm.open(ref_file) as refs:
# Run the correction
Expand Down
9 changes: 3 additions & 6 deletions romancal/refpix/tests/test_step.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import pytest

from romancal.refpix import RefPixStep
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion romancal/saturation/saturation_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 35 in romancal/saturation/saturation_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/saturation/saturation_step.py#L35

Added line #L35 was not covered by tests
ref_model = SaturationRefModel(self.ref_name)

Expand Down
16 changes: 9 additions & 7 deletions romancal/saturation/tests/test_saturation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions romancal/stpipe/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import asdf
import pytest
from astropy.time import Time
Expand Down

0 comments on commit 3d1ff9a

Please sign in to comment.