def get_d2(filename, q2_max): with open(filename, 'rb') as f: table = pickle.load(f) q2_list = [] d2_list = [] ed2_list = [] for _, a_point in table.items(): x = a_point['x'] q2 = a_point['q2'] g2 = a_point['g2'] eg2 = a_point['eg2'] if q2 < 1.5 or q2 > q2_max or len(x) < 4: continue if eg2[0] > 0.01 * numpy.abs(g2[0]): x = x[1:] g2 = g2[1:] eg2 = eg2[1:] g1 = structure_f.g1p(x, q2) eg1 = g1 * experiments.e12_06_109(x, q2) # relative error x_l = numpy.linspace(1e-3, x[0], 50) g1_l = structure_f.g1p(x_l, q2) eg1_l = g1_l * 0.1 g2_l = structure_f.g2p(x_l, q2) eg2_l = g2_l * 0.1 d2_l, ed2_l = tools.g1g2_to_d2(x_l, g1_l, g2_l, eg1_l, eg2_l) x_h = numpy.linspace(x[-1], 1, 5) g1_h = structure_f.g1p(x_h, q2) eg1_h = g1_h * 0.1 g2_h = structure_f.g2p(x_h, q2) eg2_h = g2_h * 0.1 d2_h, ed2_h = tools.g1g2_to_d2(x_h, g1_h, g2_h, eg1_h, eg2_h) d2_0, ed2_0 = tools.g1g2_to_d2(x, g1, g2, eg1, eg2) d2 = d2_l + d2_0 + d2_h ed2 = numpy.sqrt(ed2_l**2 + ed2_0**2 + ed2_h**2) q2_list.append(q2) d2_list.append(d2) ed2_list.append(ed2) return q2_list, d2_list, ed2_list
with open('g2.pkl', 'wb') as f: pickle.dump(result, f) with PdfPages('x2g2_proj.pdf') as pdf: plt.figure(figsize=(6, 6)) ax = plt.gca() ax.axhline(y=0, linestyle='--', linewidth=0.75, color='k') plt.xlabel(r'$x$') plt.ylabel(r'$x^2g_2$') plt.xlim(0, 1) x_model = numpy.linspace(0, 1, 201) index_list = [5, 15, 25, 35, 45] color_list = ['k', 'r', 'b', 'g', 'c'] markers = [] texts = [] for color, index in zip(color_list, index_list): l1, = plt.plot( x_model, x_model**2 * structure_f.g2p(x_model, result[str(round(q2_list[index], 3))]['q2']), '{}-'.format(color), linewidth=0.75) x = result[str(q2_list[index])]['x'] g2 = result[str(q2_list[index])]['g2'] eg2 = result[str(q2_list[index])]['eg2'] p1 = plt.errorbar(x, x**2 * g2, x**2 * eg2, fmt='{}.'.format(color)) markers.append((p1, l1)) texts.append(r'${}<Q^2<{}$'.format(q2_edges[index], q2_edges[index + 1])) plt.legend(markers, texts) pdf.savefig(bbox_inches='tight') plt.close()
with open('g2.pkl', 'wb') as f: pickle.dump(result, f) x_model = numpy.linspace(0, 1, 201) with PdfPages('x2g2_proj.pdf') as pdf: plt.figure() ax = plt.gca() ax.axhline(y=0, linestyle='--', linewidth=0.75, color='k') plt.xlabel(r'$x$') plt.ylabel(r'$x^2g_2$') plt.xlim(0, 1) plt.ylim(-0.04, 0.01) l6, = plt.plot(x_model, x_model**2 * structure_f.g2p(x_model, 6), 'y-', linewidth=0.75) # q2 = 6 p6 = plt.errorbar(result['6']['x'], result['6']['x']**2 * result['6']['g2'], result['6']['x']**2 * result['6']['eg2'], fmt='y.') l5, = plt.plot(x_model, x_model**2 * structure_f.g2p(x_model, 5), 'b-', linewidth=0.75) # q2 = 5 p5 = plt.errorbar(result['5']['x'], result['5']['x']**2 * result['5']['g2'], result['5']['x']**2 * result['5']['eg2'], fmt='b.') l4, = plt.plot(x_model,
import matplotlib.pyplot as plt import numpy from pysolidg2p.structure_f import g1p, g2p x = numpy.linspace(0, 1, 101) with PdfPages('x2g1g2.pdf') as pdf: plt.figure() ax = plt.gca() ax.axhline(y=0, linestyle='--', linewidth=1, color='k') plt.xlabel(r'$x$') plt.ylabel(r'$x^2g_2$') plt.xlim(0, 1) plt.ylim(-0.03, 0.01) plt.plot(x, x**2 * g2p(x, 3), 'k-') # q2 = 3 plt.plot(x, x**2 * g2p(x, 4), 'r-') # q2 = 4 plt.plot(x, x**2 * g2p(x, 5), 'g-') # q2 = 5 plt.plot(x, x**2 * g2p(x, 6), 'b-') # q2 = 6 pdf.savefig(bbox_inches='tight') plt.close() fig = plt.figure() ax = plt.gca() ax.axhline(y=0, linestyle='--', linewidth=1, color='k') plt.xlabel(r'$x$') plt.ylabel(r'$x^2g_1$') plt.xlim(0, 1) plt.ylim(-0.005, 0.035) plt.plot(x, x**2 * g1p(x, 3), 'k-') # q2 = 3 plt.plot(x, x**2 * g1p(x, 4), 'r-') # q2 = 4