Skip to content

Commit

Permalink
Added Rotation parameters to dialog window
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Duff authored and Caleb Duff committed Aug 24, 2016
1 parent 23a7d90 commit 395caa5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 18 deletions.
31 changes: 29 additions & 2 deletions xpdView/azimuthal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ class Azimuthal(object):
Attributes
----------
x_lists : list of 1d numpy arrays
list of x data for the integration patterns to be stored in
y_lists : list of 1d numpy arrays
see above, but for y data
file_names : list of strings
list of strings unique to each integration pattern
wl : float
wavelength in angstroms
poni1 : float
required by pyFAI something to do with beam placement
poni2 : float
same as above
dist : float
distance from sample to detector
rot1 : float
rotation of the detector, required by pyFAI
rot2 : float
rotation of the detector, required by pyFAI
"""

def __init__(self):
Expand All @@ -48,8 +66,10 @@ def __init__(self):
self.poni1 = None
self.poni2 = None
self.dist = None
self.rot1 = None
self.rot2 = None

def set_integration_parameters(self, wl=0.184320, poni1=.1006793, poni2=.1000774, dist=0.2418217):
def set_integration_parameters(self, wl=0.184320, poni1=.1006793, poni2=.1000774, dist=0.2418217, rot1=0, rot2=0):
"""
This method sets the integration parameters
Parameters
Expand All @@ -62,6 +82,10 @@ def set_integration_parameters(self, wl=0.184320, poni1=.1006793, poni2=.1000774
this value is required by the pyFAI integrator
dist : float
This is distance to the detector
rot1 : float
This is the rotation one parameter
rot2 : float
This is the rotation two parameter
Returns
-------
Expand All @@ -72,6 +96,8 @@ def set_integration_parameters(self, wl=0.184320, poni1=.1006793, poni2=.1000774
self.poni1 = 2*poni1
self.poni2 = 2*poni2
self.dist = dist
self.rot1 = rot1
self.rot2 = rot2

def get_right_names(self, file_names, data_list):
"""
Expand Down Expand Up @@ -117,7 +143,8 @@ def integration_time(self, data_list):
ni = pyFAI.calibrant.ALL_CALIBRANTS("Ni")
ni.set_wavelength(self.wl)
ai = pyFAI.AzimuthalIntegrator(dist=self.dist, poni1=self.poni1,
poni2=self.poni2, rot1=0, rot2=0, detector=det)
poni2=self.poni2, rot1=self.rot1,
rot2=self.rot2, detector=det)
ai.set_wavelength(self.wl)

for data in data_list:
Expand Down
59 changes: 43 additions & 16 deletions xpdView/xpd_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def data_gen(length):
for x in range(x_length):
for y in range(y_length):
height = idx + 1
if x == int(x_length/2) and y == int(y_length/2):
if x == int(x_length / 2) and y == int(y_length / 2):
array_style[x][y] = 0
else:
array_style[x][y] = height/np.sqrt((x-int(x_length/2))**2+(y-int(y_length/2))**2)
array_style[x][y] = height / np.sqrt((x - int(x_length / 2)) ** 2 + (y - int(y_length / 2)) ** 2)
data.append(array_style)
return data, keys

Expand Down Expand Up @@ -623,7 +623,7 @@ def set_x_offset(self, value):
self.water.generate_waterfall()

def set_y_offset(self, value):
self.water.y_offset = (value/10.0)
self.water.y_offset = (value / 10.0)
self.water.generate_waterfall()

def set_analysis_type(self, i):
Expand Down Expand Up @@ -879,6 +879,8 @@ def set_integration_parameters(self):
poni1 = .1006793
poni2 = .1000774
dist = 0.2418217
rot1 = 0
rot2 = 0
vbox = QtGui.QVBoxLayout()
popup.setLayout(vbox)

Expand All @@ -888,7 +890,7 @@ def set_integration_parameters(self):
wave_label = QtGui.QLabel()
wave_label.setText('Wavelength (in Angstroms): ')
wave_number = QtGui.QDoubleSpinBox()
wave_number.setDecimals(12)
wave_number.setDecimals(8)
wave_number.setValue(wavelength)
hbox1.addWidget(wave_label)
hbox1.addWidget(wave_number)
Expand All @@ -899,7 +901,7 @@ def set_integration_parameters(self):
poni1_label = QtGui.QLabel()
poni1_label.setText('Poni1: ')
poni1_number = QtGui.QDoubleSpinBox()
poni1_number.setDecimals(12)
poni1_number.setDecimals(8)
poni1_number.setValue(poni1)
hbox2.addWidget(poni1_label)
hbox2.addWidget(poni1_number)
Expand All @@ -910,7 +912,7 @@ def set_integration_parameters(self):
poni2_label = QtGui.QLabel()
poni2_label.setText('Poni2: ')
poni2_number = QtGui.QDoubleSpinBox()
poni2_number.setDecimals(12)
poni2_number.setDecimals(8)
poni2_number.setValue(poni2)
hbox3.addWidget(poni2_label)
hbox3.addWidget(poni2_number)
Expand All @@ -922,21 +924,45 @@ def set_integration_parameters(self):
dist_label.setText('Distance (m): ')
dist_number = QtGui.QDoubleSpinBox()
dist_number.setValue(dist)
dist_number.setDecimals(12)
dist_number.setDecimals(8)
hbox4.addWidget(dist_label)
hbox4.addWidget(dist_number)

# This sets up the button to accept the values and close the window
# This sets up the line for setting the rot1 value
hbox5 = QtGui.QHBoxLayout()
vbox.addLayout(hbox5)
rot1_label = QtGui.QLabel()
rot1_label.setText('Rotation 1 (Radians): ')
rot1_number = QtGui.QDoubleSpinBox()
rot1_number.setValue(rot1)
rot1_number.setDecimals(8)
hbox5.addWidget(rot1_label)
hbox5.addWidget(rot1_number)

# This sets up the line for setting the rot2 value
hbox6 = QtGui.QHBoxLayout()
vbox.addLayout(hbox6)
rot2_label = QtGui.QLabel()
rot2_label.setText('Rotation 2 (Radians): ')
rot2_number = QtGui.QDoubleSpinBox()
rot2_number.setValue(rot2)
rot2_number.setDecimals(8)
hbox6.addWidget(rot2_label)
hbox6.addWidget(rot2_number)

# This sets up the button to accept the values and close the window
hbox6 = QtGui.QHBoxLayout()
vbox.addLayout(hbox6)
accept_btn = QtGui.QPushButton()
accept_btn.setText('Accept')
hbox5.addWidget(accept_btn)
hbox6.addWidget(accept_btn)
accept_btn.clicked.connect(popup.close)
accept_btn.clicked.connect(lambda: self.Azi.set_integration_parameters(wl=wave_number.value(),
poni1=poni1_number.value(),
poni2=poni2_number.value(),
dist=dist_number.value()))
dist=dist_number.value(),
rot1=rot1_number.value(),
rot2=rot2_number.value()))

popup.show()
popup.exec_()
Expand Down Expand Up @@ -1058,7 +1084,7 @@ def update_int_data(self, file_list, data_x, data_y):
for file in file_list:
self.int_key_list.append(file)
for i in range(old_length, len(self.int_key_list)):
self.int_data_dict[self.int_key_list[i]] = [data_x[i-old_length], data_y[i-old_length]]
self.int_data_dict[self.int_key_list[i]] = [data_x[i - old_length], data_y[i - old_length]]
if len(self.int_key_list) != 0:
self.water.normalize_data()
self.water.generate_waterfall()
Expand Down Expand Up @@ -1114,7 +1140,7 @@ def add_func(self, func):
self.func_dict[func.__name__] = func

def remove_func(self, func_name):
"""This function will remove a function from the function dictionary
"""This function will remove a function from the function dictionary
To delete the name of the function must match the name of a function currently in the dictionary
Expand All @@ -1126,10 +1152,10 @@ def remove_func(self, func_name):
"""

try:
self.data_dict.__delitem__(func_name)
except KeyError:
print("There is no function matching " + func_name + " in the function dictionary")
try:
self.data_dict.__delitem__(func_name)
except KeyError:
print("There is no function matching " + func_name + " in the function dictionary")


def main():
Expand All @@ -1146,5 +1172,6 @@ def main():
viewer.show()
sys.exit(app.exec_())


if __name__ == "__main__":
main()

0 comments on commit 395caa5

Please sign in to comment.