def test_save_instrument_file(): """Tests instrument object saving """ instr = Instrument() try: save_instrument(instr, 'test.out', filetype='ascii', overwrite=True) save_instrument(instr, 'test.out', filetype='hdf5', overwrite=True) save_instrument(instr, 'test.out', filetype='taz', overwrite=True) except Exception: pytest.fail('Instrument saving failed') with pytest.raises(ValueError): save_instrument(instr, 'test.out', filetype='hdf5', overwrite=False)
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from neutronpy import Instrument, Sample from neutronpy.functions import resolution EXP = Instrument() EXP.arms = [1560, 600, 260, 300] EXP.method = 1 hkle = [1., 1., 0., 5.] EXP.sample.u = [1,0,0] EXP.sample.v = [0,1,0] EXP.calc_projections(hkle) x, y = np.meshgrid(np.linspace(-0.05, 0.05, 101), np.linspace(-0.05, 0.05, 101), sparse=True) R0, RMxx, RMyy, RMxy = EXP.get_resolution_params(hkle, 'QxQy', mode='project') p = np.array([0., 0., 1., 0, 0, R0, RMxx, RMyy, RMxy]) z = resolution(p, (x, y)) fig = plt.figure(facecolor='w', edgecolor='k') plt.pcolormesh(x, y, z, cmap=cm.jet) [x1, y1] = EXP.projections['QxQy'][0] plt.fill(x1, y1, 'r', alpha=0.25) [x1, y1] = EXP.projections['QxQySlice'][0] plt.plot(x1, y1, 'w--') plt.xlim(-0.05, 0.05)
def test_currat_axe(): with warnings.catch_warnings(record=True) as w: spurion.currat_axe_peaks(Instrument(), [[0.8, 0.8, 0], [1.2, 1.2, 0], 17], [[1, 1, 0]], angle_tol=1) assert (len(w) == 3)
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from neutronpy import Instrument, Sample from neutronpy.functions import resolution EXP = Instrument() hkle = [1., 1., 0., 5.] EXP.calc_projections(hkle) x, y = np.meshgrid(np.linspace(-0.05, 0.05, 101), np.linspace(-0.05, 0.05, 101), sparse=True) R0, RMxx, RMyy, RMxy = EXP.get_resolution_params(hkle, 'QxQy', mode='project') p = np.array([0., 0., 1., 0, 0, R0, RMxx, RMyy, RMxy]) z = resolution(p, (x, y)) fig = plt.figure(facecolor='w', edgecolor='k') plt.pcolormesh(x, y, z, cmap=cm.jet) [x1, y1] = EXP.projections['QxQy'][0] plt.fill(x1, y1, 'r', alpha=0.25) [x1, y1] = EXP.projections['QxQySlice'][0] plt.plot(x1, y1, 'w--') plt.xlim(-0.05, 0.05) plt.ylim(-0.05, 0.05) plt.show()
from neutronpy import Instrument EXP = Instrument() EXP.plot_ellipsoid([1, 1, 0, 0])
from neutronpy import Instrument from numpy import linspace EXP = Instrument() EXP.plot_projections([1., 1., 0., linspace(0, 15, 7)])
from neutronpy import Instrument EXP = Instrument() EXP.arms = [1560, 600, 260, 300] EXP.plot_instrument([1,1,0,0])