Stellar Model Database Population Script

This Python script populates a database with stellar models using the pysep library. It searches for model files in a directory structure, extracts population and parameter information from the directory names using regular expressions, and then creates and populates a database file (.dbs) with these models. The script includes functionality for normalizing file paths and handles the database operations in a manner designed for large sets of data, leveraging progress bars for user feedback.

from pysep.misc.runDB import model_DB
from pysep.dsep import load_model
 
import re
import os
import pathlib
 
from tqdm import tqdm
 
OUTPUT_ROOT = "./outputs.denseAlpha.fixedLowmass"
DB_NAME_PATTERN = r"Pop(A|E)\+(0\.\d+)\/alpha-(\d\.\d+)"
 
for root in tqdm(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"
    models = list()
    for dsepModel in tqdm(pathlib.Path(root).rglob("model.dsep"), leave=False):
        models.append(load_model(str(dsepModel)))
    # print(re.findall(DB_NAME_PATTERN, str(root)),root)
    DB = model_DB(os.path.join(str(root),DBName),str(root),mode='wr')
    DB.enroll_models(models)
    DB.normalize_file_paths(newRoot=str(root))