diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index a1c9d4327f3925d214adc5f6c1eb018b4e60c8ab..3e319e8d37a23cedcadd775fd415497dd72724f5 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -382,12 +382,13 @@ "outputs": [], "source": [ "if strixel_sensor:\n", - " from cal_tools.jungfrau.jfstrixel import double_pixel_indices, get_strixel_parameters, to_strixel\n", - " Ydouble, Xdouble = double_pixel_indices(kind=strixel_sensor)\n", - " if not Ydouble:\n", - " Ydouble = slice(None)\n", - " if not Xdouble:\n", - " Xdouble = slice(None)\n", + " from cal_tools.jungfrau.jfstrixel import get_strixel_parameters, to_strixel\n", + " strx_params = get_strixel_parameters(strixel_sensor)\n", + "\n", + " strixel_shape = strx_params[\"frame_shape\"]\n", + " Ydouble = strx_params.get(\"ydouble\", slice(None))\n", + " Xdouble = strx_params.get(\"xdouble\", slice(None))\n", + "\n", " print('Strixel sensor transformation enabled')" ] }, @@ -587,7 +588,7 @@ " \n", " # Determine total output shape.\n", " if strixel_sensor:\n", - " oshape = (*ishape[:-2], *get_strixel_parameters(strixel_sensor)[\"frame_shape\"])\n", + " oshape = (*ishape[:-2], *strixel_shape)\n", " else:\n", " oshape = ishape\n", "\n", diff --git a/src/cal_tools/jungfrau/jfstrixel.py b/src/cal_tools/jungfrau/jfstrixel.py index 2ebf04917a28509d96bc73a459942aba7db2099d..3eff2ca75dedee82dd188faf7c0686f8daccd09b 100644 --- a/src/cal_tools/jungfrau/jfstrixel.py +++ b/src/cal_tools/jungfrau/jfstrixel.py @@ -5,44 +5,46 @@ from pathlib import Path REGULAR_SHAPE = (512, 1024) DIR_PATH = package_directory = Path(__file__).resolve().parent - def get_strixel_parameters(kind): + strx_parameters = {} + if kind == "A0123": file_path = DIR_PATH / "strixel_cols_A0123-lut_mask.npz" elif kind == "A1256": file_path = DIR_PATH / "strixel_rows_A1256-lut_mask.npz" - data = np.load(file_path) + with np.load(file_path) as data: + for k in data.files: + strx_parameters[k] = data[k] - return data + return strx_parameters -def double_pixel_indices(kind): +def store_double_pixel_indices(): """Build index arrays for double-size pixels. - In raw data, the entire columns 255, 256, 511, 512, 767 and 768 + In raw data for A0123 strixel detector, + the entire columns 255, 256, 511, 512, 767 and 768 are double-size pixels. After strixelation, these end up in columns 765-776, 1539-1550 and 2313-2324 on rows 0-85 or 0-83, with a set of four columns with 86 rows followed by a set of 84 and 86 again. This function builds the index arrays for double pixels after - strixelation. - - Returns: - (ndarray, ndarray) 2D index arrays for double pixel Y and X. + strixelation and stores it in the available A0123 .npz file. """ - Ydouble = [] - Xdouble = [] + ydouble = [] + xdouble = [] + file_path = DIR_PATH / "strixel_cols_A0123-lut_mask.npz" - if kind == "A0123": + with np.load(file_path) as data: for double_col in [765, 1539, 2313]: - for col in range(double_col, double_col+12): - for row in range(84 if ((col-double_col) // 4) == 1 else 86): - Ydouble.append(row) - Xdouble.append(col) + for col in range(double_col, double_col+12): + for row in range(84 if ((col-double_col) // 4) == 1 else 86): + ydouble.append(row) + xdouble.append(col) + np.savez(file_path, **data, ydouble=ydouble, xdouble=xdouble) - return np.array(Ydouble), np.array(Xdouble) def to_strixel(data, out=None, kind="A0123"):