Source code for toolbox_scs.test.test_hrixs

import unittest

import numpy as np
from numpy.testing import assert_array_equal
import xarray as xa
from .. import hRIXS

[docs]class TestHRIXS(unittest.TestCase):
[docs] def test_integration(self): data = xa.Dataset() img = np.arange(100 * 200 * 2) img.shape = (2, 100, 200) data['hRIXS_det'] = (('trainId', 'x', 'y'), img) h = hRIXS() h.CURVE_A = 0.1 h.CURVE_B = 0.01 h.Y_RANGE = slice(30, 170) r = h.integrate(data) self.assertIs(r, data) self.assertEqual(data['spectrum'][1, 50].values[()], 28517.704705882363) self.assertEqual(data['spectrum'][1, 50].coords['energy'], 90) h.dark_image = xa.DataArray(np.ones((100, 200)), dims=('x', 'y')) h.USE_DARK = True h.integrate(data) self.assertEqual(data['spectrum'][1, 50].values[()], 28516.704705882363)
[docs] def test_centroid(self): data = xa.Dataset() img = np.array([ [[0, 0, 0, 0, 0, 0, 0,], [0, 0, 0, 0, 0, 0, 0,], [0, 0, 1, 1, 0, 0, 0,], [0, 0, 1, 1, 0, 0, 0,], [0, 0, 0, 0, 0, 0, 0,], [0, 0, 0, 0, 0, 0, 0,], [0, 0, 0, 0, 0, 0, 0,],], [[0, 0, 0, 0, 0, 0, 0,], [0, 0, 0, 0, 0, 0, 0,], [0, 0, 1, 1, 2, 0, 0,], [0, 0, 1, 7, 2, 0, 0,], [0, 0, 1, 1, 2, 0, 0,], [0, 0, 0, 0, 0, 0, 0,], [0, 0, 0, 0, 0, 0, 0,],], ]) data['hRIXS_det'] = (('trainId', 'x', 'y'), img) h = hRIXS() h.Y_RANGE = slice(0, 7) h.THRESHOLD = 0.5 h.BINS = 10 data = h.centroid(data) assert_array_equal(data['spectrum'], [ [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], ]) h.CURVE_A = 0.1 h.CURVE_B = 0.01 r = h.centroid(data) self.assertIs(r, data) assert_array_equal(data['spectrum'], [ [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
])
[docs] def test_getparam(self): # this is just a smoke test h = hRIXS() d = h.get_params() self.assertEqual(d['bins'], 100)
if __name__ == "__main__": unittest.main()