extended link, if clusters file present update entries
:copyright: Copyright (c) 2015 Jungmann Lab, Max Planck Institute of Biochemistry
"""
import os.path
+
+
def _average(args):
from glob import glob
from .io import load_locs, NoMetadataFileError
@@ -45,6 +47,11 @@ def _hdf2visp(path, pixel_size):
def _link(files, d_max, tolerance):
+ import numpy as _np
+ from tqdm import tqdm as _tqdm
+ from . import lib as _lib
+ from h5py import File
+
import glob
paths = glob.glob(files)
if paths:
@@ -62,6 +69,38 @@ def _link(files, d_max, tolerance):
info.append(link_info)
io.save_locs(base + '_link.hdf5', linked_locs, info)
+ try:
+ #Check if there is a _clusters.hdf5 file present, if yes update this file
+ #try:
+ cluster_path = base[:-7] + '_clusters.hdf5'
+ print(cluster_path)
+ clusters = io.load_clusters(cluster_path)
+ print('Clusterfile detected. Updating entries.')
+
+ n_after_link = []
+ linked_len = []
+ linked_n = []
+ linked_photonrate = []
+
+ for group in _tqdm(_np.unique(clusters['groups'])):
+ temp = linked_locs[linked_locs['group']==group]
+ n_after_link.append(len(temp))
+ linked_len.append(_np.mean(temp['len']))
+ linked_n.append(_np.mean(temp['n']))
+ linked_photonrate.append(_np.mean(temp['photon_rate']))
+
+ clusters = _lib.append_to_rec(clusters, _np.array(n_after_link, dtype=_np.int32), 'n_after_link')
+ clusters = _lib.append_to_rec(clusters, _np.array(linked_len, dtype=_np.int32), 'linked_len')
+ clusters = _lib.append_to_rec(clusters, _np.array(linked_n, dtype=_np.int32), 'linked_n')
+ clusters = _lib.append_to_rec(clusters, _np.array(linked_photonrate, dtype=_np.float32), 'linked_photonrate')
+
+
+ with File(cluster_path, 'w') as clusters_file:
+ clusters_file.create_dataset('clusters', data=clusters)
+
+ except:
+ continue
+
def _cluster_combine(files):
import glob
