diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb index 76987d79519ae0f2642d001ec22fd94b05d5c8d3..b89a5bccb3a8ca17343765f04d4e6e3ce1dc5521 100644 --- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb +++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb @@ -153,15 +153,12 @@ "\n", "instrument = karabo_id.split(\"_\")[0]\n", "\n", - "if instrument == \"SPB\":\n", - " dinstance = \"AGIPD1M1\"\n", + "if \"AGIPD1M1\" in karabo_id:\n", " nmods = 16\n", - "elif instrument == \"MID\":\n", - " dinstance = \"AGIPD1M2\"\n", - " nmods = 16\n", - "elif instrument == \"HED\":\n", - " dinstance = \"AGIPD500K\"\n", + "elif \"AGIPD500K\" in karabo_id:\n", " nmods = 8\n", + "else:\n", + " nmods = 1\n", "\n", "instrument_src = instrument_source_template.format(karabo_id, receiver_template)\n", "\n", @@ -177,7 +174,6 @@ "\n", "print(f\"Detector in use is {karabo_id}\")\n", "print(f\"Instrument {instrument}\")\n", - "print(f\"Detector instance {dinstance}\")\n", "\n", "step_timer = step_timing.StepTimer()" ] @@ -740,12 +736,14 @@ "metadata": {}, "outputs": [], "source": [ - "mnames=[]\n", - "for i in modules:\n", - " qm = module_index_to_qm(i)\n", - " mnames.append(qm)\n", - " display(Markdown(f'## Position of the module {qm} and its ASICs'))\n", - "show_processed_modules(dinstance, constants=None, mnames=mnames, mode=\"position\")" + "# This is a temporary workaround to enable dark processing for the first SM AGIPD detector\n", + "if nmods > 1: # AGIPD1M and AGIPD500K\n", + " mnames = []\n", + " for i in modules:\n", + " qm = module_index_to_qm(i)\n", + " mnames.append(qm)\n", + " display(Markdown(f'## Position of the module {qm} and its ASICs'))\n", + " show_processed_modules(karabo_id, constants=None, mnames=mnames, mode=\"position\")" ] }, { diff --git a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb index b4e01c190dd99c40c08943d02181e7e5c47d36d6..c57327ab36e65a7509640bfd6c675c3cfad27349 100644 --- a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb +++ b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb @@ -138,8 +138,6 @@ "\n", "run, prop, seq = run_prop_seq_from_path(in_folder)\n", "\n", - "dinstance = \"DSSC1M1\"\n", - "\n", "print(f\"Detector in use is {karabo_id}\") \n", "\n", "cal_db_interface = get_random_db_interface(cal_db_interface)" @@ -515,7 +513,7 @@ " display(Markdown(f'## Position of the module {qm} and its ASICs##'))\n", " mnames.append(qm)\n", " \n", - "show_processed_modules(dinstance=dinstance, constants=None, mnames=mnames, mode=\"position\")" + "show_processed_modules(karabo_id, constants=None, mnames=mnames, mode=\"position\")" ] }, { diff --git a/notebooks/LPD/LPDChar_Darks_NBC.ipynb b/notebooks/LPD/LPDChar_Darks_NBC.ipynb index bae9e2fb0649c67f53e73471c0ad9b32bef40ef6..b86a5530279009739e3a813b25ffac9988be1dcc 100644 --- a/notebooks/LPD/LPDChar_Darks_NBC.ipynb +++ b/notebooks/LPD/LPDChar_Darks_NBC.ipynb @@ -373,8 +373,6 @@ "# Retrieve existing constants for comparison\n", "clist = [\"Offset\", \"Noise\", \"BadPixelsDark\"]\n", "\n", - "dinstance = \"LPD1M1\"\n", - "detinst = getattr(Detectors, dinstance)\n", "print('Retrieve pre-existing constants for comparison.')\n", "\n", "old_const = {}\n", @@ -519,7 +517,7 @@ "outputs": [], "source": [ "show_processed_modules(\n", - " dinstance=dinstance,\n", + " karabo_id,\n", " constants=None,\n", " mnames=[module_index_to_qm(i) for i in modules],\n", " mode=\"position\"\n", diff --git a/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb b/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb index bb68d84433a6e013908334397faa75f1600ac49f..9a9012bc7388761097468d3cb25ddcd83dec5f75 100644 --- a/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb +++ b/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb @@ -74,15 +74,16 @@ "outputs": [], "source": [ "if \"AGIPD\" in karabo_id:\n", - " if \"SPB\" in karabo_id:\n", - " dinstance = \"AGIPD1M1\"\n", - " nmods = 16\n", - " elif \"MID\" in karabo_id:\n", - " dinstance = \"AGIPD1M2\"\n", + " module_shape = (512, 128)\n", + " if \"AGIPD1M\" in karabo_id:\n", " nmods = 16\n", - " elif \"HED\" in karabo_id:\n", - " dinstance = \"AGIPD500K\"\n", + " elif \"AGIPD500K\" in karabo_id:\n", " nmods = 8\n", + " else:\n", + " nmods = 1\n", + " print(\"Summary plots are not available for AGIPD single module detector\")\n", + " import sys\n", + " sys.exit(0)\n", " # This list needs to be in that order as later Adaptive or fixed gain is\n", " # decided based on the condition for the Offset constant.\n", " expected_constants = ['Offset', 'Noise', 'ThresholdsDark', 'BadPixelsDark']\n", @@ -151,8 +152,8 @@ "\n", " \n", "elif \"LPD\" in karabo_id:\n", - " dinstance = \"LPD1M1\"\n", " nmods = 16\n", + " module_shape = (256, 256)\n", " expected_constants = ['Offset', 'Noise', 'BadPixelsDark']\n", " table = []\n", " badpixels = [\n", @@ -205,8 +206,8 @@ "\"Values: $\\\\mathrm{thresholds\\\\_offset\\\\_sigma}$, $\\\\mathrm{thresholds\\\\_offset\\\\_hard}$, $\\\\mathrm{thresholds\\\\_noise\\\\_sigma}$, $\\\\mathrm{thresholds\\\\_noise\\\\_hard}$ are given as parameters.\\n\",\n", "\"\"\"))\n", "elif \"DSSC\" in karabo_id:\n", - " dinstance = \"DSSC1M1\"\n", " nmods = 16\n", + " module_shape = (128, 512)\n", " expected_constants = ['Offset', 'Noise']\n", " display(Markdown(\"\"\"\n", " \n", @@ -365,7 +366,7 @@ "outputs": [], "source": [ "display(Markdown('## Processed modules'))\n", - "show_processed_modules(dinstance, constants, mod_names, mode=\"processed\")" + "show_processed_modules(karabo_id, constants, mod_names, mode=\"processed\")" ] }, { @@ -383,28 +384,30 @@ "metadata": {}, "outputs": [], "source": [ - "if \"LPD\" in dinstance:\n", - " geom = extra_geom.LPD_1MGeometry.from_quad_positions(quad_pos=[(11.4, 299),\n", - " (-11.5, 8),\n", - " (254.5, -16),\n", - " (278.5, 275)])\n", - " module_shape = (256, 256)\n", - "\n", - "elif dinstance in ('AGIPD1M1', 'AGIPD1M2'):\n", - " geom = extra_geom.AGIPD_1MGeometry.from_quad_positions(quad_pos=[(-525, 625),\n", - " (-550, -10),\n", - " (520, -160),\n", - " (542.5, 475)])\n", - " module_shape = (512, 128)\n", - "\n", - "elif dinstance == \"AGIPD500K\":\n", + "if \"LPD\" in karabo_id:\n", + " geom = extra_geom.LPD_1MGeometry.from_quad_positions(\n", + " quad_pos=[\n", + " (11.4, 299),\n", + " (-11.5, 8),\n", + " (254.5, -16),\n", + " (278.5, 275)])\n", + "elif \"AGIPD1M\" in karabo_id:\n", + " geom = extra_geom.AGIPD_1MGeometry.from_quad_positions(\n", + " quad_pos=[\n", + " (-525, 625),\n", + " (-550, -10),\n", + " (520, -160),\n", + " (542.5, 475)])\n", + "elif \"AGIPD500K\" in karabo_id:\n", " geom = extra_geom.AGIPD_500K2GGeometry.from_origin()\n", - " module_shape = (512, 128)\n", - " \n", - "elif \"DSSC\" in dinstance:\n", - " module_shape = (128, 512)\n", + "elif \"DSSC\" in karabo_id:\n", " quadpos = [(-130, 5), (-130, -125), (5, -125), (5, 5)]\n", - " geom = extra_geom.DSSC_1MGeometry.from_quad_positions(quadpos)" + " geom = extra_geom.DSSC_1MGeometry.from_quad_positions(quadpos)\n", + "elif \"AGIPD\" in karabo_id: # single module detector\n", + " print(\"Summary plots are not available for AGIPD single module detector\")\n", + " import sys\n", + " sys.exit(0)\n", + " # TODO: geom = extra_geom.GenericGeometry.?? " ] }, { @@ -435,7 +438,7 @@ " vmin, vmax = get_range(delta, 2)\n", " vmax = max(vmax, abs(vmin)) # Center around zero\n", " geom.plot_data_fast(\n", - " delta, vmin=-vmax, vmax=vmax, ax=ax1, cmap=\"RdBu\", colorbar={\n", + " delta, vmin=-vmax, vmax=vmax, ax=ax1, colorbar={\n", " 'shrink': 0.6, 'pad': 0.1, 'label': 'ADUs'\n", " })\n", " ax1.set_title(f\"Difference with previous {const_name} - {gain_name}\", fontsize=15)\n", @@ -446,7 +449,7 @@ " vmin, vmax = get_range(delta_pct, 2)\n", " vmax = max(vmax, abs(vmin)) # Center around zero\n", " geom.plot_data_fast(\n", - " delta_pct, vmin=-vmax, vmax=vmax, ax=ax2, cmap=\"RdBu\", colorbar={\n", + " delta_pct, vmin=-vmax, vmax=vmax, ax=ax2, colorbar={\n", " 'shrink': 0.6, 'pad': 0.1, 'label': '%'\n", " })\n", " ax2.set_title(\"Percentage difference\", fontsize=15)" diff --git a/src/cal_tools/plotting.py b/src/cal_tools/plotting.py index 8638d957de82e7b665880cc3bb1b04e5cc6649cf..f084d9fe08f95dd59131f399ba3c0e30645d87df 100644 --- a/src/cal_tools/plotting.py +++ b/src/cal_tools/plotting.py @@ -231,44 +231,48 @@ def create_constant_overview(constant, name, cells, vmin=None, vmax=None, ax.set_ylim(vmin, vmax) -def show_processed_modules(dinstance: str, constants: Optional[Dict[str, Any]], - mnames: str, mode: str): +def show_processed_modules( + detector: str, + constants: Optional[Dict[str, Any]], + mnames: str, + mode: str +): """ Show the status of the processed modules. Green: Processed. Gray: Not Processed. Red: No data available. - :param dinstance: The detector instance (e.g. AGIPD1M1 or LPD1M1) - :param constants: A dict of the plotted constants data. - {"const_name":constant_data}. Can be None in case of position mode. - :param mnames: A list of available module names. - :param mode: String selecting on of the two modes of operation. - "position": To just show the position of the processed modules. - "processed": To show the modules successfully processed. - :return + Args: + detector: The detector name (karabo_id) (e.g. MID_DET_AGIPD1M-1 or FXE_DET_LPD1M-1) + constants: A dict of the plotted constants data. + {"const_name":constant_data}. Can be None in case of position mode. + mnames: A list of available module names. + mode: String selecting on of the two modes of operation. + "position": To just show the position of the processed modules. + "processed": To show the modules successfully processed. """ # Create the geometry figure for each detector - if dinstance in ('AGIPD1M1', 'AGIPD1M2'): + if "AGIPD1M" in detector: quadrants = 4 modules = 4 tiles = 8 quad_pos = [(-525, 625), (-550, -10), (520, -160), (542.5, 475)] geom = AGIPD_1MGeometry.from_quad_positions(quad_pos) - elif dinstance == 'AGIPD500K': + elif "AGIPD500K" in detector: quadrants = 2 modules = 4 tiles = 8 geom = AGIPD_500K2GGeometry.from_origin() - elif 'LPD' in dinstance: + elif 'LPD' in detector: quadrants = 4 modules = 4 tiles = 16 quad_pos = [(11.4, 299), (-11.5, 8), (254.5, -16), (278.5, 275)] geom = LPD_1MGeometry.from_quad_positions(quad_pos) - elif 'DSSC' in dinstance: + elif 'DSSC' in detector: quadrants = 4 modules = 4 tiles = 2 @@ -279,7 +283,7 @@ def show_processed_modules(dinstance: str, constants: Optional[Dict[str, Any]], quad_pos) else: - raise ValueError(f'{dinstance} is not a real detector') + raise ValueError(f'{detector} detector is not available for plotting.') # Create a dict that contains the range of tiles, in the figure, # that belong to a module.