@@ -358,15 +358,19 @@ def sets_to_int_data(self):
358358 self .point_data [data_name ] = intfun
359359 self .point_sets = {}
360360
361- def int_data_to_sets (self ):
361+ def int_data_to_sets (self , keys : list [ str ] | None = None ):
362362 """Convert all int data to {point,cell}_sets, where possible."""
363- keys = []
363+ rm_keys = []
364364 for key , data in self .cell_data .items ():
365+ if keys is not None :
366+ if key not in keys :
367+ continue
368+
365369 # handle all int and uint data
366370 if not all (v .dtype .kind in ["i" , "u" ] for v in data ):
367371 continue
368372
369- keys .append (key )
373+ rm_keys .append (key )
370374
371375 # this call can be rather expensive
372376 tags = np .unique (np .concatenate (data ))
@@ -379,25 +383,29 @@ def int_data_to_sets(self):
379383 names = list (dict .fromkeys (names ))
380384 if len (names ) != len (tags ):
381385 # alternative names
382- names = [f"set{ tag } " for tag in tags ]
386+ names = [f"set- { key } - { tag } " for tag in tags ]
383387
384388 # TODO there's probably a better way besides np.where, something from
385389 # np.unique or np.sort
386390 for name , tag in zip (names , tags ):
387391 self .cell_sets [name ] = [np .where (d == tag )[0 ] for d in data ]
388392
389393 # remove the cell data
390- for key in keys :
394+ for key in rm_keys :
391395 del self .cell_data [key ]
392396
393397 # now point data
394- keys = []
398+ rm_keys = []
395399 for key , data in self .point_data .items ():
400+ if keys is not None :
401+ if key not in keys :
402+ continue
403+
396404 # handle all int and uint data
397405 if not all (v .dtype .kind in ["i" , "u" ] for v in data ):
398406 continue
399407
400- keys .append (key )
408+ rm_keys .append (key )
401409
402410 # this call can be rather expensive
403411 tags = np .unique (data )
@@ -418,5 +426,5 @@ def int_data_to_sets(self):
418426 self .point_sets [name ] = np .where (data == tag )[0 ]
419427
420428 # remove the cell data
421- for key in keys :
429+ for key in rm_keys :
422430 del self .point_data [key ]
0 commit comments