Skip to content
Merged
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
91 changes: 27 additions & 64 deletions src/diffpy/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,
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 diffpy.srxplanargui.srxconfig import SrXconfig

ETSConfig.toolkit = "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"):
pyFAIdir = os.path.join(sys.exec_prefix, "bin")
else:
pyFAIdir = os.path.join(sys.exec_prefix, "bin")
Expand All @@ -159,7 +116,7 @@ def _pyFAIdirChanged(self):
if sys.platform == "win32":
caliscript = os.path.join(self.pyFAIdir, "pyFAI-calib.py")
intescript = os.path.join(self.pyFAIdir, "pyFAI-waxs.py")
elif sys.platform == "linux2":
elif sys.platform.startswith("linux"):
caliscript = os.path.join(self.pyFAIdir, "pyFAI-calib")
intescript = os.path.join(self.pyFAIdir, "pyFAI-waxs")
else:
Expand All @@ -170,11 +127,11 @@ def _pyFAIdirChanged(self):
return

def callPyFAICalibration(self, image=None, dspacefile=None):
if image == None:
if image is None:
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 @@ -208,7 +165,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None):

try:
os.environ.pop("QT_API")
except:
except KeyError:
pass
subprocess.call(calicmd)

Expand All @@ -227,7 +184,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,7 +213,7 @@ 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):
Expand Down Expand Up @@ -290,7 +247,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 +257,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 +280,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 +332,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 +378,8 @@ def _qmaxChanged(self):
),
),
show_border=True,
label="Plasee specify the dimension of detector and size of pixel:",
label="Please specify the dimension of detector"
+ " and size of pixel:",
visible_when='calibrationmode=="self"',
),
HGroup(
Expand All @@ -443,8 +406,8 @@ def _qmaxChanged(self):


def findFloat(line):
temp = re.findall("[-+]?\d*\.\d+|[-+]?\d+", line)
return map(float, temp)
pattern = r"[-+]?(?:\d+\.\d*|\.\d+|\d+)"
return [float(x) for x in re.findall(pattern, line)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The old version returns a map object, while your new version returns a list. Have you checked where this function is being used and whether that is acceptable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have checked the context of the function. It wants to use the list property. Since in python2 map is more like a property of list while in py3 it becomes an iterator, we need to change it to list structure.



if __name__ == "__main__":
Expand Down
70 changes: 14 additions & 56 deletions src/diffpy/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 All @@ -88,7 +40,7 @@ def _cpReftext(self, info):
class SrXguiHelp(HasTraits):

if sys.platform.startswith("win"):
if ETSConfig.toolkit == "qt4":
if ETSConfig.toolkit == "qt":
hheight = 510
hwidth = 960
else:
Expand Down Expand Up @@ -151,9 +103,15 @@ def _get_qsimage(self):
#######################

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
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 @@ -163,7 +121,7 @@ def cpReftext(self):

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

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