Automated Isolation Generation from Astrophysical Database Files

This Python script automatizes the process of generating isolation files from astrophysical database (.dbs) files related to stellar populations. It searches through a specified output directory for folders matching patterns indicative of stellar population data. For each found dataset, it verifies the existence of corresponding companion data (.dat) files within an input directory. The script then opens the database file in read mode, generates isolation data using predefined parameters, and saves this isolation data into the original directory. This automation is designed to streamline the process of analyzing stellar populations by creating isolation files, which are essential for further astrophysical analysis and modeling.

from ThomasAstro.iso import iso
from pysep.misc.runDB import model_DB
import warnings
 
import pathlib
import os
import re
 
OUTPUT_ROOT = "./outputs.denseAlpha.fixedLowmass/"
DB_NAME_PATTERN = r"Pop(A|E)\+(0\.\d+)\/alpha-(\d\.\d+)"
 
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    for root in pathlib.Path(OUTPUT_ROOT).rglob("alpha-*"):
        popInfo = re.findall(DB_NAME_PATTERN, str(root))[0]
        DBName = f"Pop{popInfo[0]}_Y+{popInfo[1]}_a+{popInfo[2]}.dbs"
        DBPath = os.path.join(str(root), DBName)
        compName = f"pop{popInfo[0]}_ngc2808_Y+{popInfo[1]}.dat"
        compPath = os.path.join("./inputs/comp", compName)
 
        assert os.path.exists(compPath)
        assert os.path.exists(DBPath)
        DB = model_DB(DBPath, str(root), mode="r")
 
        autoISO = iso(DB,compPath)
        autoISO.generate_iso(str(root), numAge=100)