Skip to content

Commit

Permalink
Merge pull request #1264 from nschloe/int-data-filter
Browse files Browse the repository at this point in the history
Int data filter
  • Loading branch information
nschloe authored Jan 20, 2022
2 parents 627cff0 + 43a1b4d commit 36ddfc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = meshio
version = 5.2.3
version = 5.2.4
author = Nico Schlömer et al.
author_email = [email protected]
description = I/O for many mesh formats
Expand Down
24 changes: 16 additions & 8 deletions src/meshio/_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,19 @@ def sets_to_int_data(self):
self.point_data[data_name] = intfun
self.point_sets = {}

def int_data_to_sets(self):
def int_data_to_sets(self, keys: list[str] | None = None):
"""Convert all int data to {point,cell}_sets, where possible."""
keys = []
rm_keys = []
for key, data in self.cell_data.items():
if keys is not None:
if key not in keys:
continue

# handle all int and uint data
if not all(v.dtype.kind in ["i", "u"] for v in data):
continue

keys.append(key)
rm_keys.append(key)

# this call can be rather expensive
tags = np.unique(np.concatenate(data))
Expand All @@ -379,25 +383,29 @@ def int_data_to_sets(self):
names = list(dict.fromkeys(names))
if len(names) != len(tags):
# alternative names
names = [f"set{tag}" for tag in tags]
names = [f"set-{key}-{tag}" for tag in tags]

# TODO there's probably a better way besides np.where, something from
# np.unique or np.sort
for name, tag in zip(names, tags):
self.cell_sets[name] = [np.where(d == tag)[0] for d in data]

# remove the cell data
for key in keys:
for key in rm_keys:
del self.cell_data[key]

# now point data
keys = []
rm_keys = []
for key, data in self.point_data.items():
if keys is not None:
if key not in keys:
continue

# handle all int and uint data
if not all(v.dtype.kind in ["i", "u"] for v in data):
continue

keys.append(key)
rm_keys.append(key)

# this call can be rather expensive
tags = np.unique(data)
Expand All @@ -418,5 +426,5 @@ def int_data_to_sets(self):
self.point_sets[name] = np.where(data == tag)[0]

# remove the cell data
for key in keys:
for key in rm_keys:
del self.point_data[key]

0 comments on commit 36ddfc7

Please sign in to comment.