add smlm clusterer to cmd
@@ -497,6 +497,40 @@ def _hdbscan(files, min_cluster, min_samples):
f"{base}_hdbclusters.hdf5"
)
+def _smlm_clusterer(files, radius, min_locs, basic_fa=False, radius_z=None):
+ import glob
+
+ paths = glob.glob(files)
+ if paths:
+ from . import io, clusterer
+ pixelsize = int(input("Enter the camera pixelsize in nm: "))
+ if radius_z is not None: # 3D
+ params = [radius, radius_z, min_locs, 0, basic_fa, 0]
+ else: # 2D
+ params = [radius, min_locs, 0, basic_fa, 0]
+
+ for path in paths:
+ print("Loading {} ...".format(path))
+ locs, info = io.load_locs(path)
+ locs = clusterer.cluster(locs, params, pixelsize)
+ clusters = clusterer.find_cluster_centers(locs, pixelsize)
+ base, ext = os.path.splitext(path)
+ smlm_cluster_info = {
+ "Generated by": "Picasso SMLM clusterer",
+ "Radius_xy": radius,
+ "Radius_z": radius_z,
+ "Min locs": min_locs,
+ "Basic frame analysis": basic_fa,
+ }
+ info.append(smlm_cluster_info)
+ io.save_locs(base + "_clusters.hdf5", locs, info)
+ io.save_locs(base + "_cluster_centers.hdf5", clusters, info)
+ print(
+ "Clustering executed. Results are saved in: \n"
+ f"{base}_clusters.hdf5\n"
+ f"{base}_cluster_centers.hdf5"
+ )
+
def _nneighbor(files):
import glob
@@ -1260,6 +1294,43 @@ def main():
help=("the higher the more points are considered noise"),
)
+ # SMLM clusterer
+ smlm_cluster_parser = subparsers.add_parser(
+ "smlm_cluster",
+ help="cluster localizations with the custom SMLM clustering algorithm",
+ )
+ smlm_cluster_parser.add_argument(
+ "files",
+ help=(
+ "one or multiple hdf5 localization files"
+ " specified by a unix style path pattern"
+ ),
+ )
+ smlm_cluster_parser.add_argument(
+ "radius",
+ type=float,
+ help=("clustering radius (in camera pixels)"),
+ )
+ smlm_cluster_parser.add_argument(
+ "min_locs",
+ type=int,
+ help=("minimum number of localizations in a cluster"),
+ )
+ smlm_cluster_parser.add_argument(
+ "basic_fa",
+ type=bool,
+ help=("whether or not perform basic frame analysis (sticking event removal)"),
+ default=False,
+ )
+ smlm_cluster_parser.add_argument(
+ "radius_z",
+ type=float,
+ help=(
+ "clustering radius in axial direction (MUST BE SET FOR 3D!!!)"
+ ),
+ default=None,
+ )
+
# Dark time
dark_parser = subparsers.add_parser(
"dark", help="compute the dark time for grouped localizations"
@@ -1606,6 +1677,14 @@ def main():
_dbscan(args.files, args.radius, args.density)
elif args.command == "hdbscan":
_hdbscan(args.files, args.min_cluster, args.min_samples)
+ elif args.command == "smlm_cluster":
+ _smlm_clusterer(
+ args.files,
+ args.radius,
+ args.min_locs,
+ args.basic_fa,
+ args.radius_z,
+ )
elif args.command == "nneighbor":
_nneighbor(args.files)
elif args.command == "dark":
