import numpy as np import helper #runs = [5,6] runs = [3,4,7,8,9] for run in runs: filename = helper.getparam("filenames", run) hist = np.zeros((1621, 141, 141)) counts = np.zeros((1621, 141, 141)) for i_block in xrange(9): hist[i_block*162:(i_block+1)*162, :, :] = np.load(\ "data_hklmat/%s_hist_%04d.npy"%(filename, i_block)) counts[i_block*162:(i_block+1)*162, :, :] = np.load(\ "data_hklmat/%s_counts_%04d.npy"%(filename, i_block)) i_block = 9 hist[i_block*162:, :, :] = np.load(\ "data_hklmat/%s_hist_%04d.npy"%(filename, i_block)) counts[i_block*162:, :, :] = np.load(\ "data_hklmat/%s_counts_%04d.npy"%(filename, i_block)) np.save("data_hklmat/%s_hist.npy"%(filename), hist) np.save("data_hklmat/%s_counts.npy"%(filename), counts) print "done run %d" % run
matplotlib.rcParams['mathtext.fontset'] = 'cm' import matplotlib.pyplot as plt plt.rc('font', family='serif', size=12) plt.rcParams['xtick.top'] = plt.rcParams['ytick.right'] = True plt.ion() from matplotlib.gridspec import GridSpec from scipy.interpolate import griddata from settings import a0, hist_bincenters, hist_binedges, a0_reciprocal from settings import Rlist, Rlist_colors, R_edges, R_barwidth from settings import slices import helper runs = [4, 3, 8, 9, 7] for i_run, run in enumerate(runs): filename = helper.getparam("filenames", run) sample = helper.getparam("samples", run) hist = np.load("data_hklmat/%s_hist.npy" % filename) counts = np.load("data_hklmat/%s_counts.npy" % filename) nx, ny, nz = hist.shape intensities = hist[:,:,68:73].sum(axis=2) * \ 1./counts[:,:,68:73].sum(axis=2) xx, yy = np.meshgrid(range(nx), range(ny), indexing='ij') coords = np.array([xx.ravel(), yy.ravel()]).T intensities = intensities.ravel() mask = np.isnan(intensities) intensities[mask] = griddata(coords[~mask], intensities[~mask], coords[mask],
import numpy as np import helper import os, sys import matplotlib.pyplot as plt from pprint import pprint runs = [3, 4] for run in runs: filename = helper.getparam('filenames', run) times_array = [] for root, dirs, files in os.walk(os.getcwd()+"/data"): if filename in files: for line in open(root+'/'+filename, 'r'): if line.startswith("#T "): times_array.append(float(line.split(' ')[1])) break # found the file, so stop looping through directory if len(times_array) != 81*7: print "file %s is wrong!" % filename continue plt.semilogy(times_array[0::7], label="0") pprint(zip(range(81), times_array[0::7])) plt.semilogy(times_array[3::7], label="3") plt.legend() plt.show() np.save("times/%s_times.npy"%filename, times_array)
runs = [4, 3, 8, 9, 7] qarray = hist_bincenters[0] * a0_reciprocal xmin, xmax = hist_binedges[1][0] * a0_reciprocal, hist_binedges[1][ -1] * a0_reciprocal ymin, ymax = hist_binedges[0][0] * a0_reciprocal, hist_binedges[0][ -1] * a0_reciprocal ## plot the 2d images fig = plt.figure(figsize=(6, 8)) grid = ImageGrid(fig, 111, nrows_ncols=(1,5), axes_pad=0.15, \ share_all=True, cbar_location='right', \ cbar_mode='single', cbar_size="15%", cbar_pad=0.15) for i_run, run in enumerate(runs): ax = grid[i_run] filename = helper.getparam("filenames", run) sample = helper.getparam("samples", runs[i_run]) orimat = np.load("orimats/%s.npy" % (helper.getparam("orimats", run))) data_orig = np.load("data_hklmat/%s_interpolated_xy.npy" % filename) im = ax.imshow(np.log10(data_orig), extent=[xmin, xmax, ymin, ymax], \ origin='lower', interpolation='nearest', \ vmax=3.0) if do_plotsurface: surf_norm = orimat.dot(qvec(50., 25., 90., 0.)) surf_norm = surf_norm / np.linalg.norm(surf_norm) print "hkl of surface =", surf_norm surf_norm = orimat.dot(qvec(60., 30., 90., 45.)) surf_norm = surf_norm / np.linalg.norm(surf_norm) print "hkl of surface =", surf_norm, "(to check if th and phi matters)" xx = np.array([-1., 1.]) * surf_norm.dot(e1)
import numpy as np import helper from orimat import angs_phifix run = 3 orimat = np.load("orimats/%s.npy" % (helper.getparam("orimats", run))) print helper.getparam("orimats", run) print angs_phifix(2, 2, 0.025, 0., orimat)
import numpy as np import sys from orimat import kivec, qvec, qvec_array from settings import imshape import time import matplotlib.pyplot as plt import helper runs = [3, 4, 7, 8, 9] hkl_centers = [] for run in runs: filename = helper.getparam("filenames", run) orimat = np.load("orimats/%s.npy" % (helper.getparam("orimats", run))) surf_norm = orimat.dot(qvec(50., 25., 90., 0.)) # th and phi don't really matter surf_norm = surf_norm / np.linalg.norm(surf_norm) print "starting run %d, filename=%s, orimat=" % (\ run, filename) print orimat i_scan = 1 now = time.time() while True: try: for i_file in [0, 1]: f = np.load("data_npz/%s_scan%d_%04d.npz"%(\ filename, i_scan, i_file)) tth = float(np.asscalar(f['tth'])) th = float(np.asscalar(f['th'])) chi = float(np.asscalar(f['chi']))
fitrg = (-0.7, 0.7) indmin, indmax = np.searchsorted(q, fitrg) q = q[indmin:indmax] C = C[indmin:indmax] np.save("fit/q.npy", q) np.save("fit/C.npy", C) ## load run 4 data to estimate error intensities0 = np.zeros((len(slices), indmax-indmin)) for i_s, (yind, zind, qperp) in enumerate(slices): intensities0[i_s] = np.load("fit/run4_slice_%s.npy"%(i_s)) intensities_err = (intensities0.max(axis=0) - intensities0.min(axis=0))*0.5 fig, ax = plt.subplots(1, 1, figsize=(10, 3.5)) for i_run, run in enumerate(runs): sample = helper.getparam('samples', run) data = [] data_err = [] data_fit = [] for i_s, (yind, zind, qperp) in enumerate(slices): if qperp != 'qperp_0p010': continue print "slice %d, yind = %d, zind = %d, %s" % (i_s, yind, zind, qperp) ## load theoretical data theory_dir = "fit/%s/" % qperp q4I_th = [] for looptype in ['int', 'vac']: for R in Rlist: ## load theoretical data _data = np.load(theory_dir+"R%d_0_%s.npz"%(R, looptype))['q4I'] ## multiply by form factor
fig_tot, ax_tot = plt.subplots(1, 1, figsize=(5, 4)) ax_tot.errorbar(-10, 0, 0, fmt='go', fillstyle='none', capsize=5, label='vac') ax_tot.errorbar(-10, 0, 0, fmt='bs', capsize=5, label='int') ## Figure for average radius fig_R, ax_R = plt.subplots(1, 1, figsize=(5, 4)) ax_R.errorbar(-10, 0, 0, fmt='go', fillstyle='none', capsize=5, label='vac') ax_R.errorbar(-10, 0, 0, fmt='bs', capsize=5, label='int') ## File for output f_table = open("fit_results.csv", 'w') f_table.write("csum in 1/atom, tot in 1/atom, Ravg in Angstrom\n\n") f_table.write("DPA\ttype\tcsum\t+\t-\ttot\t+\t-\tRavg\t+\t-\n") runs = [3, 8, 9, 7] for i_run, (run, ax1, ax2) in enumerate(zip(runs, axes1, axes2)): sample = helper.getparam('samples', run) dpa = helper.getdpa(sample) cs_int = np.zeros((len(slices), len(Rlist))) cs_vac = np.zeros((len(slices), len(Rlist))) cs_int_err = np.zeros((len(slices), len(Rlist))) cs_vac_err = np.zeros((len(slices), len(Rlist))) dcR2_int = np.zeros((len(slices), len(Rlist))) dcR2_vac = np.zeros((len(slices), len(Rlist))) tot_int = np.zeros(len(slices)) tot_vac = np.zeros(len(slices)) R_ave_int = np.zeros(len(slices)) R_ave_vac = np.zeros(len(slices)) R_ave_all = np.zeros(len(slices)) i_s_ave = [] # indices to take the average