usnistgov / mass

Microcalorimeter pulse-analysis software
MIT License
6 stars 0 forks source link

ph2energy fails with "negative samples" #216

Closed joefowler closed 2 years ago

joefowler commented 2 years ago

Original report by Charles James Titus (Bitbucket: cjtitus, GitHub: cjtitus).


~/nist_code/mass/mass/calibration/energy_calibration.py in ph2energy(self, pulse_ht, der)
    141         """
    142         if self._model_is_stale:
--> 143             self._update_converters()
    144         result = self._ph2e(pulse_ht, der=der)
    145 

~/nist_code/mass/mass/calibration/energy_calibration.py in _update_converters(self)
    423         for i in range(len(ph)-1):
    424             npts = 2+int(0.5+(ph[i+1]/ph[i]-1)*100)
--> 425             ph_pts.append(np.linspace(ph[i], ph[i+1], npts)[1:])
    426         ph_pts.append(np.linspace(ph[-1], 2*ph[-1], 101)[1:])
    427         ph_pts = np.hstack(ph_pts)

<__array_function__ internals> in linspace(*args, **kwargs)

~/.conda/envs/ucal/lib/python3.7/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    120     num = operator.index(num)
    121     if num < 0:
--> 122         raise ValueError("Number of samples, %s, must be non-negative." % num)
    123     div = (num - 1) if endpoint else num
    124 

ValueError: Number of samples, -269, must be non-negative.

Somehow, for some channels, the simple npts calculation in update_converters fails, and yields a negative npts.

This results in an uncaught exception. I will try to investigate exactly why this happens.

joefowler commented 2 years ago

Original comment by Charles James Titus (Bitbucket: cjtitus, GitHub: cjtitus).


mass.EnergyCalibration with 6 entries
        _ph: [-8842.82888657 15241.96150853 19054.56935384 19216.77239457
 23806.29451809 29847.9585508 ]
        _energies: [704.8  524.9  851.47 929.68 277.   392.4 ]
        _names: ['FeLAlphaquick_linequick_line', 'OKAlphaquick_linequick_line', 'NiLAlphaquick_linequick_line', 'CuLAlphaquick_linequick_line', 'CKAlphaquick_linequick_line', 'NKAlphaquick_linequick_line']
        _curvetype: 3
        _use_approximation: False

This seems to be because the _ph in the energy calibration has a negative point. I suggest that calibrations that result in negative points be marked as bad.

joefowler commented 2 years ago

Original comment by Charles James Titus (Bitbucket: cjtitus, GitHub: cjtitus).


I will also note that the _ph are in order of increasing energy, but the _energies are not. This sort of cross-over should never happen, and should result in a calibration being immediately marked bad. This channel indeed is missing the high energy peaks

as compared to a normal channel

The “dynamic time warping” algorithm seems to have just totally ignored this and spit out some garbage points.

joefowler commented 2 years ago

Original comment by Galen O'Neil (Bitbucket: oneilg, GitHub: oneilg).


makes sense

joefowler commented 2 years ago

Original comment by Joseph Fowler (Bitbucket: joe_fowler, ).


Calibration should fail when PH,E not monotonic

Fixes #216.

joefowler commented 1 year ago

Original comment by Joseph Fowler (Bitbucket: joe_fowler, ).


Removing milestone: v0.7 (automated comment)