Commit 0521ae53 authored by payno's avatar payno
Browse files

rename dimensions `X`, `Y`, `Z` to `dim 0`, `dim 1` and `dim 2`

parent e7dc2697
......@@ -70,7 +70,7 @@ class TestReprocessingPyMca(unittest.TestCase):
def setUp(self):
self.output_dir = tempfile.mkdtemp()
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM))
energy, mu = read_spectrum(data_file, dimensions=(Dim.DIM_0, Dim.DIM_1))
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj_ref = XASObject(
spectra=(self.spectrum,), energy=energy, dim1=1, dim2=1
......
......@@ -53,12 +53,12 @@ def convert_spectra_dims(dims):
res = []
for dim in dims:
if isinstance(dim, str):
if dim.lower() == Dim.X_DIM.value.lower():
dim = Dim.X_DIM
elif dim.lower() == Dim.Y_DIM.value.lower():
dim = Dim.Y_DIM
elif dim.lower() == Dim.Z_DIM.value.lower():
dim = Dim.Z_DIM
if dim.lower() == Dim.DIM_0.value.lower():
dim = Dim.DIM_0
elif dim.lower() == Dim.DIM_1.value.lower():
dim = Dim.DIM_1
elif dim.lower() == Dim.DIM_2.value.lower():
dim = Dim.DIM_2
dim = Dim.from_value(dim)
if dim in res:
......@@ -119,7 +119,7 @@ def get_xas_obj(
"""load xas object from command line input"""
if input_ is not None:
if input_dims is None:
input_dims = (Dim.X_DIM, Dim.Y_DIM)
input_dims = (Dim.DIM_0, Dim.DIM_1)
if has_read_spectrum:
energy, mu = read_spectrum(
input_, energy_unit=input_energy_unit, dimensions=input_dims
......@@ -130,7 +130,7 @@ def get_xas_obj(
raise ValueError("Unable to read spectrum")
else:
if input_dims is None:
input_dims = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
input_dims = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
sp, en, conf = read_xas(
spectra_url=input_spectra_url,
channel_url=input_channel_url,
......
......@@ -60,7 +60,7 @@ def main(argv):
parser.add_argument(
"--input-spectra-dims",
dest="input_spectra_dims",
default=(Dim.Z_DIM.value, Dim.Y_DIM.value, Dim.X_DIM.value),
default=(Dim.DIM_2.value, Dim.DIM_1.value, Dim.DIM_0.value),
help="spectra dimension. Should be a tuple of three values like: (Z,Y,X)",
)
parser.add_argument(
......
......@@ -61,7 +61,7 @@ def read(spectra_url, channel_url, dimensions, config_url=None, energy_unit=ur.e
"""
dimensions_ = dimensions
if dimensions_ is None:
dimensions_ = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
dimensions_ = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
reader = XASReader()
return reader.read_frm_url(
......@@ -76,7 +76,7 @@ def read(spectra_url, channel_url, dimensions, config_url=None, energy_unit=ur.e
def read_frm_file(
file_path,
energy_unit=ur.eV,
dimensions: tuple = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM),
dimensions: tuple = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
):
"""
......@@ -116,7 +116,7 @@ class XASReader(object):
def read_from_file(
file_path,
energy_unit=ur.eV,
dimensions=(Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
):
"""
......
......@@ -51,7 +51,7 @@ class TestEXAFSSingleSpectrum(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM))
energy, mu = read_spectrum(data_file, dimensions=(Dim.DIM_0, Dim.DIM_1))
spectrum = Spectrum(energy=energy, mu=mu)
exafs_configuration = {"Knots": {"Values": (1, 2, 5), "Number": 3}}
configuration = {"EXAFS": exafs_configuration}
......
......@@ -52,7 +52,7 @@ class TestFTSingleSpectrum(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM))
energy, mu = read_spectrum(data_file, dimensions=(Dim.DIM_0, Dim.DIM_1))
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
energy=energy, spectra=(self.spectrum,), dim1=1, dim2=1
......
......@@ -64,7 +64,7 @@ class TestReadWrite(unittest.TestCase):
res = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1),
)
self.assertTrue(isinstance(res, XASObject))
self.assertEqual(res.n_spectrum, 1)
......
......@@ -56,7 +56,7 @@ class TestKWeightSingleSpectrum(unittest.TestCase):
}
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM))
energy, mu = read_spectrum(data_file, dimensions=(Dim.DIM_0, Dim.DIM_1))
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
......
......@@ -56,7 +56,7 @@ class TestNormalizationSingleSpectrum(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM))
energy, mu = read_spectrum(data_file, dimensions=(Dim.DIM_0, Dim.DIM_1))
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
spectra=(self.spectrum,), energy=energy, dim1=1, dim2=1
......@@ -101,7 +101,7 @@ class TestNormalizationMultipleSpectrum(unittest.TestCase):
channel_url=DataUrl(
file_path=filename, data_path=channel_path, scheme="silx"
),
dimensions=(Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
)
def tearDown(self):
......
......@@ -76,7 +76,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1),
)
out.configuration = {"EXAFS": self.exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out)
......@@ -90,7 +90,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1),
)
out.configuration = {"EXAFS": self.exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out.to_dict())
......@@ -104,7 +104,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1),
)
out = PyMca_normalization()(xas_obj=out)
exafs_process = PyMca_exafs()
......
......@@ -58,7 +58,7 @@ class TestRoi(unittest.TestCase):
channel_url=DataUrl(
file_path=filename, data_path=channel_path, scheme="silx"
),
dimensions=(Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
)
def tearDown(self):
......
......@@ -65,7 +65,7 @@ class TestMeldWorkflow(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM))
energy, mu = read_spectrum(data_file, dimensions=(Dim.DIM_0, Dim.DIM_1))
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
energy=energy, spectra=(self.spectrum,), dim1=1, dim2=1
......
......@@ -87,13 +87,13 @@ class TestSpectraDimensions(unittest.TestCase):
channel_url = self.saveChannel(channel=channel)
# if dims are incoherent with energy, should raise an error
dims = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
dims = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
with self.assertRaises(ValueError):
XASReader().read_frm_url(
spectra_url=spectra_url, channel_url=channel_url, dimensions=dims
)
dims = (Dim.X_DIM, Dim.Y_DIM, Dim.Z_DIM)
dims = (Dim.DIM_0, Dim.DIM_1, Dim.DIM_2)
xas_obj = XASReader().read_frm_url(
spectra_url=spectra_url, channel_url=channel_url, dimensions=dims
)
......@@ -116,13 +116,13 @@ class TestSpectraDimensions(unittest.TestCase):
channel_url = self.saveChannel(channel=channel)
# if dims are incoherent with energy, should raise an error
dims = (Dim.X_DIM, Dim.Y_DIM, Dim.Z_DIM)
dims = (Dim.DIM_0, Dim.DIM_1, Dim.DIM_2)
with self.assertRaises(ValueError):
XASReader().read_frm_url(
spectra_url=spectra_url, channel_url=channel_url, dimensions=dims
)
dims = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
dims = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
xas_obj = XASReader().read_frm_url(
spectra_url=spectra_url, channel_url=channel_url, dimensions=dims
)
......
......@@ -61,7 +61,7 @@ class TestSpectrum(unittest.TestCase):
"""check that we can create a Spectrum from a pymca .dat file"""
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(
data_file, dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM)
data_file, dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1)
)
spectrum = Spectrum(energy=energy, mu=mu)
self.assertTrue(spectrum.energy is not None)
......@@ -88,7 +88,7 @@ class TestXASObject(unittest.TestCase):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
spectrum = {}
spectrum["Energy"], spectrum["Mu"] = read_spectrum(
data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM)
data_file, dimensions=(Dim.DIM_0, Dim.DIM_1)
)
self.spectrum = Spectrum(energy=spectrum["Energy"], mu=spectrum["Mu"])
self.configuration = {
......@@ -127,7 +127,7 @@ class TestXASObject(unittest.TestCase):
channel_url=DataUrl(
file_path=filename, data_path=channel_path, scheme="silx"
),
dimensions=(Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
)
self.assertEqual(self.xas_obj.spectra.shape[0], 20)
self.assertEqual(self.xas_obj.spectra.shape[1], 10)
......@@ -158,7 +158,7 @@ class TestXASObjectSerialization(unittest.TestCase):
f[self.spectra_path] = self.spectra
f[self.channel_path] = self.energy
self.dimensions = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
self.dimensions = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
self.url_spectra = DataUrl(
file_path=self.filename, data_path=self.spectra_path, scheme="silx"
......
......@@ -34,6 +34,6 @@ from silx.utils.enum import Enum
class Dim(Enum):
"""Define the possible dimension of the spectra"""
X_DIM = "X"
Y_DIM = "Y"
Z_DIM = "Z"
DIM_0 = "dim 0"
DIM_1 = "dim 1"
DIM_2 = "dim 2"
......@@ -60,7 +60,7 @@ class TestSpectra(unittest.TestCase):
"""check that we can create a Spectrum from a pymca .dat file"""
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(
data_file, dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM)
data_file, dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1)
)
spectrum = Spectrum(energy=energy, mu=mu)
......
......@@ -52,7 +52,7 @@ class TestSpectrum(unittest.TestCase):
"""check that we can create a Spectrum from a pymca .dat file"""
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(
data_file, dimensions=(Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM)
data_file, dimensions=(Dim.DIM_2, Dim.DIM_0, Dim.DIM_1)
)
spectrum = Spectrum(energy=energy, mu=mu)
self.assertTrue(spectrum.energy is not None)
......
......@@ -61,7 +61,7 @@ class TestXASObject(unittest.TestCase):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
spectrum = {}
spectrum["Energy"], spectrum["Mu"] = read_spectrum(
data_file, dimensions=(Dim.X_DIM, Dim.Y_DIM)
data_file, dimensions=(Dim.DIM_0, Dim.DIM_1)
)
self.spectrum = Spectrum(energy=spectrum["Energy"], mu=spectrum["Mu"])
self.configuration = {
......@@ -100,7 +100,7 @@ class TestXASObject(unittest.TestCase):
channel_url=DataUrl(
file_path=filename, data_path=channel_path, scheme="silx"
),
dimensions=(Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM),
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
)
self.assertEqual(self.xas_obj.spectra.shape[0], 20)
self.assertEqual(self.xas_obj.spectra.shape[1], 10)
......@@ -131,7 +131,7 @@ class TestXASObjectSerialization(unittest.TestCase):
f[self.spectra_path] = self.spectra
f[self.channel_path] = self.energy
self.dimensions = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
self.dimensions = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
self.url_spectra = DataUrl(
file_path=self.filename, data_path=self.spectra_path, scheme="silx"
......
......@@ -87,7 +87,7 @@ class XASObject(object):
:type: Union[None,str]
"""
DEFAULT_DIMENSIONS = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
DEFAULT_DIMENSIONS = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
def __init__(
self,
......@@ -305,7 +305,7 @@ class XASObject(object):
def load_frm_dict(self, ddict: dict):
"""load XAS values from a dict"""
dimensions = (Dim.Z_DIM, Dim.Y_DIM, Dim.X_DIM)
dimensions = (Dim.DIM_2, Dim.DIM_1, Dim.DIM_0)
# default yay of storing data
from est.io import load_data # avoid cyclic import
......
......@@ -248,7 +248,7 @@ class XASObjectDialog(qt.QWidget):
):
spectrumDiag = self._singleSpectrumDialog
dimensions = list(spectrumDiag.getDimensions())
dimensions.insert(0, Dim.Z_DIM)
dimensions.insert(0, Dim.DIM_2)
return read_frm_file(
file_path=spectrumDiag.getFileSelected(),
energy_unit=spectrumDiag.getEnergyUnit(),
......@@ -539,17 +539,17 @@ class _QDimComboBox(qt.QComboBox):
def __init__(self, parent, ndim):
assert ndim in (2, 3)
qt.QComboBox.__init__(self, parent)
self.addItem(Dim.X_DIM.value)
self.addItem(Dim.Y_DIM.value)
self.addItem(Dim.DIM_0.value)
self.addItem(Dim.DIM_1.value)
if ndim > 2:
self.addItem(Dim.Z_DIM.value)
self.addItem(Dim.DIM_2.value)
def setDim(self, dim):
try:
dim = Dim.from_value(dim)
except Exception as e:
_logger.warning(e)
dim = Dim.X_DIM
dim = Dim.DIM_0
index = self.findText(dim.value)
assert index >= 0
......@@ -575,9 +575,9 @@ class _SpectraDimensions(qt.QWidget):
self.layout().addRow("dim 2", self._dim2)
# set up
self._dim0.setDim(Dim.Z_DIM)
self._dim1.setDim(Dim.Y_DIM)
self._dim2.setDim(Dim.X_DIM)
self._dim0.setDim(Dim.DIM_2)
self._dim1.setDim(Dim.DIM_1)
self._dim2.setDim(Dim.DIM_0)
# connect Signal / Slot
self._dim0.currentTextChanged.connect(self._insureDimUnicity)
......@@ -598,7 +598,7 @@ class _SpectraDimensions(qt.QWidget):
assert last_modified != get_second
assert last_modified != get_third
assert type(last_modified) == type(get_second) == type(get_third)
value_set = {Dim.Z_DIM, Dim.X_DIM, Dim.Y_DIM}
value_set = {Dim.DIM_2, Dim.DIM_0, Dim.DIM_1}
last_value_set = last_modified.getDim()
value_set.remove(last_value_set)
......@@ -660,8 +660,8 @@ class _SpectrumDimensions(qt.QWidget):
self.layout().addRow("col 1", self._dim1)
# set up
self._dim0.setDim(Dim.X_DIM)
self._dim1.setDim(Dim.Y_DIM)
self._dim0.setDim(Dim.DIM_0)
self._dim1.setDim(Dim.DIM_1)
# connect Signal / Slot
self._dim0.currentIndexChanged.connect(self._insureDimUnicity)
......@@ -674,10 +674,10 @@ class _SpectrumDimensions(qt.QWidget):
else:
_to_modify = self._dim0
if last_modified.getDim() is Dim.X_DIM:
other_dim = Dim.Y_DIM
if last_modified.getDim() is Dim.DIM_0:
other_dim = Dim.DIM_1
else:
other_dim = Dim.X_DIM
other_dim = Dim.DIM_0
old = _to_modify.blockSignals(True)
if _to_modify.getDim() is not other_dim:
......
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