Commit 1826656c authored by payno's avatar payno

Merge branch 'mauro_evals' into 'master'

Mauro evals

See merge request !25
parents d0491ca3 2b65c2f4
Pipeline #23347 failed with stage
in 6 minutes and 6 seconds
[flake8]
ignore = E265, E501
......@@ -53,4 +53,8 @@ datasets/
octave-workspace
# submodules
pushworkflow
\ No newline at end of file
pushworkflow
# Visual Studio Code files
.vscode/
.empty/
......@@ -88,7 +88,7 @@ From it we can create the theoretical related functions:
Finally this is the list of variables used in larch and pymca.
An important point is that larch uses a 'group' and can store any of this values 'on the fly' during the processing.
Pymca uses dictionary as 'XASObject' to store results.
So XASObject as to adapt to both behavior as much as possible.
So XASObject has to adapt to both behavior as much as possible.
+------------------+----------------------+----------------------------------------------------+
| larch variables | pymca variables | info |
......
......@@ -38,16 +38,16 @@ import logging
_logger = logging.getLogger(__name__)
DEFAULT_SPECTRA_PATH = '/data/NXdata/data'
DEFAULT_SPECTRA_PATH = "/data/NXdata/data"
DEFAULT_CHANNEL_PATH = '/data/NXdata/Channel'
DEFAULT_CHANNEL_PATH = "/data/NXdata/Channel"
DEFAULT_CONF_PATH = '/configuration'
DEFAULT_CONF_PATH = "/configuration"
def read(spectra_url, channel_url, config_url=None, dimensions=None):
"""
:param DataUrl spectra_url: data url to the spectra
:param DataUrl channel_url: data url to the channel / energy
:param DataUrl config_url: data url to the process configuration
......@@ -55,7 +55,7 @@ def read(spectra_url, channel_url, config_url=None, dimensions=None):
Usually is (X, Y, channels) of (Channels, Y, X).
If None, by default is considered to be (Channels, Y, X)
:type: tuple
:return:
:return:
:rtype: XASObject
"""
dimensions_ = dimensions
......@@ -63,13 +63,17 @@ def read(spectra_url, channel_url, config_url=None, dimensions=None):
dimensions_ = (Dim.CHANNEL_ENERGY_DIM, Dim.Y_DIM, Dim.X_DIM)
reader = XASReader()
return reader.read_frm_url(spectra_url=spectra_url, channel_url=channel_url,
config_url=config_url, dimensions=dimensions_)
return reader.read_frm_url(
spectra_url=spectra_url,
channel_url=channel_url,
config_url=config_url,
dimensions=dimensions_,
)
def read_frm_file(file_path):
"""
:param str file_path: path to the file containing the spectra. Must ba a
.dat file that pymca can handle or a .h5py with
default path
......@@ -81,47 +85,48 @@ def read_frm_file(file_path):
class XASReader(object):
"""Simple reader of a xas file"""
@staticmethod
def read_frm_url(spectra_url, channel_url, dimensions=None,
config_url=None):
sp, en, conf = read_xas(spectra_url=spectra_url,
channel_url=channel_url,
config_url=config_url,
dimensions=dimensions)
def read_frm_url(spectra_url, channel_url, dimensions=None, config_url=None):
sp, en, conf = read_xas(
spectra_url=spectra_url,
channel_url=channel_url,
config_url=config_url,
dimensions=dimensions,
)
return XASObject(spectra=sp, energy=en, configuration=conf)
@staticmethod
def read_from_file(file_path):
"""
:param str file_path:
:param str file_path:
:return: `.XASObject`
"""
if file_path.endswith('.dat'):
if file_path.endswith((".dat", ".csv")):
return XASReader.read_frm_url(
spectra_url=DataUrl(file_path=file_path,
scheme='PyMca'),
channel_url=DataUrl(file_path=file_path,
scheme='PyMca'))
elif file_path.endswith('.xmu'):
spectra_url=DataUrl(file_path=file_path, scheme="PyMca"),
channel_url=DataUrl(file_path=file_path, scheme="PyMca"),
)
elif file_path.endswith(".xmu"):
return XASReader.read_frm_url(
spectra_url=DataUrl(file_path=file_path,
scheme='larch'),
channel_url=DataUrl(file_path=file_path,
scheme='larch'))
spectra_url=DataUrl(file_path=file_path, scheme="larch"),
channel_url=DataUrl(file_path=file_path, scheme="larch"),
)
elif h5py.is_hdf5(file_path):
return XASReader.read_frm_url(
spectra_url=DataUrl(file_path=file_path,
scheme='silx',
data_path=DEFAULT_SPECTRA_PATH),
channel_url=DataUrl(file_path=file_path,
scheme='silx',
data_path=DEFAULT_CHANNEL_PATH),
config_url=DataUrl(file_path=file_path,
scheme='silx',
data_path='configuration'))
spectra_url=DataUrl(
file_path=file_path, scheme="silx", data_path=DEFAULT_SPECTRA_PATH
),
channel_url=DataUrl(
file_path=file_path, scheme="silx", data_path=DEFAULT_CHANNEL_PATH
),
config_url=DataUrl(
file_path=file_path, scheme="silx", data_path="configuration"
),
)
else:
raise ValueError('file type not managed, unable to load')
raise ValueError("file type not managed, unable to load")
__call__ = read_from_file
......@@ -131,6 +136,7 @@ class XASWriter(object):
class to write the output file. In this case we need a class in order to
setup the output file before
"""
def __init__(self):
self._output_file = None
......@@ -143,8 +149,8 @@ class XASWriter(object):
self._output_file = file_
def setProperties(self, properties):
if '_output_file_setting' in properties:
self._output_file = properties['_output_file_setting']
if "_output_file_setting" in properties:
self._output_file = properties["_output_file_setting"]
def dump_xas(self, xas_obj, write_process=True):
"""
......@@ -161,20 +167,26 @@ class XASWriter(object):
_xas_obj = xas_obj
if not self._output_file:
_logger.warning('no output file defined, please give path to the'
'output file')
_logger.warning(
"no output file defined, please give path to the" "output file"
)
self._output_file = input()
_logger.info(('dump xas obj to', self._output_file))
_logger.info(("dump xas obj to", self._output_file))
# write raw data
write_xas(h5_file=self._output_file, energy=_xas_obj.energy,
mu=_xas_obj.absorbed_beam(), entry=_xas_obj.entry)
write_xas(
h5_file=self._output_file,
energy=_xas_obj.energy,
mu=_xas_obj.absorbed_beam(),
entry=_xas_obj.entry,
)
if write_process is True:
if len(get_xasproc(self._output_file, entry=_xas_obj.entry)) > 0:
_logger.warning('removing previous process registred. They are no '
'more accurate')
_logger.warning(
"removing previous process registred. They are no " "more accurate"
)
_xas_obj.clean_process_flow()
# write process flow
......
This diff is collapsed.
......@@ -33,8 +33,9 @@ from silx.io.url import DataUrl
from silx.gui import qt
from est.core.io import read as read_xas, read_frm_file, Dim
from est.io import InputType
from est.core.types import Dim
import logging
from est.core.types import Dim
_logger = logging.getLogger(__name__)
......@@ -110,11 +111,11 @@ class XASObjectDialog(qt.QWidget):
self._updateWidgetVisibility()
def _updateWidgetVisibility(self):
self._singleSpectrumDialog.setVisible(self._inputType.getInputType() in (InputType.dat_spectrum, InputType.xmu_spectrum))
self._singleSpectrumDialog.setVisible(self._inputType.getInputType() in (InputType.dat_spectrum, InputType.xmu_spectrum, InputType.csv_spectrum))
self._h5Dialog.setVisible(self._inputType.getInputType() == InputType.hdf5_spectra)
def buildXASObject(self):
if self.getCurrentType() in (InputType.dat_spectrum, InputType.xmu_spectrum):
if self.getCurrentType() in (InputType.dat_spectrum, InputType.xmu_spectrum, InputType.csv_spectrum):
return read_frm_file(file_path=self._singleSpectrumDialog.getFileSelected())
elif self.getCurrentType() == InputType.hdf5_spectra:
spectra_url = self._h5Dialog.getSpectraUrl()
......@@ -171,7 +172,7 @@ class _XASObjectFrmSingleSpectrum(qt.QWidget):
old = self.blockSignals(True)
dialog = qt.QFileDialog(self)
dialog.setFileMode(qt.QFileDialog.ExistingFile)
dialog.setNameFilters(["spectrum (*.dat, *.xmu)", ])
dialog.setNameFilters(["spectrum (*.dat, *.DAT, *.xmu, *.csv)", "All Files (*)"])
if not dialog.exec_():
dialog.close()
......@@ -226,6 +227,7 @@ class _XASObjFrmH5(qt.QWidget):
Interface used to define a XAS object from h5 files and data path
"""
editingFinished = qt.Signal()
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.setLayout(qt.QGridLayout())
......@@ -347,6 +349,7 @@ class _SpectraDimensions(qt.QWidget):
get_third = self._dim2 if last_modified == self._dim0 else self._dim1
unique_value = last_modified.currentText()
def getUnsetDimension():
values = self.getDimensions()
if Dim.X_DIM not in values:
......
......@@ -53,9 +53,10 @@ _logger = logging.getLogger(__name__)
class InputType(Enum):
dat_spectrum = '*.dat' # contains one spectrum
hdf5_spectra = '*.h5' # contains several spectrum
dat_spectrum = '*.dat' # contains one spectrum
hdf5_spectra = '*.h5' # contains several spectra
xmu_spectrum = '*.xmu' # contains one spectrum
csv_spectrum = '*.csv' # two columns, comma separated
def load_data(data_url, name):
......@@ -131,7 +132,7 @@ def load_data(data_url, name):
except ValueError as e:
_logger.error(e)
else:
if name =='spectra':
if name == 'spectra':
if data.ndim == 1:
return data.reshape(data.shape[0], 1, 1)
return data
......@@ -142,8 +143,8 @@ def load_data(data_url, name):
def read_xas(spectra_url, channel_url, dimensions=None, config_url=None):
"""
Read the given spectra url and the config url if any
:param Union[DataUrl, str] spectra_url:
:param Union[DataUrl, str] spectra_url:
:param DataUrl config_url:
:param dimensions: dimensions of the spectra. If None will be set to the
default (channel, Y, x)
......@@ -156,7 +157,7 @@ def read_xas(spectra_url, channel_url, dimensions=None, config_url=None):
if type(url_) is str:
try:
url_ = DataUrl(path=url_)
except:
except Exception:
url_ = DataUrl(file_path=url_, scheme='PyMca')
if not isinstance(url_, DataUrl):
......@@ -181,7 +182,7 @@ def read_xas(spectra_url, channel_url, dimensions=None, config_url=None):
spectra = load_data(_spectra_url, name='spectra')
# make sure all dimensions are defined
for dim in Dim:
if not dim in dimensions_:
if dim not in dimensions_:
err = '%s is not defined in the dimensions' % dim
raise ValueError(err)
# fit spectra according to dimension
......@@ -255,7 +256,7 @@ def write_xas_proc(h5_file, entry, process, data, processing_order,
def get_interpretation(my_data):
"""Return hdf5 attribute for this type of data"""
if isinstance(my_data, numpy.ndarray):
if my_data.ndim is 1:
if my_data.ndim == 1:
return 'spectrum'
elif my_data.ndim in (2, 3):
return 'image'
......@@ -384,11 +385,11 @@ def write_spectrum_saving_pt(h5_file, entry, obj, overwrite=True):
def get_xasproc(h5_file, entry):
"""
Return the list of all NXxasproc existing at the data_path level
:param str h5_file: hdf5 file
:param str entry: data location
:return:
:return:
:rtype: list
"""
def copy_nx_xas_process(h5_group):
......@@ -437,9 +438,9 @@ if __name__ == '__main__':
if os.path.exists(h5_file):
os.remove(h5_file)
sample = Sample(name='mysample')
data = numpy.random.rand(256*20*10)
data = numpy.random.rand(256 * 20 * 10)
data = data.reshape((256, 20, 10))
process_data = numpy.random.rand(256*20*10).reshape((256, 20, 10))
process_data = numpy.random.rand(256 * 20 * 10).reshape((256, 20, 10))
energy = numpy.linspace(start=3.25, stop=3.69, num=256)
write_xas(h5_file=h5_file, entry='scan1', sample=sample, energy=energy,
......@@ -449,6 +450,6 @@ if __name__ == '__main__':
write_xas_proc(h5_file=h5_file, entry='scan1', process=process_norm,
data=process_data, processing_order=1)
process_exafs = PyMca_exafs()
process_data2 = numpy.random.rand(256*20*10).reshape((256, 20, 10))
process_data2 = numpy.random.rand(256 * 20 * 10).reshape((256, 20, 10))
write_xas_proc(h5_file=h5_file, entry='scan1', process=process_exafs,
data=process_data2, processing_order=2)
......@@ -32,7 +32,7 @@ from PyMca5.PyMcaIO import specfilewrapper as specfile
def read_spectrum(spec_file):
"""
:param spec_file: path to the spec file containing the spectra definition
:return: (energy, mu)
:rtype: tuple
......
......@@ -45,7 +45,7 @@ import AnyQt.importhooks
if AnyQt.USED_API == "pyqt5":
# Use a backport shim to fake leftover PyQt4 imports
AnyQt.importhooks.install_backport_hook('pyqt4')
AnyQt.importhooks.install_backport_hook("pyqt4")
from Orange import canvas
from est.gui.qtapplicationmanager import QApplicationManager
......@@ -59,6 +59,7 @@ from Orange.canvas.registry import set_global_registry
from Orange.canvas.scheme import SchemeNode, SchemeLink
from Orange.canvas.registry import cache
from unittest import TestCase
log = logging.getLogger(__name__)
app = QApplicationManager()
......@@ -72,8 +73,8 @@ class OrangeWorflowTest(TestCase):
:return SchemeNode: the node created
"""
assert(type(widgetID) is str)
assert(self.widget_registry.has_widget(widgetID))
assert type(widgetID) is str
assert self.widget_registry.has_widget(widgetID)
widget_desc = self.widget_registry.widget(widgetID)
myItem = SchemeNode(widget_desc)
self.canvas_window.current_document().scheme().add_node(myItem)
......@@ -88,10 +89,10 @@ class OrangeWorflowTest(TestCase):
:param inputNode2: the input chanel to be linked
:return: the link created between the two nodes
"""
assert(type(schemeNode1) is SchemeNode)
assert(type(schemeNode2) is SchemeNode)
assert(type(outNode1) is str)
assert(type(inputNode2) is str)
assert type(schemeNode1) is SchemeNode
assert type(schemeNode2) is SchemeNode
assert type(outNode1) is str
assert type(inputNode2) is str
link = SchemeLink(schemeNode1, outNode1, schemeNode2, inputNode2)
self.canvas_window.current_document().scheme().add_link(link)
return link
......@@ -103,7 +104,7 @@ class OrangeWorflowTest(TestCase):
widget
:return: the widget instanciated for the given node
"""
assert(type(node) is SchemeNode)
assert type(node) is SchemeNode
return self.canvas_window.current_document().scheme().widget_for_node(node)
@classmethod
......@@ -115,7 +116,7 @@ class OrangeWorflowTest(TestCase):
def tearDownClass(cls):
cls.canvas_window.deleteLater()
# make sure no events are resting
while (app.hasPendingEvents()):
while app.hasPendingEvents():
app.processEvents()
cls.processOrangeEvents(cls)
app.flush()
......@@ -126,7 +127,7 @@ class OrangeWorflowTest(TestCase):
TestCase.tearDownClass()
def tearDown(self):
while(app.hasPendingEvents()):
while app.hasPendingEvents():
app.processEvents()
TestCase.tearDown(self)
......@@ -135,14 +136,16 @@ class OrangeWorflowTest(TestCase):
# Fix fonts on Os X (QTBUG 47206, 40833, 32789)
if sys.platform == "darwin":
import platform
try:
version = platform.mac_ver()[0]
version = float(version[:version.rfind(".")])
version = float(version[: version.rfind(".")])
if version >= 10.11: # El Capitan
QFont.insertSubstitution(".SF NS Text", "Helvetica Neue")
elif version >= 10.10: # Yosemite
QFont.insertSubstitution(".Helvetica Neue DeskInterface",
"Helvetica Neue")
QFont.insertSubstitution(
".Helvetica Neue DeskInterface", "Helvetica Neue"
)
elif version >= 10.9:
QFont.insertSubstitution(".Lucida Grande UI", "Lucida Grande")
except AttributeError:
......@@ -156,8 +159,10 @@ class OrangeWorflowTest(TestCase):
when their buffer is flushed (`http://bugs.python.org/issue706263`_)
"""
if sys.platform == "win32" and \
os.path.basename(sys.executable) == "pythonw.exe":
if (
sys.platform == "win32"
and os.path.basename(sys.executable) == "pythonw.exe"
):
if sys.stdout is None:
sys.stdout = open(os.devnull, "w")
if sys.stderr is None:
......@@ -167,7 +172,11 @@ class OrangeWorflowTest(TestCase):
self.canvas_window.current_document().scheme().signal_manager.process_queued()
def processOrangeEventsStack(self):
node_update_front = self.canvas_window.current_document().scheme().signal_manager.node_update_front()
node_update_front = (
self.canvas_window.current_document()
.scheme()
.signal_manager.node_update_front()
)
if node_update_front:
self.processOrangeEvents()
self.processOrangeEventsStack()
......@@ -195,8 +204,7 @@ class OrangeWorflowTest(TestCase):
config.init()
file_handler = logging.FileHandler(
filename=os.path.join(config.log_dir(), "canvas.log"),
mode="w"
filename=os.path.join(config.log_dir(), "canvas.log"), mode="w"
)
rootlogger.addHandler(file_handler)
......@@ -209,6 +217,7 @@ class OrangeWorflowTest(TestCase):
# them out if passed in argv)
open_requests = []
def onrequest(url):
log.info("Received an file open request %s", url)
open_requests.append(url)
......@@ -231,22 +240,24 @@ class OrangeWorflowTest(TestCase):
resource = "styles/" + stylesheet
if pkg_resources.resource_exists(pkg_name, resource):
stylesheet_string = \
pkg_resources.resource_string(pkg_name, resource).decode()
stylesheet_string = pkg_resources.resource_string(
pkg_name, resource
).decode()
base = pkg_resources.resource_filename(pkg_name, "styles")
pattern = re.compile(
r"^\s@([a-zA-Z0-9_]+?)\s*:\s*([a-zA-Z0-9_/]+?);\s*$",
flags=re.MULTILINE
flags=re.MULTILINE,
)
matches = pattern.findall(stylesheet_string)
for prefix, search_path in matches:
QDir.addSearchPath(prefix, os.path.join(base, search_path))
log.info("Adding search path %r for prefix, %r",
search_path, prefix)
log.info(
"Adding search path %r for prefix, %r", search_path, prefix
)
stylesheet_string = pattern.sub("", stylesheet_string)
......@@ -267,17 +278,13 @@ class OrangeWorflowTest(TestCase):
self.widget_registry = qt.QtWidgetRegistry()
widget_discovery.found_category.connect(
self.widget_registry.register_category
)
widget_discovery.found_widget.connect(
self.widget_registry.register_widget
)
widget_discovery.found_category.connect(self.widget_registry.register_category)
widget_discovery.found_widget.connect(self.widget_registry.register_widget)
cache_filename = os.path.join(cache_dir(), "widget-registry.pck")
entry_points = []
for entry_point in config.widgets_entry_points():
if entry_point.name != 'Orange Widgets':
if entry_point.name != "Orange Widgets":
entry_points.append(entry_point)
widget_discovery.run(entry_points)
# Store cached descriptions
......
Markdown is supported
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