Skip to content

Commit e104538

Browse files
committed
FieldXmf._get_dims replaces _get_dim
1 parent 8708d5f commit e104538

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

stagpy/stagyyparsers.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -716,14 +716,6 @@ def _conglomerate_meshes(
716716
return meshout
717717

718718

719-
def _try_get(file: Path, elt: Element, key: str) -> str:
720-
"""Try getting an attribute or raise a ParsingError."""
721-
att = elt.get(key)
722-
if att is None:
723-
raise ParsingError(file, f"Element {elt} has no attribute {key!r}")
724-
return att
725-
726-
727719
def _try_text(file: Path, elt: Element) -> str:
728720
"""Try getting text of element or raise a ParsingError."""
729721
text = elt.text
@@ -732,12 +724,6 @@ def _try_text(file: Path, elt: Element) -> str:
732724
return text
733725

734726

735-
def _get_dim(xdmf_file: Path, data_item: Element) -> Tuple[int, ...]:
736-
"""Extract shape of data item."""
737-
dims = _try_get(xdmf_file, data_item, "Dimensions")
738-
return tuple(map(int, dims.split()))
739-
740-
741727
@dataclass(frozen=True)
742728
class FieldSub:
743729
file: Path
@@ -790,6 +776,10 @@ def field_subdomains(self, path_root: Path, name: str) -> Iterator[FieldSub]:
790776
class FieldXmf:
791777
path: Path
792778

779+
def _get_dims(self, elt: Element) -> tuple[int, ...]:
780+
dims = elt.attrib["Dimensions"].split()
781+
return tuple(map(int, dims))
782+
793783
@cached_property
794784
def _data(self) -> Mapping[int, XmfEntry]:
795785
xs = XmlStream(filepath=self.path)
@@ -818,7 +808,7 @@ def _data(self) -> Mapping[int, XmfEntry]:
818808
twod += coord
819809
data_item = elt_geom[0]
820810
data_text = _try_text(xs.filepath, data_item)
821-
coord_shape = _get_dim(xs.filepath, data_item)
811+
coord_shape = self._get_dims(data_item)
822812
coord_filepattern = data_text.strip().split(":/", 1)[0]
823813
coord_file_chunks = coord_filepattern.split("_")
824814
coord_file_chunks[-2] = "{icore:05d}"
@@ -829,7 +819,7 @@ def _data(self) -> Mapping[int, XmfEntry]:
829819
with xs.load() as elt_fvar:
830820
name = elt_fvar.attrib["Name"]
831821
elt_data = elt_fvar[0]
832-
shape = _get_dim(xs.filepath, elt_data)
822+
shape = self._get_dims(elt_data)
833823
data_text = _try_text(xs.filepath, elt_data)
834824
h5file, group = data_text.strip().split(":/", 1)
835825
isnap = int(group[-5:])

0 commit comments

Comments
 (0)