Commit 9ea016a8 authored by David Fairbrother's avatar David Fairbrother
Browse files

Enable flake8 on scripts/test and auto fix format / import

Enables flake8 for scripts/test and Framework/WorkflowAlgs. then auto
formats and auto-imports on any files which have failed the validation
which is no longer skipped
parent defd3320
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
ignore = E114,E115,E116,E121,E123,E126,E133,E2,E704,E722,E741,E743,W503,F403,F405,F999 ignore = E114,E115,E116,E121,E123,E126,E133,E2,E704,E722,E741,E743,W503,F403,F405,F999
exclude = exclude =
.git, .git,
build
buildconfig, buildconfig,
docs, docs,
Framework/Algorithms/test, Framework/Algorithms/test,
...@@ -9,7 +10,6 @@ exclude = ...@@ -9,7 +10,6 @@ exclude =
Framework/MPIAlgorithms, Framework/MPIAlgorithms,
Framework/PythonInterface/mantid, Framework/PythonInterface/mantid,
Framework/PythonInterface/test, Framework/PythonInterface/test,
Framework/WorkflowAlgorithms,
images, images,
installers, installers,
instrument, instrument,
...@@ -21,7 +21,6 @@ exclude = ...@@ -21,7 +21,6 @@ exclude =
qt/python/mantidqt/dialogs/errorreports/resources_qt5.py qt/python/mantidqt/dialogs/errorreports/resources_qt5.py
qt/scientific_interfaces, qt/scientific_interfaces,
qt/widgets, qt/widgets,
scripts/test,
Testing/PerformanceTests, Testing/PerformanceTests,
Testing/SystemTests/lib, Testing/SystemTests/lib,
Testing/SystemTests/scripts, Testing/SystemTests/scripts,
......
...@@ -7,14 +7,15 @@ ...@@ -7,14 +7,15 @@
import unittest import unittest
from mantid.simpleapi import * from mantid.simpleapi import *
class EQSANSQ2DTest(unittest.TestCase): class EQSANSQ2DTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.test_ws_name = "EQSANS_test_ws" self.test_ws_name = "EQSANS_test_ws"
x = [1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.] x = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]
y = 491520*[0.1] y = 491520 * [0.1]
CreateWorkspace(OutputWorkspace=self.test_ws_name,DataX=x,DataY=y,DataE=y,NSpec='49152',UnitX='Wavelength') CreateWorkspace(OutputWorkspace=self.test_ws_name, DataX=x, DataY=y, DataE=y, NSpec='49152', UnitX='Wavelength')
LoadInstrument(Workspace=self.test_ws_name, InstrumentName="EQSANS", RewriteSpectraMap=True) LoadInstrument(Workspace=self.test_ws_name, InstrumentName="EQSANS", RewriteSpectraMap=True)
run = mtd[self.test_ws_name].mutableRun() run = mtd[self.test_ws_name].mutableRun()
...@@ -34,13 +35,15 @@ class EQSANSQ2DTest(unittest.TestCase): ...@@ -34,13 +35,15 @@ class EQSANSQ2DTest(unittest.TestCase):
def test_q2d(self): def test_q2d(self):
EQSANSQ2D(InputWorkspace=self.test_ws_name) EQSANSQ2D(InputWorkspace=self.test_ws_name)
ReplaceSpecialValues(InputWorkspace=self.test_ws_name+"_Iqxy",OutputWorkspace=self.test_ws_name+"_Iqxy",NaNValue=0,NaNError=0) ReplaceSpecialValues(InputWorkspace=self.test_ws_name + "_Iqxy", OutputWorkspace=self.test_ws_name + "_Iqxy",
Integration(InputWorkspace=self.test_ws_name+"_Iqxy", OutputWorkspace="__tmp") NaNValue=0, NaNError=0)
Integration(InputWorkspace=self.test_ws_name + "_Iqxy", OutputWorkspace="__tmp")
SumSpectra(InputWorkspace="__tmp", OutputWorkspace="summed") SumSpectra(InputWorkspace="__tmp", OutputWorkspace="summed")
self.assertAlmostEquals(mtd["summed"].readY(0)[0], 7.24077, 6) self.assertAlmostEquals(mtd["summed"].readY(0)[0], 7.24077, 6)
for ws in ["__tmp", "summed"]: for ws in ["__tmp", "summed"]:
if mtd.doesExist(ws): if mtd.doesExist(ws):
DeleteWorkspace(Workspace=ws) DeleteWorkspace(Workspace=ws)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import unittest import unittest
import mantid
from mantid.simpleapi import * from mantid.simpleapi import *
class SANSBeamFluxCorrectionTest(unittest.TestCase): class SANSBeamFluxCorrectionTest(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -46,5 +46,6 @@ class SANSBeamFluxCorrectionTest(unittest.TestCase): ...@@ -46,5 +46,6 @@ class SANSBeamFluxCorrectionTest(unittest.TestCase):
output_y = output[0].readY(0) output_y = output[0].readY(0)
self.assertAlmostEqual(ref_value, output_y[0], 6) self.assertAlmostEqual(ref_value, output_y[0], 6)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
...@@ -39,7 +39,7 @@ class BroadeningTest(unittest.TestCase): ...@@ -39,7 +39,7 @@ class BroadeningTest(unittest.TestCase):
(0,)) (0,))
zero_result = broadening.mesh_gaussian(sigma=np.array([[5]]), zero_result = broadening.mesh_gaussian(sigma=np.array([[5]]),
points=np.array([0,]), points=np.array([0, ]),
center=np.array([[3]])) center=np.array([[3]]))
self.assertEqual(zero_result.shape, (1, 1)) self.assertEqual(zero_result.shape, (1, 1))
self.assertFalse(zero_result.any()) self.assertFalse(zero_result.any())
...@@ -141,22 +141,21 @@ class BroadeningTest(unittest.TestCase): ...@@ -141,22 +141,21 @@ class BroadeningTest(unittest.TestCase):
freq_points, spectrum = broadening.broaden_spectrum( freq_points, spectrum = broadening.broaden_spectrum(
frequencies, bins, s_dft, sigma, scheme=scheme) frequencies, bins, s_dft, sigma, scheme=scheme)
self.assertAlmostEqual(sum(spectrum), self.assertAlmostEqual(sum(spectrum),
pre_broadening_total,) pre_broadening_total, )
# Normal scheme reproduces area as well as total; # Normal scheme reproduces area as well as total;
freq_points, full_spectrum = broadening.broaden_spectrum( freq_points, full_spectrum = broadening.broaden_spectrum(
frequencies, bins, s_dft, sigma, scheme='normal') frequencies, bins, s_dft, sigma, scheme='normal')
self.assertAlmostEqual(np.trapz(spectrum, x=freq_points), self.assertAlmostEqual(np.trapz(spectrum, x=freq_points),
pre_broadening_total * (bins[1] - bins[0]),) pre_broadening_total * (bins[1] - bins[0]), )
self.assertAlmostEqual(sum(spectrum), pre_broadening_total) self.assertAlmostEqual(sum(spectrum), pre_broadening_total)
# truncated forms will be a little off but shouldn't be _too_ off # truncated forms will be a little off but shouldn't be _too_ off
for scheme in ('gaussian_truncated', 'normal_truncated'): for scheme in ('gaussian_truncated', 'normal_truncated'):
freq_points, trunc_spectrum = broadening.broaden_spectrum( freq_points, trunc_spectrum = broadening.broaden_spectrum(
frequencies, bins, s_dft, sigma, scheme) frequencies, bins, s_dft, sigma, scheme)
self.assertLess(abs(sum(full_spectrum) - sum(trunc_spectrum)) / sum(full_spectrum), self.assertLess(abs(sum(full_spectrum) - sum(trunc_spectrum)) / sum(full_spectrum),
0.03) 0.03)
# Interpolated methods need histogram input and smooth sigma # Interpolated methods need histogram input and smooth sigma
hist_spec, _ = np.histogram(frequencies, bins, weights=s_dft) hist_spec, _ = np.histogram(frequencies, bins, weights=s_dft)
...@@ -164,7 +163,7 @@ class BroadeningTest(unittest.TestCase): ...@@ -164,7 +163,7 @@ class BroadeningTest(unittest.TestCase):
freq_points, interp_spectrum = broadening.broaden_spectrum( freq_points, interp_spectrum = broadening.broaden_spectrum(
freq_points, bins, hist_spec, hist_sigma, scheme='interpolate') freq_points, bins, hist_spec, hist_sigma, scheme='interpolate')
self.assertLess(abs(sum(interp_spectrum) - pre_broadening_total) / pre_broadening_total, self.assertLess(abs(sum(interp_spectrum) - pre_broadening_total) / pre_broadening_total,
0.05) 0.05)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
# NScD Oak Ridge National Laboratory, European Spallation Source, # NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
from itertools import product
import unittest import unittest
import numpy as np from itertools import product
from numpy.testing import assert_array_almost_equal, assert_array_equal
import abins import abins
import numpy as np
from abins.constants import FIRST_OVERTONE, FUNDAMENTALS, INT_TYPE, FLOAT_TYPE from abins.constants import FIRST_OVERTONE, FUNDAMENTALS, INT_TYPE, FLOAT_TYPE
from numpy.testing import assert_array_equal
class FrequencyPowderGeneratorTest(unittest.TestCase): class FrequencyPowderGeneratorTest(unittest.TestCase):
...@@ -182,9 +182,9 @@ class FrequencyPowderGeneratorTest(unittest.TestCase): ...@@ -182,9 +182,9 @@ class FrequencyPowderGeneratorTest(unittest.TestCase):
# Check doubles are in the right places and the maths is just a sum # Check doubles are in the right places and the maths is just a sum
self.assertTrue(np.any(fundamentals[0] * 2 == doubles)) self.assertTrue(np.any(fundamentals[0] * 2 == doubles))
self.assertTrue(np.any(fundamentals[2] + fundamentals[3] == doubles)) self.assertTrue(np.any(fundamentals[2] + fundamentals[3] == doubles))
self.assertEqual((fundamentals[double_coeffs[20,0]] self.assertEqual((fundamentals[double_coeffs[20, 0]]
+ fundamentals[double_coeffs[20,1]]), + fundamentals[double_coeffs[20, 1]]),
doubles[20]) doubles[20])
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import unittest import unittest
import numpy as np import numpy as np
from mantid.simpleapi import logger
from abins import IO, test_helpers from abins import IO, test_helpers
......
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import unittest import unittest
import numpy as np
import numpy as np
from abins.kpointsdata import KpointsData, KpointData from abins.kpointsdata import KpointsData, KpointData
from abins.constants import ACOUSTIC_PHONON_THRESHOLD
class KpointsDataTest(unittest.TestCase): class KpointsDataTest(unittest.TestCase):
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import unittest import unittest
import mantid
import abins.test_helpers
import abins.input import abins.input
import abins.test_helpers
from abins.input import CASTEPLoader from abins.input import CASTEPLoader
class LoadCASTEPTest(unittest.TestCase, abins.input.Tester): class LoadCASTEPTest(unittest.TestCase, abins.input.Tester):
# simple tests # simple tests
def test_non_existing_file(self): def test_non_existing_file(self):
......
...@@ -9,6 +9,7 @@ import abins.test_helpers ...@@ -9,6 +9,7 @@ import abins.test_helpers
import abins.input import abins.input
from abins.input import CRYSTALLoader from abins.input import CRYSTALLoader
class AbinsLoadCRYSTALTest(unittest.TestCase, abins.input.Tester): class AbinsLoadCRYSTALTest(unittest.TestCase, abins.input.Tester):
def tearDown(self): def tearDown(self):
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import unittest import unittest
from mantid.simpleapi import logger
import abins.test_helpers
import abins.input import abins.input
import abins.test_helpers
class AbinsLoadDMOL3Test(unittest.TestCase, abins.input.Tester): class AbinsLoadDMOL3Test(unittest.TestCase, abins.input.Tester):
...@@ -19,7 +19,7 @@ class AbinsLoadDMOL3Test(unittest.TestCase, abins.input.Tester): ...@@ -19,7 +19,7 @@ class AbinsLoadDMOL3Test(unittest.TestCase, abins.input.Tester):
_gamma_no_h_dmol3 = "Na2SiF6_LoadDMOL3" _gamma_no_h_dmol3 = "Na2SiF6_LoadDMOL3"
_molecule_dmol3 = "methane_LoadDMOL3" _molecule_dmol3 = "methane_LoadDMOL3"
_molecule_opt_dmol3 = "methane_opt_LoadDMOL3" _molecule_opt_dmol3 = "methane_opt_LoadDMOL3"
def test_gamma_dmol3(self): def test_gamma_dmol3(self):
self.check(name=self._gamma_dmol3, loader=abins.input.DMOL3Loader) self.check(name=self._gamma_dmol3, loader=abins.input.DMOL3Loader)
self.check(name=self._gamma_no_h_dmol3, loader=abins.input.DMOL3Loader) self.check(name=self._gamma_no_h_dmol3, loader=abins.input.DMOL3Loader)
...@@ -28,5 +28,6 @@ class AbinsLoadDMOL3Test(unittest.TestCase, abins.input.Tester): ...@@ -28,5 +28,6 @@ class AbinsLoadDMOL3Test(unittest.TestCase, abins.input.Tester):
self.check(name=self._molecule_dmol3, loader=abins.input.DMOL3Loader) self.check(name=self._molecule_dmol3, loader=abins.input.DMOL3Loader)
self.check(name=self._molecule_opt_dmol3, loader=abins.input.DMOL3Loader) self.check(name=self._molecule_opt_dmol3, loader=abins.input.DMOL3Loader)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import unittest import unittest
from mantid.simpleapi import logger
import abins.test_helpers
import abins.input import abins.input
import abins.test_helpers
class AbinsLoadGAUSSIANTest(unittest.TestCase, abins.input.Tester): class AbinsLoadGAUSSIANTest(unittest.TestCase, abins.input.Tester):
...@@ -16,6 +16,7 @@ class AbinsLoadGAUSSIANTest(unittest.TestCase, abins.input.Tester): ...@@ -16,6 +16,7 @@ class AbinsLoadGAUSSIANTest(unittest.TestCase, abins.input.Tester):
abins.test_helpers.remove_output_files(list_of_names=["LoadGAUSSIAN"]) abins.test_helpers.remove_output_files(list_of_names=["LoadGAUSSIAN"])
# *************************** USE CASES ******************************************** # *************************** USE CASES ********************************************
# =================================================================================== # ===================================================================================
# | Use cases: molecular calculation for GAUSSIAN03 Hartree Fock, Unix | # | Use cases: molecular calculation for GAUSSIAN03 Hartree Fock, Unix |
# =================================================================================== # ===================================================================================
......
...@@ -14,18 +14,18 @@ class AbinsPowderDataTest(unittest.TestCase): ...@@ -14,18 +14,18 @@ class AbinsPowderDataTest(unittest.TestCase):
# hypothetical data for two atoms # hypothetical data for two atoms
self.good_items = { self.good_items = {
"a_tensors": {0: np.asarray([[[0.01, 0.02, 0.03], "a_tensors": {0: np.asarray([[[0.01, 0.02, 0.03],
[0.01, 0.02, 0.03], [0.01, 0.02, 0.03],
[0.01, 0.02, 0.03]], [0.01, 0.02, 0.03]],
[[0.01, 0.02, 0.03], [[0.01, 0.02, 0.03],
[0.01, 0.02, 0.03], [0.01, 0.02, 0.03],
[0.01, 0.02, 0.03]]])}, [0.01, 0.02, 0.03]]])},
"b_tensors": {0: np.asarray([[[0.01, 0.02, 0.03], "b_tensors": {0: np.asarray([[[0.01, 0.02, 0.03],
[0.01, 0.02, 0.03], [0.01, 0.02, 0.03],
[0.01, 0.02, 0.03]], [0.01, 0.02, 0.03]],
[[0.01, 0.02, 0.03], [[0.01, 0.02, 0.03],
[0.01, 0.02, 0.03], [0.01, 0.02, 0.03],
[0.01, 0.02, 0.03]]])}, [0.01, 0.02, 0.03]]])},
"frequencies": {0: np.asarray([2.34, 5.67, 8.90])}} "frequencies": {0: np.asarray([2.34, 5.67, 8.90])}}
def test_bad_num_atoms(self): def test_bad_num_atoms(self):
...@@ -84,5 +84,6 @@ class AbinsPowderDataTest(unittest.TestCase): ...@@ -84,5 +84,6 @@ class AbinsPowderDataTest(unittest.TestCase):
self.assertTrue(np.allclose(self.good_items["frequencies"][k_point], self.assertTrue(np.allclose(self.good_items["frequencies"][k_point],
good_powderdata.get_frequencies()[k_point])) good_powderdata.get_frequencies()[k_point]))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -4,12 +4,10 @@ ...@@ -4,12 +4,10 @@
# NScD Oak Ridge National Laboratory, European Spallation Source, # NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import os
from mantid.simpleapi import *
from mantid import api
import unittest import unittest
import numpy as np import numpy as np
from Direct.AbsorptionShapes import (anAbsorptionShape,Cylinder,FlatPlate,HollowCylinder,Sphere) from Direct.AbsorptionShapes import (anAbsorptionShape, Cylinder, FlatPlate, HollowCylinder, Sphere)
class AbsorbtionShapesTest(unittest.TestCase): class AbsorbtionShapesTest(unittest.TestCase):
...@@ -19,227 +17,218 @@ class AbsorbtionShapesTest(unittest.TestCase): ...@@ -19,227 +17,218 @@ class AbsorbtionShapesTest(unittest.TestCase):
def test_an_Absrpn_shape_parent(self): def test_an_Absrpn_shape_parent(self):
ash = anAbsorptionShape(['V']); ash = anAbsorptionShape(['V']);
res = ash.material; res = ash.material;
self.assertEqual(res['ChemicalFormula'],'V') self.assertEqual(res['ChemicalFormula'], 'V')
ash.material = 'Cr' ash.material = 'Cr'
res = ash.material; res = ash.material;
self.assertEqual(res['ChemicalFormula'],'Cr') self.assertEqual(res['ChemicalFormula'], 'Cr')
ash.material = ['Br',10] ash.material = ['Br', 10]
res = ash.material; res = ash.material;
self.assertEqual(res['ChemicalFormula'],'Br') self.assertEqual(res['ChemicalFormula'], 'Br')
self.assertEqual(res['SampleNumberDensity'],10) self.assertEqual(res['SampleNumberDensity'], 10)
ash.material = {'ChemicalFormula': 'Al', 'SampleNumberDensity': 0.5}
ash.material = {'ChemicalFormula':'Al','SampleNumberDensity':0.5}
res = ash.material; res = ash.material;
self.assertEqual(res['ChemicalFormula'],'Al') self.assertEqual(res['ChemicalFormula'], 'Al')
self.assertEqual(res['SampleNumberDensity'],0.5) self.assertEqual(res['SampleNumberDensity'], 0.5)
self.assertRaises(TypeError,anAbsorptionShape.material.__set__,ash,[1,2,3]) self.assertRaises(TypeError, anAbsorptionShape.material.__set__, ash, [1, 2, 3])
self.assertRaises(TypeError,anAbsorptionShape.material.__set__,ash,[1,2]) self.assertRaises(TypeError, anAbsorptionShape.material.__set__, ash, [1, 2])
ash = anAbsorptionShape({'AtomicNumber':12,'AttenuationXSection':0.5,'SampleMassDensity':120}) ash = anAbsorptionShape({'AtomicNumber': 12, 'AttenuationXSection': 0.5, 'SampleMassDensity': 120})
res = ash.material; res = ash.material;
self.assertEqual(res['AtomicNumber'],12) self.assertEqual(res['AtomicNumber'], 12)
self.assertEqual(res['AttenuationXSection'],0.5) self.assertEqual(res['AttenuationXSection'], 0.5)
self.assertEqual(res['SampleMassDensity'],120) self.assertEqual(res['SampleMassDensity'], 120)
# Add extra material property, consistent with other properties. # Add extra material property, consistent with other properties.
ash.material = {'ScatteringXSection':20} ash.material = {'ScatteringXSection': 20}
res = ash.material; res = ash.material;
self.assertEqual(res['AttenuationXSection'],0.5) self.assertEqual(res['AttenuationXSection'], 0.5)
self.assertEqual(res['ScatteringXSection'],20) self.assertEqual(res['ScatteringXSection'], 20)
self.assertEqual(len(res),4) self.assertEqual(len(res), 4)
def test_adsrp_cylinder(self): def test_adsrp_cylinder(self):
ash = Cylinder('V',[10,2]) ash = Cylinder('V', [10, 2])
res = ash.shape res = ash.shape
self.assertEqual(res['Height'],10) self.assertEqual(res['Height'], 10)
self.assertEqual(res['Radius'],2) self.assertEqual(res['Radius'], 2)
self.assertTrue(ash._axis_is_default) self.assertTrue(ash._axis_is_default)
ash.shape = [5,1,[0,1,0],[0.,0.,-0.5]] ash.shape = [5, 1, [0, 1, 0], [0., 0., -0.5]]
res = ash.shape res = ash.shape
self.assertEqual(res['Height'],5) self.assertEqual(res['Height'], 5)
self.assertEqual(res['Radius'],1) self.assertEqual(res['Radius'], 1)
self.assertEqual(res['Axis'],[0,1,0]) self.assertEqual(res['Axis'], [0, 1, 0])
self.assertEqual(res['Center'],[0,0,-0.5]) self.assertEqual(res['Center'], [0, 0, -0.5])
self.assertFalse(ash._axis_is_default) self.assertFalse(ash._axis_is_default)
ash.shape = {'Height': 5, 'Radius': 2, 'Axis': [1, 0, 0], 'Center': [0., 0., 0.]}
ash.shape = {'Height':5,'Radius':2,'Axis':[1,0,0],'Center':[0.,0.,0.]}
res = ash.shape; res = ash.shape;
self.assertEqual(res['Height'],5) self.assertEqual(res['Height'], 5)
self.assertEqual(res['Radius'],2) self.assertEqual(res['Radius'], 2)
self.assertEqual(res['Axis'],[1,0,0]) self.assertEqual(res['Axis'], [1, 0, 0])
self.assertEqual(res['Center'],[0,0,0]) self.assertEqual(res['Center'], [0, 0, 0])
test_ws = CreateSampleWorkspace(NumBanks=1,BankPixelWidth=1) test_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=1)
test_ws = ConvertUnits(test_ws,'DeltaE',Emode='Direct',EFixed=2000) test_ws = ConvertUnits(test_ws, 'DeltaE', Emode='Direct', EFixed=2000)
cor_ws,corrections = ash.correct_absorption(test_ws,is_fast=True) cor_ws, corrections = ash.correct_absorption(test_ws, is_fast=True)
n_bins = corrections.blocksize() n_bins = corrections.blocksize()
corr_ranges = [n_bins,corrections.readY(0)[0],corrections.readY(0)[n_bins-1]] corr_ranges = [n_bins, corrections.readY(0)[0], corrections.readY(0)[n_bins - 1]]
np.testing.assert_almost_equal(corr_ranges,[97,0.0,0.0],4) np.testing.assert_almost_equal(corr_ranges, [97, 0.0, 0.0], 4)
mccor_ws,mc_corr = ash.correct_absorption(test_ws, EventsPerPoint=300) mccor_ws, mc_corr = ash.correct_absorption(test_ws, EventsPerPoint=300)
n_bins = mc_corr.blocksize() n_bins = mc_corr.blocksize()
mccorr_ranges = [n_bins,mc_corr.readY(0)[0],mc_corr.readY(0)[n_bins-1]] mccorr_ranges = [n_bins, mc_corr.readY(0)[0], mc_corr.readY(0)[n_bins - 1]]
np.testing.assert_almost_equal(mccorr_ranges ,[97,0.266,0.033],3) np.testing.assert_almost_equal(mccorr_ranges, [97, 0.266, 0.033], 3)
def test_MARI_axis_cylinder(self): def test_MARI_axis_cylinder(self):
""" Test that default axis for MARI is different""" """ Test that default axis for MARI is different"""
ash = Cylinder('Fe',[10,2]) ash = Cylinder('Fe', [10, 2])
res = ash.shape res = ash.shape
self.assertEqual(res['Height'],10) self.assertEqual(res['Height'], 10)
self.assertEqual(res['Radius'],2) self.assertEqual(res['Radius'], 2)
self.assertTrue(ash._axis_is_default) self.assertTrue(ash