Commit a7549417 authored by payno's avatar payno
Browse files

[converter oarnge table to XasObject]: fix issue with shape. Was probably not...

[converter oarnge table to XasObject]: fix issue with shape. Was probably not handling spectra with nelements.
parent b9f73b6b
......@@ -37,7 +37,8 @@ class TestConverter(unittest.TestCase):
"""Test conversion of xas_object to Orange.data.Table"""
def setUp(self):
self.energy, self.spectra = spectra_utils.create_dataset((128, 20, 1))
self.energy, self.spectra = spectra_utils.create_dataset(shape=(128, 20, 10))
print(self.energy.shape)
self.xas_object = XASObject(
energy=self.energy, spectra=self.spectra, dim1=20, dim2=10
)
......@@ -53,11 +54,14 @@ class TestConverter(unittest.TestCase):
xas_object.energy, converted_xas_object.energy
)
numpy.testing.assert_array_almost_equal(
xas_object.spectra[0].mu, converted_xas_object.spectra[0].mu
xas_object.spectra.data.flat[0].mu,
converted_xas_object.spectra.data.flat[0].mu,
)
numpy.testing.assert_array_almost_equal(
xas_object.spectra[5].mu, converted_xas_object.spectra[5].mu
xas_object.spectra.data.flat[5].mu,
converted_xas_object.spectra.data.flat[5].mu,
)
numpy.testing.assert_array_almost_equal(
xas_object.spectra[18].mu, converted_xas_object.spectra[18].mu
xas_object.spectra.data.flat[18].mu,
converted_xas_object.spectra.data.flat[18].mu,
)
......@@ -46,9 +46,12 @@ class Converter(object):
energy = _retrieve_energy(data_table.domain)
mu = data_table.X
mu = numpy.swapaxes(mu, 1, 0)
mu = mu.reshape(mu.shape[0], mu.shape[1], 1)
print("mu shape is", mu.shape)
mu = mu.reshape(mu.shape[0], mu.shape[1], -1)
# note: for now we only consider 2D spectra...
return XASObject(energy=energy, spectra=mu, dim2=1, dim1=mu.shape[-1])
return XASObject(
energy=energy, spectra=mu, dim2=mu.shape[-1], dim1=mu.shape[-2]
)
@staticmethod
def toDataTable(xas_object):
......@@ -64,7 +67,7 @@ class Converter(object):
# invert dimensions and axis to fit spectroscopy add-on
X = spectra.reshape((spectra.shape[0], -1))
X = numpy.swapaxes(X, 0, 1)
print("X shape is", X.shape)
domain = Orange.data.Domain(
attributes=[
Orange.data.ContinuousVariable.make("%f" % f) for f in xas_object.energy
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment