Commit 179f111c authored by payno's avatar payno
Browse files

black format

parent 949f78df
Pipeline #39463 failed with stages
in 6 minutes and 58 seconds
......@@ -64,6 +64,7 @@ def _insert_output_in_scheme(scheme, output_):
"information provided will be ignored"
)
# FIXME: spec_input should be a name tuple
def exec_(
scheme: Scheme,
......
......@@ -70,10 +70,11 @@ 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,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
energy, mu = read_spectrum(
data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj_ref = XASObject(
spectra=(self.spectrum,), energy=energy, dim1=1, dim2=1
......
......@@ -13,7 +13,11 @@ from est.core.types import Dim
def _plot(
spec_input, input_spectra_url, input_spectra_dims, input_channel_url, input_energy_unit
spec_input,
input_spectra_url,
input_spectra_dims,
input_channel_url,
input_energy_unit,
):
has_url_information = input_spectra_url or input_channel_url
(
......
......@@ -47,8 +47,13 @@ DEFAULT_CHANNEL_PATH = "/data/NXdata/Channel"
DEFAULT_CONF_PATH = "/configuration"
def read(spectra_url, channel_url, dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
config_url=None, energy_unit=ur.eV):
def read(
spectra_url,
channel_url,
dimensions=(Dim.DIM_2, Dim.DIM_1, Dim.DIM_0),
config_url=None,
energy_unit=ur.eV,
):
"""
:param DataUrl spectra_url: data url to the spectra
......
......@@ -51,10 +51,11 @@ class TestEXAFSSingleSpectrum(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
energy, mu = read_spectrum(
data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
spectrum = Spectrum(energy=energy, mu=mu)
exafs_configuration = {"Knots": {"Values": (1, 2, 5), "Number": 3}}
configuration = {"EXAFS": exafs_configuration}
......
......@@ -52,10 +52,11 @@ class TestFTSingleSpectrum(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
energy, mu = read_spectrum(
data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
energy=energy, spectra=(self.spectrum,), dim1=1, dim2=1
......
......@@ -62,10 +62,12 @@ class TestReadWrite(unittest.TestCase):
def testReadSpectrum(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
res = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 1"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 2"),
spectra_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 1"
),
channel_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 2"
),
)
self.assertTrue(isinstance(res, XASObject))
self.assertEqual(res.n_spectrum, 1)
......
......@@ -56,10 +56,11 @@ class TestKWeightSingleSpectrum(unittest.TestCase):
}
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
energy, mu = read_spectrum(
data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
......
......@@ -56,10 +56,11 @@ class TestNormalizationSingleSpectrum(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
energy, mu = read_spectrum(
data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
spectra=(self.spectrum,), energy=energy, dim1=1, dim2=1
......
......@@ -74,10 +74,12 @@ class TestStreamSingleSpectrum(unittest.TestCase):
def test_pymca_process(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 2"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 1"),
spectra_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 2"
),
channel_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 1"
),
)
out.configuration = {"EXAFS": self.exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out)
......@@ -89,10 +91,12 @@ class TestStreamSingleSpectrum(unittest.TestCase):
def test_pymca_process_with_dict(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 2"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 1"),
spectra_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 2"
),
channel_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 1"
),
)
out.configuration = {"EXAFS": self.exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out.to_dict())
......@@ -104,10 +108,12 @@ class TestStreamSingleSpectrum(unittest.TestCase):
def test_pymca_process_with_cls(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 2"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca",
data_path="Column 1"),
spectra_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 2"
),
channel_url=DataUrl(
file_path=data_file, scheme="PyMca", data_path="Column 1"
),
)
out = PyMca_normalization()(xas_obj=out)
exafs_process = PyMca_exafs()
......
......@@ -65,10 +65,11 @@ class TestMeldWorkflow(unittest.TestCase):
def setUp(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
energy, mu = read_spectrum(
data_file,
energy_col_name="Column 1",
absorption_col_name="Column 2",
)
self.spectrum = Spectrum(energy=energy, mu=mu)
self.xas_obj = XASObject(
energy=energy, spectra=(self.spectrum,), dim1=1, dim2=1
......
......@@ -177,7 +177,11 @@ class XASObject(object):
self.__spectra = energy_spectra
else:
if not len(energy_spectra) == 4:
raise ValueError('4 elements expected: energy, spectra, dim1 and dim2. get {} instead'.format(len(energy_spectra)))
raise ValueError(
"4 elements expected: energy, spectra, dim1 and dim2. get {} instead".format(
len(energy_spectra)
)
)
energy, spectra, dim1, dim2 = energy_spectra
self.__spectra = Spectra(energy=energy, spectra=spectra)
if dim1 is not None and dim2 is not None:
......
......@@ -101,6 +101,7 @@ def load_data(data_url, name, dimensions, columns_names=None, energy_unit=ur.eV)
dimensions = tuple([Dim.from_value(dim) for dim in dimensions])
assert isinstance(data_url, DataUrl)
if data_url.scheme() in ("PyMca", "PyMca5", "Spec", "spec"):
def get_energy_col_name():
if columns_names is not None:
return columns_names["energy"]
......@@ -193,7 +194,7 @@ def load_data(data_url, name, dimensions, columns_names=None, energy_unit=ur.eV)
if data.ndim == 1:
return data.reshape(data.shape[0], 1, 1)
elif data.ndim == 3:
return move_axis_to_standard(data, dimensions=dimensions)
return move_axis_to_standard(data, dimensions=dimensions)
return data
else:
_logger.warning(
......
......@@ -65,18 +65,25 @@ def read_spectrum(
if scan_header_S is not None and scan_header_S != scan.scan_header_dict["S"]:
continue
if energy_col_name not in scan.labels and absorption_col_name not in scan.labels:
if (
energy_col_name not in scan.labels
and absorption_col_name not in scan.labels
):
continue
# get energy
if energy_col_name is not None:
energy = spec_file.data_column_by_name(scan_index=i_data, label=energy_col_name)
energy = spec_file.data_column_by_name(
scan_index=i_data, label=energy_col_name
)
if energy is not None:
energy = (energy * energy_unit).m
# get absorption
if absorption_col_name is not None:
mu = spec_file.data_column_by_name(scan_index=i_data, label=absorption_col_name)
if absorption_col_name is not None:
mu = spec_file.data_column_by_name(
scan_index=i_data, label=absorption_col_name
)
if energy is not None:
assert len(mu) == len(
......@@ -93,4 +100,4 @@ def read_spectrum(
mu = mu / monitor
return energy, numpy.asarray(mu)
return energy, mu
\ No newline at end of file
return energy, mu
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