Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/UserManual/VideoTutorials/tutorial.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions easyDiffractionApp/Gui/Components/AnalysisFitables.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EaComponents.TableView {

maxRowCountShow: 8
defaultInfoText: qsTr("No Parameters Found")
enabled: ExGlobals.Constants.proxy.isFitFinished

// Table model

Expand Down
40 changes: 40 additions & 0 deletions easyDiffractionApp/Gui/Components/ResultsDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.XmlListModel 2.14

import easyAppGui.Globals 1.0 as EaGlobals
import easyAppGui.Style 1.0 as EaStyle
import easyAppGui.Elements 1.0 as EaElements
import easyAppGui.Components 1.0 as EaComponents

import Gui.Globals 1.0 as ExGlobals
import Gui.Components 1.0 as ExComponents

// Info dialog (after refinement)
EaElements.Dialog {
id: refinementResultsDialog
parent: Overlay.overlay

x: (parent.width - width) * 0.5
y: (parent.height - height) * 0.5

// modal: true
standardButtons: Dialog.Ok

title: qsTr("Refinement Results")

Column {
EaElements.Label { text: gotResults() && ExGlobals.Constants.proxy.isFitFinished ? `Success: ${ExGlobals.Constants.proxy.fitResults.success}` : "" }
EaElements.Label { text: gotResults() && ExGlobals.Constants.proxy.isFitFinished ? `Num. refined parameters: ${ExGlobals.Constants.proxy.fitResults.nvarys}` : "Fitting in progress..." }
EaElements.Label { text: gotResults() && ExGlobals.Constants.proxy.isFitFinished ? `Goodness-of-fit (reduced \u03c7\u00b2): ${ExGlobals.Constants.proxy.fitResults.redchi2.toFixed(2)}` : "" }
}

function gotResults(){
if ((ExGlobals.Constants.proxy.fitResults != null) && (ExGlobals.Constants.proxy.fitResults.success != null)){
return true
}
return false
}

}

3 changes: 3 additions & 0 deletions easyDiffractionApp/Gui/Components/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module Components

ApplicationWindow 1.0 ApplicationWindow.qml

# Separate popup windows
ResultsDialog 1.0 ResultsDialog.qml

# Main content components

SampleStructure3dVtk 1.0 SampleStructure3dVtk.qml
Expand Down
1 change: 1 addition & 0 deletions easyDiffractionApp/Gui/Logic/PyQmlProxy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 17 additions & 23 deletions easyDiffractionApp/Gui/Pages/Analysis/SideBarBasic.qml
Original file line number Diff line number Diff line change
Expand Up @@ -179,43 +179,37 @@ EaComponents.SideBarColumn {

// Start fitting button
EaElements.SideBarButton {
id: fitButton
enabled: ExGlobals.Constants.proxy.experimentLoaded
fontIcon: "play-circle"
text: qsTr("Start fitting")

fontIcon: ExGlobals.Constants.proxy.isFitFinished ? "play-circle" : "pause-circle"
text: ExGlobals.Constants.proxy.isFitFinished ? qsTr("Start fitting") : qsTr("Stop fitting")
wide: true

onClicked: {
//print("Start fitting button clicked")
ExGlobals.Constants.proxy.fit()
refinementResultsDialog.open()
}
Component.onCompleted: {
if (gotResults() && ExGlobals.Constants.proxy.isFitFinished) {
refinementResultsDialog.open()
}
}
}
}

// Info dialog (after refinement)

EaElements.Dialog {
ExComponents.ResultsDialog {
id: refinementResultsDialog

parent: Overlay.overlay

enabled: gotResults() && ExGlobals.Constants.proxy.isFitFinished
visible: gotResults() && ExGlobals.Constants.proxy.isFitFinished
x: (parent.width - width) * 0.5
y: (parent.height - height) * 0.5

modal: true
standardButtons: Dialog.Ok

title: qsTr("Refinement Results")

Column {
EaElements.Label { text: typeof ExGlobals.Constants.proxy.fitResults !== 'undefined' ? `Success: ${ExGlobals.Constants.proxy.fitResults.success}` : "" }
EaElements.Label { text: typeof ExGlobals.Constants.proxy.fitResults !== 'undefined' ? `Num. refined parameters: ${ExGlobals.Constants.proxy.fitResults.nvarys}` : "" }
EaElements.Label { text: typeof ExGlobals.Constants.proxy.fitResults !== 'undefined' && typeof ExGlobals.Constants.proxy.fitResults.redchi2 !== 'undefined' ? `Goodness-of-fit (reduced \u03c7\u00b2): ${ExGlobals.Constants.proxy.fitResults.redchi2.toFixed(2)}` : "" }
}
}

// Logic
function gotResults(){
if ((ExGlobals.Constants.proxy.fitResults != null) && (ExGlobals.Constants.proxy.fitResults.success != null)){
return true
}
return false
}

function formatFilterText(group_icon, icon, text) {
if (icon === "")
Expand Down
1 change: 1 addition & 0 deletions easyDiffractionApp/Gui/Pages/Experiment/SideBarBasic.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ EaComponents.SideBarColumn {
EaElements.GroupBox {
title: qsTr("Experimental data")
collapsible: false
enabled: ExGlobals.Constants.proxy.isFitFinished

ExComponents.ExperimentDataExplorer {}

Expand Down
1 change: 1 addition & 0 deletions easyDiffractionApp/Gui/Pages/Sample/SideBarBasic.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ EaComponents.SideBarColumn {
EaElements.GroupBox {
title: qsTr("Structural phases")
collapsible: false
enabled: ExGlobals.Constants.proxy.isFitFinished

ExComponents.SamplePhasesExplorer {}

Expand Down
28 changes: 28 additions & 0 deletions easyDiffractionApp/Logic/Fitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from PySide2.QtCore import Signal, QThread


class Fitter(QThread):
"""
Simple wrapper for calling a function in separate thread
"""
failed = Signal(str)
finished = Signal(dict)

def __init__(self, obj, method_name, *args, **kwargs):
QThread.__init__(self, None)
self._obj = obj
self.method_name = method_name
self.args = args
self.kwargs = kwargs

def run(self):
res = {}
if hasattr(self._obj, self.method_name):
func = getattr(self._obj, self.method_name)
try:
res = func(*self.args, **self.kwargs)
except Exception as ex:
self.failed.emit(str(ex))
return str(ex)
self.finished.emit(res)
return res
45 changes: 40 additions & 5 deletions easyDiffractionApp/Logic/PyQmlProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

from easyCore.Symmetry.tools import SpacegroupInfo
from easyCore.Fitting.Fitting import Fitter
from easyCore.Fitting.Constraints import ObjConstraint, NumericConstraint
from easyCore.Utils.classTools import generatePath

from easyDiffractionLib.sample import Sample
from easyDiffractionLib import Phases, Phase, Lattice, Site, Atoms, SpaceGroup
from easyDiffractionLib import Phases, Phase, Lattice, Site, SpaceGroup
from easyDiffractionLib.interface import InterfaceFactory
from easyDiffractionLib.Elements.Experiments.Experiment import Pars1D
from easyDiffractionLib.Elements.Experiments.Pattern import Pattern1D
Expand All @@ -39,6 +38,7 @@
from easyDiffractionApp.Logic.Proxies.MatplotlibBackend import MatplotlibBridge
from easyDiffractionApp.Logic.Proxies.QtChartsBackend import QtChartsBridge
from easyDiffractionApp.Logic.Proxies.BokehBackend import BokehBridge
from easyDiffractionApp.Logic.Fitter import Fitter as ThreadedFitter

from easyDiffractionApp.Logic.ScreenRecorder import ScreenRecorder

Expand Down Expand Up @@ -107,6 +107,9 @@ class PyQmlProxy(QObject):

# Status info
statusInfoChanged = Signal()

# Misc
dummySignal = Signal()

# Misc
dummySignal = Signal()
Expand Down Expand Up @@ -234,6 +237,10 @@ def __init__(self, parent=None):
self.currentMinimizerChanged.connect(self.statusInfoChanged)
self.currentMinimizerMethodChanged.connect(self.statusInfoChanged)

# Multithreading
self._fitter_thread = None
self._fit_finished = True

# Screen recorder
self._screen_recorder = ScreenRecorder()

Expand Down Expand Up @@ -1265,22 +1272,42 @@ def _onCurrentCalculatorChanged(self):

@Slot()
def fit(self):
self.isFitFinished = False
exp_data = self._data.experiments[0]

x = exp_data.x
y = exp_data.y
weights = 1 / exp_data.e
method = self._current_minimizer_method_name

res = self.fitter.fit(x, y, weights=weights, method=method)
args = (x, y)
kwargs = {"weights": weights, "method": method}
self._fitter_thread = ThreadedFitter(self.fitter, 'fit', *args, **kwargs)
self._fitter_thread.finished.connect(self._setFitResults)
self._fitter_thread.failed.connect(self._setFitResultsFailed)
self._fitter_thread.start()

self._setFitResults(res)
self.fitFinished.emit()
# self._setFitResults(res)
# self.fitFinished.emit()

@Property('QVariant', notify=fitResultsChanged)
def fitResults(self):
return self._fit_results

@Property(bool, notify=fitFinished)
# @Property(bool, constant=True)
def isFitFinished(self):
print('\n\n isfitFinished called')
return self._fit_finished

@isFitFinished.setter
def isFitFinished(self, fit_finished: bool):
print('\n\n isFitFinishedSetter called')
if self._fit_finished == fit_finished:
return
self._fit_finished = fit_finished
self.fitFinished.emit()

def _defaultFitResults(self):
return {
"success": None,
Expand All @@ -1297,6 +1324,14 @@ def _setFitResults(self, res):
"redchi2": float(res.reduced_chi)
}
self.fitResultsChanged.emit()
self.isFitFinished = True
self.fitFinished.emit()

def _setFitResultsFailed(self, res):
print("FIT FAILED")
print(str(res))
self.isFitFinished = True
self.fitFinished.emit()

def _onFitFinished(self):
print("***** _onFitFinished")
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ packages = [ { include = 'easyDiffractionApp' } ]

[tool.poetry.dependencies]
python = '^3.7, <3.8'
pygit2 = '^1.5.0'
matplotlib-backend-qtquick = '^0.0.8'
vtk = '^8.1.2'
pyobjc-core = { version = '^7.1', platform = 'darwin' }
pyobjc-framework-cocoa = { version = '^7.1', platform = 'darwin' }
# easyScience
#easyCore = { git = 'https://github.com/easyScience/easyCore.git', rev = 'xarray' }
easyDiffractionLib = { git = 'https://github.com/easyScience/easyDiffractionLib.git', rev = 'develop' }
easyAppLogic = { git = 'https://github.com/easyScience/easyAppLogic.git', rev = 'develop' }
easyAppGui = { git = 'https://github.com/easyScience/easyAppGui.git', rev = 'develop' }
Expand Down
8 changes: 8 additions & 0 deletions settings.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[AppGeometry]
height=768
width=1280
x=0
y=65

[Appearance]
theme=0