Stellar Abundance Conversion Script
This script is designed to convert hydrogen and metal mass fractions (X and Z) into the standard stellar abundance metrics: [Fe/H], [alpha/H], and a(He). It employs a serialized interpolation function to calculate these values and supports optional validation of the conversion through an external program. Key functionalities include loading the interpolation function, executing the conversion, and optionally performing validation checks with output parsing and cleaning.
from generateTOPStables import convert_XYZ_FeHAlphaHaHe, call_num_frac, parse_abundance_file, format_TOPS_string import argparse import pickle import os mass = { 'H': 1.0080, 'He': 4.0030, 'C': 12.011, 'N': 14.007, "O": 15.9999, "Ne": 20.180, "Na": 22.99, "Mg": 24.305, "Al": 26.982, "Si": 28.086, "P": 30.974, "S": 32.065, "Cl": 35.453, "Ar": 39.948, "Ca": 40.078, "Ti": 47.867, "Cr": 51.996, "Mn": 54.938, "Fe": 55.845, "Ni": 58.693, "Li": 6.693, "Be": 9.0122, "B": 10.811 } if __name__ == "__main__": parser = argparse.ArgumentParser(description="Convert XYZ to the requisite [Fe/H], [alpha/H], and a(He) values") parser.add_argument("interpF", type=str, help="Path to serialised interpolation function") parser.add_argument("X", type=float, help="Hydrogen mass fraction") parser.add_argument("Z", type=float, help="Metal mass fraction") parser.add_argument("--validationProgram", type=str, help="num frac program to use for validation") args = parser.parse_args() f = pickle.load(open(args.interpF, 'rb')) results = convert_XYZ_FeHAlphaHaHe(f,args.X, args.Z) if args.validationProgram: status = call_num_frac(args.validationProgram, "ValidationOutput.tmp", results[0], 0.0, results[1], force=True) if int(status) == 0: massFraction, X, Y, Z = parse_abundance_file("ValidationOutput.tmp") numberFractions = list(map(lambda x: (x[0], x[1]/mass[x[0]], x[2]), massFraction)) print('===========mass fractions================') print(format_TOPS_string(massFraction)) print("=========================================") if os.path.exists("ValidationOutput.tmp"): os.remove("ValidationOutput.tmp") print(f"To get X={args.X} Y={1-args.X-args.Z} Z={args.Z} use [Fe/H]={results[0]}, [alpha/H]=0.0, and a(He)={results[1]}") print(f"New X={X}, new Y={Y}, and new Z={Z}") print(f"{((X-args.X)/args.X)*100}% change in X and {((Z-args.Z)/args.Z)*100}% change in Z") else: print(f"To get X={args.X} Y={1-args.X-args.Z} Z={args.Z} use [Fe/H]={results[0]}, [alpha/H]=0.0, and a(He)={results[1]}")