diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index 95bb91ef5f09434db26126aeed0bd6772059d668..d0d89969be4e5d3abb1c89da958069a1e277b808 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -44,8 +44,8 @@ "limit_trains = 0 # ONLY FOR TESTING. process only first N trains, Use 0 to process all.\n", "chunks_ids = 32 # HDF chunk size for memoryCell and frameNumber.\n", "chunks_data = 1 # HDF chunk size for pixel data in number of frames.\n", - "replace_wrong_gain_value = -1 # Force gain value into the chosen gain [0, 1, or 2] for pixels marked with WRONG_GAIN_VALUE badpixel. Default -1 for not changing the gain values.\n", - "wrong_gain_pixels = [-1] # List with groups of 5 values (e.g. [4, 0, 255, 896, 1024]) defining the module number (4 for JNGFR04). And using the indexes of the FEM row [pixel_x_0:pixel_x_1] and column [pixel_y_0:pixel_y_1]. Set to -1 to not pick pixels for gain replacement.\n", + "wrong_gain_pixels = [-1] # List of 5 values (e.g. [4, 0, 255, 896, 1024]) defining the module number (4 for JNGFR04). And using the indexes of the FEM row [pixel_x_0:pixel_x_1] and column [pixel_y_0:pixel_y_1]. Set to -1 to not pick pixels for gain replacement.\n", + "replace_wrong_gain_value = 0 # Force gain value into the chosen gain [0, 1, or 2] for pixels specified in `wrong_gain_pixels`. This has no effect if wrong_gain_pixels = [-1]\n", "\n", "# Parameters for retrieving calibration constants\n", "integration_time = -1 # integration time in us. set to -1 to overwrite by value in file.\n", @@ -95,7 +95,7 @@ "from cal_tools.calcat_interface import JUNGFRAU_CalibrationData\n", "from cal_tools.enums import BadPixels\n", "from cal_tools.files import DataFile\n", - "from cal_tools.jungfraulib import JungfrauCtrl, replace_pixels_gain_values\n", + "from cal_tools.jungfraulib import JungfrauCtrl\n", "from cal_tools.plotting import init_jungfrau_geom\n", "from cal_tools.step_timing import StepTimer\n", "from cal_tools.tools import (\n", @@ -402,13 +402,17 @@ " # Change low gain to 2 for indexing purposes.\n", " g[g==3] = 2\n", "\n", - " if replace_wrong_gain_value > -1:\n", - " g = replace_pixels_gain_values(\n", - " g,\n", - " replace_wrong_gain_value,\n", - " wrong_gain_pixels,\n", - " local_karabo_da,\n", - " )\n", + " # A fix for a module hardware problem (e.g. Jungfrau_M302)\n", + " # of chip being stuck on the wrong gain bit.\n", + " if (\n", + " wrong_gain_pixels[0] > -1 and\n", + " wrong_gain_pixels[0] == int(local_karabo_da[-2:])\n", + " ):\n", + " x1 = wrong_gain_pixels[1]\n", + " x2 = wrong_gain_pixels[2]\n", + " y1 = wrong_gain_pixels[3]\n", + " y2 = wrong_gain_pixels[4]\n", + " g[:, x1:x2, y1:y2] = replace_wrong_gain_value\n", "\n", " # Select memory cells\n", " if memory_cells > 1:\n", diff --git a/src/cal_tools/jungfraulib.py b/src/cal_tools/jungfraulib.py index c27352e432b0b0cc03fa574be8a97b05b8f6db3a..bb1fcbcfa14439eb965d84cae47785a09725ffb0 100644 --- a/src/cal_tools/jungfraulib.py +++ b/src/cal_tools/jungfraulib.py @@ -209,36 +209,3 @@ def sort_runs_by_gain( "Please verify the selected 3 dark runs to process.") return runs - - -def replace_pixels_gain_values( - gain_arr, - new_gain_value, - wrong_gain_pixels, - karabo_da, -): - """Replace gain values with the chosen new gain value - for a single module. - - Args: - gain_arr (ndarray): The raw gain array to be updated. - new_gain_value (int): _description_ - 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_ - memory_cells (int): Number of memory cells. - - Returns: - (ndarray): The update gain_arr. - - """ - if wrong_gain_pixels[0] > -1: - if wrong_gain_pixels[0] == int(karabo_da[-2:]): - x1 = wrong_gain_pixels[1] - x2 = wrong_gain_pixels[2] - y1 = wrong_gain_pixels[3] - y2 = wrong_gain_pixels[4] - gain_arr[:, x1:x2, y1:y2] = new_gain_value - return gain_arr - else: # No gain replacement - return gain_arr \ No newline at end of file diff --git a/tests/test_jungfraulib.py b/tests/test_jungfraulib.py index c8ce1a35eba4b646219305e801499347d109a182..c7fb5258ba2c0035cbad2668e4bdc35131866855 100644 --- a/tests/test_jungfraulib.py +++ b/tests/test_jungfraulib.py @@ -1,13 +1,7 @@ -import numpy as np import pytest from extra_data import RunDirectory -from cal_tools.enums import BadPixels -from cal_tools.jungfraulib import ( - JungfrauCtrl, - replace_pixels_gain_values, - sort_runs_by_gain, -) +from cal_tools.jungfraulib import JungfrauCtrl, sort_runs_by_gain # TODO: replace with mocked RAW data as in tests/test_agipdlib.py JF = JungfrauCtrl( @@ -70,46 +64,3 @@ def test_sort_runs_by_gain(original_runs, sorted_runs): runs=original_runs, ctrl_src="FXE_XAD_JF1M/DET/CONTROL") assert validated_runs == sorted_runs - - -GAIN = np.zeros((1, 512, 1024), dtype=np.uint8) -NEW_GAIN = GAIN.copy() # all pixels in high gain. -GAIN[:, 0:255, 896:1024] = 3 # subsection of a chip is stuck in gain bit = 3 -BP = np.zeros((512, 1024, 3), dtype=np.uint32) -for i in range(3): - BP[0:255, 896:1024, i] = BadPixels.WRONG_GAIN_VALUE.value - -MEM_CELLS = 1 -KARABO_DA = "JNGFR04" -REPLACE_WRONG_GAIN_VALUE = 0 -WRONG_GAIN_PIXELS = [4, 0, 255, 896, 1024] - - -def test_replace_pixels_gain_values(): - assert np.allclose( - NEW_GAIN, - replace_pixels_gain_values( - gain_arr=GAIN, - new_gain_value=REPLACE_WRONG_GAIN_VALUE, - wrong_gain_pixels=WRONG_GAIN_PIXELS, - karabo_da=KARABO_DA, - ) - ) - assert np.allclose( - NEW_GAIN, - replace_pixels_gain_values( - gain_arr=GAIN, - new_gain_value=REPLACE_WRONG_GAIN_VALUE, - wrong_gain_pixels=WRONG_GAIN_PIXELS, - karabo_da=KARABO_DA, - ) - ) - assert np.allclose( - GAIN, # No replacement for non-selected module. - replace_pixels_gain_values( - gain_arr=GAIN, - new_gain_value=REPLACE_WRONG_GAIN_VALUE, - wrong_gain_pixels=WRONG_GAIN_PIXELS, - karabo_da="JNGFR01", - ) - )