本文整理汇总了Python中nexpy.gui.datadialogs.GridParameters.values方法的典型用法代码示例。如果您正苦于以下问题:Python GridParameters.values方法的具体用法?Python GridParameters.values怎么用?Python GridParameters.values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nexpy.gui.datadialogs.GridParameters
的用法示例。
在下文中一共展示了GridParameters.values方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OrientationDialog
# 需要导入模块: from nexpy.gui.datadialogs import GridParameters [as 别名]
# 或者: from nexpy.gui.datadialogs.GridParameters import values [as 别名]
#.........这里部分代码省略.........
message_box.setWindowTitle('%s Peak Table' % self.entry.nxtitle)
message_box.adjustSize()
message_box.show()
self.plotview = None
def plot_peak(self):
row = self.table_view.currentIndex().row()
data = self.entry.data
x, y, z = [self.table_view.model().peak_list[row][i] for i in range(1, 4)]
xmin, xmax = max(0,x-200), min(x+200,data.nxsignal.shape[2])
ymin, ymax = max(0,y-200), min(y+200,data.nxsignal.shape[1])
zmin, zmax = max(0,z-200), min(z+200,data.nxsignal.shape[0])
zslab=np.s_[z,ymin:ymax,xmin:xmax]
if self.plotview is None:
self.plotview = NXPlotView('X-Y Projection')
self.plotview.plot(data[zslab], log=True)
self.plotview.crosshairs(x, y)
def orient(self):
self.refine.primary = int(self.primary_box.text())
self.refine.secondary = int(self.secondary_box.text())
self.refine.Umat = self.refine.get_UBmat(self.refine.primary,
self.refine.secondary) \
* self.refine.Bimat
self.update_table()
def refine_orientation(self):
idx = self.refine.idx
intensities = self.refine.intensity[idx]
sigma = np.average(intensities) / intensities
p0 = self.set_parameters(idx)
def diffs(p):
self.get_parameters(p)
UBimat = np.linalg.inv(self.refine.UBmat)
Q = [UBimat * self.Gvec[i] for i in idx]
dQ = Q - np.rint(Q)
return np.array([np.linalg.norm(self.refine.Bmat*np.matrix(dQ[i]))
for i in idx]) / sigma
popt, C, info, msg, success = leastsq(diffs, p0, full_output=1)
self.get_parameters(popt)
self.update_lattice()
self.update_table()
self.status_text.setText('Score: %.4f' % self.refine.score())
def restore_orientation(self):
self.refine.Umat = self.Umat
for par in self.lattice.values():
par.value = par.init_value
self.update_table()
def update_table(self):
self.refine.hkl_tolerance = np.float32(self.tolerance_box.text())
self.table_model.peak_list = self.refine.get_peaks()
rows, columns = len(self.table_model.peak_list), 11
self.table_model.dataChanged.emit(self.table_model.createIndex(0, 0),
self.table_model.createIndex(rows-1, columns-1))
self.status_text.setText('Score: %.4f' % self.refine.score())
def update_lattice(self):
self.lattice['a'].value = self.refine.a
self.lattice['b'].value = self.refine.b
self.lattice['c'].value = self.refine.c
self.lattice['alpha'].value = self.refine.alpha
self.lattice['beta'].value = self.refine.beta
self.lattice['gamma'].value = self.refine.gamma
def set_parameters(self, idx):
x, y, z = self.refine.xp[idx], self.refine.yp[idx], self.refine.zp[idx]
self.Gvec = [self.refine.Gvec(xx,yy,zz) for xx,yy,zz in zip(x,y,z)]
self.Umat = self.refine.Umat
pars = []
for par in self.lattice.values():
par.init_value = par.value
if par.vary:
pars.append(par.value)
p0 = np.zeros(shape=(len(pars)+9), dtype=np.float32)
p0[:len(pars)] = pars
p0[len(pars):] = np.ravel(self.refine.Umat)
return p0
def get_parameters(self, p):
i = 0
for par in self.lattice.values():
if par.vary:
par.value = p[i]
i += 1
self.refine.a, self.refine.b, self.refine.c, \
self.refine.alpha, self.refine.beta, self.refine.gamma = \
[par.value for par in self.lattice.values()]
self.refine.set_symmetry()
self.refine.Umat = np.matrix(p[i:]).reshape(3,3)
def save_orientation(self):
self.write_parameters()
def write_parameters(self):
try:
self.refine.write_parameters()
except NeXusError as error:
report_error('Defining Orientation', error)
示例2: MakeDialog
# 需要导入模块: from nexpy.gui.datadialogs import GridParameters [as 别名]
# 或者: from nexpy.gui.datadialogs.GridParameters import values [as 别名]
class MakeDialog(BaseDialog):
def __init__(self, parent=None):
super(MakeDialog, self).__init__(parent)
self.scans = None
self.set_layout(self.directorybox("Choose Sample Directory",
self.choose_sample),
self.textboxes(('Scan Command', 'Pil2Mscan')),
self.action_buttons(('Select All', self.select_scans),
('Reverse All', self.reverse_scans),
('Clear All', self.clear_scans),
('Make Scan Macro', self.make_scans)),
self.close_buttons(close=True))
self.set_title('Make Scans')
def choose_sample(self):
super(MakeDialog, self).choose_directory()
self.sample_directory = self.get_directory()
self.experiment_directory = os.path.dirname(os.path.dirname(self.sample_directory))
self.macro_directory = os.path.join(self.experiment_directory, 'macros')
self.label = os.path.basename(self.sample_directory)
self.sample = os.path.basename(os.path.dirname(self.sample_directory))
self.experiment = os.path.basename(self.experiment_directory)
self.experiment_path = self.experiment
self.scan_path = os.path.join(self.experiment, self.sample, self.label)
self.setup_scans()
def setup_scans(self):
if self.scans:
self.scans.delete_grid()
self.scans = GridParameters()
all_files = [self.sample+'_'+d+'.nxs'
for d in os.listdir(self.sample_directory)
if os.path.isdir(os.path.join(self.sample_directory, d))]
filenames = sorted([f for f in all_files
if os.path.exists(os.path.join(self.sample_directory, f))],
key=natural_sort)
for i, f in enumerate(filenames):
scan = 'f%d' % i
self.scans.add(scan, i+1, f, True, self.update_scans)
self.scans[scan].checkbox.stateChanged.connect(self.update_scans)
self.insert_layout(2, self.scans.grid(header=False))
@property
def scan_list(self):
scan_list = []
for scan in self.scans.values():
if scan.checkbox.isChecked() and scan.value > 0:
scan_list.append(scan)
else:
scan.value = 0
return sorted(scan_list, key=attrgetter('value'))
def update_scans(self):
scan_list = self.scan_list
scan_number = 0
for scan in scan_list:
scan_number += 1
scan.value = scan_number
for scan in self.scans.values():
if scan.checkbox.isChecked() and scan.value == 0:
scan.value = scan_number + 1
scan_number += 1
def select_scans(self):
for i, scan in enumerate(self.scans):
self.scans[scan].value = i+1
self.scans[scan].checkbox.setChecked(True)
def reverse_scans(self):
for i, scan in enumerate(reversed(self.scan_list)):
scan.value = i+1
scan.checkbox.setChecked(True)
def clear_scans(self):
for scan in self.scans:
self.scans[scan].value = 0
self.scans[scan].checkbox.setChecked(False)
def make_scans(self):
scans = [scan.label.text() for scan in self.scan_list]
scan_command = self.textbox['Scan Command'].text()
scan_parameters = ['#command path filename temperature detx dety ' +
'phi_start phi_step phi_end chi omega frame_rate']
for scan in self.scan_list:
nexus_file = scan.label.text()
root = nxload(os.path.join(self.sample_directory, nexus_file))
temperature = root.entry.sample.temperature
base_name = os.path.basename(os.path.splitext(nexus_file)[0])
scan_dir = base_name.replace(self.sample+'_', '')
for entry in [root[e] for e in root if e != 'entry']:
if 'phi_set' in entry['instrument/goniometer']:
phi_start = entry['instrument/goniometer/phi_set']
else:
phi_start = entry['instrument/goniometer/phi']
phi_step = entry['instrument/goniometer/phi'].attrs['step']
phi_end = entry['instrument/goniometer/phi'].attrs['end']
if 'chi_set' in entry['instrument/goniometer']:
chi = entry['instrument/goniometer/chi_set']
else:
#.........这里部分代码省略.........