@@ -358,15 +358,19 @@ def sets_to_int_data(self):
358
358
self .point_data [data_name ] = intfun
359
359
self .point_sets = {}
360
360
361
- def int_data_to_sets (self ):
361
+ def int_data_to_sets (self , keys : list [ str ] | None = None ):
362
362
"""Convert all int data to {point,cell}_sets, where possible."""
363
- keys = []
363
+ rm_keys = []
364
364
for key , data in self .cell_data .items ():
365
+ if keys is not None :
366
+ if key not in keys :
367
+ continue
368
+
365
369
# handle all int and uint data
366
370
if not all (v .dtype .kind in ["i" , "u" ] for v in data ):
367
371
continue
368
372
369
- keys .append (key )
373
+ rm_keys .append (key )
370
374
371
375
# this call can be rather expensive
372
376
tags = np .unique (np .concatenate (data ))
@@ -379,25 +383,29 @@ def int_data_to_sets(self):
379
383
names = list (dict .fromkeys (names ))
380
384
if len (names ) != len (tags ):
381
385
# alternative names
382
- names = [f"set{ tag } " for tag in tags ]
386
+ names = [f"set- { key } - { tag } " for tag in tags ]
383
387
384
388
# TODO there's probably a better way besides np.where, something from
385
389
# np.unique or np.sort
386
390
for name , tag in zip (names , tags ):
387
391
self .cell_sets [name ] = [np .where (d == tag )[0 ] for d in data ]
388
392
389
393
# remove the cell data
390
- for key in keys :
394
+ for key in rm_keys :
391
395
del self .cell_data [key ]
392
396
393
397
# now point data
394
- keys = []
398
+ rm_keys = []
395
399
for key , data in self .point_data .items ():
400
+ if keys is not None :
401
+ if key not in keys :
402
+ continue
403
+
396
404
# handle all int and uint data
397
405
if not all (v .dtype .kind in ["i" , "u" ] for v in data ):
398
406
continue
399
407
400
- keys .append (key )
408
+ rm_keys .append (key )
401
409
402
410
# this call can be rather expensive
403
411
tags = np .unique (data )
@@ -418,5 +426,5 @@ def int_data_to_sets(self):
418
426
self .point_sets [name ] = np .where (data == tag )[0 ]
419
427
420
428
# remove the cell data
421
- for key in keys :
429
+ for key in rm_keys :
422
430
del self .point_data [key ]
0 commit comments