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