Verified Commit cb69d28d authored by Tobias WEBER's avatar Tobias WEBER
Browse files

tascalc: angular distances for cost function

parent 5e500ddf
......@@ -225,6 +225,27 @@ def get_E(ki, kf):
# -----------------------------------------------------------------------------
# get the difference in tas angles for two positions
def get_angle_deltas(ki1, kf1, Q_rlu1, di1, df1, \
ki2, kf2, Q_rlu2, di2, df2, \
orient_rlu, orient_up_rlu, B, sense_sample=1., a3_offs=np.pi):
# position 1
[a1_1, a2_1] = get_a1a2(ki1, di1)
[a5_1, a6_1] = get_a1a2(kf1, df1)
[a3_1, a4_1, dist_Q_plane_1] = get_a3a4(ki1, kf1, Q_rlu1, orient_rlu, orient_up_rlu, B, sense_sample, a3_offs)
# position 2
[a1_2, a2_2] = get_a1a2(ki2, di2)
[a5_2, a6_2] = get_a1a2(kf2, df2)
[a3_2, a4_2, dist_Q_plane_2] = get_a3a4(ki2, kf2, Q_rlu2, orient_rlu, orient_up_rlu, B, sense_sample, a3_offs)
return [a1_2-a1_1, a2_2-a2_1, a3_2-a3_1, a4_2-a4_1, a5_2-a5_1, a6_2-a6_1]
# -----------------------------------------------------------------------------
......@@ -285,7 +306,10 @@ class TasGUI:
)
except (ArithmeticError, la.LinAlgError) as err:
self.editBMat.setPlainText("invalid")
self.QChanged()
self.QChanged_angles()
def planeChanged(self):
self.xtalChanged()
......@@ -431,6 +455,84 @@ class TasGUI:
self.QChanged()
except (ArithmeticError, la.LinAlgError) as err:
self.editKi.setText("invalid")
def QChanged_angles(self):
Q_rlu1 = np.array([self.getfloat(self.edith1.text()), self.getfloat(self.editk1.text()), self.getfloat(self.editl1.text())])
Q_rlu2 = np.array([self.getfloat(self.edith2.text()), self.getfloat(self.editk2.text()), self.getfloat(self.editl2.text())])
ki1 = self.getfloat(self.editKi1.text())
ki2 = self.getfloat(self.editKi2.text())
kf1 = self.getfloat(self.editKf1.text())
kf2 = self.getfloat(self.editKf2.text())
di = self.getfloat(self.editDm.text())
df = self.getfloat(self.editDa.text())
try:
sense_sample = 1.
if self.checkA4Sense.isChecked() == False:
sense_sample = -1.
[da1, da2, da3, da4, da5, da6] = get_angle_deltas(\
ki1, kf1, Q_rlu1, di, df, \
ki2, kf2, Q_rlu2, di, df, \
self.orient_rlu, self.orient_up_rlu, self.B, sense_sample, self.a3_offs)
self.editdA1.setText("%.6g" % (da1 / np.pi * 180.))
self.editdA2.setText("%.6g" % (da2 / np.pi * 180.))
self.editdA3.setText("%.6g" % (da3 / np.pi * 180.))
self.editdA4.setText("%.6g" % (da4 / np.pi * 180.))
self.editdA5.setText("%.6g" % (da5 / np.pi * 180.))
self.editdA6.setText("%.6g" % (da6 / np.pi * 180.))
except (ArithmeticError, la.LinAlgError) as err:
self.editdA1.setText("invalid")
self.editdA2.setText("invalid")
self.editdA3.setText("invalid")
self.editdA4.setText("invalid")
self.editdA5.setText("invalid")
self.editdA6.setText("invalid")
def KiKfChanged_angles(self):
ki1 = self.getfloat(self.editKi1.text())
ki2 = self.getfloat(self.editKi2.text())
kf1 = self.getfloat(self.editKf1.text())
kf2 = self.getfloat(self.editKf2.text())
try:
E1 = get_E(ki1, kf1)
self.editE1.setText("%.6g" % E1)
except (ArithmeticError, la.LinAlgError) as err:
self.editE1.setText("invalid")
try:
E2 = get_E(ki2, kf2)
self.editE2.setText("%.6g" % E2)
except (ArithmeticError, la.LinAlgError) as err:
self.editE2.setText("invalid")
self.QChanged_angles()
def EChanged_angles(self):
E1 = self.getfloat(self.editE1.text())
kf1 = self.getfloat(self.editKf1.text())
E2 = self.getfloat(self.editE2.text())
kf2 = self.getfloat(self.editKf2.text())
try:
ki1 = get_ki(kf1, E1)
self.editKi1.setText("%.6g" % ki1)
except (ArithmeticError, la.LinAlgError) as err:
self.editKi1.setText("invalid")
try:
ki2 = get_ki(kf2, E2)
self.editKi2.setText("%.6g" % ki2)
except (ArithmeticError, la.LinAlgError) as err:
self.editKi2.setText("invalid")
self.QChanged_angles()
# -----------------------------------------------------------------------------
......@@ -490,8 +592,6 @@ class TasGUI:
# crystal tab
xtalpanel = qtw.QWidget()
xtallayout = qtw.QGridLayout(xtalpanel)
scpanel = xtalpanel
sclayout = xtallayout
self.editA = qtw.QLineEdit(xtalpanel)
self.editB = qtw.QLineEdit(xtalpanel)
......@@ -501,12 +601,12 @@ class TasGUI:
self.editGamma = qtw.QLineEdit(xtalpanel)
separatorXtal = qtw.QFrame(xtalpanel)
separatorXtal.setFrameStyle(qtw.QFrame.HLine)
self.editAx = qtw.QLineEdit(scpanel)
self.editAy = qtw.QLineEdit(scpanel)
self.editAz = qtw.QLineEdit(scpanel)
self.editBx = qtw.QLineEdit(scpanel)
self.editBy = qtw.QLineEdit(scpanel)
self.editBz = qtw.QLineEdit(scpanel)
self.editAx = qtw.QLineEdit(xtalpanel)
self.editAy = qtw.QLineEdit(xtalpanel)
self.editAz = qtw.QLineEdit(xtalpanel)
self.editBx = qtw.QLineEdit(xtalpanel)
self.editBy = qtw.QLineEdit(xtalpanel)
self.editBz = qtw.QLineEdit(xtalpanel)
self.editBMat = qtw.QPlainTextEdit(xtalpanel)
self.editBMat.setReadOnly(True)
......@@ -537,6 +637,7 @@ class TasGUI:
self.editBy.setText("%.6g" % sett.value("qtas/by", 1., type=float))
self.editBz.setText("%.6g" % sett.value("qtas/bz", 0., type=float))
xtallayout.addWidget(qtw.QLabel(u"a (\u212b):", xtalpanel), 0,0, 1,1)
xtallayout.addWidget(self.editA, 0,1, 1,3)
xtallayout.addWidget(qtw.QLabel(u"b (\u212b):", xtalpanel), 1,0, 1,1)
......@@ -549,15 +650,16 @@ class TasGUI:
xtallayout.addWidget(self.editBeta, 4,1, 1,3)
xtallayout.addWidget(qtw.QLabel(u"\u03b3 (deg):", xtalpanel), 5,0, 1,1)
xtallayout.addWidget(self.editGamma, 5,1, 1,3)
xtallayout.addWidget(separatorXtal, 6,0, 1,4)
sclayout.addWidget(qtw.QLabel("Orient. 1 (rlu):", scpanel), 7,0, 1,1)
sclayout.addWidget(self.editAx, 7,1, 1,1)
sclayout.addWidget(self.editAy, 7,2, 1,1)
sclayout.addWidget(self.editAz, 7,3, 1,1)
sclayout.addWidget(qtw.QLabel("Orient. 2 (rlu):", scpanel), 8,0, 1,1)
sclayout.addWidget(self.editBx, 8,1, 1,1)
sclayout.addWidget(self.editBy, 8,2, 1,1)
sclayout.addWidget(self.editBz, 8,3, 1,1)
xtallayout.addWidget(qtw.QLabel("Orient. 1 (rlu):", xtalpanel), 7,0, 1,1)
xtallayout.addWidget(self.editAx, 7,1, 1,1)
xtallayout.addWidget(self.editAy, 7,2, 1,1)
xtallayout.addWidget(self.editAz, 7,3, 1,1)
xtallayout.addWidget(qtw.QLabel("Orient. 2 (rlu):", xtalpanel), 8,0, 1,1)
xtallayout.addWidget(self.editBx, 8,1, 1,1)
xtallayout.addWidget(self.editBy, 8,2, 1,1)
xtallayout.addWidget(self.editBz, 8,3, 1,1)
xtallayout.addWidget(self.editBMat, 9,0, 2,4)
tabs.addTab(xtalpanel, "Crystal")
......@@ -568,8 +670,6 @@ class TasGUI:
# tas tab
taspanel = qtw.QWidget()
taslayout = qtw.QGridLayout(taspanel)
Qpanel = taspanel
Qlayout = taslayout
self.editA1 = qtw.QLineEdit(taspanel)
self.editA2 = qtw.QLineEdit(taspanel)
......@@ -583,22 +683,22 @@ class TasGUI:
self.editDm = qtw.QLineEdit(taspanel)
self.editDa = qtw.QLineEdit(taspanel)
self.edith = qtw.QLineEdit(Qpanel)
self.editk = qtw.QLineEdit(Qpanel)
self.editl = qtw.QLineEdit(Qpanel)
self.editE = qtw.QLineEdit(Qpanel)
self.editKi = qtw.QLineEdit(Qpanel)
self.editKf = qtw.QLineEdit(Qpanel)
self.editQAbs = qtw.QLineEdit(Qpanel)
self.edith = qtw.QLineEdit(taspanel)
self.editk = qtw.QLineEdit(taspanel)
self.editl = qtw.QLineEdit(taspanel)
self.editE = qtw.QLineEdit(taspanel)
self.editKi = qtw.QLineEdit(taspanel)
self.editKf = qtw.QLineEdit(taspanel)
self.editQAbs = qtw.QLineEdit(taspanel)
self.editQAbs.setReadOnly(True)
self.tasstatus = qtw.QLabel(taspanel)
separatorTas = qtw.QFrame(Qpanel)
separatorTas = qtw.QFrame(taspanel)
separatorTas.setFrameStyle(qtw.QFrame.HLine)
separatorTas2 = qtw.QFrame(Qpanel)
separatorTas2 = qtw.QFrame(taspanel)
separatorTas2.setFrameStyle(qtw.QFrame.HLine)
separatorTas3 = qtw.QFrame(Qpanel)
separatorTas3 = qtw.QFrame(taspanel)
separatorTas3.setFrameStyle(qtw.QFrame.HLine)
......@@ -633,20 +733,21 @@ class TasGUI:
self.checkA4Sense.stateChanged.connect(self.QChanged)
Qlayout.addWidget(qtw.QLabel("h (rlu):", Qpanel), 0,0, 1,1)
Qlayout.addWidget(self.edith, 0,1, 1,2)
Qlayout.addWidget(qtw.QLabel("k (rlu):", Qpanel), 1,0, 1,1)
Qlayout.addWidget(self.editk, 1,1, 1,2)
Qlayout.addWidget(qtw.QLabel("l (rlu):", Qpanel), 2,0, 1,1)
Qlayout.addWidget(self.editl, 2,1, 1,2)
Qlayout.addWidget(qtw.QLabel("E (meV):", Qpanel), 3,0, 1,1)
Qlayout.addWidget(self.editE, 3,1, 1,2)
Qlayout.addWidget(qtw.QLabel(u"ki, kf (\u212b\u207b\u00b9):", Qpanel), 4,0, 1,1)
Qlayout.addWidget(self.editKi, 4,1, 1,1)
Qlayout.addWidget(self.editKf, 4,2, 1,1)
Qlayout.addWidget(qtw.QLabel(u"|Q| (\u212b\u207b\u00b9):", Qpanel), 5,0, 1,1)
Qlayout.addWidget(self.editQAbs, 5,1, 1,2)
Qlayout.addWidget(separatorTas, 6,0,1,3)
taslayout.addWidget(qtw.QLabel("h (rlu):", taspanel), 0,0, 1,1)
taslayout.addWidget(self.edith, 0,1, 1,2)
taslayout.addWidget(qtw.QLabel("k (rlu):", taspanel), 1,0, 1,1)
taslayout.addWidget(self.editk, 1,1, 1,2)
taslayout.addWidget(qtw.QLabel("l (rlu):", taspanel), 2,0, 1,1)
taslayout.addWidget(self.editl, 2,1, 1,2)
taslayout.addWidget(qtw.QLabel("E (meV):", taspanel), 3,0, 1,1)
taslayout.addWidget(self.editE, 3,1, 1,2)
taslayout.addWidget(qtw.QLabel(u"ki, kf (\u212b\u207b\u00b9):", taspanel), 4,0, 1,1)
taslayout.addWidget(self.editKi, 4,1, 1,1)
taslayout.addWidget(self.editKf, 4,2, 1,1)
taslayout.addWidget(qtw.QLabel(u"|Q| (\u212b\u207b\u00b9):", taspanel), 5,0, 1,1)
taslayout.addWidget(self.editQAbs, 5,1, 1,2)
taslayout.addWidget(separatorTas, 6,0,1,3)
taslayout.addWidget(qtw.QLabel("a1, a2 (deg):", taspanel), 7,0, 1,1)
taslayout.addWidget(self.editA1, 7,1, 1,1)
taslayout.addWidget(self.editA2, 7,2, 1,1)
......@@ -656,9 +757,11 @@ class TasGUI:
taslayout.addWidget(qtw.QLabel("a5, a6 (deg):", taspanel), 9,0, 1,1)
taslayout.addWidget(self.editA5, 9,1, 1,1)
taslayout.addWidget(self.editA6, 9,2, 1,1)
taslayout.addWidget(separatorTas2, 10,0, 1,3)
taslayout.addWidget(qtw.QLabel("Sense:", taspanel), 11,0, 1,1)
taslayout.addWidget(self.checkA4Sense, 11,1, 1,2)
taslayout.addWidget(separatorTas3, 12,0, 1,3)
taslayout.addWidget(qtw.QLabel(u"Mono., Ana. d (\u212b):", taspanel), 13,0, 1,1)
taslayout.addWidget(self.editDm, 13,1, 1,1)
......@@ -670,6 +773,110 @@ class TasGUI:
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# angular distance tab
anglespanel = qtw.QWidget()
angleslayout = qtw.QGridLayout(anglespanel)
self.editdA1 = qtw.QLineEdit(anglespanel)
self.editdA2 = qtw.QLineEdit(anglespanel)
self.editdA3 = qtw.QLineEdit(anglespanel)
self.editdA4 = qtw.QLineEdit(anglespanel)
self.editdA5 = qtw.QLineEdit(anglespanel)
self.editdA6 = qtw.QLineEdit(anglespanel)
self.editdA1.setReadOnly(True)
self.editdA2.setReadOnly(True)
self.editdA3.setReadOnly(True)
self.editdA4.setReadOnly(True)
self.editdA5.setReadOnly(True)
self.editdA6.setReadOnly(True)
self.edith1 = qtw.QLineEdit(anglespanel)
self.editk1 = qtw.QLineEdit(anglespanel)
self.editl1 = qtw.QLineEdit(anglespanel)
self.editE1 = qtw.QLineEdit(anglespanel)
self.editKi1 = qtw.QLineEdit(anglespanel)
self.editKf1 = qtw.QLineEdit(anglespanel)
self.edith2 = qtw.QLineEdit(anglespanel)
self.editk2 = qtw.QLineEdit(anglespanel)
self.editl2 = qtw.QLineEdit(anglespanel)
self.editE2 = qtw.QLineEdit(anglespanel)
self.editKi2 = qtw.QLineEdit(anglespanel)
self.editKf2 = qtw.QLineEdit(anglespanel)
separatorAngles = qtw.QFrame(anglespanel)
separatorAngles.setFrameStyle(qtw.QFrame.HLine)
self.edith1.textEdited.connect(self.QChanged_angles)
self.editk1.textEdited.connect(self.QChanged_angles)
self.editl1.textEdited.connect(self.QChanged_angles)
self.editKi1.textEdited.connect(self.KiKfChanged_angles)
self.editKf1.textEdited.connect(self.KiKfChanged_angles)
self.editE1.textEdited.connect(self.EChanged_angles)
self.edith2.textEdited.connect(self.QChanged_angles)
self.editk2.textEdited.connect(self.QChanged_angles)
self.editl2.textEdited.connect(self.QChanged_angles)
self.editKi2.textEdited.connect(self.KiKfChanged_angles)
self.editKf2.textEdited.connect(self.KiKfChanged_angles)
self.editE2.textEdited.connect(self.EChanged_angles)
self.edith1.setText("%.6g" % sett.value("qtas/h1", 1., type=float))
self.editk1.setText("%.6g" % sett.value("qtas/k1", 0., type=float))
self.editl1.setText("%.6g" % sett.value("qtas/l1", 0., type=float))
#self.editE1.setText("%.6g" % sett.value("qtas/E1", 0., type=float))
self.editKi1.setText("%.6g" % sett.value("qtas/ki1", 2.662, type=float))
self.editKf1.setText("%.6g" % sett.value("qtas/kf1", 2.662, type=float))
self.edith2.setText("%.6g" % sett.value("qtas/h2", 1., type=float))
self.editk2.setText("%.6g" % sett.value("qtas/k2", 0., type=float))
self.editl2.setText("%.6g" % sett.value("qtas/l2", 0., type=float))
#self.editE2.setText("%.6g" % sett.value("qtas/E2", 0., type=float))
self.editKi2.setText("%.6g" % sett.value("qtas/ki2", 2.662, type=float))
self.editKf2.setText("%.6g" % sett.value("qtas/kf2", 2.662, type=float))
angleslayout.addWidget(qtw.QLabel("Position 1:", anglespanel), 0,1, 1,1)
angleslayout.addWidget(qtw.QLabel("Position 2:", anglespanel), 0,2, 1,1)
angleslayout.addWidget(qtw.QLabel("h (rlu):", anglespanel), 1,0, 1,1)
angleslayout.addWidget(self.edith1, 1,1, 1,1)
angleslayout.addWidget(self.edith2, 1,2, 1,1)
angleslayout.addWidget(qtw.QLabel("k (rlu):", anglespanel), 2,0, 1,1)
angleslayout.addWidget(self.editk1, 2,1, 1,1)
angleslayout.addWidget(self.editk2, 2,2, 1,1)
angleslayout.addWidget(qtw.QLabel("l (rlu):", anglespanel), 3,0, 1,1)
angleslayout.addWidget(self.editl1, 3,1, 1,1)
angleslayout.addWidget(self.editl2, 3,2, 1,1)
angleslayout.addWidget(qtw.QLabel("E (meV):", anglespanel), 4,0, 1,1)
angleslayout.addWidget(self.editE1, 4,1, 1,1)
angleslayout.addWidget(self.editE2, 4,2, 1,1)
angleslayout.addWidget(qtw.QLabel(u"ki (\u212b\u207b\u00b9):", anglespanel), 5,0, 1,1)
angleslayout.addWidget(self.editKi1, 5,1, 1,1)
angleslayout.addWidget(self.editKi2, 5,2, 1,1)
angleslayout.addWidget(qtw.QLabel(u"kf (\u212b\u207b\u00b9):", anglespanel), 6,0, 1,1)
angleslayout.addWidget(self.editKf1, 6,1, 1,1)
angleslayout.addWidget(self.editKf2, 6,2, 1,1)
angleslayout.addWidget(separatorAngles, 7,0,1,3)
angleslayout.addWidget(qtw.QLabel("Angular Distances:", anglespanel), 8,1, 1,3)
angleslayout.addWidget(qtw.QLabel("\u0394a1, \u0394a2 (deg):", anglespanel), 9,0, 1,1)
angleslayout.addWidget(self.editdA1, 9,1, 1,1)
angleslayout.addWidget(self.editdA2, 9,2, 1,1)
angleslayout.addWidget(qtw.QLabel("\u0394a3, \u0394a4 (deg):", anglespanel), 10,0, 1,1)
angleslayout.addWidget(self.editdA3, 10,1, 1,1)
angleslayout.addWidget(self.editdA4, 10,2, 1,1)
angleslayout.addWidget(qtw.QLabel("\u0394a5, \u0394a6 (deg):", anglespanel), 11,0, 1,1)
angleslayout.addWidget(self.editdA5, 11,1, 1,1)
angleslayout.addWidget(self.editdA6, 11,2, 1,1)
angleslayout.addItem(qtw.QSpacerItem(16,16, qtw.QSizePolicy.Minimum, qtw.QSizePolicy.Expanding), 12,0, 1,3)
tabs.addTab(anglespanel, "Distances")
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# info/settings tab
infopanel = qtw.QWidget()
......@@ -722,12 +929,15 @@ class TasGUI:
self.KiKfChanged()
self.comboA3ConvChanged()
#self.QChanged()
self.KiKfChanged_angles()
dlg.show()
app.exec_()
# save settings
sett.setValue("qtas/geo", dlg.saveGeometry())
sett.setValue("qtas/a", self.getfloat(self.editA.text()))
sett.setValue("qtas/b", self.getfloat(self.editB.text()))
sett.setValue("qtas/c", self.getfloat(self.editC.text()))
......@@ -740,6 +950,7 @@ class TasGUI:
sett.setValue("qtas/bx", self.getfloat(self.editBx.text()))
sett.setValue("qtas/by", self.getfloat(self.editBy.text()))
sett.setValue("qtas/bz", self.getfloat(self.editBz.text()))
sett.setValue("qtas/dm", self.getfloat(self.editDm.text()))
sett.setValue("qtas/da", self.getfloat(self.editDa.text()))
sett.setValue("qtas/h", self.getfloat(self.edith.text()))
......@@ -750,7 +961,19 @@ class TasGUI:
sett.setValue("qtas/kf", self.getfloat(self.editKf.text()))
sett.setValue("qtas/a3_conv", self.comboA3.currentIndex())
sett.setValue("qtas/a4_sense", self.checkA4Sense.isChecked())
sett.setValue("qtas/geo", dlg.saveGeometry())
sett.setValue("qtas/h1", self.getfloat(self.edith1.text()))
sett.setValue("qtas/k1", self.getfloat(self.editk1.text()))
sett.setValue("qtas/l1", self.getfloat(self.editl1.text()))
sett.setValue("qtas/ki1", self.getfloat(self.editKi1.text()))
sett.setValue("qtas/kf1", self.getfloat(self.editKf1.text()))
#sett.setValue("qtas/E1", self.getfloat(self.editE1.text()))
sett.setValue("qtas/h2", self.getfloat(self.edith2.text()))
sett.setValue("qtas/k2", self.getfloat(self.editk2.text()))
sett.setValue("qtas/l2", self.getfloat(self.editl2.text()))
sett.setValue("qtas/ki2", self.getfloat(self.editKi2.text()))
sett.setValue("qtas/kf2", self.getfloat(self.editKf2.text()))
#sett.setValue("qtas/E2", self.getfloat(self.editE2.text()))
# -----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment