Commit 454aae6e authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

tmp

parent 15d38694
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -41,21 +41,34 @@ def main():
    "the main"
    parser = argparse.ArgumentParser()
    parser.set_defaults(ntof=42, npix=32,
                        tbin1=0, tbin2=None,
                        xpix1=10,xpix2=-10,ypix1=10,ypix2=-10, whole_detector=False,
                        vmin=0, vmax=None, logz=False,
                        show=True, save=False)
    parser.add_argument('filename', metavar='file', nargs='+', help='filename to plot')

    parser.add_argument('--t1' , '-b', dest='tbin1', type=int,
                     help='set min TOF bin (default=%(default)s)')
    parser.add_argument('--t2' , '-B', dest='tbin2', type=int,
                     help='set max TOF bin (default=%(default)s)')
    parser.add_argument('--x1' , dest='xpix1', type=int,
                     help='set min. X pix (default=%(default)s)')
                     help='set min X pix (default=%(default)s)')
    parser.add_argument('--x2' , dest='xpix2', type=int,
                     help='set max. X pix (default=%(default)s)')
                     help='set max X pix (default=%(default)s)')
    parser.add_argument('--y1' , dest='ypix1', type=int,
                     help='set min. Y pix (default=%(default)s)')
                     help='set min Y pix (default=%(default)s)')
    parser.add_argument('--y2' , dest='ypix2', type=int,
                     help='set max. Y pix (default=%(default)s)')
                     help='set max Y pix (default=%(default)s)')
    parser.add_argument('--whole-detector', '-W', dest='whole_detector', action='store_true',
                        help='use the whole detector')
    #
    parser.add_argument('--vmin', '-v' , dest='vmin', type=int,
                     help='set min vertical scale (default=%(default)s)')
    parser.add_argument('--vmax', '-V' , dest='vmax', type=int,
                     help='set max vertical scale (default=%(default)s)')
    parser.add_argument('--logz',        dest='logz', action='store_true',
                     help='detector image log vertical scale')
    #
    parser.add_argument('--npix' , dest='npix', type=int,
                     help='set number of pixels (default=%(default)s)')
    parser.add_argument('--ntof' , dest='ntof', type=int,
+40 −18
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ def xyz_decomposition(xyzdata):
    into nuclear coherent, incoherent and magnetic components

    Data is expected to be a dictionary of numbers or numpy arrays
    with six keys: {x,y,z}_{up,dn}"""
    th six keys: {x,y,z}_{up,dn}"""

    res = {}
    # sum of x, y and z  measurements
@@ -45,7 +45,8 @@ def xyz_decomposition(xyzdata):
    sTOT= (sUP + sDN)/3     # total "cross section"
    sM  =  2*dZ - (dX + dY) # magnetic "cross section"
    sN  = (2*sUP - sDN)/6   # nuclear coherent
    sI  = sTOT - sN - sM    # incoherent
    #sI  = sTOT - sN - sM    # incoherent
    sI  = sUP/2 - sM

    #
    res['n_coh'] = sN
@@ -331,13 +332,13 @@ def plot_xyz(*hdfiles, **kwargs):
    plt.suptitle(title)

# NEW NEXUS FILES
def plot_xyz_single_nexus(data, info, fig, axis, **kwargs):
def plot_xyz_single_nexus(data, info, fig, axes, **kwargs):
    """plot xyz single"""
    pix = get_pix(kwargs)
    vmin    = kwargs.pop('vmin', 0)
    vmax    = kwargs.pop('vmax', None)
    #logz    = kwargs.pop('logz', None)
    #label   = kwargs.pop('label', None)
    logz    = kwargs.pop('logz', None)
    label   = kwargs.pop('label', None)
    whole_detector = kwargs.pop('whole_detector', False)
    nt, ny, nx = info['ntof'], info['npix'], info['npix']

@@ -352,22 +353,37 @@ def plot_xyz_single_nexus(data, info, fig, axis, **kwargs):

    h3,_ = np.histogramdd((neutrons[0], neutrons[1], neutrons[2]),
               bins=(tbin, ybin, xbin))

    tbin2  = tbin2 or nt
    cnts   = h3[tbin1:tbin2,0:ny,0:nx].sum(axis=0)
    wlen   = h3.sum(axis=(1,2))

    XX, YY  = np.mgrid[0:nx, 0:ny]

    # now pixel
    xpix_selection  = np.logical_not(np.logical_and(xpix1<=XX,XX<xpix2))
    cnts[xpix_selection]=0

    ypix_selection  = np.logical_not(np.logical_and(ypix1<=YY,YY<ypix2))
    cnts[ypix_selection]=0

    TT      = np.mgrid[0:nt]
    pix_selection  = np.logical_and(np.logical_and(xpix1<=XX,XX<xpix2),
                                    np.logical_and(ypix1<=YY,YY<ypix2))
    tof_selection  = np.logical_and(tbin1<=TT, TT<=tbin2)
    cnts[np.logical_not(pix_selection)]=0
    wlen[np.logical_not(tof_selection)]=0

    axis, exax = axes
    if logz:
        vmin = vmin or np.min(cnts) or 1
        vmax = vmax or np.max(cnts) or 1
        norm = colors.LogNorm(vmin, vmax)
    else:
        norm = colors.Normalize(vmin, vmax)
    im = axis.imshow(cnts.T , aspect='equal', origin='lower', norm=norm)
    fig.colorbar(im, ax=axis, use_gridspec=True)
    axis.set_title(label)
    if exax is not None:
        lam  = info['tbin']
        wlen = np.hstack((wlen,wlen[-1]))
        exax.step(lam, wlen, where='post')
        exax.set_xlabel(r'Wavelength [$\AA$]')
        exax.grid(True)
        exax.set_title(label)
        exax.set_ylim(bottom=0,)


    data['selection_counts'] = cnts.sum()

@@ -382,16 +398,22 @@ def plot_xyz_nexus(data, info, **kwargs):
                     z_dn=(1,0), y_dn=(1,1), x_dn=(1,2))

    #
    fig = plt.figure(figsize=(10,6))
    gs  = fig.add_gridspec(2,3)
    fig = plt.figure(figsize=(10,8))
    gs  = fig.add_gridspec(3,3)
    fig.subplots_adjust(hspace=0.4, wspace=0.4)
    # axes mapping
    axes = {}
    for idx in index_map.values():
        axes[idx] = fig.add_subplot(gs[idx])
    for idx in range(3):
        axes[2,idx] = fig.add_subplot(gs[2,idx])

    for label in data:
        plot_xyz_single_nexus(data[label], info, fig, axes[index_map.get(label)], label=label, **kwargs)
        axis = axes[index_map.get(label)]
        exax = None
        if 'up' in label:
            exax = axes[2,index_map.get(label)[1]]
        plot_xyz_single_nexus(data[label], info, fig, axes=(axis, exax), label=label, **kwargs)
    title = info['title'].replace('_', ' ')
    plt.suptitle(f"{info['base']}: {title}")
    #