From 88e5c7224be9c68f4fb143fa7e63da2dfeda0d46 Mon Sep 17 00:00:00 2001 From: Jon Hagg Date: Mon, 14 Dec 2020 15:37:23 -0800 Subject: [PATCH] refactor: move arg parser to separate file --- pyreisejl/utility/__init__.py | 1 - pyreisejl/utility/call.py | 83 +--------------------------------- pyreisejl/utility/parser.py | 84 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 83 deletions(-) create mode 100644 pyreisejl/utility/parser.py diff --git a/pyreisejl/utility/__init__.py b/pyreisejl/utility/__init__.py index b20b8c63..e69de29b 100644 --- a/pyreisejl/utility/__init__.py +++ b/pyreisejl/utility/__init__.py @@ -1 +0,0 @@ -__all__ = ["const", "extract_data"] diff --git a/pyreisejl/utility/call.py b/pyreisejl/utility/call.py index f56ca75e..58707b26 100644 --- a/pyreisejl/utility/call.py +++ b/pyreisejl/utility/call.py @@ -1,10 +1,9 @@ -import argparse import os from time import time import pandas as pd -from pyreisejl.utility import const +from pyreisejl.utility import const, parser from pyreisejl.utility.extract_data import extract_scenario from pyreisejl.utility.helpers import ( InvalidDateArgument, @@ -109,86 +108,6 @@ def launch_scenario( if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Run REISE.jl simulation.") - - # Arguments needed to run REISE.jl - parser.add_argument( - "-s", - "--start-date", - help="The start date for the simulation in format 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. " - "'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'.", - ) - parser.add_argument( - "-e", - "--end-date", - help="The end date for the simulation in format 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. " - "'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'. If only the date is specified " - "(without any hours), the entire end-date will be included in the simulation.", - ) - parser.add_argument( - "-int", "--interval", help="The length of each interval in hours.", type=int - ) - parser.add_argument( - "-i", - "--input-dir", - help="The directory containing the input data files. " - "Required files are 'case.mat', 'demand.csv', " - "'hydro.csv', 'solar.csv', and 'wind.csv'.", - ) - parser.add_argument( - "-x", - "--execute-dir", - help="The directory to store the results. This is optional and defaults " - "to an execute folder that will be created in the input directory " - "if it does not exist.", - ) - parser.add_argument( - "-t", - "--threads", - type=int, - help="The number of threads to run the simulation with. " - "This is optional and defaults to Auto.", - ) - parser.add_argument( - "-d", - "--extract-data", - action="store_true", - help="If this flag is used, the data generated by the simulation after the engine " - "has finished running will be automatically extracted into .pkl files, " - "and the result.mat files will be deleted. " - "The extraction process can be memory intensive. " - "This is optional and defaults to False.", - ) - parser.add_argument( - "-o", - "--output-dir", - help="The directory to store the extracted data. This is optional and defaults " - "to the execute directory. This flag is only used if the extract-data flag is set.", - ) - parser.add_argument( - "-m", - "--matlab-dir", - help="The directory to store the modified case.mat used by the engine. " - "This is optional and defaults to the execute directory. " - "This flag is only used if the extract-data flag is set.", - ) - parser.add_argument( - "-k", - "--keep-matlab", - action="store_true", - help="The result.mat files found in the execute directory will be kept " - "instead of deleted after extraction. " - "This flag is only used if the extract-data flag is set.", - ) - - # For backwards compatability with PowerSimData - parser.add_argument( - "scenario_id", - nargs="?", - default=None, - help="Scenario ID only if using PowerSimData. ", - ) - args = parser.parse_args() # Get scenario info if using PowerSimData diff --git a/pyreisejl/utility/parser.py b/pyreisejl/utility/parser.py new file mode 100644 index 00000000..a52ffb6c --- /dev/null +++ b/pyreisejl/utility/parser.py @@ -0,0 +1,84 @@ +import argparse + + +def parse_args(): + parser = argparse.ArgumentParser(description="Run REISE.jl simulation.") + + # Arguments needed to run REISE.jl + parser.add_argument( + "-s", + "--start-date", + help="The start date for the simulation in format 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. " + "'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'.", + ) + parser.add_argument( + "-e", + "--end-date", + help="The end date for the simulation in format 'YYYY-MM-DD'. 'YYYY-MM-DD HH'. " + "'YYYY-MM-DD HH:MM', or 'YYYY-MM-DD HH:MM:SS'. If only the date is specified " + "(without any hours), the entire end-date will be included in the simulation.", + ) + parser.add_argument( + "-int", "--interval", help="The length of each interval in hours.", type=int + ) + parser.add_argument( + "-i", + "--input-dir", + help="The directory containing the input data files. " + "Required files are 'case.mat', 'demand.csv', " + "'hydro.csv', 'solar.csv', and 'wind.csv'.", + ) + parser.add_argument( + "-x", + "--execute-dir", + help="The directory to store the results. This is optional and defaults " + "to an execute folder that will be created in the input directory " + "if it does not exist.", + ) + parser.add_argument( + "-t", + "--threads", + type=int, + help="The number of threads to run the simulation with. " + "This is optional and defaults to Auto.", + ) + parser.add_argument( + "-d", + "--extract-data", + action="store_true", + help="If this flag is used, the data generated by the simulation after the engine " + "has finished running will be automatically extracted into .pkl files, " + "and the result.mat files will be deleted. " + "The extraction process can be memory intensive. " + "This is optional and defaults to False.", + ) + parser.add_argument( + "-o", + "--output-dir", + help="The directory to store the extracted data. This is optional and defaults " + "to the execute directory. This flag is only used if the extract-data flag is set.", + ) + parser.add_argument( + "-m", + "--matlab-dir", + help="The directory to store the modified case.mat used by the engine. " + "This is optional and defaults to the execute directory. " + "This flag is only used if the extract-data flag is set.", + ) + parser.add_argument( + "-k", + "--keep-matlab", + action="store_true", + help="The result.mat files found in the execute directory will be kept " + "instead of deleted after extraction. " + "This flag is only used if the extract-data flag is set.", + ) + + # For backwards compatability with PowerSimData + parser.add_argument( + "scenario_id", + nargs="?", + default=None, + help="Scenario ID only if using PowerSimData. ", + ) + return parser.parse_args()