Skip to content

Commit

Permalink
ENH: add support for reading vtk with hasNativeCoordinates
Browse files Browse the repository at this point in the history
Co-authored-by: volodia99 <gaylor.wafflard@univ-grenoble-alpes.fr>
  • Loading branch information
neutrinoceros and volodia99 committed Nov 5, 2024
1 parent eaa2322 commit d6960c9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pytools/vtk_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _load_header(self, fh, geometry=None):
self._dataset_type = line.split()[1]

self.geometry = geometry
self._has_native_coordinates = False

ref_position = fh.tell()
line = fh.readline().decode("utf-8") # DIMENSIONS NX NY NZ or FIELD
Expand Down Expand Up @@ -88,6 +89,8 @@ def _load_header(self, fh, geometry=None):
self.t = np.fromfile(fh, dt, 1)
elif d.startswith("PERIODICITY"):
self.periodicity = np.fromfile(fh, dtype=dint, count=3).astype(bool)
elif d.startswith("HAS_NATIVE_COORDINATES"):
self._has_native_coordinates = np.fromfile(fh, dtype=dint, count=1).astype(bool)
else:
warnings.warn("Found unknown field %s" % d)
fh.readline() # skip extra linefeed (empty line)
Expand Down Expand Up @@ -338,6 +341,29 @@ def _load_hydro(self, fh):

fh.readline() # extra line feed

if self._has_native_coordinates:
if self.geometry == "spherical":
native2attr = {
"X1L_NATIVE_COORDS": "rl",
"X1C_NATIVE_COORDS": "r",
"X2L_NATIVE_COORDS": "thetal",
"X2C_NATIVE_COORDS": "theta",
"X3L_NATIVE_COORDS": "phil",
"X3C_NATIVE_COORDS": "phi",
}
elif self.geometry in ("cartesian", "cylindrical", "polar"):
native2attr = {
"X1L_NATIVE_COORDS": "xl",
"X1C_NATIVE_COORDS": "x",
"X2L_NATIVE_COORDS": "yl",
"X2C_NATIVE_COORDS": "y",
"X3L_NATIVE_COORDS": "zl",
"X3C_NATIVE_COORDS": "z",
}

for native_field, attr in native2attr.items():
setattr(self, attr, self.data[native_field])

def _load_particles(self, fh):
raise NotImplementedError("Particles vtk are not supported yet !")

Expand Down

0 comments on commit d6960c9

Please sign in to comment.