Skip to content

Commit

Permalink
Work around NotImplemented Quantity.tofile (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Oct 4, 2024
2 parents 8601da8 + f2c004d commit 2383105
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/1436.outlier_detection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where on_disk=True could fail due to Quantities not implementing tofile.
25 changes: 22 additions & 3 deletions romancal/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def test_outlier_do_detection_write_files_to_custom_location(tmp_path, base_imag
assert all(x.exists() for x in outlier_files_path)


def test_find_outliers(tmp_path, base_image):
@pytest.mark.parametrize("on_disk", (True, False))
def test_find_outliers(tmp_path, base_image, on_disk):
"""
Test that OutlierDetection can find outliers.
"""
Expand Down Expand Up @@ -158,13 +159,31 @@ def test_find_outliers(tmp_path, base_image):
imgs[0].data[img_0_input_coords[0], img_0_input_coords[1]] = cr_value
imgs[1].data[img_1_input_coords[0], img_1_input_coords[1]] = cr_value

input_models = ModelLibrary(imgs)
if on_disk:
# write out models and asn to disk
for img in imgs:
img.save(img.meta.filename)
asn_dict = {
"asn_id": "a3001",
"asn_pool": "none",
"products": [
{
"name": "test_asn",
"members": [
{"expname": m.meta.filename, "exptype": "science"} for m in imgs
],
}
],
}
input_models = ModelLibrary(asn_dict, on_disk=True)
else:
input_models = ModelLibrary(imgs)

outlier_step = OutlierDetectionStep()
# set output dir for all files created by the step
outlier_step.output_dir = tmp_path.as_posix()
# make sure files are written out to disk
outlier_step.in_memory = False
outlier_step.in_memory = not on_disk

result = outlier_step(input_models)

Expand Down
4 changes: 2 additions & 2 deletions romancal/outlier_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _median_with_resampling(

weight_threshold = compute_weight_threshold(drizzled_model.weight, maskpt)
drizzled_model.data[drizzled_model.weight < weight_threshold] = np.nan
computer.append(drizzled_model.data, i)
computer.append(drizzled_model.data.value, i)
del drizzled_model

# Perform median combination on set of drizzled mosaics
Expand Down Expand Up @@ -173,7 +173,7 @@ def _median_without_resampling(

weight_threshold = compute_weight_threshold(wht, maskpt)

data_copy = model.data.copy()
data_copy = model.data.value.copy()
data_copy[wht < weight_threshold] = np.nan
computer.append(data_copy, i)

Expand Down

0 comments on commit 2383105

Please sign in to comment.