Skip to content

Commit

Permalink
Catch a possible error in STATUS files
Browse files Browse the repository at this point in the history
Instead of crashing, we should ignore the line in a garbled STATUS file
like we do for other ways it can be garbled.
  • Loading branch information
berland committed Aug 22, 2024
1 parent 127c2cc commit 5858a95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ def load_status(self):
# We get where if STARTIME.split(':') does not contain
# integers only:
durations.append(np.nan)
except IndexError:
# We get here if a clock time string is invalid, like missing seconds.
print("got indexerror")
durations.append(np.nan)
status["DURATION"] = durations

# Augment data from jobs.json if that file is available:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ def test_status_load(tmpdir):
assert "FORWARD_MODEL" in status
assert np.isnan(status["DURATION"].values[0]) # Unsupported time syntax

with open(str(tmpdir.join("realization-0/STATUS")), "w") as status_fh:
status_fh.write("first line always ignored\n")
status_fh.write("INCLUDE_PC : 12:40 .... 12:40:55 \n")
real = ensemble.ScratchRealization(str(tmpdir.join("realization-0")))
status = real.get_df("STATUS")
assert len(status) == 1
assert "FORWARD_MODEL" in status
assert np.isnan(status["DURATION"].values[0]) # Unsupported time syntax

with open(str(tmpdir.join("realization-0/STATUS")), "w") as status_fh:
status_fh.write("first line always ignored\n")
status_fh.write("INCLUDE_PC : 12:40:33 .... 12:41 \n")
real = ensemble.ScratchRealization(str(tmpdir.join("realization-0")))
status = real.get_df("STATUS")
assert len(status) == 1
assert "FORWARD_MODEL" in status
assert np.isnan(status["DURATION"].values[0]) # Unsupported time syntax


def test_batch():
"""Test batch processing at time of object initialization"""
Expand Down

0 comments on commit 5858a95

Please sign in to comment.