Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
workflow
ewoksapps
est
Commits
f31dfed5
Commit
f31dfed5
authored
Oct 05, 2021
by
Henri Payno
Browse files
[orangecontrib] move a few more utils to ewoks.bindings
parent
9167f17a
Pipeline
#56005
failed with stages
in 11 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
est/core/io.py
View file @
f31dfed5
...
...
@@ -217,7 +217,7 @@ class XASWriter(object):
if
not
self
.
_output_file
:
_logger
.
warning
(
"no output file defined, please give path to the
"
"
output file"
"no output file defined, please give path to the
output file"
)
self
.
_output_file
=
input
()
...
...
est/core/process/energyroi.py
View file @
f31dfed5
...
...
@@ -83,15 +83,16 @@ class EnergyROIProcess(
xas_obj
.
spectra
.
energy
>=
roi
.
from_
)
xas_obj
.
spectra
.
energy
=
xas_obj
.
spectra
.
energy
[
mask
]
for
spectrum
in
xas_obj
.
spectra
.
data
.
flat
:
n_s
=
len
(
xas_obj
.
spectra
.
data
.
flat
)
for
i_s
,
spectrum
in
enumerate
(
xas_obj
.
spectra
.
data
.
flat
):
spectrum
.
energy
=
spectrum
.
energy
[
mask
]
spectrum
.
mu
=
spectrum
.
mu
[
mask
]
for
attached_key
in
(
"I0"
,
"I1"
,
"I2"
,
"mu_ref"
):
if
hasattr
(
spectrum
,
attached_key
):
values
=
getattr
(
spectrum
,
attached_key
)[
mask
]
setattr
(
spectrum
,
attached_key
,
values
)
#
print(spectrum.__dict__)
# print(xas_obj.__dict__)
self
.
progress
=
i_s
/
n_s
*
100.0
return
xas_obj
def
run
(
self
):
...
...
@@ -109,8 +110,10 @@ class EnergyROIProcess(
# existing roi is priority. This is the case if called from pushworkflow
# for example.
self
.
progress
=
0.0
if
self
.
_roi
is
not
None
:
xas_obj
=
self
.
_apply_roi
(
xas_obj
=
_xas_obj
,
roi
=
self
.
_roi
)
self
.
progress
=
100.0
self
.
register_process
(
_xas_obj
,
data_keys
=
(
"Mu"
,
"energy"
))
self
.
outputs
.
xas_obj
=
_xas_obj
.
to_dict
()
...
...
est/core/process/io.py
View file @
f31dfed5
...
...
@@ -31,22 +31,24 @@ __date__ = "06/11/2019"
from
.process
import
Process
from
est.core.types
import
XASObject
from
est.io.utils.information
import
InputInformation
from
typing
import
Optional
import
pkg_resources
class
DumpXasObject
(
Process
,
name
=
"dump xas object"
,
input_names
=
[
"xas_obj"
],
output_names
=
[
"result"
]
):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
missing_file_callback
:
Optional
[
str
]
=
None
,
**
kwargs
):
self
.
_missing_file_callback
=
missing_file_callback
super
().
__init__
(
**
kwargs
)
self
.
_output_file
=
kwargs
.
get
(
"varinfo"
,
dict
()).
get
(
"output_file"
,
None
)
@
property
def
output_file
(
self
):
def
output_file
(
self
)
->
Optional
[
str
]
:
return
self
.
_output_file
@
output_file
.
setter
def
output_file
(
self
,
output_file
):
def
output_file
(
self
,
output_file
:
Optional
[
str
]
):
self
.
_output_file
=
output_file
def
program_name
(
self
):
...
...
@@ -72,6 +74,8 @@ class DumpXasObject(
"xas_object should be a convertable dict or an"
"instance of XASObject"
)
if
self
.
output_file
is
None
and
self
.
_missing_file_callback
is
not
None
:
self
.
output_file
=
self
.
_missing_file_callback
()
if
self
.
output_file
is
None
:
raise
ValueError
(
"output file not provided"
)
else
:
...
...
orangecontrib/est/process.py
View file @
f31dfed5
...
...
@@ -51,8 +51,7 @@ class _ProcessForOrangeMixIn(OWEwoksWidgetOneThread):
def
outputsChanged
(
self
):
# TODO: maybe we would expect a task_outputs to match the task_inputs
if
"xas_obj"
in
self
.
task_inputs
:
print
(
"xas_obj contains"
,
self
.
task_inputs
)
if
"xas_obj"
in
self
.
output_variables
:
xas_obj
=
self
.
output_variables
[
"xas_obj"
].
value
if
isinstance
(
xas_obj
,
MissingData
):
_logger
.
warning
(
"no output data set. Unable to update the GUI"
)
...
...
@@ -65,4 +64,3 @@ class _ProcessForOrangeMixIn(OWEwoksWidgetOneThread):
elif
hasattr
(
self
,
"_window"
)
and
hasattr
(
self
.
_window
,
"xasObjViewer"
):
if
hasattr
(
self
.
_window
.
xasObjViewer
,
"setXASObj"
):
self
.
_window
.
xasObjViewer
.
setXASObj
(
xas_obj
=
xas_obj
)
# emit signal for the plot
orangecontrib/est/widgets/utils/e0calculator.py
View file @
f31dfed5
...
...
@@ -33,7 +33,7 @@ from Orange.widgets import gui
from
Orange.widgets.widget
import
OWWidget
from
Orange.widgets.widget
import
Input
,
Output
import
Orange.data
from
orangecontrib.est.
util
s
import
Converter
from
orangecontrib.est.
proces
s
import
_ProcessForOrangeMixIn
from
silx.gui
import
qt
import
functools
import
est.core.process.ignoreprocess
...
...
@@ -45,7 +45,8 @@ _logger = logging.getLogger(__file__)
class
E0calculatorOW
(
OWWidget
,
_ProcessForOrangeMixIn
,
ewokstaskclass
=
est
.
core
.
process
.
ignoreprocess
.
IgnoreE0Calculation
,
):
"""
Widget used to make compute E0 from the dataset.
...
...
@@ -70,19 +71,6 @@ class E0calculatorOW(
want_main_area
=
True
resizing_enabled
=
True
compress_signal
=
False
ewokstaskclass
=
est
.
core
.
process
.
ignoreprocess
.
IgnoreE0Calculation
class
Inputs
:
xas_obj
=
Input
(
"xas_obj"
,
XASObject
,
default
=
True
)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table
=
Input
(
"Data"
,
Orange
.
data
.
Table
)
class
Outputs
:
xas_obj
=
Output
(
"xas_obj"
,
XASObject
)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -113,8 +101,6 @@ class E0calculatorOW(
# set up
self
.
_buttons
.
hide
()
# self.handleNewSignals()
def
validateMethodToUse
(
self
,
method
):
"""Define the method to use and close the dialog"""
method
=
E0ComputationMethod
.
from_value
(
method
)
...
...
@@ -128,17 +114,8 @@ class E0calculatorOW(
else
:
return
self
.
_widget
.
getE0
(
method
=
self
.
_methodToUse
)
@
Inputs
.
data_table
def
processFrmDataTable
(
self
,
data_table
):
if
data_table
is
None
:
return
self
.
process
(
Converter
.
toXASObject
(
data_table
=
data_table
))
@
Inputs
.
xas_obj
def
process
(
self
,
xas_obj
):
if
xas_obj
is
None
:
return
self
.
_widget
.
setXasObject
(
xas_obj
=
xas_obj
)
def
inputsChanged
(
self
):
super
(
EnergyRoiOW
,
self
).
inputsChanged
()
self
.
_buttons
.
show
()
self
.
show
()
...
...
orangecontrib/est/widgets/utils/energyroi.py
View file @
f31dfed5
...
...
@@ -34,6 +34,7 @@ from Orange.widgets.settings import Setting
from
Orange.widgets.widget
import
OWWidget
from
Orange.widgets.widget
import
Input
,
Output
import
Orange.data
from
orangecontrib.est.process
import
_ProcessForOrangeMixIn
from
orangecontrib.est.utils
import
Converter
from
silx.gui
import
qt
import
est.core.process.energyroi
...
...
@@ -44,7 +45,8 @@ _logger = logging.getLogger(__file__)
class
EnergyRoiOW
(
OWWidget
,
_ProcessForOrangeMixIn
,
ewokstaskclass
=
est
.
core
.
process
.
energyroi
.
EnergyROIProcess
,
):
"""
Widget used to make the selection of a region of Interest to treat in a
...
...
@@ -55,7 +57,6 @@ class EnergyRoiOW(
id
=
"orange.widgets.xas.utils.energyroi"
description
=
"Select the energy ROI to analyse"
icon
=
"icons/curveroi.svg"
ewokstaskclass
=
est
.
core
.
process
.
energyroi
.
EnergyROIProcess
priority
=
8
category
=
"esrfWidgets"
...
...
@@ -71,23 +72,11 @@ class EnergyRoiOW(
want_main_area
=
True
resizing_enabled
=
True
compress_signal
=
False
_energy_roi
=
Setting
(
dict
())
# kept for compatibility
static_input
=
Setting
({
"xas_obj"
:
None
,
"energy_roi"
:
None
})
class
Inputs
:
xas_obj
=
Input
(
"xas_obj"
,
XASObject
,
default
=
True
)
# simple compatibility for some Orange widget and especially the
# 'spectroscopy add-on'
data_table
=
Input
(
"Data"
,
Orange
.
data
.
Table
)
class
Outputs
:
xas_obj
=
Output
(
"xas_obj"
,
XASObject
)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -121,17 +110,8 @@ class EnergyRoiOW(
def
setROI
(
self
,
roi
):
self
.
_widget
.
setROI
(
roi
=
roi
)
@
Inputs
.
data_table
def
processFrmDataTable
(
self
,
data_table
):
if
data_table
is
None
:
return
self
.
process
(
Converter
.
toXASObject
(
data_table
=
data_table
))
@
Inputs
.
xas_obj
def
process
(
self
,
xas_obj
):
if
xas_obj
is
None
:
return
self
.
_widget
.
setXasObject
(
xas_obj
=
xas_obj
)
def
inputsChanged
(
self
):
super
(
EnergyRoiOW
,
self
).
inputsChanged
()
self
.
_buttons
.
show
()
self
.
show
()
...
...
orangecontrib/est/widgets/utils/roi.py
View file @
f31dfed5
...
...
@@ -39,12 +39,14 @@ from silx.gui import qt
import
est.core.process.roi
from
est.core.types
import
XASObject
from
est.gui.roiselector
import
ROISelector
from
orangecontrib.est.process
import
_ProcessForOrangeMixIn
_logger
=
logging
.
getLogger
(
__file__
)
class
RoiSelectionOW
(
OWWidget
,
_ProcessForOrangeMixIn
,
ewokstaskclass
=
est
.
core
.
process
.
roi
.
ROIProcess
,
):
"""
Widget used to make the selection of a region of Interest to treat in a
...
...
@@ -62,25 +64,12 @@ class RoiSelectionOW(
want_main_area
=
True
resizing_enabled
=
True
compress_signal
=
False
ewokstaskclass
=
est
.
core
.
process
.
roi
.
ROIProcess
_roi_origin
=
Setting
(
tuple
())
_roi_size
=
Setting
(
tuple
())
static_input
=
Setting
({
"xas_obj"
:
None
,
"roi"
:
None
})
class
Inputs
:
xas_obj
=
Input
(
"xas_obj"
,
XASObject
,
default
=
True
)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table
=
Input
(
"Data"
,
Orange
.
data
.
Table
)
class
Outputs
:
xas_obj
=
Output
(
"xas_obj"
,
XASObject
)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -103,19 +92,8 @@ class RoiSelectionOW(
self
.
setROI
=
self
.
_widget
.
setROI
self
.
getROI
=
self
.
_widget
.
getROI
# self.handleNewSignals()
@
Inputs
.
data_table
def
processFrmDataTable
(
self
,
data_table
):
if
data_table
is
None
:
return
self
.
process
(
Converter
.
toXASObject
(
data_table
=
data_table
))
@
Inputs
.
xas_obj
def
process
(
self
,
xas_obj
):
if
xas_obj
is
None
:
return
self
.
_widget
.
setXasObject
(
xas_obj
=
xas_obj
)
def
inputsChanged
(
self
):
super
(
EnergyRoiOW
,
self
).
inputsChanged
()
self
.
_buttons
.
show
()
self
.
show
()
...
...
orangecontrib/est/widgets/utils/xas_input.py
View file @
f31dfed5
...
...
@@ -31,7 +31,6 @@ __date__ = "06/11/2019"
import
logging
from
Orange.widgets
import
gui
from
Orange.widgets.settings
import
Setting
from
Orange.widgets.widget
import
OWWidget
from
Orange.widgets.widget
import
Output
from
silx.gui
import
qt
from
silx.io.url
import
DataUrl
...
...
@@ -39,13 +38,15 @@ import est.core.io
import
est.core.process.ignoreprocess
import
est.core.process.io
from
est.gui.xas_object_definition
import
XASObjectWindow
from
ewoksorange.bindings.owwidgets
import
OWEwoksWidgetNoThread
from
est.core.types
import
XASObject
_logger
=
logging
.
getLogger
(
__file__
)
class
XASInputOW
(
OWWidget
,
OWEwoksWidgetNoThread
,
ewokstaskclass
=
est
.
core
.
process
.
io
.
ReadXasObject
,
):
"""
Widget used for signal extraction
...
...
@@ -61,7 +62,6 @@ class XASInputOW(
want_main_area
=
True
resizing_enabled
=
True
ewokstaskclass
=
est
.
core
.
process
.
io
.
ReadXasObject
_spec_file_setting
=
Setting
(
tuple
())
_spectra_url_setting
=
Setting
(
str
())
...
...
@@ -74,11 +74,6 @@ class XASInputOW(
_I2_url_setting
=
Setting
(
str
())
_mu_ref_url_setting
=
Setting
(
str
())
class
Outputs
:
xas_obj
=
Output
(
"xas_obj"
,
XASObject
)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def
__init__
(
self
):
super
().
__init__
()
self
.
_inputWindow
=
qt
.
QWidget
(
parent
=
self
)
...
...
@@ -114,8 +109,6 @@ class XASInputOW(
self
.
_inputDialog
.
getMainWindow
().
editingFinished
.
connect
(
self
.
_storeSettings
)
self
.
setFileSelected
=
self
.
_inputDialog
.
setDatFile
# self.handleNewSignals()
def
_emitNewFile
(
self
,
*
args
,
**
kwargs
):
try
:
xas_obj
=
self
.
_inputDialog
.
buildXASObject
()
...
...
orangecontrib/est/widgets/utils/xas_output.py
View file @
f31dfed5
...
...
@@ -29,11 +29,11 @@ __date__ = "06/11/2019"
from
Orange.widgets
import
gui
from
Orange.widgets.widget
import
OWWidget
from
Orange.widgets.settings
import
Setting
from
Orange.widgets.widget
import
Input
from
silx.gui
import
qt
from
est.core.types
import
XASObject
from
ewoksorange.bindings.owwidgets
import
OWEwoksWidgetNoThread
import
est.core.process.io
import
logging
import
h5py
...
...
@@ -42,7 +42,8 @@ _logger = logging.getLogger(__file__)
class
XASOutputOW
(
OWWidget
,
OWEwoksWidgetNoThread
,
ewokstaskclass
=
est
.
core
.
process
.
io
.
DumpXasObject
,
):
"""
Widget used for signal extraction
...
...
@@ -58,13 +59,9 @@ class XASOutputOW(
want_main_area
=
True
resizing_enabled
=
True
ewokstaskclass
=
est
.
core
.
process
.
io
.
DumpXasObject
_output_file_setting
=
Setting
(
str
())
class
Inputs
:
xas_obj
=
Input
(
"xas_obj"
,
XASObject
,
default
=
True
)
def
__init__
(
self
):
super
().
__init__
()
self
.
_outputWindow
=
qt
.
QWidget
(
parent
=
self
)
...
...
@@ -89,31 +86,28 @@ class XASOutputOW(
# signal / slot connection
self
.
_selectPB
.
pressed
.
connect
(
self
.
_selectFile
)
# self.handleNewSignals()
def
_selectFile
(
self
,
*
args
,
**
kwargs
):
old
=
self
.
blockSignals
(
True
)
dialog
=
qt
.
QFileDialog
(
self
)
# dialog.setFileMode(qt.QFileDialog.AnyFile)
dialog
.
setAcceptMode
(
qt
.
QFileDialog
.
AcceptSave
)
dialog
.
setFileMode
(
qt
.
QFileDialog
.
AnyFile
)
dialog
.
setNameFilters
([
"hdf5 files (*.hdf5, *.hdf, *.h5)"
])
if
not
dialog
.
exec_
():
if
dialog
.
exec_
()
is
qt
.
QDialog
.
Rejected
:
dialog
.
close
()
return
False
return
None
fileSelected
=
dialog
.
selectedFiles
()
if
len
(
fileSelected
)
==
0
:
return
Fals
e
return
Non
e
else
:
assert
len
(
fileSelected
)
==
1
file_
=
fileSelected
[
0
]
if
not
h5py
.
is_hdf5
(
file_
):
file_
+=
".h5"
if
not
file_
.
lower
().
endswith
((
".h5"
,
".hdf5"
,
".nx"
,
".nexus"
)):
file_
+=
".h5"
old
=
self
.
blockSignals
(
True
)
self
.
setFileSelected
(
file_
)
self
.
blockSignals
(
old
)
return
True
self
.
blockSignals
(
old
)
return
str
(
file_
)
def
setFileSelected
(
self
,
file_path
):
self
.
_output_file_setting
=
file_path
...
...
@@ -122,23 +116,14 @@ class XASOutputOW(
def
_getFileSelected
(
self
):
return
self
.
_inputLe
.
text
()
@
Inputs
.
xas_obj
def
process
(
self
,
xas_obj
):
if
xas_obj
is
None
:
return
if
isinstance
(
xas_obj
,
dict
):
_xas_obj
=
XASObject
.
from_dict
(
xas_obj
)
else
:
_xas_obj
=
xas_obj
has_file
=
self
.
_getFileSelected
()
!=
""
if
not
has_file
:
mess
=
qt
.
QMessageBox
(
parent
=
self
)
mess
.
setIcon
(
qt
.
QMessageBox
.
Warning
)
mess
.
setText
(
"No output file defined, please give a file path"
)
mess
.
exec_
()
has_file
=
self
.
_selectFile
()
if
not
has_file
:
_logger
.
error
(
"no valid output file given, skip save"
)
else
:
_xas_obj
.
dump
(
self
.
_getFileSelected
())
def
_missing_file_getter
(
self
):
mess
=
qt
.
QMessageBox
(
self
)
mess
.
setIcon
(
qt
.
QMessageBox
.
Warning
)
mess
.
setText
(
"No output file defined, please give a file path"
)
mess
.
exec_
()
return
self
.
_selectFile
()
def
_getTaskArguments
(
self
):
adict
=
super
().
_getTaskArguments
()
adict
[
"missing_file_callback"
]
=
self
.
_missing_file_getter
return
adict
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment