def plot_90deg_summary(): # load data data29 = load_data(join(datapath, f66029)) # 90 degrees data57 = load_data(join(datapath, f66057)) # 90 degrees data58 = load_data(join(datapath, f66058)) # 90 degrees data_1hour = data57 + data58 # get monitor counts mon57 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66057)[0])) mon58 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66058)[0])) mon29 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66029)[0])) simulation = get_simulation() axes_limits = ba.get_axes_limits(simulation.result(), ba.AxesUnits.QSPACE) qy = np.linspace(axes_limits[0], axes_limits[1], data29.shape[0]) simulation_1 = get_simulation(u0=46.0) axes_limits_1 = ba.get_axes_limits(simulation_1.result(), ba.AxesUnits.QSPACE) qy_1hour = np.linspace(axes_limits_1[0], axes_limits_1[1], data57.shape[0]) sum_29 = np.sum(data29, axis=0) / mon29 sum_1hour = np.sum(data_1hour, axis=0) / (mon57 + mon58) plt.style.use('seaborn-talk') plt.subplot(1, 2, 1) plt.semilogy(qy, sum_29, color='k', marker='o', markersize=5, linestyle='None', label=r"Over the night") plt.semilogy(qy_1hour, sum_1hour, color='b', marker='s', markersize=5, linestyle='None', label=r"1 hour") plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$I$ (a. u.)') plt.ylim([2.0e-07, 5.0e-06]) plt.title(r"Sample rotation $90^\circ$ summary", fontsize=16) plt.legend(loc='upper right', fontsize=14) plt.subplot(1, 2, 2) img = plt.imread(join(datapath, 'rot90deg.jpg')) plt.imshow(img) plt.axis('off') plt.show()
def plot_45deg_summary(): # load data data28 = load_data(join(datapath, f66028)) # 45 degrees # get monitor counts mon28 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66028)[0])) simulation = get_simulation() axes_limits = ba.get_axes_limits(simulation.result(), ba.AxesUnits.QSPACE) qy = np.linspace(axes_limits[0], axes_limits[1], data28.shape[0]) sum_28 = np.sum(data28, axis=0) / mon28 plt.style.use('seaborn-talk') plt.subplot(1, 2, 1) plt.semilogy(qy, sum_28, color='k', marker='o', markersize=5, linestyle='None', label=r"Over the night") plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$I$ (a. u.)') plt.ylim([2.0e-07, 2.0e-06]) plt.title(r"Sample rotation $45^\circ$ summary", fontsize=16) plt.legend(loc='upper right', fontsize=14) plt.subplot(1, 2, 2) img = plt.imread(join(datapath, 'rot45deg.jpg')) plt.imshow(img) plt.axis('off') plt.show()
def get_i_of_q(data, nbins=256): """ calculates I(Q) where Q = sqrt(Qx^2 + Qy^2) :param data: :return: """ simulation = get_simulation() result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) shape = data.shape x = np.linspace(axes_limits[0], axes_limits[1], shape[0]) y = np.linspace(axes_limits[2], axes_limits[3], shape[1]) # xx, yy = np.meshgrid (x, y) # q = np.sqrt(xx**2 + yy**2) # result = np.array([q.flatten(), data.flatten()]).transpose() result = [] for i in range(shape[0]): for j in range(shape[1]): q = np.sqrt(x[i]**2 + y[j]**2) result.append([q, data[i, j]]) result = np.array(result) # sort data result = result[result[:, 0].argsort()] # bin data bins = np.linspace(0.0, np.max(q), nbins) indices = np.digitize(result[:, 0], bins) a = [] for i in range(bins.size): idx = np.where(indices == i) if idx[0].size > 0: a.append([bins[i], np.mean(result[:, 1][idx])]) return np.array(a)
def plot_s3278_2d(): fname = "0006543{r1}_000{r2}_p15749_S3278-GiSANS-0.6dgr-rot-scan-m15-15dgr_HRD_standard.{ext}" runs = [(0, 1), (1, 1), (2, 2), (3, 3), (4, 4), (5, 1), (6, 2), (7, 3), (8, 0)] simulation = get_simulation() result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) plt.style.use('seaborn-talk') plt.suptitle("Sample S3278 SDD=1300 mm", fontsize=16) for i in runs: data = load_data( join(datapath, fname.format(r1=i[0], r2=i[1], ext='det'))) omega = get_rotation_angle( join(datapath, fname.format(r1=i[0], r2=i[1], ext='yaml'))) ax = plt.subplot(3, 3, i[0] + 1) plt.subplots_adjust(wspace=0.2, hspace=0.3) im = plt.imshow(data, norm=matplotlib.colors.LogNorm(0.1, 1000), extent=axes_limits, aspect='auto', cmap='jet') cb = plt.colorbar(im) # plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$Q_z$ (nm$^{-1}$)') plt.title(r"Run 0006543{n}, $\omega={om}^\circ$".format(n=i[0], om=omega)) plt.show()
def plot_all_2d(): data65952 = load_data(join(datapath, f65952)) data65953 = load_data(join(datapath, f65953)) data66023 = load_data(join(datapath, f66023)) data66024 = load_data(join(datapath, f66024)) data66028 = load_data(join(datapath, f66028)) data66029 = load_data(join(datapath, f66029)) data66055 = load_data(join(datapath, f66055)) data66057 = load_data(join(datapath, f66057)) data66058 = load_data(join(datapath, f66058)) datalist = [(65952, data65952), (65953, data65953), (66023, data66023), (66024, data66024), (66028, data66028), (66029, data66029), (66055, data66055), (66057, data66057), (66058, data66058)] simulation = get_simulation() result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) plt.style.use('seaborn-talk') plt.suptitle("Sample S3098 SDD=9200 mm", fontsize=16) i = 1 for run, data in datalist: ax = plt.subplot(3, 3, i) plt.subplots_adjust(wspace=0.2, hspace=0.3) im = plt.imshow(data, norm=matplotlib.colors.LogNorm(0.1, 50), extent=axes_limits, aspect='auto', cmap='jet') cb = plt.colorbar(im) # plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$Q_z$ (a. u.)') plt.title(r"Run {}".format(run)) i += 1 plt.show()
def plot_all_1d(): data65952 = load_data(join(datapath, f65952)) data65953 = load_data(join(datapath, f65953)) data66023 = load_data(join(datapath, f66023)) data66024 = load_data(join(datapath, f66024)) data66028 = load_data(join(datapath, f66028)) data66029 = load_data(join(datapath, f66029)) data66055 = load_data(join(datapath, f66055)) data66057 = load_data(join(datapath, f66057)) data66058 = load_data(join(datapath, f66058)) datalist = [(65952, data65952), (65953, data65953), (66023, data66023), (66024, data66024), (66028, data66028), (66029, data66029), (66055, data66055), (66057, data66057), (66058, data66058)] simulation = get_simulation() result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) plt.style.use('seaborn-talk') plt.suptitle("Sample S3098 SDD=9200 mm", fontsize=16) i = 1 for run, data in datalist: plt.subplot(3, 3, i) plt.subplots_adjust(wspace=0.2, hspace=0.3) qy = np.linspace(axes_limits[0], axes_limits[1], data.shape[0]) counts = np.sum(data, axis=0) plt.semilogy(qy, counts, color='k', marker='o', markersize=5, linestyle='None') plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$I$ (a. u.)') plt.title(r"Run {}".format(run)) i += 1 plt.show()
def plot_0deg_summary(): # load data data23 = load_data(join(datapath, f66023)) # 0 degrees data24 = load_data(join(datapath, f66024)) # 0 degrees data55 = load_data(join(datapath, f66055)) # 0 degrees data52 = load_data(join(datapath, f65952)) # 0 degrees data53 = load_data(join(datapath, f65953)) # 0 degrees data_large_slit = data52 + data53 data_small_slit = data23 + data24 # get monitor counts mon55 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66055)[0])) mon23 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66023)[0])) mon24 = get_monitor_counts("{}.yaml".format(os.path.splitext(f66024)[0])) mon52 = get_monitor_counts("{}.yaml".format(os.path.splitext(f65952)[0])) mon53 = get_monitor_counts("{}.yaml".format(os.path.splitext(f65953)[0])) simulation = get_simulation() axes_limits = ba.get_axes_limits(simulation.result(), ba.AxesUnits.QSPACE) qy = np.linspace(axes_limits[0], axes_limits[1], data23.shape[0]) simulation_1 = get_simulation(u0=45.0) axes_limits_1 = ba.get_axes_limits(simulation_1.result(), ba.AxesUnits.QSPACE) qy_1hour = np.linspace(axes_limits_1[0], axes_limits_1[1], data55.shape[0]) sum_large_slit = np.sum(data_large_slit, axis=0) / (mon52 + mon53) sum_small_slit = np.sum(data_small_slit, axis=0) / (mon23 + mon24) sum_1hour = np.sum(data55, axis=0) / mon55 plt.style.use('seaborn-talk') plt.subplot(1, 2, 1) plt.semilogy(qy, sum_small_slit, color='k', marker='o', markersize=5, linestyle='None', label=r"Small slit") plt.semilogy(qy, sum_large_slit, color='b', marker='s', markersize=5, linestyle='None', label=r"Large slit") plt.semilogy(qy_1hour, sum_1hour, color='g', marker='*', markersize=5, linestyle='None', label=r"1 hour") plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$I$ (a. u.)') plt.ylim([2.0e-07, 4.0e-05]) plt.title(r"Sample rotation $0^\circ$ summary", fontsize=16) plt.legend(loc='upper right', fontsize=14) plt.subplot(1, 2, 2) img = plt.imread(join(datapath, 'rot0deg.jpg')) plt.imshow(img) plt.axis('off') plt.show()
def plot_summary(): data00deg = load_data(join(datapath, f66023)) # 0 degrees data45deg = load_data(join(datapath, f66028)) # 45 degrees data90deg = load_data(join(datapath, f66029)) # 90 degrees simulation = get_simulation() result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) qy = np.linspace(axes_limits[0], axes_limits[1], data00deg.shape[0]) sum00deg = np.sum(data00deg, axis=0) sum45deg = np.sum(data45deg, axis=0) sum90deg = np.sum(data90deg, axis=0) mon00deg = get_monitor_counts("{}.yaml".format( os.path.splitext(f66023)[0])) mon45deg = get_monitor_counts("{}.yaml".format( os.path.splitext(f66028)[0])) mon90deg = get_monitor_counts("{}.yaml".format( os.path.splitext(f66029)[0])) plt.semilogy(qy, sum00deg / mon00deg, color='k', marker='o', markersize=5, linestyle='None', label=r"$\omega=0^\circ$") plt.semilogy(qy, sum45deg / mon45deg, color='b', marker='s', markersize=5, linestyle='None', label=r"$\omega=45^\circ$") plt.semilogy(qy, sum90deg / mon90deg, color='g', marker='*', markersize=5, linestyle='None', label=r"$\omega=90^\circ$") ymin, ymax = 2e-07, 2.5e-06 plt.axvline(x=0.0125, color='yellow', linestyle='--') plt.axvline(x=0.02, color='yellow', linestyle='--') plt.fill_between(qy, ymin, ymax, where=np.logical_and(qy >= 0.0125, qy <= 0.02), facecolor='yellow', alpha=0.3) plt.text(0.0135, 1.2e-06, "300-500 nm", fontsize=14) plt.axvline(x=0.003, color='0.7', linestyle=':') plt.axvline(x=0.006, color='0.7', linestyle=':') plt.fill_between(qy, ymin, ymax, where=np.logical_and(qy >= 0.003, qy <= 0.006), facecolor='0.7', alpha=0.3) plt.text(0.003, 6.0e-07, r"1-2 $\mu$m", fontsize=14) plt.axvline(x=-0.0125, color='yellow', linestyle='--') plt.axvline(x=-0.02, color='yellow', linestyle='--') plt.text(-0.019, 1.2e-06, "300-500 nm", fontsize=14) plt.fill_between(qy, ymin, ymax, where=np.logical_and(qy >= -0.02, qy <= -0.0125), facecolor='yellow', alpha=0.3) plt.axvline(x=-0.003, color='0.7', linestyle=':') plt.axvline(x=-0.006, color='0.7', linestyle=':') plt.fill_between(qy, ymin, ymax, where=np.logical_and(qy >= -0.006, qy <= -0.003), facecolor='0.7', alpha=0.3) plt.text(-0.006, 6.0e-07, r"1-2 $\mu$m", fontsize=14) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$I$ (a. u.)') plt.ylim([ymin, ymax]) plt.title(r"Sample rotation summary") plt.legend(loc='upper right', fontsize=14) plt.show()
def plot_sim_qspace(expdata, title, radius=150.0, d=1000.0, zmin=1.0e-09): simulation = get_simulation() # experimental data s_hist = simulation.result().histogram2d(ba.AxesUnits.QSPACE) s_hist.setContent(expdata) # run simulation sample = get_sample(radius=radius, d=d) simulation.setSample(sample) simulation.setTerminalProgressMonitor() simulation.runSimulation() result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) # plot the result plt.style.use('seaborn-talk') grid = plt.GridSpec(2, 2, wspace=0.4, hspace=0.3) # ============== # experimental data # =============== ax = plt.subplot(grid[0, 0]) plt.subplots_adjust(wspace=0.2, hspace=0.3) im = plt.imshow(s_hist.array(), norm=matplotlib.colors.LogNorm(zmin, 01.0e-06), extent=axes_limits, aspect='auto', cmap='jet') cb = plt.colorbar(im) plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$Q_x$ (nm$^{-1}$)') plt.title("{} experiment".format(title)) # ============== # Simulation # =============== ax = plt.subplot(grid[0, 1]) plt.subplots_adjust(wspace=0.2, hspace=0.3) im = plt.imshow(result.array(), norm=matplotlib.colors.LogNorm(zmin, 01.0e-06), extent=axes_limits, aspect='auto', cmap='jet') cb = plt.colorbar(im) plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$Q_x$ (nm$^{-1}$)') plt.title("Simulation") # ======= # I(Q) # ======= plt.subplot(grid[1, 0:]) qy = np.array(result.axis(0, ba.AxesUnits.QSPACE)) exp_slice = np.mean(s_hist.array(), axis=0) sim_slice = np.mean(result.array(), axis=0) plt.semilogy(qy, exp_slice, color='k', marker='.', markersize=7, linestyle='None', label='Experiment') plt.semilogy(qy, sim_slice, color='b', linestyle='-', label='Simulation') plt.axvline(x=0.003, color='0.7', linestyle='--', linewidth=1) plt.axvline(x=0.0055, color='r', linestyle='--', linewidth=1) plt.axvline(x=0.006, color='0.7', linestyle='--', linewidth=1) plt.annotate(r'{} $\mu$m'.format(1.14), xy=(0.0055, 1.3e-07), xytext=(0.007, 4.0e-07), fontsize=14, arrowprops=dict(facecolor='red', shrink=0.0, width=0.5, headwidth=4)) plt.axvline(x=0.020, color='g', linestyle='--', linewidth=1) plt.annotate(r'{} nm'.format(314), xy=(0.02, 0.17e-07), xytext=(0.017, 0.4e-07), fontsize=14, arrowprops=dict(facecolor='green', shrink=0.0, width=0.5, headwidth=4)) plt.axvline(x=0.0115, color='g', linestyle='--', linewidth=1) plt.annotate(r'{} nm'.format(546), xy=(0.0115, 0.17e-07), xytext=(0.013, 0.4e-07), fontsize=14, arrowprops=dict(facecolor='green', shrink=0.0, width=0.5, headwidth=4)) plt.fill_between(qy, 0, 1, where=np.logical_and(qy >= 0.0029, qy <= 0.0061), facecolor='0.7', alpha=0.5) plt.xlim(0.0, 0.024) plt.ylim(1.0e-10, 1.0e-06) # plt.ticklabel_format(style='sci', axis='x', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$I(Q_y)$, a.u.') plt.legend(loc='upper right', fontsize=18) plt.title(r"Integrated over $Q_x$") plt.show()
def plot_s3098_1deg(ai=1.2): fname = '00065{r}_00{s:02d}_p15749_SiO2,_Si,_Au,_Cu_SiO2,_Si,_Au,_Cu_HRD_standard.{ext}' runs = range(1) # put 22 to view the all 22 files simulation = get_simulation(ai=ai, v0=30.2) result = simulation.result() axes_limits = ba.get_axes_limits(result, ba.AxesUnits.QSPACE) # ROI, nm^-1 xmin, ymin, xmax, ymax = -0.05, 0.02, 0.05, 0.17 qSi = calc_q(ai, a_Si) qAu = calc_q(ai, a_Au) qCu = calc_q(ai, a_Cu) plt.style.use('seaborn-talk') grid = plt.GridSpec(2, 2, wspace=0.4, hspace=0.3) for i in runs: data = load_data( join(datapath, fname.format(r=483 + i, s=i, ext='det'))) omega = get_rotation_angle( join(datapath, fname.format(r=483 + i, s=i, ext='yaml'))) plt.suptitle(r"Run 00065{n}, $\omega={om}^\circ$".format(n=483 + i, om=omega), fontsize=16) # =================== # raw data # =================== plt.subplot(grid[0, 0]) plt.subplots_adjust(wspace=0.2, hspace=0.3) im = plt.imshow(data, norm=matplotlib.colors.LogNorm(0.1, 500), extent=axes_limits, aspect='auto', cmap='jet') cb = plt.colorbar(im) # plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$Q_z$ (nm$^{-1}$)') plt.title(r"Raw data") # =================== # raw data ROI # =================== plt.subplot(grid[0, 1]) plt.subplots_adjust(wspace=0.2, hspace=0.3) hist = result.histogram2d(ba.AxesUnits.QSPACE) hist.setContent(data) h = hist.crop(xmin, ymin, xmax, ymax) im = plt.imshow(h.array(), norm=matplotlib.colors.LogNorm(0.1, 500), extent=[xmin, xmax, ymin, ymax], aspect='auto', cmap='jet') cb = plt.colorbar(im) plt.axhline(y=qSi, color='0.3', linestyle='--', linewidth=1) plt.axhline(y=qAu, color='b', linestyle='--', linewidth=1) plt.axhline(y=qCu, color='g', linestyle='--', linewidth=1) # plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.ylabel(r'$Q_z$ (nm$^{-1}$)') plt.title(r"Raw data (ROI)") # =================== # qz slice (degrees) # =================== plt.subplot(grid[1, 0]) plt.subplots_adjust(wspace=0.2, hspace=0.3) hist = result.histogram2d(ba.AxesUnits.DEGREES) hist.setContent(data) zslice = hist.projectionY(0.0) plt.semilogy(zslice.getBinCenters(), zslice.getBinValues(), color='k', marker='o', markersize=5, linestyle='None') plt.axvline(x=ai, color='r', linestyle='--') plt.annotate(r'$\alpha_i={}^\circ$'.format(ai), xy=(ai, 300), xytext=(0.9, 500), fontsize=14, arrowprops=dict(facecolor='red', shrink=0.0, width=0.5, headwidth=4)) plt.xlabel(r'$\alpha_f$ ($^{\circ}$)') plt.title(r"Slice along $\alpha_f$") # =================== # qy slice (nm^-1) # =================== plt.subplot(grid[1, 1]) plt.subplots_adjust(wspace=0.2, hspace=0.3) hist = result.histogram2d(ba.AxesUnits.QSPACE) hist.setContent(data) ysliceSi = hist.projectionX(qSi) ysliceCu = hist.projectionX(qCu) ysliceAu = hist.projectionX(qAu) plt.semilogy(ysliceSi.getBinCenters(), ysliceSi.getBinValues(), color='0.3', marker='o', markersize=7, linestyle='None', label=r'$Q_c(Si)={:.3f} $'.format(qSi) + r'nm$^{-1}$') plt.semilogy(ysliceAu.getBinCenters(), ysliceAu.getBinValues(), color='b', marker='s', markersize=7, linestyle='None', label=r'$Q_c$(Au)={:.3f} '.format(qAu) + r'nm$^{-1}$') plt.semilogy(ysliceCu.getBinCenters(), ysliceCu.getBinValues(), color='g', marker='*', markersize=9, linestyle='None', label=r'$Q_c$(Cu)={:.3f} '.format(qCu) + r'nm$^{-1}$') plt.xlim([0.0, 0.2]) plt.ylim([0.7, 10]) plt.xlabel(r'$Q_y$ (nm$^{-1}$)') plt.title(r"Slices along $Q_y$") plt.legend(loc='upper right', fontsize=12) plt.show()