Skip to content

Commit

Permalink
initial fitting updates. Merged new (pre-single-crystal) code from
Browse files Browse the repository at this point in the history
master
  • Loading branch information
rozyczko committed Jan 24, 2025
1 parent f1545f1 commit 596f6cf
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 42 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ __pycache__
.venv*
.coverage
.pyc
#resources.py
resources.py

# Pytest
.tests

# C++

Expand All @@ -40,6 +43,8 @@ build
*.user
settings.ini*
.ci/
ci/
ci_*/
.idea/
.build/
temp/
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ This is a test version of EasyDiffraction with improved GUI and overall performa

### Bug Fixes

- The correct x-axis title is now displayed for graphs with TOF data
- The startup splash screen now appears before the calculation libraries are loaded
- The correct x-axis title is now displayed for graphs with TOF data.
- The startup splash screen now appears before the calculation libraries are loaded.

# Version 0.9.4 (26 Jun 2024)

This is a test version of EasyDiffraction with improved GUI and overall performance. This version temporarily does not use the EasyScience framework, contains only CrysPy as calculation engine and uses only Lmfit for minimization.

### New Features

- Point background is now implemented for time-of-flight (TOF) type of experiments
- Point background is now implemented for time-of-flight (TOF) type of experiments.

# Version 0.9.3 (21 Jun 2024)

This is a test version of EasyDiffraction with improved GUI and overall performance. This version temporarily does not use the EasyScience framework, contains only CrysPy as calculation engine and uses only Lmfit for minimization.

### Bug Fixes

- The package for Snap Store (Linux) has been added back
- The package for Snap Store (Linux) has been added back.

# Version 0.9.2 (20 Jun 2024)

This is a test version of EasyDiffraction with improved GUI and overall performance. This version temporarily does not use the EasyScience framework, contains only CrysPy as calculation engine and uses only Lmfit for minimization.

### New Features

- The analysis page now has an _html_-based analysis summary
- The CIF-based report on the Summary page has now been moved from _Main View_ to _Sidebar_ (`Text mode` tab)
- User can now save the analysis summary in _html_ format
- Installers for macOS and Windows are now signed
- The analysis page now has an _html_-based analysis summary.
- The CIF-based report on the Summary page has now been moved from _Main View_ to _Sidebar_ (`Text mode` tab).
- User can now save the analysis summary in _html_ format.
- Installers for macOS and Windows are now signed.

### Bug Fixes

- Measured and processed TOF data are now correctly displayed on the Summary page
- Measured and processed TOF data are now correctly displayed on the Summary page.

# Version 0.9.1-alpha0 (29 May 2024)

Expand Down
27 changes: 15 additions & 12 deletions easyDiffractionApp/Logic/Experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def __init__(self, parent, interface=None):

self._chartRanges = []

@Property('QVariant', constant=True)
def job(self):
return self._job

Expand Down Expand Up @@ -255,6 +256,8 @@ def loadExperimentsFromFiles(self, fpaths):

def loadExperimentFromCifString(self, cifString="", job_name=""):
console.debug(f"Loading experiment(s) from: {job_name}")
# assure we reference the right interface
self._interface = self._job.interface
self.loadExperimentsFromEdCif(cifString)

self._job.add_experiment_from_string(cifString)
Expand All @@ -268,8 +271,9 @@ def loadExperimentFromCifString(self, cifString="", job_name=""):
self._currentIndex = len(self._dataBlocksNoMeas) - 1
if not self.defined:
self.defined = bool(len(self._dataBlocksNoMeas))

self.dataBlocksChanged.emit()
self._job.interface = self._interface
#self._job.interface = self._interface

def jobToBlock(self, job=None, name=None):
'''
Expand Down Expand Up @@ -1339,28 +1343,27 @@ def isSpinPolarized(self):
def runProfileCalculations(self):

# shove it all into the calculator.
# result = self._interface.calculate_profile()

# console.debug(formatMsg('sub', 'Profle calculations', 'finished'))

result = self._interface.calculate_profile()
# debug stuff - remove before merging
# simx = self._xArrays
# simx = self._dataBlocksMeasOnly[0]['loops']['_pd_meas'][0]['2theta_scan']['value']
# result = self._job.create_simulation(simx)
# chiSq = result[0]
# self._proxy.fitting._pointsCount = result[1]
# self._proxy.fitting._freeParamsCount = len(result[4])
# self._proxy.fitting.chiSq = chiSq / (self._proxy.fitting._pointsCount - self._proxy.fitting._freeParamsCount)

console.debug(formatMsg('sub', 'Profle calculations', 'finished'))
# gofLastIter = self._proxy.fitting.chiSq # NEED FIX

chiSq = result[0]
self._proxy.fitting._pointsCount = result[1]
self._proxy.fitting._freeParamsCount = len(result[4])
self._proxy.fitting.chiSq = chiSq / (self._proxy.fitting._pointsCount - self._proxy.fitting._freeParamsCount)
_ = self._job.calculate_profile() # this fills out calculator _inOutDict

gofLastIter = self._proxy.fitting.chiSq # NEED FIX
# if self._proxy.fitting.chiSqStart is None:
# self._proxy.status.goodnessOfFit = f'{gofLastIter:0.2f}' # NEED move to connection
# else:
# gofStart = self._proxy.fitting.chiSqStart # NEED FIX
# self._proxy.status.goodnessOfFit = f'{gofStart:0.2f} → {gofLastIter:0.2f}' # NEED move to connection
# if not self._proxy.fitting._freezeChiSqStart:
# self._proxy.fitting.chiSqStart = self._proxy.fitting.chiSq
pass

def setMeasuredArraysForSingleExperiment(self, idx):
diffrn_radiation_type = self.dataBlocksNoMeas[idx]['params']['_diffrn_radiation']['type']['value']
Expand Down
4 changes: 2 additions & 2 deletions easyDiffractionApp/Logic/Fitting2.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, proxy=None, interface=None):
self.interface = interface
# self.fitter = CoreFitter(self.parent.sample(), self.interface.fit_func)
# self.fitter = CoreFitter(self.parent.experiment.job(), self.parent.experiment.job().create_simulation)
self.fitter = CoreFitter(self.parent.experiment.job(), self.interface.fit_func)
self.fitter = CoreFitter(self.parent.experiment.job, self.interface.fit_func)

# Multithreading
# self._fitter_thread = None
Expand Down Expand Up @@ -227,7 +227,7 @@ def onFailed(self, ex):
@Slot()
def startStop(self):
# self.data = self.parent.pdata()
name = 'pd_' + self.parent.experiment.job().experiment.name
name = 'pd_' + self.parent.experiment.job.experiment.name
self.data = self.interface.data()._inOutDict[name]
if self.use_threading:
if not self.fit_thread.is_alive():
Expand Down
3 changes: 1 addition & 2 deletions easyDiffractionApp/Logic/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def addDefaultPhase(self):
def atomData(self, typeSymbol, key):
if typeSymbol == '':
return ''
typeSymbol = re.sub(r'[0-9]', '', typeSymbol) # '162Dy' -> 'Dy'
typeSymbol = re.sub(r'[0-9\+\-]', '', typeSymbol) # '162Dy' -> 'Dy', 'Co2+' -> 'Co'
if key == 'color':
return COLOR_TABLE[typeSymbol]
try:
Expand Down Expand Up @@ -620,7 +620,6 @@ def removeDataBlockLoopRow(self, category, rowIndex):
console.debug(formatMsg('sub', 'Intern dict', 'removed', f'{block}[{blockIdx}].{category}[{rowIndex}]'))

def appendDataBlockLoopRow(self, category):
print("\nappendDataBlockLoopRow\n")
block = 'model'
blockIdx = self._currentIndex

Expand Down
26 changes: 18 additions & 8 deletions easyDiffractionApp/Logic/Project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2023 EasyDiffraction contributors
# SPDX-License-Identifier: BSD-3-Clause
# © © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>
# © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>

import os
import time
Expand All @@ -13,7 +13,7 @@
from easydiffraction.io.cif import dataBlockToCif
from easydiffraction.io.cif import cifV2ToV1
from EasyApp.Logic.Logging import console

from Logic.Helpers import formatMsg


_EMPTY_DATA = {
Expand Down Expand Up @@ -76,11 +76,11 @@
'description': 'neutrons, powder, time-of-flight, SEPD@Argonne',
'path': ':/Examples/Si_SEPD@Argonne/project.cif'
},
{
'name': 'CeCuAl3 (Polaris)',
'description': 'neutrons, powder, time-of-flight, Polaris@ISIS',
'path': ':/Examples/CeCuAl3_Polaris@ISIS/project.cif'
},
#{
# 'name': 'CeCuAl3 (Polaris)',
# 'description': 'neutrons, powder, time-of-flight, Polaris@ISIS',
# 'path': ':/Examples/CeCuAl3_Polaris@ISIS/project.cif'
#},
{
'name': 'Na2Ca3Al2F14 (Osiris)',
'description': 'neutrons, powder, time-of-flight, Osiris@ISIS',
Expand All @@ -91,6 +91,16 @@
'description': 'neutrons, powder, time-of-flight, WISH@ISIS',
'path': ':/Examples/Na2Ca3Al2F14_WISH@ISIS/project.cif'
},
{
'name': 'CeO2 (iMATERIA)',
'description': 'neutrons, powder, time-of-flight, iMATERIA@J-PARC',
'path': ':/Examples/CeO2_iMATERIA@J-PARC/project.cif'
},
{
'name': 'Tb2Ti2O7 (HEiDi)',
'description': 'neutrons, single crystal, constant wavelength, HEiDi@MLZ',
'path': ':/Examples/Tb2Ti2O7_HEiDi@MLZ/project.cif'
},
#{
# 'name': 'Co2SiO4-Mult-Phases',
# 'description': 'neutrons, powder, constant wavelength, D20@ILL, 2 phases',
Expand Down Expand Up @@ -121,6 +131,7 @@ class Project(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self._proxy = parent
self._recent = []
self.resetAll()

@Slot()
Expand All @@ -130,7 +141,6 @@ def resetAll(self):
self._examples = _EXAMPLES
self._created = False
self._needSave = False
self._recent = []
self._isExample = False

self._location = str(Path.home())
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
'toml',
'darkdetect',
'numdifftools',
'funcy',
'cryspy @ git+https://github.com/ikibalin/cryspy.git@beta',
'EasyApp @ git+https://github.com/easyscience/EasyApp.git@beta',
'easyDiffraction @ git+https://github.com/easyscience/EasyDiffractionLib.git@new_param'
Expand Down
14 changes: 7 additions & 7 deletions tools/Scripts/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def __getitem__(self, key):
return self.__dict__[key]

def matrixOs(self, matrix_os):
if matrix_os is None:
return None
if 'ubuntu-24.04' in matrix_os:
matrix_os = 'ubuntu-22.04' # NEED FIX: Temporary solution to test the 22.04 build on 24.04
elif 'flyci' in matrix_os:
matrix_os = matrix_os.removeprefix('flyci-') # Simplify the default flyci name
matrix_os = matrix_os.removesuffix('-m2') # Simplify the default flyci name
#if matrix_os is None:
# return None
#if 'ubuntu-24.04' in matrix_os:
# matrix_os = 'ubuntu-22.04' # NEED FIX: Temporary solution to test the 22.04 build on 24.04
#elif 'flyci' in matrix_os:
# matrix_os = matrix_os.removeprefix('flyci-') # Simplify the default flyci name
# matrix_os = matrix_os.removesuffix('-m2') # Simplify the default flyci name
return matrix_os

# https://doc.qt.io/qtinstallerframework/scripting.html
Expand Down
1 change: 1 addition & 0 deletions tools/Scripts/FreezeApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def runPyInstaller():
'--clean', # Clean PyInstaller cache and remove temporary files before building
'--windowed', # Windows and Mac OS X: do not provide a console window for standard i/o.
'--onedir', # Create a one-folder bundle containing an executable (default)
#'--target-architecture', 'universal2', # Target architecture (macOS only; valid values: x86_64, arm64, universal2). Error: _multiarray_tests.cpython-311-darwin.so is not a fat binary! (i.e. not multi-architecture)
#'--specpath', workDirPath(), # Folder to store the generated spec file (default: current directory)
'--distpath', CONFIG.dist_dir, # Where to put the bundled app (default: ./dist)
'--workpath', CONFIG.build_dir, # Where to put all the temporary work files, .log, .pyz and etc. (default: ./build)
Expand Down
1 change: 0 additions & 1 deletion tools/Scripts/Functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def installSilently(installer, silent_script, sudo=False):
args = [installer, '--verbose', '--script', silent_script]
if sudo:
args = ['sudo', *args]

run(*args)
except Exception as exception:
printFailMessage(message, exception)
Expand Down

0 comments on commit 596f6cf

Please sign in to comment.