def create_legacy_kmeans_nodes(f, new_group_name, legacy_group_name, namedtuple, clustering_key):
""" Soft-link a legacy-structured (CR 1.2) kmeans subgroup (dest) to a new-style (CR 1.3) subgroup (src).
The old-style was a group called 'kmeans' with subgroups named _K.
The new-style is a group called 'clustering' with subgroups named kmeans_K_clusters, etc. """
group = f.create_group(f.root, legacy_group_name)
cluster_type, cluster_param = parse_clustering_key(clustering_key)
if cluster_type != CLUSTER_TYPE_KMEANS:
return
legacy_key = format_legacy_clustering_key(cluster_type, cluster_param)
subgroup = f.create_group(group, legacy_key)
for field in namedtuple._fields:
target = '/%s/_%s/%s' % (new_group_name, clustering_key, field)
if f.__contains__(target):
# NOTE: coerce `target` to 'str' here because pytables chokes on unicode `target`
f.create_soft_link(subgroup, field, target=str(target))
else:
sys.stderr.write('Skipped soft-link of legacy dataset to %s; node doesn\'t exist\n' % target)
评论列表
文章目录