diff --git a/cal_tools/cal_tools/plotting.py b/cal_tools/cal_tools/plotting.py index 5bafa91c67fb5fd0a1c96e7a036f2adc2ec87d2a..2eda7286b05cc55c192b2ee6339bcd5de526f28d 100644 --- a/cal_tools/cal_tools/plotting.py +++ b/cal_tools/cal_tools/plotting.py @@ -1,7 +1,10 @@ +from typing import Any, Dict, Optional + +from extra_geom import AGIPD_500K2GGeometry import matplotlib.pyplot as plt +from matplotlib import colors from matplotlib.patches import Patch, Rectangle from mpl_toolkits.axes_grid1 import AxesGrid -from mpl_toolkits.mplot3d import Axes3D import numpy as np @@ -92,7 +95,6 @@ def rebin(a, *args): ''' shape = a.shape lenShape = len(shape) - factor = np.asarray(shape) // np.asarray(args) evList = ['a.reshape('] + \ ['args[%d],factor[%d],' % (i, i) for i in range(lenShape)] + \ [')'] + ['.sum(%d)' % (i + 1) for i in range(lenShape)] + \ @@ -199,7 +201,8 @@ def create_constant_overview(constant, name, cells, vmin=None, vmax=None, ax.set_ylim(vmin, vmax) -def show_processed_modules(dinstance, constants, mnames, mode): +def show_processed_modules(dinstance: 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. @@ -214,9 +217,9 @@ def show_processed_modules(dinstance, constants, mnames, mode): """ fig, ax = plt.subplots(1, figsize=(10, 10)) ax.set_axis_off() - counter = 0 + counter = 0 # Used as index within the `Noise` matrix, found in constants - if 'AGIPD' in dinstance: + if dinstance in ('AGIPD1M1', 'AGIPD1M2'): ax.set_xlim(0, 90) ax.set_ylim(0, 75) @@ -273,6 +276,62 @@ def show_processed_modules(dinstance, constants, mnames, mode): elif mode == "processed": ax.text(q_x[0] + 14.5, q_x[1] - q_st * im + 1.5, f'Q{iq+1}M{im+1}', fontsize=24, color='gold') + + elif dinstance == 'AGIPD500K': + # Create a dict that contains the range of tiles, in the figure, + # that belong to a module. + ranges = dict() + count = 0 + for quadrant in range(1, 3): + for module in range(1, 5): + ranges[f'Q{quadrant}M{module}'] = [count, count + 8] + count += 8 + + geom = AGIPD_500K2GGeometry.from_origin() + ax = geom.inspect() + + ax.set_title('') # Cannot remove title + ax.set_axis_off() + ax.get_legend().set_visible(False) + ax.figure.set_dpi(100) + + # Remove non-tiles markings from figure + tiles, = ax.collections = ax.collections[:1] + + # Set each tile colour individually + facecolors = tiles.get_facecolors().tolist() * 64 + + # Set module name fonts + for text in ax.texts: + text.set_fontweight('regular') + + texts = [t for t in ax.texts if t.get_text() in mnames] + for text in texts: + text.set_fontweight('extra bold') + text.set_fontsize(14) + + if mode == 'position': # Highlight selected modules + for module in mnames: + start, stop = ranges[module] + for idx in range(start, stop): + facecolors[idx] = colors.to_rgba('pink') + + if mode == 'processed': # Highlight processed modules + for module, (start, stop) in ranges.items(): + color = 'grey' # Unprocessed modules are grey + + if module in mnames: + color = 'green' + if ('Noise' not in constants.keys() or + np.nanmean(constants['Noise'][counter, :, :, :, 0]) == 0): # noqa + color = 'red' + counter += 1 + + for idx in range(start, stop): # Set the colours + facecolors[idx] = colors.to_rgba(color) + + tiles.set_facecolors(facecolors) # Update colours in figure + elif 'LPD' in dinstance: ax.set_xlim(0, 97) @@ -412,5 +471,5 @@ def show_processed_modules(dinstance, constants, mnames, mode): _ = ax.legend(handles=[Patch(facecolor='red', label='No data'), Patch(facecolor='gray', label='Not processed'), Patch(facecolor='green', label='Processed')], - loc='outside-top', ncol=3, bbox_to_anchor=(0.1, 0.25, 0.7, 0.8)) + loc='best', ncol=3, bbox_to_anchor=(0.1, 0.25, 0.7, 0.8)) plt.show() diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb index 5dc3a6c48990ee9e1ef68ad05dfc3f0bd9014668..c6bf10fa17e13457251c5cb641c9b3ec97778009 100644 --- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb +++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb @@ -636,14 +636,12 @@ }, "outputs": [], "source": [ - "# TODO: add show_processed_modules diagram for Mini-Half AGIPD\n", - "if dinstance != \"AGIPD500K\":\n", - " mnames=[]\n", - " for i in modules:\n", - " qm = f\"Q{i//4+1}M{i % 4+1}\"\n", - " mnames.append(qm)\n", - " display(Markdown(f'## Position of the module {qm} and it\\'s ASICs##'))\n", - " show_processed_modules(dinstance, constants=None, mnames=mnames, mode=\"position\")" + "mnames=[]\n", + "for i in modules:\n", + " qm = f\"Q{i//4+1}M{i % 4+1}\"\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\")" ] }, { diff --git a/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb b/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb index 5747928d6c6e309d653ed911767b1d142dc3f773..e829ab03d5cf621cce718c1b8880fe4e4c0e157a 100644 --- a/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb +++ b/notebooks/generic/overallmodules_Darks_Summary_NBC.ipynb @@ -253,10 +253,8 @@ }, "outputs": [], "source": [ - "# TODO: add show_processed_modules diagram for Mini-Half AGIPD\n", - "if dinstance != \"AGIPD500K\":\n", - " display(Markdown('## Processed modules ##'))\n", - " show_processed_modules(dinstance, constants, mod_names, mode=\"processed\")" + "display(Markdown('## Processed modules ##'))\n", + "show_processed_modules(dinstance, constants, mod_names, mode=\"processed\")" ] }, { diff --git a/requirements.txt b/requirements.txt index ef5eb2bcafe7bb789943d452ce37dee6a7482a8f..37722e730835f2a7e3b20787b438e80234823b4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ astsearch == 0.1.3 Cython == 0.29.21 dill == 0.3.0 extra_data == 1.2.0 -extra_geom == 0.8.0 +extra_geom == 1.0.0 fabio == 0.9.0 gitpython == 3.1.0 h5py == 2.10.0