Commit 3c06dfd4 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

diffrun bugs fixed

parent a0cbfd4e
Loading
Loading
Loading
Loading
+36 −18
Original line number Diff line number Diff line
@@ -294,7 +294,12 @@ def plot_diffrun(axis, filenames, **kwargs):
    noqerr = t1 is None or t2 is None
    nfiles = len(filenames)
    ylabel = None
    axis_r = axis
    if len(selection)>1 and ('flip_ratio' in selection or 'coherent_ratio' in selection):
        axis_r = axis.twinx()


    lines = []
    for _i, filename in enumerate(filenames):
        res  = read_diffrun(filename) #
        meta  = res.get('summary')
@@ -314,8 +319,16 @@ def plot_diffrun(axis, filenames, **kwargs):
            q1  = q[1::2]
            cnt = result[::, 2] # detector sum
        else:
            q0, _ = _get_q(q[0::2], wlen[0::2], t1, t2)
            q1, _ = _get_q(q[1::2], wlen[1::2], t1, t2)
            if  wlen.shape[0]  == q.shape[0]:
                wlen0 = wlen[0::2]
                wlen1 = wlen[1::2]
            elif 2*wlen.shape[0] == q.shape[0]:
                wlen0 = wlen
                wlen1 = wlen
            else:
                raise RuntimeError('wrong wavelength shape (bug)')
            q0, _ = _get_q(q[0::2], wlen0, t1, t2)
            q1, _ = _get_q(q[1::2], wlen1, t1, t2)
            cnt = np.sum(det[:,0,t1:t2], axis=-1)

        # up count
@@ -364,39 +377,44 @@ def plot_diffrun(axis, filenames, **kwargs):
            data = np.vstack( data )
            data = data[:, data[0].argsort()]
            label="%s (%s)" % (os.path.basename(filename), kwargs.pop('lbl'))
            axis.errorbar(data[0], data[1], yerr=data[2], label=label, **kwargs)
            p = axis.errorbar(data[0], data[1], yerr=data[2], label=label, **kwargs)
            if out:
                np.savetxt(out, data.T, fmt='%.3g', header = "%s\nQ counts err" % label)
            return p

        if 'up' in selection:
            _make_plot(axis, (q0, cup, ecup ), marker='^', lbl='up')
            lines.append(_make_plot(axis, (q0, cup, ecup ), marker='^', lbl='up'))
        if 'down' in selection:
            _make_plot(axis, (q1, cdn, ecdn ), marker='v', lbl='down')
            lines.append(_make_plot(axis, (q1, cdn, ecdn ), marker='v', lbl='down'))
        if 'coherent' in selection:
            _make_plot(axis, (qmean, coherent, ecoherent ),     marker='+', lbl='C')
            lines.append(_make_plot(axis, (qmean, coherent, ecoherent ),     marker='+', lbl='C'))
        if 'incoherent' in selection:
            _make_plot(axis, (qmean, incoherent, eincoherent ), marker='x', lbl='I')
            lines.append(_make_plot(axis, (qmean, incoherent, eincoherent ), marker='x', lbl='I'))
        if 'average' in selection:
            average  = (coherent+incoherent)/2
            eaverage = sqrt(ecoherent**2+eincoherent**2)
            _make_plot(axis, (qmean, average, eaverage), marker='s', lbl='<A>')
            lines.append(_make_plot(axis, (qmean, average, eaverage), marker='s', lbl='<A>'))
        # ratios
        if 'flip_ratio' in selection:
            #fratio = np.where(fratio>1.0, fratio, 1.0/fratio)
            #if axis1 is None:
            #    axis1 = axis.twinx()
            _make_plot(axis, (qmean, fratio, eratio ), marker='o', lbl='FR')
            fratio = np.where(fratio>1.0, fratio, 1.0/fratio)
            lines.append(_make_plot(axis_r, (qmean, fratio, eratio ), marker='o', lbl='FR'))
            if axis_r!=axis:
                axis_r.set_ylabel('Flip Ratio')
            else:
                ylabel = 'Flip Ratio'

        if 'coherent_ratio' in selection:
            cratio  = (2*fratio - 1)/3
            ecratio = (2*eratio)/3
            #if axis1 is None:
            #    axis1 = axis.twinx()
            _make_plot(axis, (qmean, cratio, ecratio), marker='s', lbl='C/I')
            lines.append(_make_plot(axis_r, (qmean, cratio, ecratio), marker='*', lbl='C/I'))
            if axis_r!=axis:
                axis_r.set_ylabel('Coherent/Incoherent Ratio')
            else:
                ylabel = 'Coherent/Incoherent Ratio'

    axis.set_yscale('log' if logscale else 'linear')
    axis.legend(loc='best')
    # added these three lines
    axis.legend(lines, [l.get_label() for l in lines ], loc=0)
    axis.grid(True, which='both')
    if ylabel:
        axis.set_ylabel(ylabel)
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
PySEN revision module
"""
import sys
__version__  = "2.0.7rc1"
__version__  = "2.0.7rc2"
__date__     = "Oct 21, 2025"

def version(full=False):