def dict_to_colfile(c): titles = list(c.keys()) nrows = len(c[titles[0]]) for t in titles: assert len(c[t]) == nrows, t colf = columnfile.newcolumnfile(titles=titles) colf.nrows = nrows colf.set_bigarray([c[t] for t in titles]) return colf
def tocolumnfile(self): """ Return a columnfile """ cof = columnfile.newcolumnfile(self.alltitles) dlist = [self.data[t] for t in self.alltitles] cof.bigarray = numpy.array(dlist, numpy.float) cof.nrows = len(self.data[self.alltitles[0]]) cof.ncols = len(self.alltitles) cof.set_attributes() return cof
allpeaks[key] = mytransformer.colfile.bigarray[:,i] nold = nold + 1 else: nnew = nnew + 1 allpeaks[key] = mytransformer.colfile.bigarray[:,i] print("total peaks",len(list(allpeaks.keys())), "ignored", nignore, "new",nnew, "replacements",nold) assert nignore + nold + nnew == mytransformer.colfile.nrows keys = list(allpeaks.keys()) keys.sort() c = newcolumnfile( titles ) assert len(titles) == len(allpeaks[keys[0]]) bigarray = [allpeaks[k] for k in keys] c.bigarray = numpy.array(bigarray).T print(c.bigarray.shape) c.nrows = len(keys) c.set_attributes() c.setcolumn(numpy.array(list(range(len(keys)))),"spot3d_id") c.writefile( outf ) mytransformer = transformer.transformer() mytransformer.loadfileparameters( pars )
U12.append(U[0, 1]) U13.append(U[0, 2]) U21.append(U[1, 0]) U22.append(U[1, 1]) U23.append(U[1, 2]) U31.append(U[2, 0]) U32.append(U[2, 1]) U33.append(U[2, 2]) eps11.append(eps[0]) eps12.append(eps[1]) eps13.append(eps[2]) eps22.append(eps[3]) eps23.append(eps[4]) eps33.append(eps[5]) gff = ic.newcolumnfile(titles) gff.ncols = len(titles) gff.nrows = len(grainno) gff.bigarray = n.zeros((gff.ncols, gff.nrows)) gff.set_attributes() gff.addcolumn(grainno, "grainno") gff.addcolumn(x, "x") gff.addcolumn(y, "y") gff.addcolumn(z, "z") gff.addcolumn(rodx, "rodx") gff.addcolumn(rody, "rody") gff.addcolumn(rodz, "rodz") gff.addcolumn(U11, "U11") gff.addcolumn(U12, "U12") gff.addcolumn(U13, "U13") gff.addcolumn(U21, "U21")
def ubi_to_gff(ubi,par): from ImageD11 import grain as ig from ImageD11 import parameters as ip from string import split from xfab import tools from six.moves import range list_of_grains = ig.read_grain_file(ubi) p = ip.parameters() p.loadparameters(par) uc = [p.parameters['cell__a'],p.parameters['cell__b'],p.parameters['cell__c'],p.parameters['cell_alpha'],p.parameters['cell_beta'],p.parameters['cell_gamma']] #print(uc) grainno = [] x = [] y = [] z = [] rodx = [] rody = [] rodz = [] unitcell_a = [] unitcell_b = [] unitcell_c = [] unitcell_alpha = [] unitcell_beta = [] unitcell_gamma = [] U11 = [] U12 = [] U13 = [] U21 = [] U22 = [] U23 = [] U31 = [] U32 = [] U33 = [] eps11 = [] eps22 = [] eps33 = [] eps23 = [] eps13 = [] eps12 = [] titles = ["grainno","x","y","z","rodx","rody","rodz","U11","U12","U13","U21","U22","U23","U31","U32","U33","unitcell_a","unitcell_b","unitcell_c","unitcell_alpha","unitcell_beta","unitcell_gamma","eps11","eps22","eps33","eps23","eps13","eps12"] for i in range(len(list_of_grains)): if hasattr(list_of_grains,'name') == False: grainno.append(i) elif hasattr(list_of_grains,'name') == True: grainno.append(eval(split(list_of_grains[i].name,':')[0])) x.append(list_of_grains[i].translation[0]/1000.) y.append(list_of_grains[i].translation[1]/1000.) z.append(list_of_grains[i].translation[2]/1000.) ubi = list_of_grains[i].ubi (U,eps) = tools.ubi_to_u_and_eps(ubi,uc) uc_a, uc_b, uc_c, uc_alpha, uc_beta, uc_gamma = tools.ubi_to_cell(ubi) unitcell_a.append(uc_a) unitcell_b.append(uc_b) unitcell_c.append(uc_c) unitcell_alpha.append(uc_alpha) unitcell_beta.append(uc_beta) unitcell_gamma.append(uc_gamma) rod = tools.u_to_rod(U) rodx.append(rod[0]) rody.append(rod[1]) rodz.append(rod[2]) U11.append(U[0,0]) U12.append(U[0,1]) U13.append(U[0,2]) U21.append(U[1,0]) U22.append(U[1,1]) U23.append(U[1,2]) U31.append(U[2,0]) U32.append(U[2,1]) U33.append(U[2,2]) eps11.append(eps[0]) eps12.append(eps[1]) eps13.append(eps[2]) eps22.append(eps[3]) eps23.append(eps[4]) eps33.append(eps[5]) gff = cl.newcolumnfile(titles) gff.ncols = len(titles) gff.nrows = len(grainno) gff.bigarray = np.zeros((gff.ncols,gff.nrows)) gff.set_attributes() gff.addcolumn(grainno,"grainno") gff.addcolumn(x,"x") gff.addcolumn(y,"y") gff.addcolumn(z,"z") gff.addcolumn(rodx,"rodx") gff.addcolumn(rody,"rody") gff.addcolumn(rodz,"rodz") gff.addcolumn(U11,"U11") gff.addcolumn(U12,"U12") gff.addcolumn(U13,"U13") gff.addcolumn(U21,"U21") gff.addcolumn(U22,"U22") gff.addcolumn(U23,"U23") gff.addcolumn(U31,"U31") gff.addcolumn(U32,"U32") gff.addcolumn(U33,"U33") gff.addcolumn(unitcell_a,"unitcell_a") gff.addcolumn(unitcell_b,"unitcell_b") gff.addcolumn(unitcell_c,"unitcell_c") gff.addcolumn(unitcell_alpha,"unitcell_alpha") gff.addcolumn(unitcell_beta,"unitcell_beta") gff.addcolumn(unitcell_gamma,"unitcell_gamma") gff.addcolumn(eps11,"eps11") gff.addcolumn(eps22,"eps22") gff.addcolumn(eps33,"eps33") gff.addcolumn(eps23,"eps23") gff.addcolumn(eps13,"eps13") gff.addcolumn(eps12,"eps12") return gff, uc