Commit 7bdd85d0 authored by Henri Payno's avatar Henri Payno
Browse files

[core]register_process: add a relative_to parameter to store numpy array...

[core]register_process: add a relative_to parameter to store numpy array relative to "r" values and not only "energy"
parent c66dbfa4
......@@ -111,7 +111,8 @@ class Larch_xftf(Process):
self._pool_process(xas_obj=_xas_obj)
self._advancement.endProcess()
self.register_process(_xas_obj,
data_keys=('chi', 'chir', 'chir_mag', 'k', 'r'))
data_keys=('chir_im', 'chir_re', 'chir_mag', 'r'),
relative_to='r')
return _xas_obj
def _pool_process(self, xas_obj):
......
......@@ -93,7 +93,7 @@ class Process(object):
else:
return None
def register_process(self, xas_obj, data_keys):
def register_process(self, xas_obj, data_keys, relative_to='energy'):
"""
Store the current process in the linked h5 file if any,
output data stored will be the one defined by the data_keys
......@@ -101,6 +101,7 @@ class Process(object):
:param :class:`.XASObject` xas_obj: object for which we want to save the
treatment
:param tuple data_keys: keys of the id to save
:param str relative_to: x value
"""
if xas_obj.has_linked_file():
_data = {}
......@@ -109,7 +110,8 @@ class Process(object):
_data[key] = XASObject._spectra_volume(xas_obj.spectra,
key=key,
dim_1=xas_obj.dim1,
dim_2=xas_obj.dim2)
dim_2=xas_obj.dim2,
relative_to=relative_to)
except KeyError:
pass
xas_obj.register_processing(process=self, data=_data)
......@@ -211,14 +211,15 @@ class XASObject(object):
dim_2=self.dim2)
@staticmethod
def _spectra_volume(spectra, key, dim_1, dim_2):
def _spectra_volume(spectra, key, dim_1, dim_2, relative_to='energy'):
"""Convert a list of spectra (mu) to a numpy array.
..note: only convert raw data for now"""
if len(spectra) is 0:
return None
else:
assert len(spectra) == dim_1 * dim_2
array = numpy.zeros((len(spectra[0].energy), dim_1 * dim_2))
array = numpy.zeros((len(getattr(spectra[0], relative_to)),
dim_1 * dim_2))
for i_spectrum, spectrum in enumerate(spectra):
subkeys = key.split('/')
value = spectrum[subkeys[0]]
......@@ -226,7 +227,8 @@ class XASObject(object):
value = value[subkey]
array[:, i_spectrum] = value
return array.reshape((len(spectra[0].energy), dim_1, dim_2))
return array.reshape((len(getattr(spectra[0], relative_to)),
dim_1, dim_2))
def load_frm_dict(self, ddict):
"""load XAS values from a dict"""
......
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