Skip to content

Commit e1385e2

Browse files
authored
Merge pull request #93 from daavid00/fixWarnings
Option to hide Python warnings
2 parents 77a0db9 + 767d5a1 commit e1385e2

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/pyopmspe11/core/pyopmspe11.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Main script for pyopmspe11"""
55
import os
66
import argparse
7+
import warnings
78
from pyopmspe11.utils.inputvalues import process_input, check_deck, handle_tuning
89
from pyopmspe11.utils.runs import simulations, plotting, data
910
from pyopmspe11.visualization.plotting import plot_results
@@ -29,6 +30,9 @@ def pyopmspe11():
2930
dic["dt_data"] = float(
3031
cmdargs["write"].strip()
3132
) # Temporal resolution to write the sparse and performance data
33+
dic["showpywarn"] = int(cmdargs["showpywarn"]) # Show or hidde python warnings
34+
if dic["showpywarn"] != 1:
35+
warnings.warn = lambda *args, **kwargs: None
3236
# If the compare plots are generated, then we exit right afterwards
3337
if dic["compare"]:
3438
plot_results(dic)
@@ -154,6 +158,12 @@ def load_parser():
154158
help="Time interval for the sparse and performance data (spe11a [h]; spe11b/c [y]) "
155159
"('0.1' by default).",
156160
)
161+
parser.add_argument(
162+
"-s",
163+
"--showpywarn",
164+
default=0,
165+
help="Set to 1 to show Python warnings ('0' by default).",
166+
)
157167
return vars(parser.parse_known_args()[0])
158168

159169

src/pyopmspe11/utils/runs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def plotting(dic):
5252
"-d " + f"{dic['spe11']}",
5353
"-g " + f"{dic['generate']}",
5454
"-r " + f"{dic['resolution']}",
55+
"-s " + f"{dic['showpywarn']}",
5556
]
5657
print(" ".join(plot_exe))
5758
prosc = subprocess.run(plot_exe, check=True)
@@ -81,6 +82,7 @@ def data(dic):
8182
"-t " + f"{dic['time_data']}",
8283
"-w " + f"{dic['dt_data']}",
8384
"-u " + f"{dic['use']}",
85+
"-s " + f"{dic['showpywarn']}",
8486
]
8587
print(" ".join(data_exe))
8688
prosc = subprocess.run(data_exe, check=True)

src/pyopmspe11/visualization/data.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# SPDX-FileCopyrightText: 2023 NORCE
22
# SPDX-License-Identifier: MIT
3-
# pylint: disable=C0302, R0912, R0914
3+
# pylint: disable=C0302, R0912, R0914, R0801
44

55
""""
66
Script to write the benchmark data
77
"""
88

99
import os
1010
import argparse
11+
import warnings
1112
import csv
1213
from io import StringIO
1314
from shapely.geometry import Polygon
@@ -86,7 +87,15 @@ def main():
8687
default="resdata",
8788
help="Using the 'resdata' or python package (resdata by default).",
8889
)
90+
parser.add_argument(
91+
"-s",
92+
"--showpywarn",
93+
default=0,
94+
help="Set to 1 to show Python warnings ('0' by default).",
95+
)
8996
cmdargs = vars(parser.parse_known_args()[0])
97+
if int(cmdargs["showpywarn"]) != 1: # Show or hidde python warnings
98+
warnings.warn = lambda *args, **kwargs: None
9099
dig = {"path": cmdargs["path"].strip()}
91100
dig["case"] = cmdargs["deck"].strip()
92101
dig["mode"] = cmdargs["generate"].strip()

src/pyopmspe11/visualization/plotting.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# SPDX-FileCopyrightText: 2023 NORCE
22
# SPDX-License-Identifier: MIT
3-
# pylint: disable=R0912
3+
# pylint: disable=R0912, R0801
44

55
""""
66
Script to plot the results
77
"""
88

99
import argparse
1010
import os
11+
import warnings
1112
import math as mt
1213
import numpy as np
1314
import matplotlib
@@ -62,7 +63,15 @@ def main():
6263
"'dense_performance', 'dense_sparse', 'performance_sparse', "
6364
"'dense_performance-spatial', 'dense_performance_sparse', or 'all'",
6465
)
66+
parser.add_argument(
67+
"-s",
68+
"--showpywarn",
69+
default=0,
70+
help="Set to 1 to show Python warnings ('0' by default).",
71+
)
6572
cmdargs = vars(parser.parse_known_args()[0])
73+
if int(cmdargs["showpywarn"]) != 1: # Show or hidde python warnings
74+
warnings.warn = lambda *args, **kwargs: None
6675
dic = {"folders": [cmdargs["folder"].strip()]}
6776
dic["case"] = cmdargs["deck"].strip()
6877
dic["generate"] = cmdargs["generate"].strip()

0 commit comments

Comments
 (0)