Skip to content

Commit dcca001

Browse files
author
Deepak Mewar
committed
Python tool for extracting IDS names and nodes
having name and identifier with no child nodes, excluding identifier structure(name, index, description) Signed-off-by: Deepak Mewar <deepak.mewar@iter.org>
1 parent bcd47fe commit dcca001

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tools/idslist_name_identifier.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import imas
2+
from imas.util import find_paths
3+
import re
4+
5+
cp = imas.IDSFactory("3.42.0")
6+
ids_list = cp.ids_names()
7+
8+
for ids_name in ids_list:
9+
obj = cp.new(ids_name)
10+
# Find parents that have both 'name' and 'identifier' children
11+
name_paths = find_paths(obj, "(^|/)name$")
12+
id_paths = find_paths(obj, "(^|/)identifier$")
13+
14+
def parent_of(p):
15+
return p.rsplit('/', 1)[0] if '/' in p else ''
16+
17+
name_parents = set(parent_of(p) for p in name_paths)
18+
id_parents = set(parent_of(p) for p in id_paths)
19+
20+
both_parents = sorted(name_parents & id_parents)
21+
filtered = []
22+
for parent in both_parents:
23+
# build sibling full paths
24+
def full(p):
25+
return f"{parent}/{p}" if parent else p
26+
27+
has_index = bool(find_paths(obj, f'^{re.escape(full("index"))}$'))
28+
has_desc = bool(find_paths(obj, f'^{re.escape(full("description"))}$'))
29+
30+
# Exclude parents that have name + index + description (full identifier struct)
31+
if has_index and has_desc:
32+
continue
33+
filtered.append(parent)
34+
35+
if filtered:
36+
print(ids_name, filtered)
37+

0 commit comments

Comments
 (0)