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
97 changes: 29 additions & 68 deletions dpx/srxplanargui/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,32 @@
import re
import sys

import numpy as np
from traits.etsconfig.api import ETSConfig

ETSConfig.toolkit = "qt4"

from diffpy.srxconfutils.tools import module_exists_lower
from diffpy.srxplanar.selfcalibrate import selfCalibrate
from diffpy.srxplanar.srxplanar import SrXplanar
from diffpy.srxplanar.srxplanarconfig import checkMax
from pyface.api import ImageResource, SplashScreen
from pyface.api import ImageResource
from traits.api import (
Any,
Copy link
Contributor Author

@stevenhua0320 stevenhua0320 Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete imports that unused

Array,
Bool,
Button,
CFloat,
CInt,
DelegatesTo,
Dict,
Directory,
Enum,
Event,
File,
Float,
HasTraits,
Instance,
Int,
List,
Property,
Range,
Str,
cached_property,
on_trait_change,
property_depends_on,
)
from traitsui.api import (
Action,
ArrayEditor,
ButtonEditor,
CheckListEditor,
Controller,
EnumEditor,
Group,
Handler,
HGroup,
HistoryEditor,
ImageEditor,
InstanceEditor,
Item,
RangeEditor,
Tabbed,
TableEditor,
TextEditor,
TitleEditor,
VGroup,
View,
spring,
)
from traitsui.menu import (
CancelButton,
Menu,
MenuBar,
OKButton,
OKCancelButtons,
ToolBar,
)
from traits.etsconfig.api import ETSConfig
from traitsui.api import Group, Handler, HGroup, Item, VGroup, View
from traitsui.menu import CancelButton, OKButton

from dpx.srxplanargui.srxconfig import SrXconfig

ETSConfig.toolkit = "qt"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change deprecated "qt4" to "qt"

if module_exists_lower("pyfai"):
import pyFAI

Expand Down Expand Up @@ -146,7 +103,7 @@ def locatePyFAI(self):
pythonbin = sys.executable
if sys.platform == "win32":
pyFAIdir = os.path.join(sys.exec_prefix, "Scripts")
elif sys.platform == "linux2":
elif sys.platform.startswith("linux"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change deprecated "linux2" platform check to "linux"

pyFAIdir = os.path.join(sys.exec_prefix, "bin")
else:
pyFAIdir = os.path.join(sys.exec_prefix, "bin")
Expand All @@ -170,11 +127,11 @@ def _pyFAIdirChanged(self):
return

def callPyFAICalibration(self, image=None, dspacefile=None):
if image == None:
if image is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python2 cond check fix

image = self.image
else:
self.image = image
if dspacefile == None:
if dspacefile is None:
dspacefile = self.dspacefile
else:
self.dspacefile = dspacefile
Expand Down Expand Up @@ -206,11 +163,8 @@ def callPyFAICalibration(self, image=None, dspacefile=None):

import subprocess

try:
os.environ.pop("QT_API")
except:
pass
subprocess.call(calicmd)
os.environ.pop("QT_API", None)
subprocess.run(calicmd, check=True)

# integrate image
ponifile = os.path.splitext(str(image))[0] + ".poni"
Expand All @@ -227,7 +181,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None):
return

def parsePyFAIoutput(self, image=None):
if image == None:
if image is None:
image = self.image

filename = os.path.splitext(image)[0] + ".xy"
Expand Down Expand Up @@ -256,12 +210,12 @@ def parsePyFAIoutput(self, image=None):

def selfCalibration(self, image=None):
# self.addfiles.selected[0].fullname
if image == None:
if image is None:
image = self.image

if os.path.exists(image) and os.path.isfile(image):
for mode, showresults in zip(
["x", "y", "x", "y"], [False, False, False, True]
["x", "y", "x", "y"], [False, False, False, True]
):
selfCalibrate(
self.srx,
Expand Down Expand Up @@ -290,7 +244,8 @@ def calibration(self, image=None, dspacefile=None):
qmaxcali = Float(10.0)

@on_trait_change(
"srxconfig.[xpixelsize, ypixelsize, distance, wavelength, xdimension, ydimension]"
"srxconfig.[xpixelsize, ypixelsize, distance, "
"wavelength, xdimension, ydimension]"
)
def _qmaxChanged(self):
tthmax, qmax = checkMax(self.srxconfig)
Expand All @@ -299,10 +254,12 @@ def _qmaxChanged(self):
return

inst1 = Str(
"Please install pyFAI and FabIO to use the calibration function (refer to help)."
"Please install pyFAI and FabIO to use"
"the calibration function (refer to help)."
)
inst2 = Str(
"(http://github.com/kif/pyFAI, https://forge.epn-campus.eu/projects/azimuthal/files)"
"(http://github.com/kif/pyFAI,"
"https://forge.epn-campus.eu/projects/azimuthal/files)"
)
main_View = View(
# Item('calibrationmode', style='custom', label='Calibration mode'),
Expand All @@ -320,7 +277,8 @@ def _qmaxChanged(self):
show_border=True,
visible_when='calibrationmode=="calibrant"',
enabled_when="not missingpyFAI",
label="Please specify the d-space file and the location of pyFAI executable",
label="Please specify the d-space file and"
+ " the location of pyFAI executable",
),
HGroup(
Item(
Expand Down Expand Up @@ -371,7 +329,8 @@ def _qmaxChanged(self):
label="Camera Length(mm)",
visible_when='configmode == "TEM"',
),
label="Please specify the wavelength and distance between sample and detector:",
label="Please specify the wavelength and"
+ " distance between sample and detector:",
show_border=True,
visible_when='calibrationmode=="self"',
),
Expand Down Expand Up @@ -416,7 +375,8 @@ def _qmaxChanged(self):
),
),
show_border=True,
label="Plasee specify the dimension of detector and size of pixel:",
label="Plasee specify the dimension of detector"
+ " and size of pixel:",
visible_when='calibrationmode=="self"',
),
HGroup(
Expand All @@ -443,8 +403,9 @@ def _qmaxChanged(self):


def findFloat(line):
temp = re.findall("[-+]?\d*\.\d+|[-+]?\d+", line)
return map(float, temp)
"""Extract all floats from a string and return them as a list."""
pattern = r"[-+]?\d*\.\d+|[-+]?\d+"
return [float(x) for x in re.findall(pattern, line)]


if __name__ == "__main__":
Expand Down
71 changes: 15 additions & 56 deletions dpx/srxplanargui/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,13 @@
##############################################################################
"""Provide help for SrXgui."""

import os
import sys

import numpy as np
from pyface.api import ImageResource
from traits.api import (
Any,
Array,
Bool,
Button,
CFloat,
CInt,
DelegatesTo,
Dict,
Directory,
Enum,
Event,
File,
Float,
HasTraits,
Instance,
Int,
List,
Property,
Range,
Str,
cached_property,
on_trait_change,
property_depends_on,
)
from traits.api import HasTraits, Int, Property, property_depends_on
from traits.etsconfig.api import ETSConfig
from traitsui.api import (
Action,
ArrayEditor,
ButtonEditor,
CheckListEditor,
Controller,
EnumEditor,
Group,
Handler,
HGroup,
HistoryEditor,
ImageEditor,
InstanceEditor,
Item,
RangeEditor,
Tabbed,
TableEditor,
TextEditor,
TitleEditor,
VGroup,
View,
spring,
)
from traitsui.menu import CancelButton, Menu, OKButton, ToolBar
from traitsui.api import Action, Handler, ImageEditor, Item, View
from traitsui.menu import OKButton


class HelpHandler(Handler):
Expand Down Expand Up @@ -150,10 +102,17 @@ def _get_qsimage(self):
# reference
#######################

reftext = """
xPDFsuite (main GUI) :X. Yang, P. Juhas, C. L. Farrow and Simon J. L. Billinge xPDFsuite: an end-to-end software solution for high throughput pair distribution function transformation, visualization and analysis, arXiv 1402.3163 (2014)

SrXplanar (2D image integration):X. Yang, P. Juhas, S.J.L. Billinge, On the estimation of statistical uncertainties on powder diffraction and small-angle scattering data from two-dimensional X-ray detectors, J. Appl. Cryst. (2014). 47, 1273-1283
reftext = """
xPDFsuite (main GUI) :X. Yang, P. Juhas, C. L. Farrow and Simon J. L. Billinge
xPDFsuite: an end-to-end software solution
for high throughput pair distribution function transformation,
visualization and analysis, arXiv 1402.3163 (2014)

SrXplanar (2D image integration):X. Yang, P. Juhas, S.J.L. Billinge,
On the estimation of statistical uncertainties on
powder diffraction and small-angle scattering data from two-dimensional X-ray detectors,
J. Appl. Cryst. (2014). 47, 1273-1283
"""

def cpReftext(self):
Expand All @@ -162,8 +121,8 @@ def cpReftext(self):


def cpToClipboard(s):
if ETSConfig.toolkit == "qt4":
from pyface.qt import QtCore, QtGui
if ETSConfig.toolkit == "qt":
from pyface.qt import QtGui

cb = QtGui.QApplication.clipboard()
cb.clear(mode=cb.Clipboard)
Expand Down