Loading pysen/inout/nexus.py +1 −1 Original line number Diff line number Diff line Loading @@ -186,7 +186,7 @@ def _dummy_callback(*_args, **_kwargs): return True # process scan def process_nexus(filename, **kwargs): def process_nexus_scan(filename, **kwargs): "process nexus file (scan indices)" scan_type = kwargs.pop('scan_type', None) scanpoint_cb = kwargs.pop('scanpoint_cb', _dummy_callback) Loading pysen/inout/nxs2echo.py +10 −6 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ import os.path import logging import argparse from pysen.inout import EchoWriter from pysen.inout import EchoWriter, DiffractionWriter, get_nsefiletype def main(): "the main" Loading Loading @@ -37,11 +37,15 @@ def main(): if not os.path.exists(file_name): log.warning("file '%s' does not exist", file_name) continue writer = EchoWriter() #writer = DiffractionWriter() if not writer.read_nexus(file_name, npix=args.npix, ntof=args.ntof, phase_step=args.step): file_type = get_nsefiletype(file_name) writer_class = { 'application/nexus-nse-echo' : EchoWriter, 'application/nexus-diffraction' : DiffractionWriter, }.get(file_type, None) if not isinstance(writer_class, type): log.warning("file '%s' unknown file type %s", file_name, file_type) continue writer = writer_class() if not writer.read_nexus(file_name, npix=args.npix, ntof=args.ntof, phase_step=args.step): continue writer.save(outdir=args.outdir) Loading pysen/inout/scans.py +34 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ import logging import numpy as np from ..config import NXCHAN as NPIX, NTCHAN as NTOF from .nexus import process_nexus, print_nexus_info, X0_PIX, Y0_PIX, XWID2, YWID2 from .nexus import process_nexus_scan, print_nexus_info, X0_PIX, Y0_PIX, XWID2, YWID2 # BUNCH OF HARD CODED CONSTANTS Loading Loading @@ -45,7 +45,7 @@ class BaseScan: kwargs.setdefault('ntof', NTOF) scan_type = kwargs.setdefault('scan_type', None) # self.info = process_nexus(nxsfile, scanpoint_cb=self.phasepoint_callback, self.info = process_nexus_scan(nxsfile, scanpoint_cb=self.phasepoint_callback, scan_type=scan_type) if self.info is None: return False Loading @@ -61,6 +61,38 @@ class BaseScan: self.log.debug("nexus info: %s", print_nexus_info(self.info)) return True class TransmissionScan: """Read SNS-NSE EPICS/NeXus transmission scan file """ def __init__(self): "the constructor" self.log = logging.getLogger() self.data = {} self.info = None def read_nexus(self, nxsfile, **kwargs): """read nexus file""" self.log.info("reading nexus file %s", nxsfile) # kwargs.setdefault('npix', NPIX) kwargs.setdefault('ntof', NTOF) scan_type = kwargs.setdefault('scan_type', None) # self.info = process_nexus_scan(nxsfile, scanpoint_cb=self.phasepoint_callback, scan_type=scan_type) if self.info is None: return False self.info.update(**kwargs) # lmin = self.info.get('lmin', 5.0) lmax = self.info.get('lmax', 8.0) self.info['xbin'] = np.linspace(X0_PIX-XWID2, X0_PIX+XWID2, self.info['npix']+1) self.info['ybin'] = np.linspace(Y0_PIX-YWID2, Y0_PIX+YWID2, self.info['npix']+1) self.info['tbin'] = np.linspace(lmin, lmax, self.info['ntof']+1) # # debug self.log.debug("nexus info: %s", print_nexus_info(self.info)) return True class DiffractionScan(BaseScan): """Read SNS-NSE EPICS/NeXus diffraction scan file Loading test/test_fit.py +9 −1 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ class FitModelTestCase(unittest.TestCase): err = 0.01 def setUp(self): # initalize random number generator for unit testing rng = np.random.default_rng(1966) t = np.logspace(np.log10(self.tmin), np.log10(self.tmax), 101) sqt = kww( t,self.t0, self.beta)*self.norm sqt_err = self.err*sqt sqt = sqt+np.random.normal(0,sqt_err) sqt = sqt+rng.normal(0,sqt_err) self.t = t self.sqt = (sqt, sqt_err) Loading @@ -36,6 +38,12 @@ class FitModelTestCase(unittest.TestCase): "basic fitting test" model = FitModel(FitFunction('kww', norm=True)) model.fit(tau=self.t, sqt=self.sqt[0], sqt_err=self.sqt[1]) #print("Normalized KWW function", model.__doc__.split('\n')[0]) #print((model.results['pars'][0]-self.t0 )/self.t0 < self.err) #print((model.results['pars'][1]-self.beta)/self.beta, self.err) #print((model.results['pars'][2]-self.norm)/self.norm, self.err) self.assertEqual("Normalized KWW function", model.__doc__.split('\n')[0]) self.assertTrue(abs(model.results['pars'][0]-self.t0 )/self.t0 < self.err) self.assertTrue(abs(model.results['pars'][1]-self.beta)/self.beta < self.err) Loading test/test_inout_nexus.py +8 −3 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ import h5py import numpy as np from pysen.inout.nexus import (pixel_decompose, timevalue_array, get_slice_average, process_nexus, get_run_info, time_format) process_nexus_scan, get_run_info, time_format) TestDataDir = os.path.join(os.path.dirname(__file__), 'data') Loading Loading @@ -93,9 +93,14 @@ class InOut_Nexus_TestCase(unittest.TestCase): self.assertAlmostEqual(t, times[i] , places=1, msg=f"time {key}[{i}]: {t:.2f}!={times[i]:.2f}") self.assertAlmostEqual(v, vals[key][i], places=2, msg=f"value {key}[{i}]: {v:.2f}!={vals[key][i]:.2f}") def z_test_z_process_nexus(self): def z_test_z_process_nexus_plain(self): "test nexus processing" res = process_nexus(self.filename) res = process_nexus_scan(self.filename) print(res) def z_test_z_process_nexus_scan(self): "test nexus processing" res = process_nexus_scan(self.filename) print(res) if __name__ == "__main__": Loading Loading
pysen/inout/nexus.py +1 −1 Original line number Diff line number Diff line Loading @@ -186,7 +186,7 @@ def _dummy_callback(*_args, **_kwargs): return True # process scan def process_nexus(filename, **kwargs): def process_nexus_scan(filename, **kwargs): "process nexus file (scan indices)" scan_type = kwargs.pop('scan_type', None) scanpoint_cb = kwargs.pop('scanpoint_cb', _dummy_callback) Loading
pysen/inout/nxs2echo.py +10 −6 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ import os.path import logging import argparse from pysen.inout import EchoWriter from pysen.inout import EchoWriter, DiffractionWriter, get_nsefiletype def main(): "the main" Loading Loading @@ -37,11 +37,15 @@ def main(): if not os.path.exists(file_name): log.warning("file '%s' does not exist", file_name) continue writer = EchoWriter() #writer = DiffractionWriter() if not writer.read_nexus(file_name, npix=args.npix, ntof=args.ntof, phase_step=args.step): file_type = get_nsefiletype(file_name) writer_class = { 'application/nexus-nse-echo' : EchoWriter, 'application/nexus-diffraction' : DiffractionWriter, }.get(file_type, None) if not isinstance(writer_class, type): log.warning("file '%s' unknown file type %s", file_name, file_type) continue writer = writer_class() if not writer.read_nexus(file_name, npix=args.npix, ntof=args.ntof, phase_step=args.step): continue writer.save(outdir=args.outdir) Loading
pysen/inout/scans.py +34 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ import logging import numpy as np from ..config import NXCHAN as NPIX, NTCHAN as NTOF from .nexus import process_nexus, print_nexus_info, X0_PIX, Y0_PIX, XWID2, YWID2 from .nexus import process_nexus_scan, print_nexus_info, X0_PIX, Y0_PIX, XWID2, YWID2 # BUNCH OF HARD CODED CONSTANTS Loading Loading @@ -45,7 +45,7 @@ class BaseScan: kwargs.setdefault('ntof', NTOF) scan_type = kwargs.setdefault('scan_type', None) # self.info = process_nexus(nxsfile, scanpoint_cb=self.phasepoint_callback, self.info = process_nexus_scan(nxsfile, scanpoint_cb=self.phasepoint_callback, scan_type=scan_type) if self.info is None: return False Loading @@ -61,6 +61,38 @@ class BaseScan: self.log.debug("nexus info: %s", print_nexus_info(self.info)) return True class TransmissionScan: """Read SNS-NSE EPICS/NeXus transmission scan file """ def __init__(self): "the constructor" self.log = logging.getLogger() self.data = {} self.info = None def read_nexus(self, nxsfile, **kwargs): """read nexus file""" self.log.info("reading nexus file %s", nxsfile) # kwargs.setdefault('npix', NPIX) kwargs.setdefault('ntof', NTOF) scan_type = kwargs.setdefault('scan_type', None) # self.info = process_nexus_scan(nxsfile, scanpoint_cb=self.phasepoint_callback, scan_type=scan_type) if self.info is None: return False self.info.update(**kwargs) # lmin = self.info.get('lmin', 5.0) lmax = self.info.get('lmax', 8.0) self.info['xbin'] = np.linspace(X0_PIX-XWID2, X0_PIX+XWID2, self.info['npix']+1) self.info['ybin'] = np.linspace(Y0_PIX-YWID2, Y0_PIX+YWID2, self.info['npix']+1) self.info['tbin'] = np.linspace(lmin, lmax, self.info['ntof']+1) # # debug self.log.debug("nexus info: %s", print_nexus_info(self.info)) return True class DiffractionScan(BaseScan): """Read SNS-NSE EPICS/NeXus diffraction scan file Loading
test/test_fit.py +9 −1 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ class FitModelTestCase(unittest.TestCase): err = 0.01 def setUp(self): # initalize random number generator for unit testing rng = np.random.default_rng(1966) t = np.logspace(np.log10(self.tmin), np.log10(self.tmax), 101) sqt = kww( t,self.t0, self.beta)*self.norm sqt_err = self.err*sqt sqt = sqt+np.random.normal(0,sqt_err) sqt = sqt+rng.normal(0,sqt_err) self.t = t self.sqt = (sqt, sqt_err) Loading @@ -36,6 +38,12 @@ class FitModelTestCase(unittest.TestCase): "basic fitting test" model = FitModel(FitFunction('kww', norm=True)) model.fit(tau=self.t, sqt=self.sqt[0], sqt_err=self.sqt[1]) #print("Normalized KWW function", model.__doc__.split('\n')[0]) #print((model.results['pars'][0]-self.t0 )/self.t0 < self.err) #print((model.results['pars'][1]-self.beta)/self.beta, self.err) #print((model.results['pars'][2]-self.norm)/self.norm, self.err) self.assertEqual("Normalized KWW function", model.__doc__.split('\n')[0]) self.assertTrue(abs(model.results['pars'][0]-self.t0 )/self.t0 < self.err) self.assertTrue(abs(model.results['pars'][1]-self.beta)/self.beta < self.err) Loading
test/test_inout_nexus.py +8 −3 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ import h5py import numpy as np from pysen.inout.nexus import (pixel_decompose, timevalue_array, get_slice_average, process_nexus, get_run_info, time_format) process_nexus_scan, get_run_info, time_format) TestDataDir = os.path.join(os.path.dirname(__file__), 'data') Loading Loading @@ -93,9 +93,14 @@ class InOut_Nexus_TestCase(unittest.TestCase): self.assertAlmostEqual(t, times[i] , places=1, msg=f"time {key}[{i}]: {t:.2f}!={times[i]:.2f}") self.assertAlmostEqual(v, vals[key][i], places=2, msg=f"value {key}[{i}]: {v:.2f}!={vals[key][i]:.2f}") def z_test_z_process_nexus(self): def z_test_z_process_nexus_plain(self): "test nexus processing" res = process_nexus(self.filename) res = process_nexus_scan(self.filename) print(res) def z_test_z_process_nexus_scan(self): "test nexus processing" res = process_nexus_scan(self.filename) print(res) if __name__ == "__main__": Loading