Skip to content
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

Support antialiased lines in *_n reductions #1262

Merged
merged 1 commit into from Aug 2, 2023
Merged

Support antialiased lines in *_n reductions #1262

merged 1 commit into from Aug 2, 2023

Conversation

ianthomas23
Copy link
Member

This adds support for antialiased lines in *_n reductions such as max_n and first_n. They return reasonable results, but these are not necessarily consistent with the non-*_n reductions yet. Support for antialiased where reductions will follow this, and then a full review of whether the results are consistent for all of the different line types supported (axis 0, axis 1, etc).

Example of output using this script

import datashader as ds
import numpy as np
import pandas as pd

df = pd.DataFrame(dict(
    ystart=[0.2, 0, 1, 0.8],
    yend=[0.2, 1, 0, 0.8],
    value=[2, 4, 1, 3],
))
kwargs = dict(source=df, x=np.asarray([0, 1]), y=["ystart", "yend"], axis=1, line_width=15)

reductions = dict(
    first_n=ds.first_n("value", n=2),
    last_n=ds.last_n("value", n=2),
    min_n=ds.min_n("value", n=2),
    max_n=ds.max_n("value", n=2),
    min_n_row_index=ds._min_n_row_index(n=2),
    max_n_row_index=ds._max_n_row_index(n=2),
)

cvs = ds.Canvas(plot_width=200, plot_height=150, x_range=(-0.1, 1.1), y_range=(-0.1, 1.1))
for name, reduction in reductions.items():
    agg = cvs.line(agg=reduction, **kwargs)
    span = (np.nanmin(agg), np.nanmax(agg))
    for k in range(agg.shape[2]):
        im = ds.transfer_functions.shade(agg[:, :, k], how="linear", span=span)
        ds.utils.export_image(im, f"temp_{name}_{k}", background="white")

first_n showing [:, :, 0] then [:, :, 1]:
temp_first_n_0 temp_first_n_1

last_n:
temp_last_n_0 temp_last_n_1

min_n:
temp_min_n_0 temp_min_n_1

max_n:
temp_max_n_0 temp_max_n_1

_min_n_row_index:
temp_min_n_row_n_0 temp_min_n_row_n_1

_max_n_row_index:
temp_max_n_row_n_0 temp_max_n_row_n_1

@ianthomas23 ianthomas23 added this to the v0.15.2 milestone Aug 1, 2023
@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #1262 (1f91111) into main (0b71920) will decrease coverage by 0.19%.
The diff coverage is 67.36%.

@@            Coverage Diff             @@
##             main    #1262      +/-   ##
==========================================
- Coverage   83.62%   83.43%   -0.19%     
==========================================
  Files          35       35              
  Lines        8938     9069     +131     
==========================================
+ Hits         7474     7567      +93     
- Misses       1464     1502      +38     
Files Changed Coverage Δ
datashader/core.py 88.25% <ø> (ø)
datashader/utils.py 76.89% <28.84%> (-5.82%) ⬇️
datashader/compiler.py 90.03% <83.33%> (-0.21%) ⬇️
datashader/reductions.py 80.10% <90.14%> (+0.94%) ⬆️
datashader/antialias.py 96.87% <100.00%> (+0.10%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ianthomas23 ianthomas23 merged commit f1e61b8 into holoviz:main Aug 2, 2023
14 of 16 checks passed
@ianthomas23 ianthomas23 deleted the aa_stage_2_max_n_etc branch August 2, 2023 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant