예제 #1
0
    def test_adsrp_sphere(self):
        ash = Sphere('Al', 10)
        res = ash.shape
        self.assertEqual(res['Radius'], 10)

        ash.shape = [5, [1, 0, 0]]
        res = ash.shape
        rad = res['Radius']
        self.assertEqual(rad, 5)
        cen = res['Center']
        self.assertEqual(cen, [1, 0, 0])

        ash.shape = {'Radius': 3, 'Center': [0., 0., 0.]}
        res = ash.shape
        rad = res['Radius']
        self.assertEqual(rad, 3)
        cen = res['Center']
        self.assertEqual(cen, [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=6)
        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)

        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, 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.66, 0.51], 2)
예제 #2
0
    def test_string_conversion(self):
        """ check if shape conversion to string representation works"""
        ash = HollowCylinder('V', [10, 2, 4])
        ash_str = str(ash)
        ash_rec = anAbsorptionShape.from_str(ash_str)

        self.assertTrue(isinstance(ash_rec, HollowCylinder))
        self.assertDictEqual(ash.material, ash_rec.material)
        self.assertDictEqual(ash.shape, ash_rec.shape)

        ash = Sphere(['Al', 10], 10)
        ash_str = str(ash)
        ash_rec = anAbsorptionShape.from_str(ash_str)

        self.assertTrue(isinstance(ash_rec, Sphere))
        self.assertDictEqual(ash.material, ash_rec.material)
        self.assertDictEqual(ash.shape, ash_rec.shape)