/usr/share/pyshared/PyMca/PyMcaHKLImageWindow.py is in pymca 4.5.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | #/*##########################################################################
# Copyright (C) 2004-2011 European Synchrotron Radiation Facility
#
# This file is part of the PyMCA X-ray Fluorescence Toolkit developed at
# the ESRF by the Beamline Instrumentation Software Support (BLISS) group.
#
# This toolkit is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# PyMCA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PyMCA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyMCA follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program.
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license
# is a problem for you.
#############################################################################*/
__author__ = "V.A. Sole - ESRF Data Analysis"
import sys
import numpy
from PyMca import PyMcaImageWindow
from PyMca import SixCircle
arctan = numpy.arctan
DEBUG = 0
class PyMcaHKLImageWindow(PyMcaImageWindow.PyMcaImageWindow):
def __init__(self, *var, **kw):
PyMcaImageWindow.PyMcaImageWindow.__init__(self, *var, **kw)
self._HKLOn = False
def _graphSignal(self, ddict):
if (ddict['event'] != "MouseAt") or (not self._HKLOn):
return PyMcaImageWindow.PyMcaImageWindow._graphSignal(self, ddict)
if self._imageData is None:
self.graphWidget.setInfoText(" H = ???? K = ???? L = ???? I = ????")
return
#pixel coordinates
x = round(ddict['y'])
if x < 0: x = 0
y = round(ddict['x'])
if y < 0: y = 0
limits = self._imageData.shape
x = min(int(x), limits[0]-1)
y = min(int(y), limits[1]-1)
z = self._imageData[x, y]
text = " X = %d Y = %d Z = %.7g " % (y, x, z)
info = self._getHKLInfoFromWidget()
toDeg = 180.0/numpy.pi
phi = info['phi']
chi = info['chi']
theta = info['theta']
if 0:
# delta in vertical (following BM28)
# gamma in horizontal (following BM28)
deltaH = toDeg * numpy.arctan((x - info['pixel_zero_h']) *\
(info['pixel_size_h']/info['distance']))
deltaV = toDeg *arctan((y - info['pixel_zero_v'])*\
(info['pixel_size_v']/info['distance']))
if 0:
#original
gamma = info['gamma'] + deltaH
delta = info['delta'] - deltaV
else:
#MarCCD settings
gamma = info['gamma'] - deltaV
delta = info['delta'] - deltaH
#end of BM28 customization
else:
#ID03
deltaH = toDeg * numpy.arctan((x - info['pixel_zero_v']) *\
(info['pixel_size_v']/info['distance']))
deltaV = toDeg *arctan((y - info['pixel_zero_h'])*\
(info['pixel_size_h']/info['distance']))
#delta in horizontal
#gamma in vertical
gamma = info['gamma'] - deltaH
delta = info['delta'] - deltaV
if 0:
#ID03 test for EH1
wavelength = 1.03321027
ub = [1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0]
ub[0] = 0.060082400000000001
ub[1] = 0.054556500000000001
ub[2] = -0.92985700000000004
ub[3] = -1.5089399999999999
ub[4] = -2.61991
ub[5] = -0.0203886
ub[6] = -2.1539600000000001
ub[7] = 0.230518
ub[8] = -0.011654299999999999
delta, theta, chi, phi, mu, gamma = 44.0035, -92.968, 90.715,\
1.26, 0.3, 0.578
print(" Expected value = ", 1, 1, 0.1)
mu = info['mu']
wavelength = info['lambda']
ub = info['ub']
if 0:
#This should always give 1 1 1
wavelength = 0.363504
ub = [1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0]
ub[0] = -4.080
ub[1] = 0.000
ub[2] = 0.000
ub[3] = 0.000
ub[4] = 4.080
ub[5] = 0.000
ub[6] = 0.000
ub[7] = 0.000
ub[8] = -4.080
delta, theta, chi, phi, mu, gamma = 23.5910, 47.0595, -135.,\
0.0, 0.0, 0.0
HKL = SixCircle.getHKL(wavelength,
ub,
phi=phi,
chi=chi,
theta=theta,
gamma=gamma,
delta=delta,
mu=mu)
HKL.shape = -1
text += "H = %.3f " % HKL[0]
text += "K = %.3f " % HKL[1]
text += "L = %.3f " % HKL[2]
self.graphWidget.setInfoText(text)
def _getHKLInfoFromWidget(self):
ddict = {}
ddict['lambda'] = 1.0 # In Angstroms
ddict['distance'] = 1000. # Same units as pixel size
ddict['pixel_size_h'] = 0.080 # Same units as distance
ddict['pixel_size_v'] = 0.080 # Same units as distance
ddict['pixel_zero_h'] = 1024. # In pixel units (float)
ddict['pixel_zero_v'] = 1024. # In pixel units (float)
ddict['orientation'] = 0
ddict['ub'] = [1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0]
ddict['phi'] = 0.0
ddict['chi'] = 0.0
ddict['theta'] = 0.0
ddict['gamma'] = 0.0
ddict['delta'] = 0.0
ddict['mu'] = 0.0
legend = self.dataObjectsList[0]
dataObject = self.dataObjectsDict[legend]
info = dataObject.info
#try to get the information from the motors
motPos = info.get('motor_pos', "")
motMne = info.get('motor_mne', "")
motPos = motPos.split()
motMne = motMne.split()
if len(motPos) == len(motMne):
idx = -1
for mne in motMne:
idx += 1
if mne.upper() in ['ENERGY', 'NRJ']:
energy = float(motPos[idx])
ddict['lambda'] = 12.39842 / energy
continue
if mne in ['phi', 'chi', 'mu']:
ddict[mne] = float(motPos[idx])
continue
if mne in ['th', 'theta']:
ddict['theta'] = float(motPos[idx])
continue
if mne in ['del', 'delta', 'tth', 'twotheta']:
ddict['delta'] = float(motPos[idx])
continue
if mne in ['gam', 'gamma']:
ddict['gamma'] = float(motPos[idx])
continue
#and update it from the counters
cntPos = info.get('counter_pos', "").split()
cntMne = info.get('counter_mne', "").split()
cntInfo = {}
if len(cntPos) == len(cntMne):
for i in range(len(cntMne)):
cntInfo[cntMne[i]] = cntPos[i]
for key in cntInfo.keys():
# diffractometer
if key in ['phicnt']:
ddict['phi'] = float(cntInfo[key])
continue
if key in ['chicnt']:
ddict['chi'] = float(cntInfo[key])
continue
if key in ['thcnt', 'thetacnt']:
ddict['theta'] = float(cntInfo[key])
continue
if key in ['tthcnt'] and ('delcnt' not in cntInfo.keys()):
#Avoid ID03 trap because they have delcnt and tthcnt ...
ddict['delta'] = float(cntInfo[key])
continue
if key in ['delcnt', 'deltacnt']:
ddict['delta'] = float(cntInfo[key])
continue
if key in ['gamcnt', 'gammacnt']:
ddict['gamma'] = float(cntInfo[key])
continue
if key in ['mucnt']:
ddict['mu'] = float(cntInfo[key])
continue
for key in info.keys():
# UB matrix
if key.upper() in ['UB_POS']:
ddict['ub'] = [float(x) for x in info[key].split()]
continue
# direct beam
if key in ['beam_x', 'pixel_zero_x']:
ddict['pixel_zero_h'] = float(info[key])
continue
if key in ['beam_y', 'pixel_zero_y']:
ddict['pixel_zero_v'] = float(info[key])
continue
#sample to direct beam distance
if key in ['detector_distance', 'd_sample_det']:
ddict['distance'] = float(info[key])
continue
#pixel sizes
if key in ['pixel_size_x']:
ddict['pixel_size_h'] = float(info[key])
continue
if key in ['pixel_size_y']:
ddict['pixel_size_v'] = float(info[key])
continue
#wave length
if key in ['source_wavelength']:
ddict['lambda'] = float(info[key])
continue
if DEBUG:
for key in ddict.keys():
print(key, ddict[key])
return ddict
|