Skip to content
Snippets Groups Projects
Commit 221a0656 authored by Karim Ahmed's avatar Karim Ahmed
Browse files

remove unneeded replace_pixels_wrong_gain_badpixel

parent 15367405
No related branches found
No related tags found
1 merge request!916[Jungfrau][Correct] Force replacement for gain value in Jungfrau correction
......@@ -211,50 +211,14 @@ def sort_runs_by_gain(
return runs
def replace_pixels_wrong_gain_badpixel(
gain_arr,
new_gain_value,
badpixel_map,
memory_cells,
):
"""Replace the gain value with the given new gain value for pixels
indicated as bad with WRONG_GAIN_VALUE bit.
Args:
gain_arr (ndarray): The raw gain array to be updated.
new_gain_value (int): The new gain value to replace the gain value
for the pixels with WRONG_GAIN_VALUE badpixel.
badpixel_map (ndarray): The badpixel map for a cell.
memory_cells (int): Number of memory cells for the processed detector.
Returns:
ndarray: The updated gain_arr
"""
import numpy as np
from cal_tools.enums import BadPixels
# replace gain with WRONG_GAIN_VALUE pixels in the badpixel mask
wrong_gain_mask = BadPixels.WRONG_GAIN_VALUE.value
# Create a boolean mask to identify the elements that meet the condition
condition_mask = (badpixel_map[..., new_gain_value] & wrong_gain_mask) == wrong_gain_mask
if memory_cells == 1:
condition_mask = condition_mask[np.newaxis, :, :] # gain_arr.shape = [1, 512, 1024]
gain_arr[condition_mask] = new_gain_value
return gain_arr
def replace_pixels_gain_values(
gain_arr,
new_gain_value,
wrong_gain_pixels,
karabo_da,
badpixel_map,
memory_cells
):
"""Replace gain values with the chosen new gain value
for a single module.
Args:
gain_arr (ndarray): The raw gain array to be updated.
......@@ -262,7 +226,6 @@ def replace_pixels_gain_values(
wrong_gain_pixels (list): [module_index, row1, row12, col1, col2].
e.g. [4, 0, 255, 896, 1024] for JNGFR04 slicing module [0:255, 896:1024].
karabo_da (str): _description_
badpixel_map (ndarray): The badpixel map for one cell.
memory_cells (int): Number of memory cells.
Returns:
......@@ -278,12 +241,4 @@ def replace_pixels_gain_values(
gain_arr[:, x1:x2, y1:y2] = new_gain_value
return gain_arr
else: # No gain replacement
return gain_arr
else: # replace gain with WRONG_GAIN_VALUE pixels in the badpixel mask
return replace_pixels_wrong_gain_badpixel(
gain_arr,
new_gain_value,
badpixel_map,
memory_cells,
)
\ No newline at end of file
return gain_arr
\ No newline at end of file
......@@ -86,18 +86,6 @@ REPLACE_WRONG_GAIN_VALUE = 0
WRONG_GAIN_PIXELS = [4, 0, 255, 896, 1024]
def test_replace_pixels_wrong_gain_badpixel():
assert np.allclose(
NEW_GAIN,
replace_pixels_wrong_gain_badpixel(
gain_arr=GAIN,
new_gain_value=REPLACE_WRONG_GAIN_VALUE,
badpixel_map=BP,
memory_cells=MEM_CELLS,
)
)
def test_replace_pixels_gain_values():
assert np.allclose(
NEW_GAIN,
......@@ -106,8 +94,6 @@ def test_replace_pixels_gain_values():
new_gain_value=REPLACE_WRONG_GAIN_VALUE,
wrong_gain_pixels=WRONG_GAIN_PIXELS,
karabo_da=KARABO_DA,
badpixel_map=BP,
memory_cells=MEM_CELLS,
)
)
assert np.allclose(
......@@ -117,8 +103,6 @@ def test_replace_pixels_gain_values():
new_gain_value=REPLACE_WRONG_GAIN_VALUE,
wrong_gain_pixels=WRONG_GAIN_PIXELS,
karabo_da=KARABO_DA,
badpixel_map=BP,
memory_cells=MEM_CELLS,
)
)
assert np.allclose(
......@@ -128,7 +112,5 @@ def test_replace_pixels_gain_values():
new_gain_value=REPLACE_WRONG_GAIN_VALUE,
wrong_gain_pixels=WRONG_GAIN_PIXELS,
karabo_da="JNGFR01",
badpixel_map=BP,
memory_cells=MEM_CELLS,
)
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment