Skip to content

Commit ac1598a

Browse files
committed
Fix types in stagyyparsers
1 parent 8edaa6e commit ac1598a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

stagpy/_step.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ def _header(self):
343343
return stagyyparsers.fields(binfiles.pop(), only_header=True)
344344
elif self.step.sdat.hdf5:
345345
xmf = self.step.sdat.hdf5 / 'Data.xmf'
346-
return stagyyparsers.read_geom_h5(xmf, self.step.isnap)[0]
346+
header = stagyyparsers.read_geom_h5(xmf, self.step.isnap)[0]
347+
return header if header else None
347348

348349
@crop
349350
def geom(self):

stagpy/stagyyparsers.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def _maybe_get(elt: Element, item: str, info: str,
739739

740740
def read_geom_h5(
741741
xdmf_file: Path, snapshot: Optional[int]
742-
) -> Tuple[Optional[Dict[str, Any]], Element]:
742+
) -> Tuple[Dict[str, Any], Element]:
743743
"""Extract geometry information from hdf5 files.
744744
745745
Args:
@@ -751,7 +751,7 @@ def read_geom_h5(
751751
header: Dict[str, Any] = {}
752752
xdmf_root = xmlET.parse(str(xdmf_file)).getroot()
753753
if snapshot is None:
754-
return None, xdmf_root
754+
return {}, xdmf_root
755755

756756
# Domain, Temporal Collection, Snapshot
757757
# should check that this is indeed the required snapshot
@@ -922,7 +922,7 @@ def read_tracers_h5(xdmf_file: Path, infoname: str, snapshot: int,
922922
Tracers data organized by attribute and block.
923923
"""
924924
xdmf_root = xmlET.parse(str(xdmf_file)).getroot()
925-
tra: Dict[str, List[ndarray]] = {}
925+
tra: Dict[str, List[Dict[int, ndarray]]] = {}
926926
tra[infoname] = [{}, {}] # two blocks, ordered by cores
927927
if position:
928928
for axis in 'xyz':
@@ -942,12 +942,14 @@ def read_tracers_h5(xdmf_file: Path, infoname: str, snapshot: int,
942942
icore, data = _get_field(
943943
xdmf_file, _try_find(xdmf_file, data_attr, 'DataItem'))
944944
tra[infoname][ibk][icore] = data
945+
tra_concat: Dict[str, List[ndarray]] = {}
945946
for info in tra:
946947
tra[info] = [trab for trab in tra[info] if trab] # remove empty blocks
947-
for iblk, trab in enumerate(tra[info]):
948-
tra[info][iblk] = np.concatenate([trab[icore]
949-
for icore in range(len(trab))])
950-
return tra
948+
tra_concat[info] = []
949+
for trab in tra[info]:
950+
tra_concat[info].append(
951+
np.concatenate([trab[icore] for icore in range(len(trab))]))
952+
return tra_concat
951953

952954

953955
def read_time_h5(h5folder: Path) -> Iterator[Tuple[int, int]]:

0 commit comments

Comments
 (0)