Skip to content

Commit

Permalink
refactor: move arg parser to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Hagg committed Dec 14, 2020
1 parent 814a3b2 commit 88e5c72
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 83 deletions.
1 change: 0 additions & 1 deletion pyreisejl/utility/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
__all__ = ["const", "extract_data"]
83 changes: 1 addition & 82 deletions pyreisejl/utility/call.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
84 changes: 84 additions & 0 deletions pyreisejl/utility/parser.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 88e5c72

Please sign in to comment.