Loading Attenuation Codes/salt_attenuation.py 0 → 100644 +129 −0 Original line number Diff line number Diff line import os import numpy as np import matplotlib.pyplot as plt import pandas as pd from tabulate import tabulate attenuation_df = pd.read_excel('Attenuation_book.xlsx') print("Select the x-ray energy") #an easy way to choose incoming energy level print(tabulate([ [1,"1.00E-03" ],[2,"1.50E-03" ],[3,"2.00E-03" ],[4,"3.00E-03" ],[5,"4.00E-03" ], [6,"5.00E-03" ],[7,"6.00E-03" ],[8,"8.00E-03" ],[9,"1.00E-02" ],[10,"1.50E-02"], [11,"2.00E-02"],[12,"3.00E-02"],[13,"4.00E-02"],[14,"5.00E-02"],[15,"6.00E-02"], [16,"8.00E-02"],[17,"8.80E-02"],[18,"1.00E-01"],[19,"1.23E-01"],[20,"1.50E-01"],[21,"1.85E-01"], [22,"2.00E-01"],[23,"2.46E-01"],[24,"3.00E-01"],[25,"3.70E-01"],[26,"4.00E-01"], [27,"5.00E-01"],[28,"6.00E-01"],[29,"8.00E-01"],[30,"1.00E+00"],[31,"1.25E+00"], [32,"1.50E+00"],[33,"2.00E+00"],[34,"3.00E+00"],[35,"4.00E+00"],[36,"5.00E+00"], [37,"6.00E+00"],[38,"8.00E+00"],[39,"1.00E+01"],[40,"1.50E+01"],[41,"2.00E+01"]], headers=["Index","Energy (MeV)"], tablefmt="fancy_outline")) energy = int(input("Provide index: ")) if((energy > 0) and (energy <41)): print() #I couldn't figure out how to access the energy level from the table so I created a new list to store them for future calculations energies = [0.001, 0.0015, 0.002, 0.003, 0.004, 0.005, 0.006, 0.008, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.08, 0.088, 0.1, 0.123, 0.15, 0.185, 0.2, 0.246, 0.3, 0.370, 0.4, 0.5, 0.6, 0.8, 1, 1.25, 1.5, 2, 3, 4, 5, 6, 8, 10, 15, 20] incoming_energy = energies[energy-1] print("You selected " + str(incoming_energy) + " MeV") print() n = int(input("Enter the number of elements in your compound: ")) if(n < 1) or (n > 92): print() print("Please select a number of elements between 1 and 92") print() exit() print() element_list = [] contribution_list = [] #the elements and contribution by weights are stored in two separate lists that will be combined #they are printed for the user to ensure the correct elements and ratios #if an element has z > 92, the program will end, the excel file does not have data for elements z > 92 for i in range(0,n): el = str(input("Enter the name of element " + str(i + 1) + " (Ex. Lithium = Li): ")) cont = float(input("Enter the decimal contribution of this element by weight (Ex. 21% = 0.21): ")) print() if(cont < 0): print("There cannot be a negative contribution") print() exit() contribution_list.append(cont) element_list.append(el) #print(element_list) #print(contribution_list) if (sum(contribution_list) > 1.1): print("The sum of contributions must equal 1") print() exit() print() working_df = attenuation_df.loc[energy-1, element_list] #print(working_df) name = energy-1 last_element = element_list[-1] print() working_df = pd.DataFrame([working_df]) for index, element in enumerate(working_df.columns): working_df.loc['Contribution', element] = contribution_list[index] row_names = ['Attenuation', 'Contribution'] working_df = working_df.set_axis(row_names, axis = 'index') mult_df = working_df.cumprod(axis="index") mult_df = mult_df.cumsum(axis="columns") length = len(element_list)-1 ddp_attenuation = mult_df.iloc[1, length] print("The mass attenuation is " + str(round(ddp_attenuation, 4)) + " (cm^2/g)") print() density = float(input("Please enter the density of your compound (g/cm^3): ")) print() total_attenuation = ddp_attenuation * density print("The attenuation of the salt is " + str(round(total_attenuation,4)) + " (cm-^1).") print() distance = float(input("Please enter the thickness of your compound (cm): ")) print() raised = -1 * distance * total_attenuation unabs_energy = incoming_energy * np.exp(raised) percent = ((unabs_energy/incoming_energy)) * 100 percent = round(percent, 2) percent = str(percent) rounded_energy = round(unabs_energy, 4) print("The unabsorbed energy is " + str(rounded_energy) + " MeV.") print() print(percent + "% of incoming x-rays penetrate the sample") print() else: print("Help me out here. Please enter a valid index." ) No newline at end of file Loading
Attenuation Codes/salt_attenuation.py 0 → 100644 +129 −0 Original line number Diff line number Diff line import os import numpy as np import matplotlib.pyplot as plt import pandas as pd from tabulate import tabulate attenuation_df = pd.read_excel('Attenuation_book.xlsx') print("Select the x-ray energy") #an easy way to choose incoming energy level print(tabulate([ [1,"1.00E-03" ],[2,"1.50E-03" ],[3,"2.00E-03" ],[4,"3.00E-03" ],[5,"4.00E-03" ], [6,"5.00E-03" ],[7,"6.00E-03" ],[8,"8.00E-03" ],[9,"1.00E-02" ],[10,"1.50E-02"], [11,"2.00E-02"],[12,"3.00E-02"],[13,"4.00E-02"],[14,"5.00E-02"],[15,"6.00E-02"], [16,"8.00E-02"],[17,"8.80E-02"],[18,"1.00E-01"],[19,"1.23E-01"],[20,"1.50E-01"],[21,"1.85E-01"], [22,"2.00E-01"],[23,"2.46E-01"],[24,"3.00E-01"],[25,"3.70E-01"],[26,"4.00E-01"], [27,"5.00E-01"],[28,"6.00E-01"],[29,"8.00E-01"],[30,"1.00E+00"],[31,"1.25E+00"], [32,"1.50E+00"],[33,"2.00E+00"],[34,"3.00E+00"],[35,"4.00E+00"],[36,"5.00E+00"], [37,"6.00E+00"],[38,"8.00E+00"],[39,"1.00E+01"],[40,"1.50E+01"],[41,"2.00E+01"]], headers=["Index","Energy (MeV)"], tablefmt="fancy_outline")) energy = int(input("Provide index: ")) if((energy > 0) and (energy <41)): print() #I couldn't figure out how to access the energy level from the table so I created a new list to store them for future calculations energies = [0.001, 0.0015, 0.002, 0.003, 0.004, 0.005, 0.006, 0.008, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.08, 0.088, 0.1, 0.123, 0.15, 0.185, 0.2, 0.246, 0.3, 0.370, 0.4, 0.5, 0.6, 0.8, 1, 1.25, 1.5, 2, 3, 4, 5, 6, 8, 10, 15, 20] incoming_energy = energies[energy-1] print("You selected " + str(incoming_energy) + " MeV") print() n = int(input("Enter the number of elements in your compound: ")) if(n < 1) or (n > 92): print() print("Please select a number of elements between 1 and 92") print() exit() print() element_list = [] contribution_list = [] #the elements and contribution by weights are stored in two separate lists that will be combined #they are printed for the user to ensure the correct elements and ratios #if an element has z > 92, the program will end, the excel file does not have data for elements z > 92 for i in range(0,n): el = str(input("Enter the name of element " + str(i + 1) + " (Ex. Lithium = Li): ")) cont = float(input("Enter the decimal contribution of this element by weight (Ex. 21% = 0.21): ")) print() if(cont < 0): print("There cannot be a negative contribution") print() exit() contribution_list.append(cont) element_list.append(el) #print(element_list) #print(contribution_list) if (sum(contribution_list) > 1.1): print("The sum of contributions must equal 1") print() exit() print() working_df = attenuation_df.loc[energy-1, element_list] #print(working_df) name = energy-1 last_element = element_list[-1] print() working_df = pd.DataFrame([working_df]) for index, element in enumerate(working_df.columns): working_df.loc['Contribution', element] = contribution_list[index] row_names = ['Attenuation', 'Contribution'] working_df = working_df.set_axis(row_names, axis = 'index') mult_df = working_df.cumprod(axis="index") mult_df = mult_df.cumsum(axis="columns") length = len(element_list)-1 ddp_attenuation = mult_df.iloc[1, length] print("The mass attenuation is " + str(round(ddp_attenuation, 4)) + " (cm^2/g)") print() density = float(input("Please enter the density of your compound (g/cm^3): ")) print() total_attenuation = ddp_attenuation * density print("The attenuation of the salt is " + str(round(total_attenuation,4)) + " (cm-^1).") print() distance = float(input("Please enter the thickness of your compound (cm): ")) print() raised = -1 * distance * total_attenuation unabs_energy = incoming_energy * np.exp(raised) percent = ((unabs_energy/incoming_energy)) * 100 percent = round(percent, 2) percent = str(percent) rounded_energy = round(unabs_energy, 4) print("The unabsorbed energy is " + str(rounded_energy) + " MeV.") print() print(percent + "% of incoming x-rays penetrate the sample") print() else: print("Help me out here. Please enter a valid index." ) No newline at end of file