Skip to content

Commit

Permalink
Merge branch 'remove-var-flat' of https://github.com/schlafly/romancal
Browse files Browse the repository at this point in the history
…into remove-var-flat
  • Loading branch information
schlafly committed Oct 4, 2024
2 parents 714ad9e + 4316420 commit f9ebf61
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
9 changes: 3 additions & 6 deletions romancal/flatfield/flat_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def do_flat_field(output_model, flat_model, include_var_flat=False):
log.info("Skipping flat field - no flat reference file.")
output_model.meta.cal_step.flat_field = "SKIPPED"
else:
apply_flat_field(output_model, flat_model,
include_var_flat=include_var_flat)
apply_flat_field(output_model, flat_model, include_var_flat=include_var_flat)
output_model.meta.cal_step.flat_field = "COMPLETE"


Expand Down Expand Up @@ -130,10 +129,8 @@ def apply_flat_field(science, flat, include_var_flat=False):
try:
science.var_flat = science.data**2 / flat_data_squared * flat_err**2
except AttributeError:
science["var_flat"] = np.zeros(
shape=science.data.shape, dtype=np.float32)
science.var_flat = (science.data**2
/ flat_data_squared * flat_err**2)
science["var_flat"] = np.zeros(shape=science.data.shape, dtype=np.float32)
science.var_flat = science.data**2 / flat_data_squared * flat_err**2

Check warning on line 133 in romancal/flatfield/flat_field.py

View check run for this annotation

Codecov / codecov/patch

romancal/flatfield/flat_field.py#L131-L133

Added lines #L131 - L133 were not covered by tests
total_var += science.var_flat

science.err = np.sqrt(total_var)
Expand Down
4 changes: 1 addition & 3 deletions romancal/flatfield/flat_field_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def process(self, input_model):

# Do the flat-field correction
output_model = flat_field.do_correction(
input_model,
reference_file_model,
include_var_flat=self.include_var_flat
input_model, reference_file_model, include_var_flat=self.include_var_flat
)

# Close reference file
Expand Down
8 changes: 4 additions & 4 deletions romancal/flatfield/tests/test_flatfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def test_skip_var_flat():

wfi_image1 = maker_utils.mk_level2_image()
wfi_image2 = maker_utils.mk_level2_image()
del wfi_image1['var_flat']
del wfi_image2['var_flat']
del wfi_image1["var_flat"]
del wfi_image2["var_flat"]
wfi_image_model1 = ImageModel(wfi_image1)
wfi_image_model2 = ImageModel(wfi_image2)
result1 = FlatFieldStep.call(wfi_image_model1, include_var_flat=False)
result2 = FlatFieldStep.call(wfi_image_model2, include_var_flat=True)
assert not hasattr(result1, 'var_flat')
assert hasattr(result2, 'var_flat')
assert not hasattr(result1, "var_flat")
assert hasattr(result2, "var_flat")


@pytest.mark.parametrize(
Expand Down
3 changes: 1 addition & 2 deletions romancal/regtest/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def test_resample_single_file(rtdata, ignore_asdf_paths):
}"""
)
assert all(
hasattr(resample_out, x)
for x in ["data", "err", "var_poisson", "var_rnoise"]
hasattr(resample_out, x) for x in ["data", "err", "var_poisson", "var_rnoise"]
)

step.log.info(
Expand Down
7 changes: 4 additions & 3 deletions romancal/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ def __init__(

with self.input_models:
models = list(self.input_models)
self.all_have_var_flat = np.all([
hasattr(model, 'var_flat') for model in models])
self.all_have_var_flat = np.all(
[hasattr(model, "var_flat") for model in models]
)

# update meta.basic
populate_mosaic_basic(self.blank_output, models)
Expand All @@ -191,7 +192,7 @@ def __init__(
self.input_models.shelve(m, i, modify=False)

if not self.all_have_var_flat:
del self.blank_output._instance['var_flat']
del self.blank_output._instance["var_flat"]

def do_drizzle(self):
"""Pick the correct drizzling mode based on ``self.single``."""
Expand Down
6 changes: 3 additions & 3 deletions romancal/resample/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def test_var_flat_presence(exposure_1, include_var_flat):
if not include_var_flat:
exposure_1 = [e.copy() for e in exposure_1]
for e in exposure_1:
del e._instance['var_flat']
del e._instance["var_flat"]
input_models = ModelLibrary(exposure_1)
resample_data = ResampleData(input_models)

Expand All @@ -617,9 +617,9 @@ def test_var_flat_presence(exposure_1, include_var_flat):
output_model = output_models.borrow(0)

if not include_var_flat:
assert not hasattr(output_model, 'var_flat')
assert not hasattr(output_model, "var_flat")
else:
assert hasattr(output_model, 'var_flat')
assert hasattr(output_model, "var_flat")

output_models.shelve(output_model, 0, modify=False)

Expand Down

0 comments on commit f9ebf61

Please sign in to comment.