Skip to content

Commit

Permalink
datashader speedup and bugfixes (#309)
Browse files Browse the repository at this point in the history
Co-authored-by: Sonja Stockhaus <[email protected]>
Co-authored-by: Luca Marconato <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tim Treis <[email protected]>
  • Loading branch information
5 people authored Oct 23, 2024
1 parent 80c6f77 commit bc2db2c
Show file tree
Hide file tree
Showing 29 changed files with 514 additions and 105 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ and this project adheres to [Semantic Versioning][].
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [0.2.7] - 2024-09-04
## [0.2.7] - tbd

### Added

-
- The user can now specify `datashader_reduction` to control the rendering behaviour (#309)
- Rendering outlines of shapes with datashader works now (#309)

### Changed

-

### Fixed

- datashader now uses canvas size = image size which speeds up the rendering (#309)
- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309)
- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309)
- Giving a custom colormap when rendering a multiscale image now works (#586)

## [0.2.6] - 2024-09-04
Expand Down
26 changes: 21 additions & 5 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,15 @@ def render_shapes(
Name of the table containing the color(s) columns. If one name is given than the table is used for each
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
elements, as specified under element.
**kwargs : Any
Additional arguments to be passed to cmap and norm.
Additional arguments for customization. This can include:
datashader_reduction : Literal[
"sum", "mean", "any", "count", "std", "var", "max", "min"
], default: "sum"
Reduction method for datashader when coloring by continuous values. Defaults to 'sum'.
Notes
-----
Expand Down Expand Up @@ -264,13 +271,13 @@ def render_shapes(
scale=scale,
table_name=table_name,
method=method,
ds_reduction=kwargs.get("datashader_reduction", None),
)

sdata = self._copy()
sdata = _verify_plotting_tree(sdata)
n_steps = len(sdata.plotting_tree.keys())
outline_params = _set_outline(outline_alpha > 0, outline_width, outline_color)

for element, param_values in params_dict.items():
cmap_params = _prepare_cmap_norm(
cmap=cmap,
Expand All @@ -291,7 +298,8 @@ def render_shapes(
transfunc=kwargs.get("transfunc", None),
table_name=param_values["table_name"],
zorder=n_steps,
method=method,
method=param_values["method"],
ds_reduction=param_values["ds_reduction"],
)
n_steps += 1

Expand Down Expand Up @@ -361,8 +369,14 @@ def render_points(
Name of the table containing the color(s) columns. If one name is given than the table is used for each
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
elements, as specified under element.
kwargs
Additional arguments to be passed to cmap and norm.
**kwargs : Any
Additional arguments for customization. This can include:
datashader_reduction : Literal[
"sum", "mean", "any", "count", "std", "var", "max", "min"
], default: "sum"
Reduction method for datashader when coloring by continuous values. Defaults to 'sum'.
Returns
-------
Expand All @@ -388,6 +402,7 @@ def render_points(
norm=norm,
size=size,
table_name=table_name,
ds_reduction=kwargs.get("datashader_reduction", None),
)

if method is not None:
Expand Down Expand Up @@ -419,6 +434,7 @@ def render_points(
table_name=param_values["table_name"],
zorder=n_steps,
method=method,
ds_reduction=param_values["ds_reduction"],
)
n_steps += 1

Expand Down
Loading

0 comments on commit bc2db2c

Please sign in to comment.