Skip to content

Commit

Permalink
First commit for cross section extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eitan Weinstein committed Aug 2, 2024
1 parent 1fac9f1 commit 9d88d95
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/DataLib/fendl32B_retrofit/process_fendl3.2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def main():
groupr_tools.cleanup_njoy_files()

pKZA = tp.extract_gendf_pkza(gendf_path)
# Extract MT values again from GENDF file as there may be some difference
# from the original MT values in the ENDF/PENDF files
endftk_file_obj, MTs = tp.extract_endf_specs(gendf_path, 'GENDF')
gendf_data = tp.iterate_MTs(MTs, endftk_file_obj, mt_dict, pKZA)

if __name__ == '__main__':
main()
94 changes: 91 additions & 3 deletions src/DataLib/fendl32B_retrofit/tendl_processing.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Import packages
import ENDFtk
import pandas as pd

def extract_endf_specs(path):
def extract_endf_specs(path, filetype = 'ENDF'):
"""
Extract the material ID and MT numbers from an ENDF file.
Arguments:
path (str): File path to the selected ENDF file.
filetype (str, optional): Either ENDF or GENDF (case insensitive).
Defaults to 'ENDF'.
Returns:
matb (int): Unique material ID extracted from the file.
MTs (list): List of reaction types (MT's) present in the file.
file (ENDFtk.tree.File or None): ENDFtk file object containing the
contents for a specific material's cross-section data.
Only returns the file for GENDF filetypes.
"""

tape = ENDFtk.tree.Tape.from_file(path)
Expand All @@ -21,7 +27,12 @@ def extract_endf_specs(path):
# Extract the MT numbers that are present in the file
MTs = [MT.MT for MT in file.sections.to_list()]

return matb, MTs
if filetype.lower() == 'gendf':
return file, MTs
else:
return matb, MTs

return (endf_specs)

def extract_gendf_pkza(gendf_path):
"""
Expand Down Expand Up @@ -49,4 +60,81 @@ def extract_gendf_pkza(gendf_path):
M = 1 if 'm' in A.lower() else 0
A = int(A.lower().split(' ')[0].split('m')[0])
pKZA = (Z * 1000 + A) * 10 + M
return pKZA
return pKZA

def extract_cross_sections(file, MT):
"""
Parse through the contents of a GENDF file section to extract the
cross-section data for a specific reaction type (MT).
Arguments:
file (ENDFtk.tree.File): ENDFtk file object containing a specific
material's cross-section data.
MT (int): Numerical identifier for the reaction type corresponding to
the file's sectional organization.
Returns:
sigma_list (list): All of the cross-sections for a given reaction type
and material, listed as floating point numbers. If the run fails,
the function will just return an empty list.
"""

section = file.section(MT).content

# Only every 2nd line starting at the 3rd line has cross-section data.
lines = section.split('\n')[2:-2:2]

# Extract the 3rd token and convert to more conventional string
# representation of a float
sigma_list = [
float(line.split(' ')[2].replace('+','E+').replace('-','E-'))
for line in lines
]

return sigma_list

def iterate_MTs(MTs, file_obj, mt_dict, pKZA):
"""
Iterate through all of the MTs present in a given GENDF file to extract
the necessary data to be able to run ALARA.
Arguments:
MTs (list of int): List of reaction types present in the GENDF file.
file_obj (ENDFtk.tree.File): ENDFtk file object containing the
contents for a specific material's cross-section data.
mt_dict (dict): Dictionary formatted data structure for mt_table.csv
pKZA (int): Parent KZA identifier.
Returns:
gendf_data (pandas.core.frame.DataFrame): Pandas DataFrame containing
parent KZA values, daughter KZA values, emitted particles,
counts of the number of non-zero groups in the Vitamin-J groupwise
structure, and the cross-section values for those groups.
"""

cross_sections_by_MT = []
emitted_particles_list = []
dKZAs = []
groups = []

for MT in MTs:
sigma_list = extract_cross_sections(file_obj, MT)
if mt_dict[MT]['delKZA'] == 'N/A':
dKZA = 'N/A'
else:
dKZA = pKZA - mt_dict[MT]['delKZA']
emitted_particles = mt_dict[MT]['Emitted Particles']
cross_sections_by_MT.append(sigma_list)
dKZAs.append(dKZA)
emitted_particles_list.append(emitted_particles)
groups.append(len(sigma_list))

gendf_data = pd.DataFrame({
'Parent KZA' : [pKZA] * len(dKZAs),
'Daughter KZA' : dKZAs,
'Emitted Particles' : emitted_particles_list,
'Non-Zero Groups' : groups,
'Cross Sections' : cross_sections_by_MT
})

return gendf_data

0 comments on commit 9d88d95

Please sign in to comment.