Skip to content

Commit 1d6f6fb

Browse files
committed
Try reading surrounding h5 files if data not found
File numbers can get slightly out of sync between cores, leading to erroneous file names in the xdmf file (which is a bug in StagYY). This commit is a quick fix to be able to read the data anyway by looking at the previous and next file when a field is not found in the file where it is expected. A more robust fix would be to get rid of reading the Data.xmf file altogether and actually look at where the data is. StagYY output should be fixed as well.
1 parent 3dac498 commit 1d6f6fb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

stagpy/stagyyparsers.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,30 @@ def _get_field(xdmf_file, data_item):
652652
shp = _get_dim(data_item)
653653
h5file, group = data_item.text.strip().split(':/', 1)
654654
icore = int(group.split('_')[-2]) - 1
655-
fld = _read_group_h5(xdmf_file.parent / h5file, group).reshape(shp)
655+
fld = None
656+
try:
657+
fld = _read_group_h5(xdmf_file.parent / h5file, group).reshape(shp)
658+
except KeyError:
659+
# test previous/following snapshot files as their numbers can get
660+
# slightly out of sync between cores
661+
h5file_parts = h5file.split('_')
662+
fnum = h5file_parts[-2]
663+
if fnum > 0:
664+
h5file_parts[-2] = '{:05d}'.format(fnum - 1)
665+
h5f = xdmf_file.parent / '_'.join(h5file_parts)
666+
try:
667+
fld = _read_group_h5(h5f, group).reshape(shp)
668+
except OSError, KeyError:
669+
pass
670+
if fld is None:
671+
h5file_parts[-2] = '{:05d}'.format(fnum + 1)
672+
h5f = xdmf_file.parent / '_'.join(h5file_parts)
673+
try:
674+
fld = _read_group_h5(h5f, group).reshape(shp)
675+
except OSError, KeyError:
676+
pass
677+
if fld is None:
678+
raise
656679
return icore, fld
657680

658681

0 commit comments

Comments
 (0)