def addcellpeaks(self, limit=None): """ Adds unit cell predicted peaks for fitting against Optional arg limit gives highest angle to use Depends on parameters: 'cell__a','cell__b','cell__c', 'wavelength' # in angstrom 'cell_alpha','cell_beta','cell_gamma' # in degrees 'cell_lattice_[P,A,B,C,I,F,R]' """ # # Given unit cell, wavelength and distance, compute the radial positions # in microns of the unit cell peaks # pars = self.parameterobj.get_parameters() cell = [ pars[name] for name in [ 'cell__a', 'cell__b', 'cell__c', 'cell_alpha', 'cell_beta', 'cell_gamma' ] ] lattice = pars['cell_lattice_[P,A,B,C,I,F,R]'] if "tth" not in self.colfile.titles: self.compute_tth_eta() # Find last peak in radius if limit is None: highest = numpy.maximum.reduce(self.getcolumn("tth")) else: highest = limit w = pars['wavelength'] ds = 2 * numpy.sin(transform.radians(highest) / 2.) / w self.dslimit = ds self.unitcell = unitcell.unitcell(cell, lattice) # If the space group is provided use xfab for generate unique hkls if 'cell_sg' in pars: self.theorypeaks = self.unitcell.gethkls_xfab(ds, pars['cell_sg']) tths = [] self.theoryds = [] for i in range(len(self.theorypeaks)): tths.append(2 * numpy.arcsin(w * self.theorypeaks[i][0] / 2.)) self.theoryds.append(self.theorypeaks[i][0]) else: # HO: I have removed this part as it seems redundant ringds also calls gethkls # JPW: It was not redundant. theorypeaks is not defined anywhere else and you # can't write a g-vector file without it. self.theorypeaks = self.unitcell.gethkls(ds) self.unitcell.makerings(ds) self.theoryds = self.unitcell.ringds tths = [ numpy.arcsin(w * dstar / 2) * 2 for dstar in self.unitcell.ringds ] self.theorytth = transform.degrees(numpy.array(tths))
def gof(self, args): """ Compute how good is the fit of obs/calc peak positions in tth """ self.applyargs(args) # Here, pars is a dictionary of name/value pairs to pass to compute_tth_eta tth, eta = self.compute_tth_eta() w = self.parameterobj.get("wavelength") gof = 0. npeaks = 0 for i in range(len(self.tthc)):# (twotheta_rad_cell.shape[0]): self.tthc[i] = transform.degrees(math.asin(self.fitds[i] * w / 2) * 2) diff = numpy.take(tth, self.indices[i]) - self.tthc[i] # print "peak",i,"diff",maximum.reduce(diff),minimum.reduce(diff) gof = gof + numpy.sum(diff * diff) npeaks = npeaks + len(diff) gof = gof / npeaks return gof * 1e6