[REMI] [Correct] At least one bin is needed for hist2d
Description
If only one hit is found, as in p4796 r142, the notebook tries to call ax.hist2d with 0 bins in the TOF dimension, which fails:
Traceback
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-18-a09f53e9c2df> in <module>
28 for ax, dim_label in zip([txp, typ], ['x', 'y']):
29 ax.hist2d(flat_hits['t'], flat_hits[dim_label], bins=(int((max_tof - min_tof) // 5), 256),
---> 30 range=[[min_tof, max_tof], [-im_radius, im_radius]], norm=LogNorm())
31 ax.set_ylabel(f'{dim_label.upper()} / mm')
32
/gpfs/exfel/sw/software/exfel_environments/sqs-remi-preview/lib/python3.7/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1350 def inner(ax, *args, data=None, **kwargs):
1351 if data is None:
-> 1352 return func(ax, *map(sanitize_sequence, args), **kwargs)
1353
1354 bound = new_sig.bind(ax, *args, **kwargs)
/gpfs/exfel/sw/software/exfel_environments/sqs-remi-preview/lib/python3.7/site-packages/matplotlib/axes/_axes.py in hist2d(self, x, y, bins, range, density, weights, cmin, cmax, **kwargs)
7071
7072 h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=range,
-> 7073 density=density, weights=weights)
7074
7075 if cmin is not None:
<__array_function__ internals> in histogram2d(*args, **kwargs)
/gpfs/exfel/sw/software/exfel_environments/sqs-remi-preview/lib/python3.7/site-packages/numpy/lib/twodim_base.py in histogram2d(x, y, bins, range, normed, weights, density)
742 xedges = yedges = asarray(bins)
743 bins = [xedges, yedges]
--> 744 hist, edges = histogramdd([x, y], bins, range, normed, weights, density)
745 return hist, edges[0], edges[1]
746
<__array_function__ internals> in histogramdd(*args, **kwargs)
/gpfs/exfel/sw/software/exfel_environments/sqs-remi-preview/lib/python3.7/site-packages/numpy/lib/histograms.py in histogramdd(sample, bins, range, normed, weights, density)
1046 if bins[i] < 1:
1047 raise ValueError(
-> 1048 '`bins[{}]` must be positive, when an integer'.format(i))
1049 smin, smax = _get_outer_edges(sample[:,i], range[i])
1050 try:
ValueError: `bins[0]` must be positive, when an integer
I have prepared this in case a hotfix is needed, but the main problem I was called for seems to be a migration issue: https://redmine.xfel.eu/issues/151221
How Has This Been Tested?
Modifying the failing notebook and running interactively
Relevant Documents (optional)
SQS_REMI_DLD6_correct_004796_r142_230407_062019.pdf
Types of changes
- Bug fix (non-breaking change which fixes an issue)
Checklist:
- My code follows the code style of this project.