Loading pysen/revision.py +2 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ PySEN revision module """ import sys __version__ = "2.0" __release__ = ".7b1" __date__ = "Sep 12, 2025" __release__ = ".7b2" __date__ = "Sep 15, 2025" def version(full=False): "get pysen version number" Loading pysen/ui/nseflipper.py 0 → 100755 +110 −0 Original line number Diff line number Diff line #!/usr/bin/env python """ script to calculate Mezei flipper curves """ import argparse import logging import numpy as np import matplotlib.pyplot as plt from pysen import version, setup_logger from pysen.config import INST_POSITIONS, L2, Ltot, HMN, ANGSTROM, DEFAULT_ACCELERATOR_FREQ from pysen.echo.flippers import FlipperPi, FlipperPi2, tof_curve flippers = { "fpi21" : FlipperPi2('fpi21', position =-2.824663, thickness=0.010, turns_density=833.33), #w=0.10 h=0.18, i33 "fpi21rs": FlipperPi ('fpi21rs', position =-2.283902, thickness=0.010, turns_density=833.33), #w=0.10 h=0.18, i37 "fpi" : FlipperPi ('fpi', position =-0.146000, thickness=0.013, turns_density=833.33), #w=0.18 h=0.18, i32 "fpi22rs": FlipperPi ('fpi22rs', position =+2.279194, thickness=0.010, turns_density=821.40), #w=0.28 h=0.28, i38 "fpi22" : FlipperPi2('fpi22', position =+2.823903, thickness=0.010, turns_density=821.40), #w=0.28 h=0.28, i34 } def curve_test(axs, name='fpi', **kwargs): "test with plots" pos =kwargs.pop('pos', 'p2') freq =kwargs.pop('freq', 60.0) points=kwargs.pop('points', 163) lmax=kwargs.pop('lmax', 8.0) compare=kwargs.pop('compare', None) scale =kwargs.pop('scale', 1.0) 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] # compare_data = None if compare is not None: try: compare_data = np.loadtxt(compare) except FileNotFoundError as err: log.error("cannot load compare file (%s)",err) 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 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()) def main(): "TBD" description="<unknown>" # 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='.') #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)') parser.add_argument('--frequency', '-F', dest='freq', type=float, help='accelerator frequency (default %(default)s)') parser.add_argument('--wavelength', '-L', dest='lmax', type=float, 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, help='current scale factor (default %(default)s)') parser.add_argument('--compare', '-c', dest='compare', help='compare with file (default %(default)s)') parser.add_argument('--outdir', '-o', dest='out', help='set output directory (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', help='verbose output') parser.add_argument('--quiet', '-q', dest='loglevel', action='store_const', const=0, help='verbose output') args = parser.parse_args() kwargs = vars(args) loglevel = kwargs.pop('loglevel') _outdir = kwargs.pop('out') setup_logger(loglevel) fig, ax1 = plt.subplots(1,1,figsize=(8,6)) fig.suptitle(rf'{args.name} $\lambda_{{max}}$={args.lmax:g}$\AA$') curve_test(ax1, **kwargs) ax1.legend() ax1.set_ylabel(r'I (A)') ax1.grid() plt.show() if __name__ == "__main__": main() setup.py +1 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ setup( 'console_scripts': [ 'nseplot = pysen.ui.nseplot:main', 'nxs2taco = pysen.inout.nxs2taco:main', 'nseflipper = pysen.ui.nseflipper:main', ], }, scripts = [ Loading Loading
pysen/revision.py +2 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ PySEN revision module """ import sys __version__ = "2.0" __release__ = ".7b1" __date__ = "Sep 12, 2025" __release__ = ".7b2" __date__ = "Sep 15, 2025" def version(full=False): "get pysen version number" Loading
pysen/ui/nseflipper.py 0 → 100755 +110 −0 Original line number Diff line number Diff line #!/usr/bin/env python """ script to calculate Mezei flipper curves """ import argparse import logging import numpy as np import matplotlib.pyplot as plt from pysen import version, setup_logger from pysen.config import INST_POSITIONS, L2, Ltot, HMN, ANGSTROM, DEFAULT_ACCELERATOR_FREQ from pysen.echo.flippers import FlipperPi, FlipperPi2, tof_curve flippers = { "fpi21" : FlipperPi2('fpi21', position =-2.824663, thickness=0.010, turns_density=833.33), #w=0.10 h=0.18, i33 "fpi21rs": FlipperPi ('fpi21rs', position =-2.283902, thickness=0.010, turns_density=833.33), #w=0.10 h=0.18, i37 "fpi" : FlipperPi ('fpi', position =-0.146000, thickness=0.013, turns_density=833.33), #w=0.18 h=0.18, i32 "fpi22rs": FlipperPi ('fpi22rs', position =+2.279194, thickness=0.010, turns_density=821.40), #w=0.28 h=0.28, i38 "fpi22" : FlipperPi2('fpi22', position =+2.823903, thickness=0.010, turns_density=821.40), #w=0.28 h=0.28, i34 } def curve_test(axs, name='fpi', **kwargs): "test with plots" pos =kwargs.pop('pos', 'p2') freq =kwargs.pop('freq', 60.0) points=kwargs.pop('points', 163) lmax=kwargs.pop('lmax', 8.0) compare=kwargs.pop('compare', None) scale =kwargs.pop('scale', 1.0) 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] # compare_data = None if compare is not None: try: compare_data = np.loadtxt(compare) except FileNotFoundError as err: log.error("cannot load compare file (%s)",err) 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 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()) def main(): "TBD" description="<unknown>" # 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='.') #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)') parser.add_argument('--frequency', '-F', dest='freq', type=float, help='accelerator frequency (default %(default)s)') parser.add_argument('--wavelength', '-L', dest='lmax', type=float, 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, help='current scale factor (default %(default)s)') parser.add_argument('--compare', '-c', dest='compare', help='compare with file (default %(default)s)') parser.add_argument('--outdir', '-o', dest='out', help='set output directory (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', help='verbose output') parser.add_argument('--quiet', '-q', dest='loglevel', action='store_const', const=0, help='verbose output') args = parser.parse_args() kwargs = vars(args) loglevel = kwargs.pop('loglevel') _outdir = kwargs.pop('out') setup_logger(loglevel) fig, ax1 = plt.subplots(1,1,figsize=(8,6)) fig.suptitle(rf'{args.name} $\lambda_{{max}}$={args.lmax:g}$\AA$') curve_test(ax1, **kwargs) ax1.legend() ax1.set_ylabel(r'I (A)') ax1.grid() plt.show() if __name__ == "__main__": main()
setup.py +1 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ setup( 'console_scripts': [ 'nseplot = pysen.ui.nseplot:main', 'nxs2taco = pysen.inout.nxs2taco:main', 'nseflipper = pysen.ui.nseflipper:main', ], }, scripts = [ Loading