From 706f3c1da95e64413f0e47f25c193287d00ab838 Mon Sep 17 00:00:00 2001 From: pseudocubic Date: Sat, 5 Mar 2016 15:45:06 -0700 Subject: [PATCH] DOC: Handedness of coordinate frame of Instrument Resolves #54 The Instrument class attributes dir1, dir2 and mondir are depreciated in favor of mono.dir, sample.dir, and ana.dir. These attributes control the handedness of the coordinate frame. Documentation in _Monochromator and Instrument class is updated to reflect correct usage. --- neutronpy/__init__.py | 1 - tests/test_resolution.py | 46 ++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/neutronpy/__init__.py b/neutronpy/__init__.py index 6c83b1b..31665d2 100644 --- a/neutronpy/__init__.py +++ b/neutronpy/__init__.py @@ -11,7 +11,6 @@ from . import spurion from . import lattice from . import io -from . import instrument as resolution from .kmpfit import Fitter from .energy import Energy from .data import Data diff --git a/tests/test_resolution.py b/tests/test_resolution.py index e85eb12..5ee06d7 100644 --- a/tests/test_resolution.py +++ b/tests/test_resolution.py @@ -8,7 +8,7 @@ from mock import patch from matplotlib import use import numpy as np -from neutronpy import resolution +from neutronpy import instrument from neutronpy.io import load_instrument from neutronpy.sample import Sample use('Agg') @@ -17,9 +17,9 @@ def angle2(x, y, z, h, k, l, lattice): r'''Function necessary for Prefactor functions ''' - latticestar = resolution._star(lattice)[-1] + latticestar = instrument._star(lattice)[-1] - return np.arccos(2 * np.pi * (h * x + k * y + l * z) / resolution._modvec([x, y, z], lattice) / resolution._modvec([h, k, l], latticestar)) + return np.arccos(2 * np.pi * (h * x + k * y + l * z) / instrument._modvec([x, y, z], lattice) / instrument._modvec([h, k, l], latticestar)) def SqwDemo(H, K, L, W, p): @@ -78,7 +78,7 @@ def PrefDemo(H, K, L, EXP, p): ''' [sample, rsample] = EXP.get_lattice() - q2 = resolution._modvec([H, K, L], rsample) ** 2 + q2 = instrument._modvec([H, K, L], rsample) ** 2 sd = q2 / (16 * np.pi ** 2) ff = 0.0163 * np.exp(-35.883 * sd) + 0.3916 * np.exp(-13.223 * sd) + 0.6052 * np.exp(-4.339 * sd) - 0.0133 @@ -109,7 +109,7 @@ def PrefDemo2(H, K, L, EXP, p): ''' [sample, rsample] = EXP.get_lattice() - q2 = resolution._modvec([H, K, L], rsample) ** 2 + q2 = instrument._modvec([H, K, L], rsample) ** 2 sd = q2 / (16 * np.pi ** 2) ff = 0.0163 * np.exp(-35.883 * sd) + 0.3916 * np.exp(-13.223 * sd) + 0.6052 * np.exp(-4.339 * sd) - 0.0133 @@ -151,7 +151,7 @@ def __init__(self, *args, **kwargs): self.sumIavg = 1654.37911333 self.sumIstd = 0.5 - instr = resolution.Instrument(test=1) + instr = instrument.Instrument(test=1) instr.method = 0 instr.mono.tau = 'PG(002)' @@ -193,7 +193,7 @@ def test_cooper_nathans(self): NP = EXP.RMS R = EXP.R0 - BraggWidths = resolution.get_bragg_widths(NP) + BraggWidths = instrument.get_bragg_widths(NP) angles = self.EXP_popovici.get_angles_and_Q(hkle)[0] ResVol = (2 * np.pi) ** 2 / np.sqrt(np.linalg.det(NP)) * 2 @@ -222,7 +222,7 @@ def test_popovici(self): NP = self.EXP_popovici.RMS R = self.EXP_popovici.R0 - BraggWidths = resolution.get_bragg_widths(NP) + BraggWidths = instrument.get_bragg_widths(NP) angles = self.EXP_popovici.get_angles_and_Q(hkle)[0] ResVol = (2 * np.pi) ** 2 / np.sqrt(np.linalg.det(NP)) * 2 @@ -239,7 +239,7 @@ def test_4d_conv(self): sample = Sample(6, 7, 8, 90, 90, 90) sample.u = [1, 0, 0] sample.v = [0, 0, 1] - EXP = resolution.Instrument(14.7, sample, hcol=[80, 40, 40, 80], vcol=[120, 120, 120, 120], mono='pg(002)', ana='pg(002)') + EXP = instrument.Instrument(14.7, sample, hcol=[80, 40, 40, 80], vcol=[120, 120, 120, 120], mono='pg(002)', ana='pg(002)') EXP.moncor = 0 p = np.array([3, 3, 3, 30, 0.4, 6e4, 40]) @@ -264,7 +264,7 @@ def test_sma_conv(self): sample = Sample(6, 7, 8, 90, 90, 90) sample.u = [1, 0, 0] sample.v = [0, 0, 1] - EXP = resolution.Instrument(14.7, sample, hcol=[80, 40, 40, 80], vcol=[120, 120, 120, 120], mono='pg(002)', ana='pg(002)') + EXP = instrument.Instrument(14.7, sample, hcol=[80, 40, 40, 80], vcol=[120, 120, 120, 120], mono='pg(002)', ana='pg(002)') EXP.moncor = 0 p = np.array([3, 3, 3, 30, 0.4, 6e4, 40]) @@ -285,7 +285,7 @@ def test_sma_conv(self): def test_plotting(self, mock_show): '''Test Plotting methods ''' - EXP = resolution.Instrument() + EXP = instrument.Instrument() EXP.plot_instrument([1, 0, 0, 0]) EXP.plot_projections([1, 0, 0, 0]) EXP.calc_resolution([[1, 2], 0, 0, 0]) @@ -326,10 +326,10 @@ def test_sample(self): def test_GetTau(self): '''Test monochromator crystal tau value finder ''' - self.assertTrue(resolution.GetTau(1.87325, getlabel=True) == 'pg(002)') - self.assertTrue(resolution.GetTau(1.8, getlabel=True) == '') - self.assertTrue(resolution.GetTau(10) == 10) - self.assertRaises(KeyError, resolution.GetTau, 'blah') + self.assertTrue(instrument.GetTau(1.87325, getlabel=True) == 'pg(002)') + self.assertTrue(instrument.GetTau(1.8, getlabel=True) == '') + self.assertTrue(instrument.GetTau(10) == 10) + self.assertRaises(KeyError, instrument.GetTau, 'blah') def test_CleanArgs_err(self): '''Test exception capture in CleanArgs @@ -340,9 +340,9 @@ def test_fproject(self): '''Test projection function ''' x = np.ones((4, 4, 1)) - resolution.fproject(x, 0) - resolution.fproject(x, 1) - resolution.fproject(x, 2) + instrument.fproject(x, 0) + instrument.fproject(x, 1) + instrument.fproject(x, 2) def test_constants(self): '''Test constants @@ -353,7 +353,7 @@ def test_constants(self): def test_errors(self): '''Test exception handling ''' - EXP = resolution.Instrument() + EXP = instrument.Instrument() EXP.sample.u = [1, 0, 0] EXP.sample.v = [2, 0, 0] self.assertRaises(ValueError, EXP.calc_resolution, [1, 1, 0, 0]) @@ -361,7 +361,7 @@ def test_errors(self): def test_calc_res_cases(self): '''Test different resolution cases ''' - EXP = resolution.Instrument() + EXP = instrument.Instrument() EXP.sample.shape = np.eye(3) EXP.calc_resolution([1, 0, 0, 0]) @@ -381,7 +381,7 @@ def test_calc_res_cases(self): EXP.ana.Q = 1.5 EXP.calc_resolution([1, 0, 0, 0]) - EXP.Smooth = resolution._dummy() + EXP.Smooth = instrument._dummy() EXP.Smooth.X = 1 EXP.Smooth.Y = 1 EXP.Smooth.Z = 1 @@ -391,13 +391,13 @@ def test_calc_res_cases(self): def test_projection_calc(self): '''Test different cases of resolution ellipse slices/projections ''' - EXP = resolution.Instrument() + EXP = instrument.Instrument() EXP.calc_resolution([1, 0, 0, 0]) EXP.calc_projections([0, 1, 0, 0]) EXP.get_resolution_params([0, 1, 0, 0], 'QxQy', 'slice') self.assertRaises(ValueError, EXP.get_resolution_params, [1, 1, 0, 0], 'QxQy', 'slice') - EXP = resolution.Instrument() + EXP = instrument.Instrument() EXP.get_resolution_params([1, 0, 0, 0], 'QxQy', 'slice') EXP.get_resolution_params([1, 0, 0, 0], 'QxQy', 'project') EXP.get_resolution_params([1, 0, 0, 0], 'QxW', 'slice')