Astronomical Isochrone Fitting and Visualization Script

This Python script is used for fitting and visualizing isochrone models in astrophysical research. It loads fitting results from a pickle file, performs isochrone age interpolation, applies bolometric corrections, and generates scatter plots comparing observed photometric data with theoretical isochrone models for different filters. The script also handles directory creation for saving the generated figures.

from fidanka.isochrone.isochrone import interp_isochrone_age
from fidanka.isofit.fit import bol_correct_iso
 
import matplotlib.pyplot as plt
import pickle as pkl
import numpy as np
import os
import shutil
 
figRoot = "./BestFitFigures"
 
if os.path.exists(figRoot):
    shutil.rmtree(figRoot)
os.mkdir(figRoot)
 
with open("./fitResults.denseAlpha.pkl", 'rb') as f:
    fitResults = pkl.load(f)
 
phot = fitResults['phot']
color = phot["F275W"] - phot["F814W"]
mag = phot["F814W"]
 
for bfA, bfE in zip(fitResults['bf']['A'], fitResults['bf']['E']):
    isoAAtAge = interp_isochrone_age(bfA[6], bfA[1][0])
    isoEAtAge = interp_isochrone_age(bfE[6], bfE[1][0])
 
    isoAColor, isoAMags = bol_correct_iso(
            isoAAtAge,
            bfA[5],
            filters=("F275W", "F814W", "F814W"),
            Av = bfA[1][2],
            distance = bfA[1][1]
            )
    isoEColor, isoEMags = bol_correct_iso(
            isoEAtAge,
            bfE[5],
            filters=("F275W", "F814W", "F814W"),
            Av = bfE[1][2],
            distance = bfE[1][1]
            )
    fig, ax = plt.subplots(1, 1, figsize=(10, 7))
    ax.scatter(color, mag, s=1, c='k')
    ax.plot(isoAColor, isoAMags, c='r', label="A")
    ax.plot(isoEColor, isoEMags, c='b', label="E")
    ax.invert_yaxis()
    ax.legend(loc='best')
    ax.set_xlabel("F275W - F814W")
    ax.set_ylabel("F814W")
    ax.set_title("Age: {:.2f} Gyr".format(bfA[1][0]))
 
    plt.savefig(os.path.join(figRoot, "bestFit_{:.2f}.png".format(bfA[1][0])))
    plt.close()