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

Fix antialiased line issues #1072

Merged
merged 10 commits into from
Apr 23, 2022
Merged

Fix antialiased line issues #1072

merged 10 commits into from
Apr 23, 2022

Conversation

ianthomas23
Copy link
Member

This is a WIP to fix various issues with antialiased lines for the impending release.

The major change is support for both 1 and 2-stage aggregations. Where possible (e.g. ds.any and ds.max) a single-stage agg is used on an individual line segment basis. ds.min always uses a 2-stage agg on an individual line segment basis. ds.count and ds.sum now have 2 options controlled by self_intersect boolean kwarg. If False the usual 2-stage agg is used which is very accurate but slower and ignores line self-intersections. If True, the default, a 1-stage agg is used that considers the previous line segment so that pixels are not overwritten at line segment joins; this therefore deals with self-intersections and is faster but there will be rendering artifacts in some situations (some are fixable, others are unavoidable).

I am open to suggestions for a better name for the kwarg than self_intersect.

Antialiased self-intersecting path using ds.count now looks like this (from 15-Large_Data.ipynb):
paths

Antialiased multiple timeseries using ds.count now looks like this (from 3_Timeseries.ipynb):
overlap_ts

datashader/glyphs/line.py Outdated Show resolved Hide resolved
@ianthomas23
Copy link
Member Author

The above multiple timeseries plot has artifacts to the left of y-extrema. This is now fixed:

lw1

Here is the equivalent line_width=0 plot:

lw0

@ianthomas23
Copy link
Member Author

Performance of antialiased lines is slower than non-antialiased for 2 reasons:

  1. Low-level pixel-setting code is more complicated.
  2. Two-stage agg code has multiple agg-combining calls, each of which is a NaN-aware combination of 2 arrays of same shape as canvas plus a reset of one of those arrays to zero (or NaN). This does not occur for one-stage agg.

Timings using code based on last plot in Timeseries jupyter notebook that combines nlines lines of 10-points each onto a 1000x400 pixel canvas. Timed line_width=1 for both ds.count(self_intersect=True) (1-stage agg) and ds.count(self_intersect=False) (2-stage agg) compared to line_width=0.

nlines Slowdown factor for 1-stage agg Slowdown factor for 2-stage agg
100 1.3 2.5
1k 1.6 4.7
10k 3.3 7.9
100k 5.4 13.0
1M 5.7 13.7

@ianthomas23
Copy link
Member Author

ianthomas23 commented Apr 22, 2022

Example output for multiple timeseries (1000 here) where x-values are spaced apart, for line_width=1:
ts_lw1

Compare with line_width=0:
ts_lw0

This uses agg=ds.count() and how='eq_hist'.

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know any clearer option name, so it looks ready to merge to me!

datashader/core.py Outdated Show resolved Hide resolved
datashader/glyphs/line.py Outdated Show resolved Hide resolved
@jbednar jbednar marked this pull request as ready for review April 23, 2022 03:33
@jbednar jbednar merged commit d7d51b5 into holoviz:master Apr 23, 2022
@ianthomas23 ianthomas23 deleted the aa_fixes branch July 19, 2023 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants