def _get_reader(self, filename, fobj): from ufit.data import data_formats, data_formats_image if self.format == 'auto': for n, m in iteritems(data_formats): # check 'simple' formats last if not n.startswith('simple') and m.check_data(fobj): return m, n in data_formats_image for n, m in iteritems(data_formats): if n.startswith('simple') and m.check_data(fobj): return m, n in data_formats_image raise UFitError('File %r has no recognized file format' % filename) return data_formats[self.format], self.format in data_formats_image
def getPts(self): retpts = [] for name, sp in iteritems(self.sps): # if (self.pt == PlaneType.h0lplane and sp[self.cz] == 0): # only points in this plane if (np.dot(PlaneType.GetVector(self.pt), sp) == 0): if (self.pt == PlaneType.h0lplane or self.pt == PlaneType.hhlplane): vec = [sp[0], sp[2]] elif (self.pt == PlaneType.hk0plane): vec = sp[:2] else: raise NotImplementedError pts = [] # print name, sp for gpt in self.gpts: pts.append(gpt + vec) pts.append(gpt - vec) pts.append(gpt + vec * inva) pts.append(gpt - vec * inva) if (self.pt == PlaneType.hk0plane): # tetragonal vec.reverse() pts.append(gpt + vec) pts.append(gpt - vec) pts.append(gpt + vec * inva) pts.append(gpt - vec * inva) retpts.append(np.array(pts)) return retpts
def update_enables(self, *ignored): for p, ctls in iteritems(self.param_controls): # if there is an expr... if ctls[4].currentText(): # disable value and minmax, check "fixed" and disable "fixed" ctls[1].setEnabled(False) ctls[3].setCheckState(Qt.PartiallyChecked) # implicitly fixed ctls[3].setEnabled(False) ctls[5].setEnabled(False) ctls[6].setEnabled(False) ctls[7].setEnabled(False) # else, if "fixed" is checked... elif ctls[3].checkState() == Qt.Checked: # enable value, but disable expr and minmax ctls[1].setEnabled(True) ctls[4].setEnabled(False) ctls[5].setEnabled(False) ctls[6].setEnabled(False) ctls[7].setEnabled(False) # else: not fixed, no expr else: # enable everything ctls[1].setEnabled(True) ctls[3].setEnabled(True) ctls[3].setCheckState(Qt.Unchecked) ctls[3].setTristate(False) ctls[4].setEnabled(True) ctls[5].setEnabled(True) ctls[6].setEnabled(True) ctls[7].setEnabled(True)
def update_from_controls(self): for p, ctls in iteritems(self.param_controls): _, val, _, fx, expr, pmin, pmax, delta = ctls p.value = float(val.text()) if val.text() else 0 if fx.checkState() == Qt.Checked: p.expr = str(val.text()) else: p.expr = str(expr.currentText()) p.pmin = float(pmin.text()) if pmin.text() else None p.pmax = float(pmax.text()) if pmax.text() else None p.delta = float(delta.text()) if delta.text() else 0 self.update_enables() session.set_dirty()
def prepare_params(params, meta): # find parameters that need to vary dependent = {} varying = [] varynames = [] for p in params: if p.initexpr: try: p.value = param_eval(p.initexpr, {'data': meta}) except Exception: pass # can happen for heterogeneous data collections if p.expr: dependent[p.name] = [p.expr, None] else: varying.append(p) varynames.append(p.name) pd = dict((p.name, p.value) for p in varying) pd.update(expr_namespace) pd['data'] = meta # poor man's dependency tracking of parameter expressions dep_order = [] maxit = len(dependent) + 1 while dependent: maxit -= 1 if maxit == 0: s = '\n'.join(' %s: %s' % (k, v[1]) for (k, v) in iteritems(dependent)) raise UFitError('Detected unresolved parameter dependencies:\n' + s) for p, (expr, _) in listitems(dependent): # dictionary will change try: pd[p] = param_eval(expr, pd) except NameError as e: dependent[p][1] = str(e) except AttributeError as e: dependent[p][1] = 'depends on data.' + str(e) else: del dependent[p] dep_order.append((p, expr)) # pd.pop('__builtins__', None) return varying, varynames, dep_order, pd
def getLines(self): def additem(col, main, v): col.append([main + v, np.arctan2(*(v))]) retpts = [] for gpt in self.gpts: pts = [] for name, sp in iteritems(self.sps): if (np.dot(PlaneType.GetVector(self.pt), sp) == 0): # only points in this plane if (self.pt == PlaneType.h0lplane or self.pt == PlaneType.hhlplane): vec = [sp[0], sp[2]] elif (self.pt == PlaneType.hk0plane): vec = sp[:2] else: raise NotImplementedError additem(pts, gpt, vec) vec[:] = [-x for x in vec] additem(pts, gpt, vec) vec = list(vec * inva) additem(pts, gpt, vec) vec[:] = [-x for x in vec] additem(pts, gpt, vec) if (self.pt == PlaneType.hk0plane): # tetragonal vec.reverse() additem(pts, gpt, vec) vec[:] = [-x for x in vec] additem(pts, gpt, vec) vec = list(vec * inva) additem(pts, gpt, vec) vec[:] = [-x for x in vec] additem(pts, gpt, vec) # pts.sort() # ptdict = {} # for pt in pts: # ptdict[pt[1]] = pt[0] pts = sorted(pts, key=lambda s: s[1]) pts = np.array(pts)[:, 0] pts = np.array(list(pts)) retpts.append(pts) return retpts
def datavalues(self): d = dict((k, [v]) for (k, v) in iteritems(self[0].data.meta)) for res in self[1:]: for k, v in iteritems(res.data.meta): d[k].append(v) return d
sympoints = { "Gamma": [0, 0, 0], "X": [0, 0, 0.5], "N": [0, 0.5, 0], "Z": [0.5, 0.5, -0.5], "P": [0.25, 0.25, 0.25], "Y": [-zeta, zeta, 0.5], "Y1": [0.5, 0.5, -zeta], "Sigma": [-eta, eta, eta], "Sigma1": [eta, 1 - eta, -eta], } init_printing() def mult(x, a, b, c): return x[0] * a + x[1] * b + x[2] * c print(b1, b2, b3) print() init_printing() for n, sp in iteritems(sympoints): h = simplify(mult(sp, b1, b2, b3)[0] * a / 2 / pi) k = simplify(mult(sp, b1, b2, b3)[1] * a / 2 / pi) l = simplify(mult(sp, b1, b2, b3)[2] * c / 2 / pi) print("%s\t%s\t%s\t%s" % (n, h, k, l))