Created
August 2, 2023 13:31
-
-
Save grst/c06d0f5b66ca972553b8e311dd778609 to your computer and use it in GitHub Desktop.
Get bounding box for squidpy spatial plot to be equivalent to the scanpy.pl.spatial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_bbox(adata, library_id, *, library_key="sample", img_key="hires", margin=50): | |
adata = adata[adata.obs[library_key] == library_id, :] | |
coords = adata.obsm["spatial"] | |
scale_factor = adata.uns["spatial"][library_id]["scalefactors"][f"tissue_{img_key}_scalef"] | |
return tuple( | |
np.array( | |
[ | |
np.min(coords[:, 0]) - margin, | |
np.min(coords[:, 1]) - margin, | |
np.max(coords[:, 0]) + margin, | |
np.max(coords[:, 1]) + margin, | |
] | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment