我试图使用conda中的"PyCGNS“python包来提取CGNS文件中所有”区域“的列表。附加的是打开文件的快照视图。
我想要的是:
zone_list = [zone1, zone2, ..., zone51]我很感谢你的帮助。

提示:
以下是print(tree)值:
['CGNSTree', None, [['CGNSLibraryVersion', array([3.21], dtype=float32), [], 'CGNSLibraryVersion_t'], ['Base', array([3, 3]), [['zone41', array([[ 77, 76, 0],
[113, 112, 0],
[ 49, 48, 0]], dtype=int64), [['ZoneType', array([b'S', b't', b'r', b'u', b'c', b't', b'u', b'r', b'e', b'd'],
dtype='|S1'), [], 'ZoneType_t'], ['GridCoordinates', None, [['CoordinateX', array(....发布于 2022-06-23 13:59:03
这是我终于要找的答案(感谢kcw78的帮助)
def zone_extractor(fname: str) -> List:
"""This function extracts all the zones in a CGNS file
Args:
fname (str): _description_
Returns:
List: _description_
"""
(tree, links, paths) = CGM.load(Path(FILE_DIR) / fname)
zones = []
for node in tree:
if (node is not None) and isinstance(node, list) and (node[1][0] == 'Base'):
zones = [child[0] for child in node[1][2] if child[0].startswith('zone')]
return sorted_nicely(zones)https://stackoverflow.com/questions/72719544
复制相似问题