lbl-anp / becquerel

Becquerel is a Python package for analyzing nuclear spectroscopic measurements.
Other
44 stars 16 forks source link

Fitter.custom_plot fails if roi is not defined #256

Open cosama opened 3 years ago

cosama commented 3 years ago

I currently get this error:

becquerel/core/fitting.py in custom_plot(self, title, savefname, title_fontsize, title_fontweight, residual_type, **kwargs)
    913                     param_name, v, e, np.abs(e / v))
    914         # Add info about the ROI and units
--> 915         s += 'ROI: [{0:.3f}, {1:.3f}]\n'.format(*self.roi)
    916         s += 'X units: {:s}\n'.format(self.xmode if self.xmode else 'None')
    917         s += 'Y units: {:s}\n'.format(self.ymode if self.ymode else 'None')

TypeError: format() argument after * must be an iterable, not NoneType

if I don't provide the roi kwarg to Fitter.__init__. Temporary fix is to use roi=[0, np.inf]. Seems like by adding ROI to the custom_plot output we require this to be populated.

jvavrek commented 3 years ago

Ah, I see, it's the 0:.3f formatting that breaks it. I guess a full if would be more complete:

if self.roi:
    s += 'ROI: [{0:.3f}, {1:.3f}]\n'.format(*self.roi)
else:
    s += 'ROI: None\n'

Edit: even then, if self.roi = (None, None), this doesn't work.