Commit 9be1c26c authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

bug fix: catch error where neutron flux is "empty"

parent d3aad6c7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -181,6 +181,8 @@ def echo_fit(shape_func, dj, counts, ecounts, **kwargs):
            minimizer = phase_fit_global
        dj0, chi = minimizer(shape_func, dj, counts, ecounts, **kwargs)
        success  = np.isfinite(chi) and (max_chi is None or chi<max_chi)
        if not success:
            dj0 = np.nan

    # extract echo parameters
    chi, res = linear_fit(shape_func(dj-dj0), counts, ecounts)
@@ -273,6 +275,8 @@ def fit_echo_current(current, counts, spectrum, lam0, phase0, **kwargs):
        phase_pf,_ = fit_poly_current(current, counts, maximum=not incoherent) # max count
    dj  = np.radians(phasesens*(current  - phase0))/OMEGA_N/lam0 # convert currents to dJ
    ddj = dphase/OMEGA_N/lam0 # fit range
    if not npsum(spectrum.flux):
        raise RuntimeError("empty neutron flux")
    sfun   = partial(spectrum_weighted_eshape, spectrum=spectrum)
    dj0    = np.radians(phasesens*(phase_pf - phase0))/OMEGA_N/lam0
    res    = echo_fit(sfun, dj, counts[0], counts[1], dj0=dj0, djlim=(dj0-ddj,dj0+ddj))
+5 −1
Original line number Diff line number Diff line
@@ -536,9 +536,13 @@ def plot_echo(hdfile, iecho=None, **kwargs):
        ey = sqrt(y)
        dn = y[nph:n_idx['up']]
        up = y[n_idx['up']:]
        try:
            _ = fit_echo_current(cur[:nph], (y[:nph], ey[:nph]), spectrum,
                             lam0=lam0, phase0=phase0, phasesens=phasesens,
                             incoherent=incoherent)
        except RuntimeError as exc:
            log.warning("fit error: tau=%gns %s", tau0, exc)
            continue
        (phase_ef0, phase_err) , (xef,yef), res = _
        if center_only:
            only_echo = only_echo or not (len(up) or len(dn))
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ PySEN revision module
"""
import sys
__version__  = "2.1"
__release__  = "b7"
__date__     = "Apr 22, 2025"
__release__  = "b8"
__date__     = "May 8, 2025"

def version(full=False):
    "get pysen version number"