Loading scripts/ipynse.py→misc/ipynse.py +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ """ what is that??? """ #pylint: disable=skip-file import sys import time Loading scripts/atariplot.py +3 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import h5py import matplotlib.pyplot as plt from pysen import ANGSTROM, NANOSECOND from pysen import ANGSTROM, NANOSECOND, version from pysen.io import echo_to_hdf from pysen.atarilib import fit_echo_current, Spectrum Loading Loading @@ -148,6 +148,8 @@ def main(): help='set max TOF bin (default=%(default)s)') parser.add_argument('--only-echo', '-N', dest='only_echo', action='store_true', default=False, help='show only echo (no up/down)') parser.add_argument('--version', action='version', version='%(prog)s pysen={version}'.format(version=version(full=True))) args = parser.parse_args() logging.basicConfig(level=args.loglevel, format=r'%(message)s') Loading scripts/echoplot.py +4 −11 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import h5py import matplotlib.pyplot as plt from pysen import ANGSTROM, NANOSECOND, version from pysen.plotutil import get_nsubplots from pysen.io import echo_to_hdf from pysen.atarilib import fit_echo_current, Spectrum Loading Loading @@ -50,15 +51,7 @@ def echo_plot(hdfile, iecho=0, **kwargs): for echo in list(hdfile['/data'].values()): if iecho is None or echo.attrs['id'] == iecho: ntaus = ntaus + 1 print(ntaus) if ntaus>4: nxtau = 4 nytau = int(np.ceil(ntaus/4)) else: nxtau = 1 nytau = ntaus #print(nxtau, nytau) #fig0, axes0 = plt.subplots(nxtau,nytau, figsize=(8,8)) nxtau, nytau = get_nsubplots(ntaus) fig0 = plt.figure(figsize=(8,8)) fig0.suptitle(r'%s | %s' % (sample, base)) Loading Loading @@ -213,14 +206,14 @@ def main(): help='set min TOF bin (default=%(default)s)') parser.add_argument('--t2', '-T', dest='tbin2', type=int, default=None, help='set max TOF bin (default=%(default)s)') parser.add_argument('--center-only', '-C', dest='center_only', action='store_true', default=False, help='show only center patch') parser.add_argument('--verbose', '-v', dest='loglevel', action='store_const', const=logging.DEBUG, help='verbose output') parser.add_argument('--quiet', '-q', dest='loglevel', action='store_const', const=logging.WARNING, help='verbose output') parser.add_argument('--version', action='version', version='%(prog)s pysen={version}'.format(version=version(full=True))) parser.add_argument('--center-only', '-C', dest='center_only', action='store_true', default=False, help='show only center patch') args = parser.parse_args() if args.loglevel>=logging.INFO: Loading scripts/genecho.py +3 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import logging import numpy as np from pysen import version, config, ANGSTROM, NANOSECOND from pysen import version, NANOSECOND from pysen.io.writer import generate_echo def resolution(t, lam=6.4, H=0.7): Loading Loading @@ -109,8 +109,9 @@ def main(): fd = sys.stdin else: fd = open(args.file) #pylint: disable=exec-used exec(compile(fd.read(), args.file, 'exec'), glbs) #pylint: disable=undefined-variable generate_echo(outfile, numor=args.num, sample=sample, detector=detector, physics=physics, taus=taus) else: Loading scripts/mag_field.py +34 −18 Original line number Diff line number Diff line Loading @@ -10,21 +10,31 @@ import matplotlib.pyplot as plt from pysen import ANGSTROM, NANOSECOND, GAUSS, MICRO, OMEGA_N, version from pysen.io import echo_to_hdf from pysen.plotutil import get_nsubplots #from pysen.atarilib import fit_echo_current, Spectrum MAX_CHI2_DEFAULT = 1e-2 def plot_field(ax,t,v,**kwargs): "plot mag field" label = kwargs.get('label' , '') max_chi2 = kwargs.get('max_chi2', 1e-2) max_chi2 = kwargs.get('max_chi2', MAX_CHI2_DEFAULT) v0 = np.sqrt(np.sum(v**2,axis=-1)) # a,b = np.polyfit(t,v0,deg=1) v1 = np.polyval([a,b],t) r = np.corrcoef(t,v0) r = r[1,0] r = np.cov(t,v0) rr = r[0,0]*r[1,1] if rr>0: r = r[1,0]/np.sqrt(rr) else: r = np.nan #r = np.corrcoef(t,v0) #r = r[1,0] chi2 = np.sum((v0-v1)**2) #maxd = max(abs(v0-v1)) descr1 = r'a=%.2e b=%.3g' % (a, b) descr2 = r'$\rho$=%.3g $\chi^2$=%.1e' % (r, chi2) #descr2 = r'$\rho$=%.3g $\chi^2$=%.1e $(\Delta B)_{max}$=%.3g' % (r, chi2, maxd) # va = np.average(v0) vd = max(abs(v0-va)) Loading @@ -33,11 +43,14 @@ def plot_field(ax,t,v,**kwargs): ax.plot(t,v0, '.--', lw=1, label=label) ax.plot(t,v1, '-') ax.set_ylim(bottom=vmin, top=vmax) ax.legend(loc='best') ax.text(0.05,0.20,descr1, transform=ax.transAxes, fontsize=7) ax.text(0.05,0.10,descr2, transform=ax.transAxes, fontsize=7) ax.grid(True, lw=0.5) ax.legend(loc='upper left') if chi2>max_chi2: ax.set_facecolor('yellow') def plot_magnetic_fields(hdfile, iecho=0): def plot_magnetic_fields(hdfile, iecho=0, max_chi2=MAX_CHI2_DEFAULT): "plot magnetic fields" # base = os.path.splitext(os.path.basename(hdfile.filename))[0] Loading @@ -50,9 +63,9 @@ def plot_magnetic_fields(hdfile, iecho=0): for echo in list(hdfile['/data'].values()): if iecho is not None and echo.attrs['id'] != iecho: print("skipping ", echo.name) #print("skipping ", echo.name) continue print("processing", echo.name) #print("processing", echo.name) phase = echo['phase'] physics = echo['phys'] Loading @@ -70,20 +83,20 @@ def plot_magnetic_fields(hdfile, iecho=0): cur = phase['phase_current'][:, 0] # actual value dj = np.radians(phasesens*(cur-cur0))/OMEGA_N/lam0 nplots = int(np.ceil(np.sqrt(len(bfield)))) nxplot, nyplot = get_nsubplots(len(bfield)) fig, axes = plt.subplots(nplots,nplots, figsize=(9,6)) fig.subplots_adjust(hspace=0.3, wspace=0.3) fig, axes = plt.subplots(nxplot,nyplot, figsize=(9,7)) fig.subplots_adjust(hspace=0.4, wspace=0.4) fig.suptitle(r'%s | %s | $\lambda$=%.2g$\AA$ $Q$=%.3f$\AA^{-1}$ $\tau$=%.3fns' % (sample, base, lam0/ANGSTROM, q0, tau0)) for iplt, bsensor in enumerate(bfield): bmag = bfield[bsensor] label = bsensor.split('.')[-1] ax = axes[iplt//nplots,iplt%nplots] plot_field(ax, dj[:nph]/MICRO, bmag[:nph,:]*GAUSS/MICRO, label=label) for iplt in range(iplt+1, nplots*nplots): ax = axes[iplt//nplots,iplt%nplots] ax = axes[iplt//nxplot,iplt%nxplot] plot_field(ax, dj[:nph]/MICRO, bmag[:nph,:]*GAUSS/MICRO, label=label, max_chi2=max_chi2) for iplt in range(iplt+1, nxplot*nyplot): ax = axes[iplt//nxplot,iplt%nxplot] ax.axis('off') Loading @@ -92,10 +105,13 @@ def main(): import argparse parser = argparse.ArgumentParser(description='plot magnetic fields') parser.set_defaults(loglevel=logging.INFO, outdir='.') parser.set_defaults(loglevel=logging.INFO, outdir='.', echo=None, chi2=MAX_CHI2_DEFAULT) parser.add_argument('file', metavar='filename', help='file to process', nargs='+') parser.add_argument('--echo', '-e', dest='echo', type=int, default=None, parser.add_argument('--echo', '-e', dest='echo', type=int, help='set echo to display (default=%(default)s)') parser.add_argument('--max-chi2', '-x', dest='chi2', type=float, help='set chi2 threshold (default=%(default)s)') parser.add_argument('--verbose', '-v', dest='loglevel', action='store_const', const=logging.DEBUG, help='verbose output') parser.add_argument('--quiet', '-q', dest='loglevel', action='store_const', Loading @@ -121,7 +137,7 @@ def main(): else: hfile = filename with h5py.File(hfile, 'r') as hdf5file: plot_magnetic_fields(hdf5file, iecho=args.echo) plot_magnetic_fields(hdf5file, iecho=args.echo, max_chi2=args.chi2) plt.show() if __name__ == "__main__": Loading Loading
scripts/ipynse.py→misc/ipynse.py +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ """ what is that??? """ #pylint: disable=skip-file import sys import time Loading
scripts/atariplot.py +3 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import h5py import matplotlib.pyplot as plt from pysen import ANGSTROM, NANOSECOND from pysen import ANGSTROM, NANOSECOND, version from pysen.io import echo_to_hdf from pysen.atarilib import fit_echo_current, Spectrum Loading Loading @@ -148,6 +148,8 @@ def main(): help='set max TOF bin (default=%(default)s)') parser.add_argument('--only-echo', '-N', dest='only_echo', action='store_true', default=False, help='show only echo (no up/down)') parser.add_argument('--version', action='version', version='%(prog)s pysen={version}'.format(version=version(full=True))) args = parser.parse_args() logging.basicConfig(level=args.loglevel, format=r'%(message)s') Loading
scripts/echoplot.py +4 −11 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import h5py import matplotlib.pyplot as plt from pysen import ANGSTROM, NANOSECOND, version from pysen.plotutil import get_nsubplots from pysen.io import echo_to_hdf from pysen.atarilib import fit_echo_current, Spectrum Loading Loading @@ -50,15 +51,7 @@ def echo_plot(hdfile, iecho=0, **kwargs): for echo in list(hdfile['/data'].values()): if iecho is None or echo.attrs['id'] == iecho: ntaus = ntaus + 1 print(ntaus) if ntaus>4: nxtau = 4 nytau = int(np.ceil(ntaus/4)) else: nxtau = 1 nytau = ntaus #print(nxtau, nytau) #fig0, axes0 = plt.subplots(nxtau,nytau, figsize=(8,8)) nxtau, nytau = get_nsubplots(ntaus) fig0 = plt.figure(figsize=(8,8)) fig0.suptitle(r'%s | %s' % (sample, base)) Loading Loading @@ -213,14 +206,14 @@ def main(): help='set min TOF bin (default=%(default)s)') parser.add_argument('--t2', '-T', dest='tbin2', type=int, default=None, help='set max TOF bin (default=%(default)s)') parser.add_argument('--center-only', '-C', dest='center_only', action='store_true', default=False, help='show only center patch') parser.add_argument('--verbose', '-v', dest='loglevel', action='store_const', const=logging.DEBUG, help='verbose output') parser.add_argument('--quiet', '-q', dest='loglevel', action='store_const', const=logging.WARNING, help='verbose output') parser.add_argument('--version', action='version', version='%(prog)s pysen={version}'.format(version=version(full=True))) parser.add_argument('--center-only', '-C', dest='center_only', action='store_true', default=False, help='show only center patch') args = parser.parse_args() if args.loglevel>=logging.INFO: Loading
scripts/genecho.py +3 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import logging import numpy as np from pysen import version, config, ANGSTROM, NANOSECOND from pysen import version, NANOSECOND from pysen.io.writer import generate_echo def resolution(t, lam=6.4, H=0.7): Loading Loading @@ -109,8 +109,9 @@ def main(): fd = sys.stdin else: fd = open(args.file) #pylint: disable=exec-used exec(compile(fd.read(), args.file, 'exec'), glbs) #pylint: disable=undefined-variable generate_echo(outfile, numor=args.num, sample=sample, detector=detector, physics=physics, taus=taus) else: Loading
scripts/mag_field.py +34 −18 Original line number Diff line number Diff line Loading @@ -10,21 +10,31 @@ import matplotlib.pyplot as plt from pysen import ANGSTROM, NANOSECOND, GAUSS, MICRO, OMEGA_N, version from pysen.io import echo_to_hdf from pysen.plotutil import get_nsubplots #from pysen.atarilib import fit_echo_current, Spectrum MAX_CHI2_DEFAULT = 1e-2 def plot_field(ax,t,v,**kwargs): "plot mag field" label = kwargs.get('label' , '') max_chi2 = kwargs.get('max_chi2', 1e-2) max_chi2 = kwargs.get('max_chi2', MAX_CHI2_DEFAULT) v0 = np.sqrt(np.sum(v**2,axis=-1)) # a,b = np.polyfit(t,v0,deg=1) v1 = np.polyval([a,b],t) r = np.corrcoef(t,v0) r = r[1,0] r = np.cov(t,v0) rr = r[0,0]*r[1,1] if rr>0: r = r[1,0]/np.sqrt(rr) else: r = np.nan #r = np.corrcoef(t,v0) #r = r[1,0] chi2 = np.sum((v0-v1)**2) #maxd = max(abs(v0-v1)) descr1 = r'a=%.2e b=%.3g' % (a, b) descr2 = r'$\rho$=%.3g $\chi^2$=%.1e' % (r, chi2) #descr2 = r'$\rho$=%.3g $\chi^2$=%.1e $(\Delta B)_{max}$=%.3g' % (r, chi2, maxd) # va = np.average(v0) vd = max(abs(v0-va)) Loading @@ -33,11 +43,14 @@ def plot_field(ax,t,v,**kwargs): ax.plot(t,v0, '.--', lw=1, label=label) ax.plot(t,v1, '-') ax.set_ylim(bottom=vmin, top=vmax) ax.legend(loc='best') ax.text(0.05,0.20,descr1, transform=ax.transAxes, fontsize=7) ax.text(0.05,0.10,descr2, transform=ax.transAxes, fontsize=7) ax.grid(True, lw=0.5) ax.legend(loc='upper left') if chi2>max_chi2: ax.set_facecolor('yellow') def plot_magnetic_fields(hdfile, iecho=0): def plot_magnetic_fields(hdfile, iecho=0, max_chi2=MAX_CHI2_DEFAULT): "plot magnetic fields" # base = os.path.splitext(os.path.basename(hdfile.filename))[0] Loading @@ -50,9 +63,9 @@ def plot_magnetic_fields(hdfile, iecho=0): for echo in list(hdfile['/data'].values()): if iecho is not None and echo.attrs['id'] != iecho: print("skipping ", echo.name) #print("skipping ", echo.name) continue print("processing", echo.name) #print("processing", echo.name) phase = echo['phase'] physics = echo['phys'] Loading @@ -70,20 +83,20 @@ def plot_magnetic_fields(hdfile, iecho=0): cur = phase['phase_current'][:, 0] # actual value dj = np.radians(phasesens*(cur-cur0))/OMEGA_N/lam0 nplots = int(np.ceil(np.sqrt(len(bfield)))) nxplot, nyplot = get_nsubplots(len(bfield)) fig, axes = plt.subplots(nplots,nplots, figsize=(9,6)) fig.subplots_adjust(hspace=0.3, wspace=0.3) fig, axes = plt.subplots(nxplot,nyplot, figsize=(9,7)) fig.subplots_adjust(hspace=0.4, wspace=0.4) fig.suptitle(r'%s | %s | $\lambda$=%.2g$\AA$ $Q$=%.3f$\AA^{-1}$ $\tau$=%.3fns' % (sample, base, lam0/ANGSTROM, q0, tau0)) for iplt, bsensor in enumerate(bfield): bmag = bfield[bsensor] label = bsensor.split('.')[-1] ax = axes[iplt//nplots,iplt%nplots] plot_field(ax, dj[:nph]/MICRO, bmag[:nph,:]*GAUSS/MICRO, label=label) for iplt in range(iplt+1, nplots*nplots): ax = axes[iplt//nplots,iplt%nplots] ax = axes[iplt//nxplot,iplt%nxplot] plot_field(ax, dj[:nph]/MICRO, bmag[:nph,:]*GAUSS/MICRO, label=label, max_chi2=max_chi2) for iplt in range(iplt+1, nxplot*nyplot): ax = axes[iplt//nxplot,iplt%nxplot] ax.axis('off') Loading @@ -92,10 +105,13 @@ def main(): import argparse parser = argparse.ArgumentParser(description='plot magnetic fields') parser.set_defaults(loglevel=logging.INFO, outdir='.') parser.set_defaults(loglevel=logging.INFO, outdir='.', echo=None, chi2=MAX_CHI2_DEFAULT) parser.add_argument('file', metavar='filename', help='file to process', nargs='+') parser.add_argument('--echo', '-e', dest='echo', type=int, default=None, parser.add_argument('--echo', '-e', dest='echo', type=int, help='set echo to display (default=%(default)s)') parser.add_argument('--max-chi2', '-x', dest='chi2', type=float, help='set chi2 threshold (default=%(default)s)') parser.add_argument('--verbose', '-v', dest='loglevel', action='store_const', const=logging.DEBUG, help='verbose output') parser.add_argument('--quiet', '-q', dest='loglevel', action='store_const', Loading @@ -121,7 +137,7 @@ def main(): else: hfile = filename with h5py.File(hfile, 'r') as hdf5file: plot_magnetic_fields(hdf5file, iecho=args.echo) plot_magnetic_fields(hdf5file, iecho=args.echo, max_chi2=args.chi2) plt.show() if __name__ == "__main__": Loading