Skip to content

Commit

Permalink
make the channel visualized customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Aug 6, 2024
1 parent 4870b7d commit d550ec7
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ def visualize_cluster_umap_coefs(
input_umap_hdf5_path: Path,
input_cluster_hdf5_path: Path,
output_png_path: Path,
channel: str = "cluster",
) -> None:
# load the input data
umap_image = MultiChannelImage.read_hdf5(path=input_umap_hdf5_path)
cluster_image = MultiChannelImage.read_hdf5(path=input_cluster_hdf5_path)

# read the cluster labels
cluster_labels = cluster_image.data_flat.sel(c="cluster").values.ravel()
# read the labels to visualize
labels = cluster_image.data_flat.sel(c=channel).values.ravel()

# read the umap coordinates
umap_coords = umap_image.data_flat.values.T

# scatter
fig, ax = plt.subplots(figsize=(10, 10))
ax.scatter(umap_coords[:, 0], umap_coords[:, 1], c=cluster_labels, s=1, cmap="tab10")
ax.scatter(umap_coords[:, 0], umap_coords[:, 1], c=labels, s=1, cmap="tab10")
ax.set_title(f"UMAP of {channel}")
ax.axis("off")

# save the figure
plt.savefig(output_png_path, bbox_inches="tight", pad_inches=0)
Expand Down

0 comments on commit d550ec7

Please sign in to comment.