Skip to content

Commit a216a1a

Browse files
Merge pull request #18 from softwareengineerprogrammer/mc-command-line
MC command line enhancements NREL#153
2 parents 7c8645c + 5a4bef1 commit a216a1a

File tree

10 files changed

+55
-13
lines changed

10 files changed

+55
-13
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.4.19
2+
current_version = 3.4.20
33
commit = True
44
tag = True
55

.cookiecutterrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ default_context:
5454
sphinx_doctest: "no"
5555
sphinx_theme: "sphinx-py3doc-enhanced-theme"
5656
test_matrix_separate_coverage: "no"
57-
version: 3.4.19
57+
version: 3.4.20
5858
version_manager: "bump2version"
5959
website: "https://github.com/NREL"
6060
year_from: "2023"

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Free software: `MIT license <LICENSE>`__
4747
:alt: Supported implementations
4848
:target: https://pypi.org/project/geophires-x
4949

50-
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.4.19.svg
50+
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.4.20.svg
5151
:alt: Commits since latest release
52-
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.4.19...main
52+
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.4.20...main
5353

5454
.. |docs| image:: https://readthedocs.org/projects/GEOPHIRES-X/badge/?style=flat
5555
:target: https://nrel.github.io/GEOPHIRES-X

docs/Monte-Carlo-User-Guide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ bin edges: [-43.34 -43.2258 -43.1116 -42.9974 -42.8832 -42.769 -42.6548 -42.5
109109
110110
```
111111

112+
You may also run from the command line:
113+
114+
```
115+
python -mgeophires_monte_carlo GEOPHIRESv3.py GEOPHIRES-example1.txt MC_GEOPHIRES_Settings_file.txt MC_GEOPHIRES_Result.txt
116+
```
117+
112118
## Documentation
113119

114120
See [module documentation](reference/geophires_monte_carlo.html)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
year = '2023'
1919
author = 'NREL'
2020
copyright = f'{year}, {author}'
21-
version = release = '3.4.19'
21+
version = release = '3.4.20'
2222

2323
pygments_style = 'trac'
2424
templates_path = ['./templates']

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read(*names, **kwargs):
1313

1414
setup(
1515
name='geophires-x',
16-
version='3.4.19',
16+
version='3.4.20',
1717
license='MIT',
1818
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
1919
long_description='{}\n{}'.format(

src/geophires_monte_carlo/MC_GeoPHIRES3.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ def main(command_line_args=None):
240240
# keep track of execution time
241241
tic = time.time()
242242

243-
# set the starting directory to be the directory that this file is in
244-
working_dir = os.path.dirname(os.path.abspath(__file__))
245-
os.chdir(working_dir)
246-
working_dir = working_dir + os.sep
247-
248243
# get the values off the command line
249244
parser = argparse.ArgumentParser()
250245
parser.add_argument('Code_File', help='Code File')
@@ -268,7 +263,11 @@ def main(command_line_args=None):
268263
inputs = []
269264
outputs = []
270265
iterations = 0
271-
output_file = args.MC_OUTPUT_FILE if 'MC_OUTPUT_FILE' in args and args.MC_OUTPUT_FILE is not None else ''
266+
output_file = (
267+
args.MC_OUTPUT_FILE
268+
if 'MC_OUTPUT_FILE' in args and args.MC_OUTPUT_FILE is not None
269+
else str(Path(Path(args.Input_file).parent, 'MC_Result.txt').absolute())
270+
)
272271
python_path = 'python'
273272

274273
for line in flist:
@@ -312,6 +311,11 @@ def main(command_line_args=None):
312311
with open(output_file, 'w') as f:
313312
f.write(s)
314313

314+
# set the starting directory to be the directory that this file is in
315+
working_dir = os.path.dirname(os.path.abspath(__file__))
316+
os.chdir(working_dir)
317+
working_dir = working_dir + os.sep
318+
315319
# build the args list
316320
pass_list = [inputs, outputs, args, output_file, working_dir, python_path] # this list never changes
317321

src/geophires_monte_carlo/__main__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import sys
3+
from pathlib import Path
4+
5+
from geophires_monte_carlo import MC_GeoPHIRES3
6+
from geophires_monte_carlo import common
7+
8+
if __name__ == '__main__':
9+
log = common._get_logger()
10+
stash_cwd = Path.cwd()
11+
12+
try:
13+
command_line_args = []
14+
for i in range(len(sys.argv[1:])):
15+
arg = sys.argv[i + 1]
16+
if Path(arg).exists():
17+
arg = str(Path(arg).absolute())
18+
log.info(f'Converted arg to absolute path: {arg}')
19+
20+
command_line_args.append(arg)
21+
22+
MC_GeoPHIRES3.main(command_line_args=command_line_args)
23+
except Exception as e:
24+
raise RuntimeError(f'Monte Carlo encountered an exception: {e!s}') from e
25+
except SystemExit:
26+
raise RuntimeError('Monte Carlo exited without giving a reason') from None
27+
finally:
28+
# Undo MC internal global settings changes
29+
os.chdir(stash_cwd)

src/geophires_x/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.4.19'
1+
__version__ = '3.4.20'

tests/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
HIP.out
22
*.log
3+
MC_Result.json
4+
MC_Result.txt
5+
*.png

0 commit comments

Comments
 (0)