def calc_roi(self): edges = np.geomspace(*self.region, 1e6) midpoints = (edges[1:] + edges[:-1]) / 2 widths = (edges[1:] - edges[:-1]) flux = select_flux_spectrum(self.source, 1)[2] rectangles = self.func(midpoints) * flux(midpoints) * widths rectangles = rectangles / np.sum(rectangles) cdf_vals = np.cumsum(rectangles) cdf = interp1d(midpoints, cdf_vals, fill_value=(rectangles[0], rectangles[-1])) l, r = self.findroot(0.05, cdf), self.findroot(0.95, cdf) return l, r
def plot(self, power): flux = select_flux_spectrum(self.source, 1)[2] fig = plt.figure(1) ax = fig.add_subplot(111) ax.set_xlim(*self.region) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlabel('E eV') ax.set_ylabel('R(E) barns cm$^{-1}$s$^{-1}$eV$^{-1}$') x = np.geomspace(*self.region, 1000) y = self.func(x) * flux(x) * power ax.plot(x, y, 'k', linewidth=1.5) fig.savefig('plot/{}.png'.format(self.plotname), dpi=300)
def calc_1g_xs(self, power): flux = select_flux_spectrum(self.source, 1)[2] def rr(e): return flux(e) * self.func(e) space = np.geomspace(*self.region, 1000) top = 0 bot = 0 for i in range(len(space) - 1): top += quad(rr, space[i], space[i + 1])[0] bot += quad(flux, space[i], space[i + 1])[0] return top / bot, bot * power
def discretize(self, eb): response_function = np.empty(len(eb[1:])) binned_flux = np.empty(len(eb[1:])) flux = select_flux_spectrum(self.source, 1)[2] def rr(e): return flux(e) * self.func(e) for g in range(len(eb[1:])): space = np.geomspace(eb[g], eb[g + 1], 100) top = 0 bot = 0 for i in range(len(space) - 1): top += quad(rr, space[i], space[i + 1])[0] bot += quad(flux, space[i], space[i + 1])[0] response_function[g] = top / bot binned_flux[g] = bot return response_function, binned_flux
if __name__ == "__main__": from flux_spectrum import Flux from master_data import isos, img_directory from response import generate_responses from multigroup_utilities import energy_groups, plot_multigroup_data from flux import select_flux_spectrum import matplotlib.pyplot as plt from nice_plots import init_nice_plots init_nice_plots() isos_cd = ['u233cd113', 'u235cd113', 'pu238cd113', 'pu239cd113', 'pu241cd113'] isos_gd = ['u233gd155', 'u235gd155', 'pu238gd155', 'pu239gd155', 'pu241gd155'] struct = 'wims69' phi_triga = select_flux_spectrum('trigaC', 1)[2] # added for testing # flux = Flux(7, 600.0) # phi_triga = flux.evaluate name = 'test_wims69_resp.p' resp = generate_responses(isos+isos_cd+isos_gd, phi_triga, struct=struct, name=name, overwrite=True) R = integral_response(name) RF = resp['response'] phi_ref = resp['phi'] phi_ref = phi_ref / sum(phi_ref) eb = resp['eb'] isos_1 = ['u235', 'u238', 'th232'] isos_2 = ['u235', 'u238', 'th232', 'np237', 'pu238']
def amalgamate(experimentname, element_names, foil_library, source, P): source_sf = 1 if source == 'triga_nebp': source_sf = 1e-4 # nice plotting rc('font', **{'family': 'serif'}) rcParams['xtick.direction'] = 'out' rcParams['ytick.direction'] = 'out' rcParams['xtick.labelsize'] = 12 rcParams['ytick.labelsize'] = 12 rcParams['lines.linewidth'] = 1.0 rcParams['axes.labelsize'] = 15 rcParams.update({'figure.autolayout': True}) # set up environment fig = plt.figure(101, figsize=(8, 4.5)) ax1 = fig.add_subplot(111) ax1.set_xscale('log') ax1.set_yscale('log') ax1.set_xlim(1E-5, 1E9) ax1.set_ylim(1E2 * source_sf, 1E18 * source_sf) ax1.set_xlabel('Energy (eV)') ax1.set_ylabel('$\Phi$ ($cm^{-2}s^{-1}$)') ax2 = ax1.twinx() ax2.set_yscale('log') ax2.set_xlim(1E-5, 1E9) ax2.set_ylim(1E-6, 1E8) ax2.set_ylabel('$\sigma$ ($barns$)') # flux x = np.logspace(-5, 8, 1000) flux = select_flux_spectrum(source, P)[2] y = flux(x) ax1.plot(x, y, 'k', label='$\Phi$') colors = [ 'green', 'gold', 'red', 'blue', 'indigo', 'fuchsia', 'black', 'coral', 'slategrey', 'darkcyan', 'blueviolet', 'lawngreen', 'lightsalmon', 'maroon', 'cyan', 'papayawhip', 'chocolate', 'darkkhaki' ] linestyles = [ ':', '--', '-', ':', '-.', ':', '--', '-', ':', '-.', '-', ':', '--', '-.', ':', '--', '-.', ':' ] resonance = [] threshold = [] for key, foil in foil_library.items(): if key in element_names: if foil.classification == 'resonance': resonance.append(foil) else: threshold.append(foil) resonance = sorted(resonance, key=lambda x: -(np.log(x.roi[1]) - np.log(x.roi[0]))) threshold = sorted(threshold, key=lambda x: np.log(x.roi[1]) - np.log(x.roi[0])) res_heights = np.array([1e3, 1e4, 1e5, 1e6, 1e7, 1e14, 1e15, 1e16, 1e17 ]) * 0.5 * source_sf thresh_heights = np.geomspace(1e10, 1e17, 8) * source_sf i = 0 new_resonance = [] for r in range(len(resonance)): new_resonance.append(res_heights[i]) if (r + 1) % 2: i += 1 i *= -1 res_heights = np.sort(new_resonance) for i, foil in enumerate(resonance): # cross section xs = foil.func region = foil.region reg = np.geomspace(*region, 1000)[:-1] ax2.plot(reg, xs(reg), color=colors[i], label=foil.label, linestyle=linestyles[i]) # region ax1.plot(foil.roi, [res_heights[i]] * 2, color=colors[i], linewidth=2.0) ax1.text(foil.roi[0] * 0.4, res_heights[i] * 2, foil.label) for i, foil in enumerate(threshold): l = len(resonance) # region ax1.plot(foil.roi, [thresh_heights[i]] * 2, color=colors[i + l], linewidth=2.0) ax1.text(foil.roi[0] * 0.1, thresh_heights[i] * 2, foil.label) # cross section xs = foil.func region = foil.region reg = np.geomspace(*region, 1000)[:-1] ax2.plot(reg, xs(reg), color=colors[i + l], label=foil.label, linestyle=linestyles[i + l]) fig.savefig('plot/amalgamated_{}.pdf'.format(experimentname))
def activity_calc(foil, m, P, t_i, t_ci, t_cf, t_f, detector, source, plotname='decay.png', node=1, experimentname='theoretical'): ''' Stuff. ''' # facts of life Na = 6.0221409E23 # atoms / mol # set up N_i N_i = np.zeros(2) N_i[0] = ((m * 1E-3 * Na) / foil.M) * foil.abundance # calculate decay constants with halflifes decay_constants = np.array([0, foil.decay_constant]) # load in spectrum phi = select_flux_spectrum(source, P)[node] def reaction_rate(e, phi, sigma): return (sigma(e) * 1E-24) * phi(e) R = np.zeros(2) R[0] = 1 total_phi = 0 e = np.logspace(-5, 9, 100) for i in range(len(e) - 1): total_phi += quad(phi, e[i], e[i + 1])[0] R[1] += quad(reaction_rate, e[i], e[i + 1], args=(phi, foil.func))[0] R[0] = 0 plot_xs(foil, phi) def decay(N, t, lam, t_i, R, P): ''' Radioactive decay. ''' phi_i = 1 # flux at a certain power # flux info if t < t_i: phi_0 = phi_i else: phi_0 = 0 A = np.diag(-lam) A[:, 0] = R * phi_0 return A.dot(N) # solve times = np.linspace(0, t_f, 10000) N = odeint(decay, N_i, times, args=(decay_constants, t_i, R, P)) activities = decay_constants * N # counting act_fun = interp1d(times, activities[:, 1], bounds_error=False, fill_value=0) raw = quad(act_fun, t_ci, t_cf)[0] detected = raw * foil.BR detected *= hpge_efficiency[detector](foil.erg) counts = detected # Bq to uCi activities *= (1 / 3.7E10) * 1E6 total_activity = np.sum(activities, axis=1) # print some info total_act_fun = interp1d(times, total_activity, bounds_error=False, fill_value=0) scram_act = total_act_fun(t_i) count_act = total_act_fun(t_ci) print('Counting Activity: {:4.2e} uCi'.format(float(count_act))) if plotname: plot_activities(foil, times, activities, experimentname, node) return counts, scram_act, count_act