arfc / pride

(P)lan for (R)ap(I)d (DE)carbonization
BSD 3-Clause "New" or "Revised" License
3 stars 7 forks source link

Verify existence of log file #143

Open samgdotson opened 3 years ago

samgdotson commented 3 years ago

This issue can be closed when data_parser.py (rather, functions therein) check for a log file from Temoa before attempting to parse any data.

Current behavior: attempts to parse data, even if no log files exist. Desired behavior: only parse data IF log files exist.

Guidance: This can be accomplished with either an assert statement e.g.

assert(filename is not None), "No log file found"

This will throw an AssertionError.

Or with a Try/Except block

e.g.

def get_output_files():
    """
    This function returns a list of paths to the Temoa output files.

    Returns:
    --------
    path_list : list of strings
        The list of paths to output files.
    """

    path = "./data_files/**/*.log"

    try:
        path_list = glob.glob(path, recursive=True)
    except FileNotFoundError:
        print("No log files found")
    return path_list

I think the first solution might be better because glob will succeed, even if it returns an empty list.