Skip to content

Commit

Permalink
BUG: do not normalise field names to upper case in Idefix vtk (#251)
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Robert <cr52@protonmail.com>
Co-authored-by: Marc Van den Bossche <marc.vanden-bossche@univ-grenoble-alpes.fr>
  • Loading branch information
3 people authored Apr 18, 2023
1 parent a35018e commit 6887eb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions yt_idefix/_io/vtk_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def read_grid_coordinates(
return Coordinates(coords[0], coords[1], coords[2], array_shape)


def read_field_offset_index(fh: BinaryIO, shape: Shape) -> dict[str, int]:
def read_field_offset_index(
fh: BinaryIO, shape: Shape, *, upper_case_varnames: bool
) -> dict[str, int]:
# assuming fh is correctly positioned (read_grid_coordinates must be called first)
retv: dict[str, int] = {}

Expand All @@ -215,10 +217,8 @@ def read_field_offset_index(fh: BinaryIO, shape: Shape) -> dict[str, int]:
s = line.decode()
datatype, varname, dtype = s.split()

# some versions of Pluto define field names in lower case
# so we normalize to upper case to avoid duplicating data
# in IdefixVtkFieldInfo.known_other_fields
varname = varname.upper()
if upper_case_varnames:
varname = varname.upper()

if datatype == "SCALARS":
next(fh)
Expand Down
7 changes: 6 additions & 1 deletion yt_idefix/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,16 @@ def _parse_parameter_file(self):
super()._parse_parameter_file()
# from here self.geometry is assumed to be set

# some versions of Pluto define field names in lower case
# so we normalize to upper case to avoid duplicating data
# in BaseVtkFields.known_other_fields
normalize_varnames = self.dataset_type == "pluto-vtk"

# parse the grid
with open(self.filename, "rb") as fh:
coords = vtk_io.read_grid_coordinates(fh, geometry=self.geometry)
self._field_offset_index = vtk_io.read_field_offset_index(
fh, coords.array_shape
fh, coords.array_shape, upper_case_varnames=normalize_varnames
)
self._detected_field_list = list(self._field_offset_index.keys())

Expand Down

0 comments on commit 6887eb4

Please sign in to comment.