From 41501a2ece68de2a86d8b943cf381d8d93e004a2 Mon Sep 17 00:00:00 2001 From: rozyczko Date: Mon, 17 Feb 2025 12:40:16 +0100 Subject: [PATCH] moved around toStdDevSmalestPrecision Added missing examples to the resources --- easyDiffractionApp/Logic/Helpers.py | 37 ++++------------------------- easyDiffractionApp/resources.qrc | 16 +++++++++++++ 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/easyDiffractionApp/Logic/Helpers.py b/easyDiffractionApp/Logic/Helpers.py index c6db489..b8f10b3 100644 --- a/easyDiffractionApp/Logic/Helpers.py +++ b/easyDiffractionApp/Logic/Helpers.py @@ -7,16 +7,14 @@ import os import pathlib import sys -import decimal -import importlib.util import numpy as np from uncertainties import ufloat from PySide6.QtCore import Qt, QObject, QCoreApplication, QUrl, Signal, Slot, Property -#from PySide6.QtGui import QStyleHints from PySide6.QtWidgets import QApplication from EasyApp.Logic.Logging import console +from easydiffraction.io.cif import toStdDevSmalestPrecision as toStdDevSmalestPrecisionLib class PersistentSettingsHandler: @@ -235,19 +233,9 @@ def listToUri(self, fpathParts): @Slot(float, float, result='QVariant') def toStdDevSmalestPrecision(self, value, std_dev): - if std_dev > 1: - value_str = f'{round(value)}' - std_dev_str = f'{round(std_dev)}' - value_with_std_dev_str = f'{value_str}({std_dev_str})' - else: - precision = 1 - std_dev_decimals = precision - int(np.floor(np.log10(std_dev) + 1)) - std_dev = round(std_dev, std_dev_decimals) - std_dev_str = f'{std_dev:.{std_dev_decimals}f}' - value = round(value, std_dev_decimals) - value_str = f'{value:.{std_dev_decimals}f}' - clipped_std_dev = int(round(std_dev * 10**std_dev_decimals)) - value_with_std_dev_str = f'{value_str}({clipped_std_dev})' + value, std_dev, _ = toStdDevSmalestPrecisionLib(value, std_dev) + value_str = f'{value}' + std_dev_str = f'{std_dev}' return {'value': value_str, 'std_dev': std_dev_str} @@ -313,20 +301,3 @@ def formatMsg(type, *args): msg = ' ▌ '.join(msgs) msg = f'{mark} {msg}' return msg - - @staticmethod - def toStdDevSmalestPrecision(value, std_dev): - if std_dev > 1: - value_str = f'{round(value)}' - std_dev_str = f'{round(std_dev)}' - value_with_std_dev_str = f'{value_str}({std_dev_str})' - else: - precision = 1 - std_dev_decimals = precision - int(np.floor(np.log10(std_dev) + 1)) - std_dev = round(std_dev, std_dev_decimals) - std_dev_str = f'{std_dev:.{std_dev_decimals}f}' - value = round(value, std_dev_decimals) - value_str = f'{value:.{std_dev_decimals}f}' - clipped_std_dev = int(round(std_dev * 10**std_dev_decimals)) - value_with_std_dev_str = f'{value_str}({clipped_std_dev})' - return value_str, std_dev_str, value_with_std_dev_str diff --git a/easyDiffractionApp/resources.qrc b/easyDiffractionApp/resources.qrc index 06b0b78..c98c36c 100644 --- a/easyDiffractionApp/resources.qrc +++ b/easyDiffractionApp/resources.qrc @@ -228,5 +228,21 @@ Examples/Na2Ca3Al2F14_WISH@ISIS/models/ncaf_light.png Examples/Na2Ca3Al2F14_WISH@ISIS/summary/report.cif Examples/Na2Ca3Al2F14_WISH@ISIS/project.cif + Examples/CeO2_iMATERIA@J-PARC/experiments/imateria.cif + Examples/CeO2_iMATERIA@J-PARC/experiments/imateria_dark.png + Examples/CeO2_iMATERIA@J-PARC/experiments/imateria_light.png + Examples/CeO2_iMATERIA@J-PARC/models/ceo.cif + Examples/CeO2_iMATERIA@J-PARC/models/ceo_dark.png + Examples/CeO2_iMATERIA@J-PARC/models/ceo_light.png + Examples/CeO2_iMATERIA@J-PARC/summary/report.cif + Examples/CeO2_iMATERIA@J-PARC/project.cif + Examples/Tb2Ti2O7_HEiDi@MLZ/experiments/heidi.cif + Examples/Tb2Ti2O7_HEiDi@MLZ/experiments/heidi_dark.png + Examples/Tb2Ti2O7_HEiDi@MLZ/experiments/heidi_light.png + Examples/Tb2Ti2O7_HEiDi@MLZ/models/tbti.cif + Examples/Tb2Ti2O7_HEiDi@MLZ/models/tbti_dark.png + Examples/Tb2Ti2O7_HEiDi@MLZ/models/tbti_light.png + Examples/Tb2Ti2O7_HEiDi@MLZ/summary/report.cif + Examples/Tb2Ti2O7_HEiDi@MLZ/project.cif