Skip to content

Commit

Permalink
Fix output to subdirectories in csv2ecl summary
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Feb 25, 2021
1 parent a9fb0e4 commit 9ec0e0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ecl2df/csv2ecl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"CSV2ECL(<SUBCOMMAND>=equil, <CSVFILE>=equil.csv, "
"<OUTPUT>=eclipse/include/equil.inc)``"
"CSV2ECL(<SUBCOMMAND>=summary, <CSVFILE>=summary-monthly.csv, "
"<OUTPUT>=MONTHLYSUMMARY)``"
"<OUTPUT>=eclipse/model/MONTHLYSUMMARY)``"
)


Expand Down
11 changes: 10 additions & 1 deletion ecl2df/summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide a two-way Pandas DataFrame interface to Eclipse summary data (UNSMRY)"""
import os
import logging
from pathlib import Path

Expand Down Expand Up @@ -694,6 +695,14 @@ def summary_reverse_main(args):
summary_df = pd.read_csv(args.csvfile)
logger.info("Parsed %s", args.csvfile)

eclsum = df2eclsum(summary_df, args.output)
outputdir = Path(args.output).parent
eclbase = Path(args.output).name

# EclSum.fwrite can only write to current directory:
cwd = os.getcwd()
os.chdir(outputdir)
eclsum = df2eclsum(summary_df, eclbase)
EclSum.fwrite(eclsum)
os.chdir(cwd)

logger.info("Wrote to %s and %s", args.output + ".UNSMRY", args.output + ".SMSPEC")
38 changes: 29 additions & 9 deletions tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def test_df2eclsum_errors():


@pytest.mark.integration
def test_csv2ecl_summary(tmpdir):
def test_csv2ecl_summary(tmpdir, mocker):
"""Check that we can call df2eclsum through the csv2ecl command line
utility"""
dframe = pd.DataFrame(
Expand All @@ -758,14 +758,34 @@ def test_csv2ecl_summary(tmpdir):
)
tmpdir.chdir()
dframe.to_csv("summary.csv")
sys.argv = [
"csv2ecl",
"summary",
"-v",
"summary.csv",
"--output",
"SYNTHETIC",
]
mocker.patch(
"sys.argv",
[
"csv2ecl",
"summary",
"-v",
"summary.csv",
"--output",
"SYNTHETIC",
],
)
csv2ecl.main()
assert Path("SYNTHETIC.UNSMRY").is_file()
assert Path("SYNTHETIC.SMSPEC").is_file()

# Check that we can write to a subdirectory
Path("foo").mkdir()
mocker.patch(
"sys.argv",
[
"csv2ecl",
"summary",
"-v",
"summary.csv",
"--output",
str(Path("foo") / Path("SYNTHETIC")),
],
)
csv2ecl.main()
assert ("foo" / Path("SYNTHETIC.UNSMRY")).is_file()
assert ("foo" / Path("SYNTHETIC.SMSPEC")).is_file()

0 comments on commit 9ec0e0d

Please sign in to comment.