Skip to content

Commit

Permalink
add test for csv output
Browse files Browse the repository at this point in the history
provide new input file and add test for csv_output.py to check all values are positive floats
  • Loading branch information
clmould committed Sep 22, 2023
1 parent e187442 commit 8fbb4d2
Show file tree
Hide file tree
Showing 4 changed files with 1,907 additions and 5 deletions.
15 changes: 11 additions & 4 deletions examples/csv_output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Fetching list of variables from /home/clair/PROCESS/process/io/mfile_to_csv_vars.json\n",
"Reading from MFILE: /home/clair/PROCESS/tests/integration/data/large_tokamak_MFILE.DAT\n",
"Writing to csv file: /home/clair/PROCESS/tests/integration/data/large_tokamak_MFILE.csv\n",
"Fetching list of variables from /home/clair/development/PROCESS/process/io/mfile_to_csv_vars.json\n",
"Reading from MFILE: /home/clair/development/PROCESS/examples/csv_output_large_tokamak_MFILE.DAT\n",
"Writing to csv file: /home/clair/development/PROCESS/examples/csv_output_large_tokamak_MFILE.csv\n",
"Complete.\n"
]
}
Expand All @@ -53,7 +53,7 @@
"proj_dir = Path.cwd().parent\n",
"\n",
"# Replace this path/to/MFILE.DAT with your target file:\n",
"mfilename = proj_dir / 'tests/integration/data/large_tokamak_MFILE.DAT'\n",
"mfilename = proj_dir / 'examples/csv_output_large_tokamak_MFILE.DAT'\n",
"\n",
"# Either replace this with your own path/to/file.json target, \n",
"# or add your required variables into the identified file:\n",
Expand All @@ -65,6 +65,13 @@
"# call to function:\n",
"mfile_to_csv.main(args=[\"-f\", str(mfilename), \"-v\", str(varfilename)])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
39 changes: 39 additions & 0 deletions examples/csv_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# %% [markdown]
# # Output to csv
#
# Routine to read from a PROCESS MFILE and write specified values into a csv.
#
# Input files:
# - MFILE.DAT as output from PROCESS
# - .json variable list as defined by user (defaults to local `mfile_to_csv_vars.json`)
#
# Instructions:
# - from command line: `python mfile_to_csv.py -f </path/to/mfile.dat> -v </path/to/varfile.json>`
# - from this Jupyter notebook: run the cell below
#
# Output file:
# - .csv will be saved to the directory of the input file

# %%
from pathlib import Path
from process.io import mfile_to_csv

# Project directory for example result file and default .json list;
# not needed if you replace both target filepaths below.
proj_dir = Path.cwd().parent

# Replace this path/to/MFILE.DAT with your target file:
mfilename = proj_dir / "examples/csv_output_large_tokamak_MFILE.DAT"

# Either replace this with your own path/to/file.json target,
# or add your required variables into the identified file:
varfilename = proj_dir / "process/io/mfile_to_csv_vars.json"
# This routine attempts to find every variable in the given list and
# writes the variable name, description and value to the output csv.
# Any listed variable that isn't in that MFILE will be skipped.

# call to function:
mfile_to_csv.main(args=["-f", str(mfilename), "-v", str(varfilename)])


# %%
Loading

0 comments on commit 8fbb4d2

Please sign in to comment.