Commit 89f20e98 authored by payno's avatar payno
Browse files

[io][InputInformation] fix and input information from a spec file

parent 0ed45889
Pipeline #51022 failed with stages
in 6 minutes and 8 seconds
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "07/21/2021"
from est.io.utils.information import InputInformation
from est.io.utils.information import SpecInputInformation
from silx.io.url import DataUrl
import unittest
import os
try:
import PyMca5
except ImportError:
has_pymca = False
else:
has_pymca = True
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
@unittest.skipIf(has_pymca is False, "PyMca5 is not installed")
class TestInputInformation(unittest.TestCase):
"""Test the TestInputInformation"""
def testSpecInput(self):
"""Test the different way of providing a spec file entry are
all valid"""
self.data_input_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
input_information_1 = InputInformation(
spectra_url=DataUrl(
file_path=self.data_input_file,
scheme="PyMca",
data_path="Column 1",
),
channel_url=DataUrl(
file_path=self.data_input_file,
scheme="PyMca",
data_path="Column 2",
),
)
input_information_2 = InputInformation(
spec_input=SpecInputInformation(spec_file=self.data_input_file)
)
input_information_3 = InputInformation(
spec_input=SpecInputInformation(
spec_file=self.data_input_file,
energy_abs_col_name="Column 1",
input_abs_col_name="Column 2",
)
)
self.assertEqual(input_information_1, input_information_2)
self.assertEqual(input_information_1, input_information_3)
......@@ -31,7 +31,7 @@ __date__ = "25/01/2021"
from est.core.types import Dim
from est.units import ur
from silx.io.url import DataUrl
from typing import Iterable
from typing import Iterable, Union
class SpecInputInformation:
......@@ -124,7 +124,7 @@ class InputInformation:
self.__dimensions = None
self.__config_url = None
self.__energy_unit = None
self.__spec_info = None
self.__spec_info = spec_input
self.__columns_names = None
# "fancy information"
......@@ -268,7 +268,7 @@ class InputInformation:
@property
def input_energy_col_name(self):
if self.is_spec_input():
return self.spec_info.input_energy_col_name
return self.spec_info.energy_abs_col_name
else:
return None
......@@ -306,13 +306,21 @@ class InputInformation:
else:
return url.path()
converted = dump_url(self.spectra_url)
reconverted = DataUrl(path=converted)
dimensions = self.dimensions
if dimensions is None:
pass
else:
if not isinstance(dimensions, Iterable):
raise TypeError(
"dimensions is expected to be an Iterable "
"not {}".format(type(dimensions))
)
else:
dimensions = tuple([dim.value for dim in self.dimensions])
return {
"spectra_url": dump_url(self.spectra_url),
"channel_url": dump_url(self.channel_url),
"dimensions": tuple([dim.value for dim in self.dimensions]),
"dimensions": dimensions,
"config_url": dump_url(self.config_url),
"energy_unit": str(self.energy_unit),
"columns_names": self.columns_names,
......@@ -334,9 +342,11 @@ class InputInformation:
else:
return DataUrl(path=url)
def load_dimensions(dimensions: Iterable):
assert isinstance(dimensions, Iterable)
return tuple([Dim.from_value(dim) for dim in dimensions])
def load_dimensions(dimensions: Union[Iterable, None]):
if dimensions is None:
return None
else:
return tuple([Dim.from_value(dim) for dim in dimensions])
return InputInformation(
spectra_url=load_url(spectra_url),
......
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