I have about 2,000 .txt files that have light curve data in them. Each .txt file is a different parameter combination. There are 12 parameters each with 2-3 options, which is why the number of files is so large and each runs about five iterations. I'm using WSL to try to parse my files to get one combination of each parameter so that way when I run the light curves I can put them on a multiplot with different param combos for each set of light curves. I'm wondering if anyone can think of a simpler way to parse files than my code which is as follows: ''' import os import re import shutil import yaml from itertools import product #Load and flatten YAML yaml_path = 'my path with parameters' with open(yaml_path, 'r') as f: raw_params = yaml.safe_load(f) #Flatten nested YAML structure into one dict params = {} for section in raw_params.values(): if isinstance(section, dict): params.update(section) #Keys we want to track from filename grid_keys = [ 'sp', 'inclination', 'angwidth', 'p', 'vff', 'ymax', 'numclouds', 'opening_angle', 'angwidth_pol', 'p_pol', 'vff_pol', 'ymax_pol', 'cl_fraction' ] #Make sure all grid_keys exist in YAML missing_keys = [k for k in grid_keys if k not in params] if missing_keys: raise KeyError(f"The following required keys are missing from the YAML: {missing_keys}") #Build Cartesian product of all parameter combinations param_values = [params[k] for k in grid_keys] full_param_grid = [dict(zip(grid_keys, combo)) for combo in product(*param_values)] ''' The light curve section is simpler because each .txt file has a list of dates and a list of fluxes, so my main issue is with parsing files. I've been trying this code and while it works individually, I usually have to go in for each trial and edit it a ton to make it work. New to WSL so would appreciate any help. Continue reading...