Astrophysical Model Analysis Script

The content is a Python script designed for analyzing astrophysical models, specifically by iterating through files with a '.dsep' extension within a directory structure, extracting specific parameters such as effective temperature (Teff) and luminosity (L) from both preliminary (prems) and main sequence evolutionary point (iso) models of stars based on their mass. Additionally, the script generates a visual comparison of these parameters between the preliminary and evolutionary models in the form of a two-panel plot, saved as a PDF file.

# coding: utf-8
 
from pysep.dsep import load_model
import re
from pathlib import Path
import matplotlib.pyplot as plt
results = dict()
for path in Path(".").rglob("*.dsep"):
    base = path.parts[0]
    mass = re.findall(r"M(0\.\d+)", base)[0]
    model, tdir = load_model(path)
    prems_header = model.premsf['header']
    premsRes = {"log_Teff": prems_header['log_Teff'], 'log_L': prems_header['log_L']}
    try:
        iso = model['iso']
        modelRes = {"log_Teff": iso.iloc[0]['Log_T'], 'log_L': iso.iloc[0]['Log_L']}
    except IndexError:
        modelRes = {"log_Teff": None, "log_L": None}
    results[mass] = {"model": modelRes, "prems": premsRes}
fResults = dict(filter(lambda x: bool(x[1]['model']['log_Teff']), results.items()))
fig, ax = plt.subplots(2,1, figsize=(14, 7))
for mass, comp in fResults.items():
    ax[0].plot([float(mass)], [comp['model']['log_Teff']], 'ko')
    ax[0].plot([float(mass)], [comp['prems']['log_Teff']], 'k+')
    ax[1].plot([float(mass)], [comp['model']['log_L']], 'ko')
    ax[1].plot([float(mass)], [comp['prems']['log_L']], 'k+')
ax[0].set_xlabel("mass"); ax[0].set_ylabel("log Teff")
ax[1].set_ylabel("Log L")
plt.savefig("prems_model_first_ev_model_comp.pdf", bbox_inches="tight")