|
120 | 120 | ")" |
121 | 121 | ] |
122 | 122 | }, |
123 | | - { |
124 | | - "cell_type": "code", |
125 | | - "execution_count": null, |
126 | | - "metadata": {}, |
127 | | - "outputs": [], |
128 | | - "source": [ |
129 | | - "# Delete temp dir\n", |
130 | | - "temp_dir.cleanup()" |
131 | | - ] |
132 | | - }, |
133 | 123 | { |
134 | 124 | "cell_type": "markdown", |
135 | 125 | "metadata": {}, |
136 | 126 | "source": [ |
137 | 127 | "## View key output variables\n", |
138 | | - "Run the large tokamak scenario using `SingleRun` to set some values on the `CostModel` instance and then print them." |
| 128 | + "Using the `MFILE` we generated by running the large tokamak scenario above, we have set some values on the `CostModel` instance and can print them." |
139 | 129 | ] |
140 | 130 | }, |
141 | 131 | { |
|
144 | 134 | "metadata": {}, |
145 | 135 | "outputs": [], |
146 | 136 | "source": [ |
147 | | - "# Define input file name relative to project dir\n", |
148 | | - "input_rel = script_dir / \"data/large_tokamak_IN.DAT\"\n", |
149 | | - "print(input_rel)\n", |
150 | | - "temp_dir, temp_input_path, _ = copy_to_temp_dir(input_rel)\n", |
| 137 | + "import process.data_structure\n", |
151 | 138 | "\n", |
152 | | - "# Run process on an input file\n", |
153 | | - "single_run = SingleRun(temp_input_path.as_posix())\n", |
154 | | - "single_run.run()" |
| 139 | + "# Print some values on the CostModel instance\n", |
| 140 | + "print(f\"Heat transport system: {process.data_structure.cost_variables.c226:.3e} M$\")\n", |
| 141 | + "print(f\"Electrical plant equipment: {process.data_structure.cost_variables.c24:.3e} M$\")" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "cell_type": "markdown", |
| 146 | + "metadata": {}, |
| 147 | + "source": [ |
| 148 | + "## Convert to CSV format\n", |
| 149 | + "This demonstrates how you would read from a PROCESS MFILE and write specified values into a csv using the `mfile_to_csv` function" |
155 | 150 | ] |
156 | 151 | }, |
157 | 152 | { |
|
160 | 155 | "metadata": {}, |
161 | 156 | "outputs": [], |
162 | 157 | "source": [ |
163 | | - "import process.data_structure\n", |
164 | | - "\n", |
165 | | - "# Print some values on the CostModel instance\n", |
166 | | - "print(f\"Heat transport system: {process.data_structure.cost_variables.c226:.3e} M$\")\n", |
167 | | - "print(f\"Electrical plant equipment: {process.data_structure.cost_variables.c24:.3e} M$\")" |
| 158 | + "from process.io import mfile_to_csv\n", |
| 159 | + "\n", |
| 160 | + "data_dir = Path(\"data\")\n", |
| 161 | + "\n", |
| 162 | + "# mfile_to_csv requires two inputs:\n", |
| 163 | + "# - path to the MFILE\n", |
| 164 | + "# - .json containing the variable names to include in the csv file\n", |
| 165 | + "\n", |
| 166 | + "# This routine attempts to find every variable listed in the json file\n", |
| 167 | + "# in the MFILE and writes the variable name, description and value\n", |
| 168 | + "# to the output csv.\n", |
| 169 | + "# Any listed variable that isn't in that MFILE will be skipped.\n", |
| 170 | + "# The .csv file is saved to the directory of the input file\n", |
| 171 | + "\n", |
| 172 | + "mfile_to_csv.main(\n", |
| 173 | + " args=[\n", |
| 174 | + " \"-f\",\n", |
| 175 | + " (data_dir / \"large_tokamak_1_MFILE.DAT\").as_posix(),\n", |
| 176 | + " \"-v\",\n", |
| 177 | + " (data_dir / \"mfile_to_csv_vars.json\").as_posix(),\n", |
| 178 | + " ]\n", |
| 179 | + ")" |
168 | 180 | ] |
169 | 181 | }, |
170 | 182 | { |
|
0 commit comments