Skip to content

Commit

Permalink
* add warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhughes-usgs committed Nov 22, 2023
1 parent 1fba8fe commit ea70772
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions flopy/mf6/utils/mfsimlistfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib as pl
import re
import warnings

import numpy as np

Expand Down Expand Up @@ -97,11 +98,13 @@ def get_runtime(
if line == "":
return np.nan

# yank out the floating point values from the Elapsed run time string
# parse floating point values from the Elapsed run time string
times = list(map(float, re.findall(r"[+-]?[0-9.]+", line)))

# pad an array with zeros and times with
# [days, hours, minutes, seconds]
times = np.array([0 for _ in range(4 - len(times))] + times)

# convert all to seconds
time2sec = np.array([24 * 60 * 60, 60 * 60, 60, 1])
times_sec = np.sum(times * time2sec)
Expand All @@ -112,7 +115,8 @@ def get_runtime(
if line == "":
return np.nan
times_sec = float(line.split()[3])
# return in the requested units

# return time in the requested units
if units == "seconds":
return times_sec
elif units == "minutes":
Expand Down Expand Up @@ -275,7 +279,15 @@ def get_memory_summary(self, units: str = "gigabytes") -> dict:
# initialize the return variable
memory_summary = None

if self.memory_print_option == "summary":
if self.memory_print_option != "summary":
msg = (
"Cannot retrieve memory data using get_memory_summary() "
+ "since memory_print_option is not set to 'SUMMARY'. "
+ "Returning None."
)
warnings.warn(msg, category=Warning)

else:
# rewind the file
self._rewind_file()

Expand Down Expand Up @@ -341,7 +353,13 @@ def get_memory_all(self, units: str = "gigabytes") -> dict:
"LOGICAL": 4.0,
"STRING": 1.0,
}
if self.memory_print_option == "all":
if self.memory_print_option != "all":
msg = (
"Cannot retrieve memory data using get_memory_all() since "
+ "memory_print_option is not set to 'ALL'. Returning None."
)
warnings.warn(msg, category=Warning)
else:
# rewind the file
self._rewind_file()

Expand Down

0 comments on commit ea70772

Please sign in to comment.