Stellar Model Composition Data Extraction Script

This script is designed to walk through directories to find files with the extension '.track', extract specific pieces of stellar model data (e.g., Model #, Age, log Luminosity, etc.) from these files, and then compile this information into a Python dictionary. This dictionary, mapping model names to their respective composition data, is then serialized and saved as a pickle file. Additionally, the script reports the number of files skipped due to being below a certain size threshold.

import os
from pysep.io.trk import read_trk
import pandas as pd
from tqdm import tqdm
import sys
import pickle
trks = list()
for root, dirs, files in os.walk(sys.argv[1]):
    trkFiles = list(filter(lambda x: x.endswith(".track"), files))
    if trkFiles:
        trkFile = trkFiles[0]
        trks.append(os.path.join(root, trkFile))
temp, meta = read_trk(trks[0])
names = [x for x in temp[0].columns]
names.append("MODELName")
compInfo = dict()
skipped = 0
for trk in tqdm(trks):
    modelName = '.'.join(os.path.basename(trk).split('.')[:2])
    if not os.stat(trk).st_size < 1e4:
        trkContnent, metaContnent = read_trk(trk)
        trkContnent = trkContnent[0]
        comp = trkContnent[['Model_#', 'AGE', 'log_L', 'log_R', 'log_g', 'log_Teff', 'Xenv', 'Zenv', 'CA_He3', 'SA_He3']]
        compInfo[modelName] = comp
    else:
        skipped += 1
 
with open(f'{os.path.join(sys.argv[1], "composition.pkl")}', 'wb') as f:
    pickle.dump(compInfo, f)
print(skipped)