From 60a4f7a454608ead6af57941ee9a2037dddea5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Thu, 20 Jan 2022 10:27:54 +0100 Subject: [PATCH 1/2] select keys in int_data_to_sets --- src/meshio/_mesh.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/meshio/_mesh.py b/src/meshio/_mesh.py index c416861a6..65646d349 100644 --- a/src/meshio/_mesh.py +++ b/src/meshio/_mesh.py @@ -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)) @@ -379,7 +383,7 @@ 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 @@ -387,17 +391,21 @@ def int_data_to_sets(self): 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) @@ -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] From 43a1b4d2293ef6468a9367659bb222b6606ea1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Thu, 20 Jan 2022 10:28:14 +0100 Subject: [PATCH 2/2] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ba6c23d2d..422674df0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = meshio -version = 5.2.3 +version = 5.2.4 author = Nico Schlömer et al. author_email = nico.schloemer@gmail.com description = I/O for many mesh formats