-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
static plotting for spatial data #437
Merged
Changes from 1 commit
Commits
Show all changes
253 commits
Select commit
Hold shift + click to select a range
9845461
Merge pull request #418 from theislab/fix/update-contributing
michalk8 9cca775
Fix patching ForwardRef when generating docs
michalk8 019a1e1
Require numba>=0.52.0 (#420)
michalk8 b30c3c2
[auto][ci skip] Generate news fragment (#420)
michalk8 f5ee6dd
Fix CI cron job, remove cond in newsgen (#424)
michalk8 2cae246
[auto][ci skip] Update dev release notes (#424)
michalk8 21b59d7
Fix None in ligrec source/target (#434)
michalk8 a7419bc
[auto][ci skip] Generate news fragment (#434)
michalk8 be45fab
[auto][ci skip] Update dev release notes (#434)
michalk8 f825d62
allow Key.uns.library_id to return list
giovp 172f905
fix logic for Kye.uns.library_id
giovp 0d5fbaa
add Key.uns.image_id
giovp e864116
fix logic Key.uns.image_id
giovp 083edc0
Merge branch 'dev' into plspatial
giovp 6f0bd35
fix logic and add scalefactors_id method
giovp 4cdacc0
return mapping if library_id is None
giovp 974dd37
rename scalefactors to scalefactor
giovp d90acaa
fix logic for return type
giovp f6b8361
fix haystack
giovp f506219
init spatial pl
giovp 20bcbb3
add docstring for _get_unique-map
giovp 9425d38
Fix an import for python 3.10 (#438)
dcjones 2d8dfed
[auto][ci skip] Update dev release notes (#438)
michalk8 39a07ff
change mypy
giovp f7d48a3
clean spatial_attrs and add sanitize_anndata
giovp fed1852
add utils to check val in adata.obs
giovp 4780421
init def spatial
giovp 9dad946
add axis
giovp 1d5127f
add axis
giovp d5677a3
get values and color vector
giovp 3994ab0
Merge branch 'dev' into plspatial
giovp 80a9787
fix tests
giovp c6a806d
fix more tests
giovp d3e03cb
set titles and axis
giovp f6b15e3
add scatter and circles and polygons
giovp 6f11939
add label
giovp 2e9aad7
add size and handle case with no image
giovp a1c43db
fix _get_coords
giovp 814e1ca
add img and crops
giovp 98b9bd6
minor fix
giovp 8f67497
fixes for multiple library plotting
giovp 485d1a9
add colormap, title and axis labels
giovp d3bca63
fix cmap for shaped_collection
giovp e0efc67
add scalebar
giovp 0c45893
fix scalebar kwargs
giovp 84e4cdb
fix outline
giovp b4ec6bc
fixes
giovp 9eddb72
fixes for scalebar
giovp 553c1d9
fix logic for non-visium data
giovp 2cc03ca
more comments
giovp 38518a8
more comments
giovp f092d59
add edges
giovp 9034c4f
change import
giovp a21b06b
add edges_kwargs
giovp 2254e02
change type of crop_coord
giovp a2fa113
some docs for review
giovp 5534d7d
add mode enum for shapes, handle partial and use spatial_conn from pa…
giovp c39a1a6
handle polygons with array and fix types
giovp e087de7
more comments
giovp 382b0a6
more comments and fix palette handling
giovp 7849e97
fix palette handling
giovp c0d88c5
remove print
giovp c7e443e
handle cmap args better
giovp 0ac9eb7
more comments
giovp 88f9ded
fix _get_palette for tests
giovp b2d343f
handle crops better
giovp 7405d15
more comments
giovp 0cc524e
more comments
giovp cda4298
more comments
giovp 7990d8d
fix axis label
giovp ffa14ee
fix axis label
giovp 28d5788
add scalebar to requirements and minor fixes
giovp 665d99c
add scalebar to requirements and minor fixes and handle better na in …
giovp e9d5566
remove non from na_color type
giovp 96e5bd7
make helper function for spatial non image
giovp 8865662
minor fix
giovp 5b7e1db
fix types
giovp 2546a1c
more fix types
giovp 0e9e127
more comments and chekc dimensions
giovp 3380444
fix check dimensions
giovp 9578a8f
remove 3d projection and fixes
giovp 851baa9
make ref count
giovp c4dba90
minor fix on _get_list
giovp 8b418bc
another fix on _get_list
giovp 3bfa4b5
minor fixes
giovp e45509d
minor fixes in pkc_constants
giovp eb4410a
minor fix container
giovp d989b5e
fix types
giovp 86febf4
fix more types and change img_alpha
giovp b437f32
fix pkg constants
giovp edb1dd4
edges -> edge
giovp 8716ca2
edge -> edges
giovp 70a250b
enable panel order by library or color
giovp 738ec73
fix iter
giovp a09bed0
make decorate axes and add img channel
giovp 41e1c0e
add _spatial_utils module
giovp c668b9a
add imports of types
giovp 99fc9f9
minor fix on pkg_constants
giovp 2e4b866
add additional def
giovp 1988b07
[ci skip] Update CONTRIBUTING.rst to mention dev
michalk8 dd3188c
Merge branch 'dev' into plspatial
giovp dab25cf
Merge branch 'plspatial' of https://github.com/theislab/squidpy into …
giovp 86b2769
add type
giovp 70ef5be
add segmentation
giovp 1e7bf2f
add api and minor fixes
giovp 2bf7182
update
giovp baae5cf
import crops in coord
giovp 33f0221
Update _utils.py (#454)
dnjst 154a331
Fixes napari slider and contrast limits (#453)
michalk8 075a09b
[ci skip] Use Literal in ligrec
michalk8 7d33b0e
major refactor
giovp 0a831c5
cleanup
giovp 2a1d448
Merge branch 'dev' into plspatial
giovp e262ff9
remove axs
giovp 5695fa7
Update squidpy/pl/_spatial.py
giovp 19b59d6
Update squidpy/pl/_spatial_utils.py
giovp 0458737
isaac comments
giovp 5aa0c8e
Merge branch 'master' into plspatial
giovp 5d0ba2d
add logging error to palette
giovp 046a794
more comments
giovp d727904
more comments and init NamedTuple
giovp f220bd6
more NamedTuple
giovp 04ddc79
more comments
giovp 067c304
fix typing
giovp 570e65e
more comments
giovp 6ceb8fe
more comments
giovp d7f2fd4
fix for annoying warning
giovp fe8d28c
init docs
giovp d3487ac
continue docs
giovp 8f3d210
try delete params
giovp 39ca951
continue docs
giovp ede14c9
fix docs
giovp 294dfb8
modi gitignore
giovp 07d2690
fix typing
giovp 9277fa7
add _color_utils
giovp faefebb
fix value_to_lot=None
giovp 1afcad3
change modenum to inherit str
giovp a91ee5a
improve docs
giovp f59d506
more improvements
giovp 88b9ec2
fix spellcheck
giovp 6b45448
fix library_id handling
giovp 6a105ec
add img_res_key condition for scalefactor logic
giovp 971c4a8
Merge branch 'master' into plspatial
giovp 2a59ec8
change arguments and unify spatial scatter
giovp ef743b0
init cached datasets and static spatial tests
giovp 106009c
fix fixtures
giovp 34cc288
fix cached tests
giovp 0809fbd
fix cached tests
giovp 5c900ca
add first images
giovp 7567660
add first images
giovp cf4588c
add fixture session
giovp 6a27de3
add CI cache for datasets download
giovp 6cec5b3
add CI cache for datasets download
giovp ccd4e84
add image
giovp cb51c82
fix CI
giovp 4ad0771
fix CI on macos
giovp c7a8e77
fix docs
giovp 5fab926
Merge branch 'master' into plspatial
giovp 0283ddd
raise valueError when multiple library_id found but no library_key
giovp 7104a17
better error message for wrong list
giovp 5043847
more tests
giovp ba7b19e
fix seg boundaries
giovp 459acc8
fix logic for segmentation masks and boundaries
giovp 57468dc
install squidpy for download data step
giovp dd4af93
add library_id tests and more segment plots
giovp 9673248
Merge branch 'master' into plspatial
giovp 0e4e23d
add more tests
giovp 9220c61
fix __init__.py
giovp 6af8d7a
remove print statemtns
giovp e6c5596
fix title
giovp 34b5f73
fix docs
giovp e8dd4b4
re add Union
giovp 0eb0980
add spellcheck
giovp 3bac60c
add another test
giovp fc46e1f
change dpi
giovp 0fefd23
change figure
giovp 62ca04b
Fix square scatter
michalk8 0155ee5
fixes CI
giovp fc9acae
fixes CI
giovp 26a8945
fix notimplemented error and docs
giovp 06cf116
type test
giovp 3d5a429
more comments
giovp b01a60d
remove columns redundandcy
giovp c834e00
fix img_res_key
giovp e5c651c
fix tests
giovp d9e4755
more comments
giovp cb3ba62
more comments
giovp 853fbcc
more comments
giovp e6bf145
more comments types
giovp 9d82b9d
fix tests
giovp e6dee05
more comments
giovp cb9cfc7
more comments
giovp 7cd514a
more comments
giovp 3a699b1
fix tests
giovp 8390d1d
fix lint
giovp c0052ac
more comments
giovp b3d3e53
fix size from mike comments
giovp b69b430
use grayscale
giovp ed77308
check for valid types in lists
giovp fc04040
cehck for empty color list
giovp 4e32001
add types from scanpy
giovp aa6b2da
remove edges and add conn_key
giovp 28f148a
fix spelling
giovp 11621c3
Fix frameon=True
michalk8 2a83f44
Fix cmap being reset
michalk8 31c6e66
Fix warning in groups
michalk8 68b9d04
Fix NA color when groups!=None
michalk8 1755a5b
Fix pet peeve - condition
michalk8 7e59e4f
Be strict with palettes
michalk8 f79134f
remove empty space between plots
giovp 723133c
revert back space in grid
giovp 200f311
more fixes and handle outline when na_color is present
giovp df375be
Merge branch 'master' into plspatial
giovp 1cdd6df
fix docs
giovp a189c03
fix tests and cleanup
giovp 3348d33
add more tests
giovp 1a21627
add wrapper for func signature
giovp 5798fe7
modify wrapper
giovp 5173a5f
more comments
giovp 4eff458
fix spelling
giovp 367492d
Fix not calling decorator function
michalk8 5bc916e
Clean docs a bit
michalk8 d51afcc
Fix cropping bug, _get_list bug, pet peeves
michalk8 a4bd078
test and add test
giovp e6459e3
Merge branch 'master' into plspatial
giovp 1eec5ca
Merge branch 'master' into plspatial
giovp f28b4b1
add params
giovp f94ee76
Merge branch 'master' into plspatial
giovp 40ebdf4
Merge branch 'master' into plspatial
giovp 92260d4
[ci skip] Fix linting
michalk8 64c9924
[ci skip] Remove dead interpolation code, docs
michalk8 f0e7340
Merge branch 'master' into plspatial
giovp c03597e
[ci skip] Don't use future annotations
michalk8 e6df313
Merge branch 'plspatial' of ssh://github.com/theislab/squidpy into pl…
michalk8 4c4a43e
[ci skip] Update defaults
michalk8 e4a6842
Fix pet peeve in docs
michalk8 9b50894
Minor doc improvements
michalk8 4fc07b8
Add seealso's
michalk8 1493e9e
Add option to return axes
michalk8 371d67e
Add test timeout
michalk8 ddf838a
Readd autoscale_view
michalk8 f88194a
Fix undefined variable, pet peeves
michalk8 8fb5476
Fix pet peeve v2
michalk8 0f0827c
Remove macOS 3.7 job
michalk8 60fdd8e
Add initial dask support
michalk8 a453fce
Regenerate figures
michalk8 8a63673
Fix grayscale for dask
michalk8 bd1e32c
Skip 2 tests on mac
michalk8 156e80a
Fix truthiness when img/seg are arrays
michalk8 141df25
Fix truthiness check
michalk8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add library_id tests and more segment plots
- Loading branch information
commit dd4af931dc7075289e040cb432801addfc48c3ee
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from functools import partial | ||
import pytest | ||
|
||
from anndata import AnnData | ||
|
@@ -8,6 +9,7 @@ | |
|
||
from squidpy import pl | ||
from tests.conftest import PlotTester, PlotTesterMeta | ||
from squidpy.pl._spatial_utils import _get_library_id | ||
from squidpy._constants._pkg_constants import Key | ||
|
||
C_KEY = "Cluster" | ||
giovp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -39,24 +41,78 @@ def test_plot_spatial_segment(self, adata_mibitof: AnnData): | |
na_color="lightgrey", | ||
) | ||
|
||
def test_plot_spatial_segment_group(self, adata_mibitof: AnnData): | ||
pl.spatial_segment( | ||
adata_mibitof, | ||
color=["Cluster"], | ||
groups=["Fibroblast", "Endothelial"], | ||
library_key="library_id", | ||
cell_id_key="cell_id", | ||
img=False, | ||
seg=True, | ||
figsize=(5, 5), | ||
legend_na=False, | ||
scalebar_dx=2.0, | ||
scalebar_kwargs={"scale_loc": "bottom", "location": "lower right"}, | ||
) | ||
|
||
def test_plot_spatial_segment_crop(self, adata_mibitof: AnnData): | ||
pl.spatial_segment( | ||
adata_mibitof, | ||
color=["Cluster", "cell_size"], | ||
groups=["Fibroblast", "Endothelial"], | ||
library_key="library_id", | ||
cell_id_key="cell_id", | ||
img=True, | ||
seg=True, | ||
seg_outline=True, | ||
seg_contourpx=15, | ||
figsize=(5, 5), | ||
cmap="magma", | ||
vmin=500, | ||
crop_coord=[[0, 500, 0, 500], [0, 500, 0, 500], [0, 500, 0, 500]], | ||
img_alpha=0.5, | ||
) | ||
|
||
|
||
class TestSpatialStaticUtils: | ||
def create_anndata(self, shape, library_id, library_key): | ||
def _create_anndata(self, shape, library_id, library_key): | ||
giovp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
n_obs = len(library_id) * 2 if isinstance(library_id, list) else 2 | ||
obsm = np.random.normal(size=(n_obs, 2)) | ||
X = (np.empty((n_obs, 3)),) | ||
if isinstance(library_id, list): | ||
if library_key is not None: | ||
obs = pd.Series(library_id * 2, name=library_key) | ||
uns = {Key.uns.spatial: {i: {} for i in "library_id"}} | ||
return AnnData(X, obs=obs, uns=uns, obsm=obsm) | ||
obs = None | ||
return AnnData(X, obs=obs, uns=uns, obsm=obsm) | ||
X = np.empty((n_obs, 3)) | ||
if not isinstance(library_id, list) and library_id is not None: | ||
library_id = [library_id] | ||
if library_id is not None: | ||
obs = pd.DataFrame(library_id * 2, columns=[library_key]) | ||
uns = {Key.uns.spatial: {k: None for k in library_id}} | ||
return AnnData(X, obs=obs, uns=uns, dtype=X.dtype) | ||
else: | ||
return AnnData(X, dtype=X.dtype) | ||
|
||
@pytest.mark.parametrize("shape", ["circle", None]) | ||
@pytest.mark.parametrize("library_id", [None, "1", ["1"], ["1", "2"]]) | ||
@pytest.mark.parametrize("library_key", [None, "batch_key"]) | ||
def test_get_library_id(self, shape, library_id, library_key): | ||
pass | ||
|
||
self._create_anndata(shape, library_id, library_key) | ||
adata = self._create_anndata(shape, library_id, library_key) | ||
if not isinstance(library_id, list) and library_id is not None: | ||
library_id = [library_id] | ||
_get_libid = partial( | ||
_get_library_id, | ||
shape=shape, | ||
library_id=library_id, | ||
library_key=library_key, | ||
) | ||
if shape is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think it makes sense to remove the parametrization by shape, just by looking at the jagged if/else... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the pytest.raise check is different though |
||
if library_id is None: | ||
if library_key is None: | ||
assert _get_libid(adata) == [""] | ||
else: | ||
with pytest.raises(ValueError, match="library_key"): | ||
_get_libid(adata) | ||
else: | ||
assert library_id == _get_libid(adata) | ||
else: | ||
if library_id is None: | ||
with pytest.raises(KeyError, match=Key.uns.spatial): | ||
_get_libid(adata) | ||
else: | ||
assert library_id == _get_libid(adata) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to avoid that cell_id is modifed in place across iterations.