Skip to content

Commit 17726c9

Browse files
authored
added fix and test for diagnostics files with many vertical levels (#310)
1 parent f7bd67c commit 17726c9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

xmitgcm/test/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,24 @@ def test_parse_diagnostics(all_mds_datadirs, layers_mds_datadirs):
946946
assert ad[key] == val
947947

948948

949+
def test_parse_diagnostics_bad_levels(tmpdir):
950+
from xmitgcm.utils import parse_available_diagnostics
951+
# Try parsing a 'bad' available_diagnostics.log file
952+
bad_diags_path = tmpdir / 'available_diagnostics.log'
953+
with open(bad_diags_path, 'x') as bad_diags:
954+
bad_diags.writelines(["", "", "", ""])
955+
bad_diags.write(" 26 |THETA |*** | |SMR MR|degC |Potential Temperature")
956+
957+
ad = parse_available_diagnostics(bad_diags_path)
958+
expected_diags = {
959+
'THETA': {'dims': ['k', 'j', 'i'],
960+
'attrs': {'units': 'degC',
961+
'long_name': 'Potential Temperature',
962+
'standard_name': 'THETA'}},
963+
}
964+
for key, val in expected_diags.items():
965+
assert ad[key] == val
966+
949967
@pytest.mark.parametrize("domain", ['llc', 'aste', 'cs'])
950968
@pytest.mark.parametrize("nx", [90, 270])
951969
def test_get_extra_metadata(domain, nx):

xmitgcm/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ def process_buffer(f):
492492
key = c[1].strip()
493493
diag_id = int(c[0].strip())
494494
diag_id_lookup[diag_id] = key
495-
levs = int(c[2].strip())
495+
try:
496+
levs = int(c[2].strip())
497+
except ValueError:
498+
levs = np.NaN
496499
mate = c[3].strip()
497500
if mate:
498501
mate = int(mate)

0 commit comments

Comments
 (0)