Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAS plugin modifications to handle MFUEL output. #113

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/watts/plugin_sas.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class PluginSAS(PluginGeneric):
List of command-line arguments used to call the executable
conv_channel
Path to CHANNELtoCSV utility executable
conv_mfuel
Path to MFUELPeaktoCSV utility executable
conv_primar4
Path to PRIMAR4toCSV utility executable

Expand All @@ -118,6 +120,7 @@ def __init__(
# Set other executables based on the main SAS executable
suffix = executable.suffix
self._conv_channel = executable.with_name(f"CHANNELtoCSV{suffix}")
self._conv_mfuel = executable.with_name(f"MFUELtoCSV{suffix}")
self._conv_primar4 = executable.with_name(f"PRIMAR4toCSV{suffix}")

@property
Expand All @@ -128,6 +131,10 @@ def conv_channel(self) -> Path:
def conv_primar4(self) -> Path:
return self._conv_primar4

@property
def conv_mfuel(self) -> Path:
return self._conv_mfuel

@conv_channel.setter
def conv_channel(self, exe: PathLike):
if shutil.which(exe) is None:
Expand All @@ -140,6 +147,12 @@ def conv_primar4(self, exe: PathLike):
raise RuntimeError(f"PRIMAR4toCSV utility executable '{exe}' is missing.")
self._conv_primar4 = Path(exe)

@conv_mfuel.setter
def conv_mfuel(self, exe: PathLike):
if shutil.which(exe) is None:
raise RuntimeError(f"MFUELtoCSV utility executable '{exe}' is missing.")
self._conv_mfuel = Path(exe)

@property
def execute_command(self):
return [str(self.executable), "-i", self.input_name, "-o", "out.txt"]
Expand All @@ -159,9 +172,10 @@ def postrun(self, params: Parameters, exec_info: ExecInfo) -> ResultsSAS:
SAS results object
"""

# Convert CHANNEl.dat and PRIMER4.dat to csv files
# Convert CHANNEl.dat and PRIMAR4.dat and MFUELss.dat to csv files
# using SAS utilities. Check if files exist because
# they may not be outputted per user's choice.

if Path("CHANNEL.dat").is_file():
with open("CHANNEL.dat", "r") as file_in, open("CHANNEL.csv", "w") as file_out:
subprocess.run(str(self.conv_channel), stdin=file_in, stdout=file_out)
Expand All @@ -170,4 +184,8 @@ def postrun(self, params: Parameters, exec_info: ExecInfo) -> ResultsSAS:
with open("PRIMAR4.dat", "r") as file_in, open("PRIMAR4.csv", "w") as file_out:
subprocess.run(str(self.conv_primar4), stdin=file_in, stdout=file_out)

if Path("MFUELss_C000001.dat").is_file():
with open("MFUELss_C000001.dat", "r") as file_in:
subprocess.run(str(self.conv_mfuel), stdin=file_in)

return super().postrun(params, exec_info)