Commit 5b3614de authored by Henri Payno's avatar Henri Payno
Browse files

[xasObject] manage the ft.radius, ft. intensity... that can of differetn size

parent 6d770211
......@@ -116,17 +116,31 @@ class Process(object):
"NormalizedMu", "NormalizedSignal", "EXAFSKValues",
"EXAFSSignal"):
relative_to = 'energy'
use = '_spectra_volume'
elif key in ('chir_re', 'chir_im', 'chir_mag', 'r'):
relative_to = 'r'
use = '_spectra_volume'
elif key in ('ft.radius', 'ft.intensity', 'ft.imaginary'):
relative_to = 'ft.radius'
try:
_data[key] = XASObject._spectra_volume(xas_obj.spectra,
key=key,
dim_1=xas_obj.dim1,
dim_2=xas_obj.dim2,
relative_to=relative_to)
except KeyError:
mess = '%s: unable to store %s, parameter not found' % (self.name, key)
_logger.error(mess)
relative_to = 'radius'
use = '_list_res_ft'
if use == '_spectra_volume':
# if we can display the result as a numpy.array 3d
try:
_data[key] = XASObject._spectra_volume(xas_obj.spectra,
key=key,
dim_1=xas_obj.dim1,
dim_2=xas_obj.dim2,
relative_to=relative_to)
except KeyError:
mess = '%s: unable to store %s, parameter not found' % (self.name, key)
_logger.error(mess)
elif use == '_list_res_ft':
res = []
key_ = key.split('.')[-1]
for spectrum in xas_obj.spectra:
res.append(getattr(spectrum.ft, key_))
_data[key] = res
else:
raise ValueError()
xas_obj.register_processing(process=self, data=_data)
......@@ -91,12 +91,18 @@ def process_spectr_ft(spectrum, configuration, overwrite=True, callback=None,
set2 = set2[goodi, :]
if set2.size == 0:
ft = {"FTIntensity": set2}
ft = {
"FTImaginary": numpy.nan,
"FTIntensity": numpy.nan,
"FTRadius": numpy.nan,
}
else:
ft = pymca_xas.fourierTransform(set2[:,0], set2[:, 1],
kMin=spectrum["KMin"],
kMax=spectrum["KMax"])
assert "FTIntensity" in ft
assert "FTRadius" in ft
assert ft["FTRadius"] is not None
assert ft["FTIntensity"] is not None
if callback:
callback()
......@@ -108,12 +114,10 @@ def process_spectr_ft(spectrum, configuration, overwrite=True, callback=None,
spectrum_.update(spectrum)
assert spectrum_
spectrum_.ft = ft
assert spectrum_.ft.intensity is not None
if output is not None:
assert output_dict is not None
output[output_dict[spectrum]] = spectrum_
assert spectrum_.ft.intensity is not None
return configuration, spectrum_
......@@ -174,7 +178,6 @@ class PyMca_ft(Process):
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
overwrite=True)
assert spectrum.ft.intensity is not None
else:
from multiprocessing import Manager
manager = Manager()
......
......@@ -73,7 +73,8 @@ class TestNxWriting(unittest.TestCase):
def setUp(self):
self.output_dir = tempfile.mkdtemp()
energy, spectra = spectra_utils.create_dataset(shape=(256, 20, 10))
self.xas_obj = XASObject(spectra=spectra, energy=energy)
self.xas_obj = XASObject(spectra=spectra, energy=energy, dim1=20,
dim2=10)
self.h5_file = os.path.join(self.output_dir, 'output_file.h5')
def tearDown(self):
......
......@@ -181,9 +181,11 @@ class TestSaveFlowAuto(unittest.TestCase):
"""
def setUp(self):
self.output_dir = tempfile.mkdtemp()
spectra = spectra_utils.create_dataset(shape=(10, 10, 10))
energy = numpy.linspace(start=3.26, stop=3.96, num=10)
self.xas_obj = XASObject(spectra=spectra, energy=energy)
energy, spectra = spectra_utils.create_dataset(shape=(100, 10, 10))
assert spectra.shape == (100, 10, 10)
assert len(energy) == spectra.shape[0]
self.xas_obj = XASObject(spectra=spectra, energy=energy, dim1=10,
dim2=10)
self.h5_file = os.path.join(self.output_dir, 'output_file.h5')
def tearDown(self):
......
......@@ -232,7 +232,7 @@ class XASObject(object):
return object[name]
def get_relative_to_value(relative):
paths_ = relative_to.split('.')
paths_ = relative.split('.')
value = getattr(spectra[0], paths_[0])
for path_ in paths_[1:]:
value = getattr(value, path_)
......@@ -243,6 +243,7 @@ class XASObject(object):
else:
assert len(spectra) == dim_1 * dim_2
if relative_to:
assert get_relative_to_value(relative_to) is not None
array = numpy.zeros((len(get_relative_to_value(relative_to)),
dim_1 * dim_2))
else:
......
Supports Markdown
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