Loading .gitignore +3 −0 Original line number Diff line number Diff line *~ .*history .coverage .vscode *.code-workspace *.pyc *.log *.h5 *.mac* *.swp work doc/build .ipynb_checkpoints Loading ChangeLog +3 −1 Original line number Diff line number Diff line * release v2.0.7 TBD - nseflipper program - updates to biotsavart module * release v2.0.6 (bugfix) Sep 02, 2025 - clarify nseplot help messages Loading pysen/plot/qplot.py +2 −2 Original line number Diff line number Diff line Loading @@ -373,9 +373,9 @@ def plot_diffrun(axis, filenames, **kwargs): if 'down' in selection: _make_plot(axis, (q1, cdn, ecdn ), marker='v', lbl='down') if 'coherent' in selection: _make_plot(axis, (qmean, coherent, ecoherent ), marker='^', lbl='C') _make_plot(axis, (qmean, coherent, ecoherent ), marker='+', lbl='C') if 'incoherent' in selection: _make_plot(axis, (qmean, incoherent, eincoherent ), marker='v', lbl='I') _make_plot(axis, (qmean, incoherent, eincoherent ), marker='x', lbl='I') if 'average' in selection: average = (coherent+incoherent)/2 eaverage = sqrt(ecoherent**2+eincoherent**2) Loading pysen/ui/nseflipper.py +40 −21 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ import numpy as np import matplotlib.pyplot as plt from pysen import version, setup_logger from pysen.constants import GAUSS from pysen.config import INST_POSITIONS, L2, Ltot, HMN, ANGSTROM, DEFAULT_ACCELERATOR_FREQ from pysen.echo.flippers import FlipperPi, FlipperPi2, tof_curve Loading @@ -25,16 +26,20 @@ def curve_test(axs, name='fpi', **kwargs): pos = kwargs.pop('pos', 'p2') freq = kwargs.pop('freq', 60.0) points = kwargs.pop('points', 163) shift = kwargs.pop('shift', 0) lmax = kwargs.pop('lmax', 8.0) compare = kwargs.pop('compare', None) scale = kwargs.pop('scale', 1.0) out = kwargs.pop('out', None) b_x = kwargs.pop('b_x', 0.0) # horizontal external field in GAUSS b_z = kwargs.pop('b_z', 0.0) # vertical external field in GAUSS log = logging.getLogger() L = Ltot.get(pos) # [m] source to detector L1 = L - L2 # [m] source to sample GAUSS = 1e-4 # T B_ext = [ 1.000692*GAUSS, 0, -0.039814*GAUSS ] # ext. field #B_ext = [ 0.0, 0.0, 0.0] #B_ext = [ 1.000692*GAUSS, 0, -0.039814*GAUSS ] # ext. field B_ext = np.asarray([ b_x, 0.0, b_z])*GAUSS # ext. field # compare_data = None if compare is not None: Loading @@ -45,18 +50,23 @@ def curve_test(axs, name='fpi', **kwargs): compare_data = None delam = HMN/(freq*L) # wavelengtgh band print(f"lambda = ({lmax-delam/ANGSTROM:g} - {lmax:g}) A") lmax = lmax*ANGSTROM f = flippers.get(name) print(f"flipper {f}") curve = tof_curve(f, lmax, delam, points=points, sample_to_source=L1, freq=freq, b_ext=B_ext, rewind=5) scurve = curve*f.current(lmax)/scale curve = np.roll(curve, shift) scurve = curve*f.current(lmax)*scale p = axs.plot(scurve,'-', lw=1, label='calc %s' % name) if compare is not None: axs.plot(compare_data,'s', ms=2, lw=1, label='compare %s' % compare, color=p[0].get_color()) axs.plot(compare_data,'--', lw=1, label='compare %s' % compare, color=p[0].get_color()) if out: with open(out, 'wt') as fd: fd.write(f"# flipper {f}\n") fd.write(f"# lambda = ({lmax-delam/ANGSTROM:g} - {lmax:g}) A\n") for point in scurve: fd.write(f"{point:g}\n") def main(): "TBD" Loading @@ -65,8 +75,10 @@ def main(): description='Tool to generate flipper curves' parser = argparse.ArgumentParser(description=description) parser.set_defaults(name='fpi', pos='p2', freq=DEFAULT_ACCELERATOR_FREQ, points=163, lmax=8.0, scale=1.0, compare=None, loglevel=2, out='.') pos='p2', freq=DEFAULT_ACCELERATOR_FREQ, points=163, shift=0, lmax=8.0, scale=1.0, compare=None, loglevel=2, out=None, savefig=None) #parser.add_argument('filename', metavar='file', nargs='+', help='file name to process') parser.add_argument('--name', '-n', dest='name', choices=flippers.keys(), help='flipper name (default %(default)s)') Loading @@ -76,12 +88,16 @@ def main(): help='set (max) neutron wavelength in Angstroms (default %(default)s)') parser.add_argument('--pos', '-p', dest='pos', choices=INST_POSITIONS, help='instrument position to determine wavelength band (default %(default)s)') parser.add_argument('--scale', '-S', dest='scale', type=float, parser.add_argument('--shift', dest='shift', type=float, help='shift the curve by a number of points (default %(default)s)') parser.add_argument('--scale', dest='scale', type=float, help='current scale factor (default %(default)s)') parser.add_argument('--compare', '-c', dest='compare', help='compare with file (default %(default)s)') parser.add_argument('--safe-figure', '-S', dest='savefig', metavar='file', help='save the output figure to a file and do not show it.') parser.add_argument('--outdir', '-o', dest='out', help='set output directory (default %(default)s)') help='write data into a file (default %(default)s)') parser.add_argument('--version', action='version', version='%(prog)s pysen={version}'.format(version=version(full=True))) parser.add_argument('--verbose', '-v', dest='loglevel', action='count', Loading @@ -92,7 +108,7 @@ def main(): args = parser.parse_args() kwargs = vars(args) loglevel = kwargs.pop('loglevel') _outdir = kwargs.pop('out') savefig = kwargs.pop('savefig') setup_logger(loglevel) fig, ax1 = plt.subplots(1,1,figsize=(8,6)) Loading @@ -103,6 +119,9 @@ def main(): ax1.set_ylabel(r'I (A)') ax1.grid() if savefig: fig.savefig(savefig) else: plt.show() Loading pysen/ui/nseplot.py +28 −1 Original line number Diff line number Diff line Loading @@ -346,6 +346,30 @@ def add_ptab_options(subparser, parents=None): pars.add_argument('--threshold', dest='threshold', metavar='thres', type=float, help='clustering threshold (advanced option)') def add_flipper_options(subparser, parents=None): "make phase table" pars = subparser.add_parser('flipper', parents=parents, aliases=['flp',], help='helpe to creat flipper curves', description='is flipper') pars.set_defaults(name='fpi', pos='p2', #freq=DEFAULT_ACCELERATOR_FREQ, points=163, shift=0, lmax=8.0, scale=1.0, compare=None, loglevel=2, out=None, savefig=None) #pars.add_argument('file', metavar='filename', help='file to process', nargs='+') pars.add_argument('--name', '-n', dest='name', choices=['f1', 'f2'], #flippers.keys(), help='flipper name (default %(default)s)') pars.add_argument('--frequency', '-F', dest='freq', type=float, help='accelerator frequency (default %(default)s)') pars.add_argument('--wavelength', '-L', dest='lmax', type=float, help='set (max) neutron wavelength in Angstroms (default %(default)s)') pars.add_argument('--pos', '-p', dest='pos', choices=INST_POSITIONS, help='instrument position to determine wavelength band (default %(default)s)') pars.add_argument('--shift', dest='shift', type=float, help='shift the curve by a number of points (default %(default)s)') pars.add_argument('--scale', dest='scale', type=float, help='current scale factor (default %(default)s)') pars.add_argument('--compare', '-c', dest='compare', help='compare with file (default %(default)s)') def add_gui_options(subparser, parents=None): "make phase table" _pars = subparser.add_parser('gui', parents=parents, Loading Loading @@ -394,6 +418,8 @@ def main(): add_qtau_options(subparsers, parents=[pars_com, pars_fig, ]) # phase table add_ptab_options(subparsers, parents=[pars_com, pars_fig, pars_tof, pars_pix]) # flipper add_flipper_options(subparsers, parents=[pars_com, pars_fig]) # xyz2 plot (old) add_old_xyz_options (subparsers, parents=[pars_com, pars_fig, pars_tof, pars_pix, pars_zsc]) # Loading Loading @@ -425,6 +451,7 @@ def main(): datreat=nseplt.action_datreat, dtr=nseplt.action_datreat, qtau=nseplt.action_qtau, qt=nseplt.action_qtau, phase_table=nseplt.action_phase_table, pt=nseplt.action_phase_table, flipper=nseplt.phase_table, #action_flipper, flp=nseplt.action_flipper, old_xyz=nseplt.action_old_xyz).get(args.command, None) if action is None: raise RuntimeError('no action specified for %s' % args.command) Loading Loading
.gitignore +3 −0 Original line number Diff line number Diff line *~ .*history .coverage .vscode *.code-workspace *.pyc *.log *.h5 *.mac* *.swp work doc/build .ipynb_checkpoints Loading
ChangeLog +3 −1 Original line number Diff line number Diff line * release v2.0.7 TBD - nseflipper program - updates to biotsavart module * release v2.0.6 (bugfix) Sep 02, 2025 - clarify nseplot help messages Loading
pysen/plot/qplot.py +2 −2 Original line number Diff line number Diff line Loading @@ -373,9 +373,9 @@ def plot_diffrun(axis, filenames, **kwargs): if 'down' in selection: _make_plot(axis, (q1, cdn, ecdn ), marker='v', lbl='down') if 'coherent' in selection: _make_plot(axis, (qmean, coherent, ecoherent ), marker='^', lbl='C') _make_plot(axis, (qmean, coherent, ecoherent ), marker='+', lbl='C') if 'incoherent' in selection: _make_plot(axis, (qmean, incoherent, eincoherent ), marker='v', lbl='I') _make_plot(axis, (qmean, incoherent, eincoherent ), marker='x', lbl='I') if 'average' in selection: average = (coherent+incoherent)/2 eaverage = sqrt(ecoherent**2+eincoherent**2) Loading
pysen/ui/nseflipper.py +40 −21 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ import numpy as np import matplotlib.pyplot as plt from pysen import version, setup_logger from pysen.constants import GAUSS from pysen.config import INST_POSITIONS, L2, Ltot, HMN, ANGSTROM, DEFAULT_ACCELERATOR_FREQ from pysen.echo.flippers import FlipperPi, FlipperPi2, tof_curve Loading @@ -25,16 +26,20 @@ def curve_test(axs, name='fpi', **kwargs): pos = kwargs.pop('pos', 'p2') freq = kwargs.pop('freq', 60.0) points = kwargs.pop('points', 163) shift = kwargs.pop('shift', 0) lmax = kwargs.pop('lmax', 8.0) compare = kwargs.pop('compare', None) scale = kwargs.pop('scale', 1.0) out = kwargs.pop('out', None) b_x = kwargs.pop('b_x', 0.0) # horizontal external field in GAUSS b_z = kwargs.pop('b_z', 0.0) # vertical external field in GAUSS log = logging.getLogger() L = Ltot.get(pos) # [m] source to detector L1 = L - L2 # [m] source to sample GAUSS = 1e-4 # T B_ext = [ 1.000692*GAUSS, 0, -0.039814*GAUSS ] # ext. field #B_ext = [ 0.0, 0.0, 0.0] #B_ext = [ 1.000692*GAUSS, 0, -0.039814*GAUSS ] # ext. field B_ext = np.asarray([ b_x, 0.0, b_z])*GAUSS # ext. field # compare_data = None if compare is not None: Loading @@ -45,18 +50,23 @@ def curve_test(axs, name='fpi', **kwargs): compare_data = None delam = HMN/(freq*L) # wavelengtgh band print(f"lambda = ({lmax-delam/ANGSTROM:g} - {lmax:g}) A") lmax = lmax*ANGSTROM f = flippers.get(name) print(f"flipper {f}") curve = tof_curve(f, lmax, delam, points=points, sample_to_source=L1, freq=freq, b_ext=B_ext, rewind=5) scurve = curve*f.current(lmax)/scale curve = np.roll(curve, shift) scurve = curve*f.current(lmax)*scale p = axs.plot(scurve,'-', lw=1, label='calc %s' % name) if compare is not None: axs.plot(compare_data,'s', ms=2, lw=1, label='compare %s' % compare, color=p[0].get_color()) axs.plot(compare_data,'--', lw=1, label='compare %s' % compare, color=p[0].get_color()) if out: with open(out, 'wt') as fd: fd.write(f"# flipper {f}\n") fd.write(f"# lambda = ({lmax-delam/ANGSTROM:g} - {lmax:g}) A\n") for point in scurve: fd.write(f"{point:g}\n") def main(): "TBD" Loading @@ -65,8 +75,10 @@ def main(): description='Tool to generate flipper curves' parser = argparse.ArgumentParser(description=description) parser.set_defaults(name='fpi', pos='p2', freq=DEFAULT_ACCELERATOR_FREQ, points=163, lmax=8.0, scale=1.0, compare=None, loglevel=2, out='.') pos='p2', freq=DEFAULT_ACCELERATOR_FREQ, points=163, shift=0, lmax=8.0, scale=1.0, compare=None, loglevel=2, out=None, savefig=None) #parser.add_argument('filename', metavar='file', nargs='+', help='file name to process') parser.add_argument('--name', '-n', dest='name', choices=flippers.keys(), help='flipper name (default %(default)s)') Loading @@ -76,12 +88,16 @@ def main(): help='set (max) neutron wavelength in Angstroms (default %(default)s)') parser.add_argument('--pos', '-p', dest='pos', choices=INST_POSITIONS, help='instrument position to determine wavelength band (default %(default)s)') parser.add_argument('--scale', '-S', dest='scale', type=float, parser.add_argument('--shift', dest='shift', type=float, help='shift the curve by a number of points (default %(default)s)') parser.add_argument('--scale', dest='scale', type=float, help='current scale factor (default %(default)s)') parser.add_argument('--compare', '-c', dest='compare', help='compare with file (default %(default)s)') parser.add_argument('--safe-figure', '-S', dest='savefig', metavar='file', help='save the output figure to a file and do not show it.') parser.add_argument('--outdir', '-o', dest='out', help='set output directory (default %(default)s)') help='write data into a file (default %(default)s)') parser.add_argument('--version', action='version', version='%(prog)s pysen={version}'.format(version=version(full=True))) parser.add_argument('--verbose', '-v', dest='loglevel', action='count', Loading @@ -92,7 +108,7 @@ def main(): args = parser.parse_args() kwargs = vars(args) loglevel = kwargs.pop('loglevel') _outdir = kwargs.pop('out') savefig = kwargs.pop('savefig') setup_logger(loglevel) fig, ax1 = plt.subplots(1,1,figsize=(8,6)) Loading @@ -103,6 +119,9 @@ def main(): ax1.set_ylabel(r'I (A)') ax1.grid() if savefig: fig.savefig(savefig) else: plt.show() Loading
pysen/ui/nseplot.py +28 −1 Original line number Diff line number Diff line Loading @@ -346,6 +346,30 @@ def add_ptab_options(subparser, parents=None): pars.add_argument('--threshold', dest='threshold', metavar='thres', type=float, help='clustering threshold (advanced option)') def add_flipper_options(subparser, parents=None): "make phase table" pars = subparser.add_parser('flipper', parents=parents, aliases=['flp',], help='helpe to creat flipper curves', description='is flipper') pars.set_defaults(name='fpi', pos='p2', #freq=DEFAULT_ACCELERATOR_FREQ, points=163, shift=0, lmax=8.0, scale=1.0, compare=None, loglevel=2, out=None, savefig=None) #pars.add_argument('file', metavar='filename', help='file to process', nargs='+') pars.add_argument('--name', '-n', dest='name', choices=['f1', 'f2'], #flippers.keys(), help='flipper name (default %(default)s)') pars.add_argument('--frequency', '-F', dest='freq', type=float, help='accelerator frequency (default %(default)s)') pars.add_argument('--wavelength', '-L', dest='lmax', type=float, help='set (max) neutron wavelength in Angstroms (default %(default)s)') pars.add_argument('--pos', '-p', dest='pos', choices=INST_POSITIONS, help='instrument position to determine wavelength band (default %(default)s)') pars.add_argument('--shift', dest='shift', type=float, help='shift the curve by a number of points (default %(default)s)') pars.add_argument('--scale', dest='scale', type=float, help='current scale factor (default %(default)s)') pars.add_argument('--compare', '-c', dest='compare', help='compare with file (default %(default)s)') def add_gui_options(subparser, parents=None): "make phase table" _pars = subparser.add_parser('gui', parents=parents, Loading Loading @@ -394,6 +418,8 @@ def main(): add_qtau_options(subparsers, parents=[pars_com, pars_fig, ]) # phase table add_ptab_options(subparsers, parents=[pars_com, pars_fig, pars_tof, pars_pix]) # flipper add_flipper_options(subparsers, parents=[pars_com, pars_fig]) # xyz2 plot (old) add_old_xyz_options (subparsers, parents=[pars_com, pars_fig, pars_tof, pars_pix, pars_zsc]) # Loading Loading @@ -425,6 +451,7 @@ def main(): datreat=nseplt.action_datreat, dtr=nseplt.action_datreat, qtau=nseplt.action_qtau, qt=nseplt.action_qtau, phase_table=nseplt.action_phase_table, pt=nseplt.action_phase_table, flipper=nseplt.phase_table, #action_flipper, flp=nseplt.action_flipper, old_xyz=nseplt.action_old_xyz).get(args.command, None) if action is None: raise RuntimeError('no action specified for %s' % args.command) Loading