-
Notifications
You must be signed in to change notification settings - Fork 40
fix: DataFilterExtension get_filter_category #884
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
Draft
ATL2001
wants to merge
20
commits into
developmentseed:main
Choose a base branch
from
ATL2001:category_filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d37c8ce
add FilterCategoryAccessor modeled after FilterValueAccessor
ATL2001 53abc41
use FilterCategoryAccessor for get_filter_category, and set the min v…
ATL2001 8ff247e
pass filterSize and categorySize if they're both defined to the _Data…
ATL2001 5c7f72e
add temporary example notebook
ATL2001 a1f519b
lint
ATL2001 e5281be
more linting...
ATL2001 732fcf2
Merge branch 'main' into category_filter
kylebarron 2403779
simplify if/else blocks and add defaults if None on python side
ATL2001 e4625c2
change min values to 1 and set default to 1 for filter_size
ATL2001 647a111
default category_size to None, filter_size to 1
ATL2001 b0086ad
added a few more cells to make sure I didnt break anything :)
ATL2001 daf0a51
lint the trowaway notebook
ATL2001 fa6d94b
Merge branch 'main' into category_filter
ATL2001 6f2a8da
Merge branch 'main' into category_filter
ATL2001 90426c0
update docstring for filter/category_size being optional
ATL2001 4270606
need to use ravel("C") for multiple categories
ATL2001 00b0763
add data filter extension tests
ATL2001 7046fad
Merge remote-tracking branch 'upstream/main' into category_filter
ATL2001 d733fce
move FilterCategoryAccessor to _extensions.py
ATL2001 23b8fc7
import TraitError from traitlets
ATL2001 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
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "9ffdeba2", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# no intention of actually keeping this notebook in the repo, once it's all working good I'll make up a new doc about the category_filter\n", | ||
| "# I have added it for now to demonstrate that I've got the data filter filter_categories functionality working for numeric inputs\n", | ||
| "# looking at the deck gl docs: https://deck.gl/docs/api-reference/extensions/data-filter-extension#layer-properties\n", | ||
| "# it appears that we should be able to use strings for the categories but when I try to use string data the layer simply doesnt work\n", | ||
| "\n", | ||
| "import geopandas as gpd\n", | ||
| "import ipywidgets\n", | ||
| "import pyarrow as pa # noqa\n", | ||
| "from shapely.geometry import Point\n", | ||
| "\n", | ||
| "import lonboard\n", | ||
| "from lonboard.basemap import CartoBasemap\n", | ||
| "from lonboard.layer_extension import DataFilterExtension\n", | ||
| "\n", | ||
| "cat_col = \"int_col\"\n", | ||
| "# int_col: works\n", | ||
| "# float_col: works\n", | ||
| "# str_col: does NOT work :(\n", | ||
| "# as is it will throw an arro3 ValueError: Expected object with __arrow_c_array__ method or implementing buffer protocol.\n", | ||
| "# we can avoid the arro3 exception by using pyarrow as the input to get_filter_category when we create the layer:\n", | ||
| "# `get_filter_category=pa.array(gdf[cat_col])`\n", | ||
| "# but the layer doesn't display and throws a lot of the following WebGL error:\n", | ||
| "# GL_INVALID_OPERATION: Vertex shader input type does not match the type of the bound vertex attribute\n", | ||
| "\n", | ||
| "\n", | ||
| "d = {\n", | ||
| " \"int_col\": [0, 1, 2, 3, 4, 5],\n", | ||
| " \"float_col\": [0.0, 1.5, 0.0, 1.5, 0.0, 1.5],\n", | ||
| " \"str_col\": [\"even\", \"odd\", \"even\", \"odd\", \"even\", \"odd\"],\n", | ||
| " \"geometry\": [\n", | ||
| " Point(0, 0),\n", | ||
| " Point(1, 1),\n", | ||
| " Point(2, 2),\n", | ||
| " Point(3, 3),\n", | ||
| " Point(4, 4),\n", | ||
| " Point(5, 5),\n", | ||
| " ],\n", | ||
| "}\n", | ||
| "gdf = gpd.GeoDataFrame(d, crs=\"EPSG:4326\")\n", | ||
| "\n", | ||
| "point_layer = lonboard.ScatterplotLayer.from_geopandas(\n", | ||
| " gdf,\n", | ||
| " get_fill_color=(0, 255, 0),\n", | ||
| " radius_min_pixels=10,\n", | ||
| " extensions=[\n", | ||
| " DataFilterExtension(filter_size=0, category_size=1),\n", | ||
| " ], # no range filter, just a category\n", | ||
| " get_filter_category=gdf[cat_col], # use the cat column for the filter category\n", | ||
| ")\n", | ||
| "\n", | ||
| "m = lonboard.Map(layers=[point_layer], basemap_style=CartoBasemap.DarkMatter)\n", | ||
| "\n", | ||
| "filter_enabled_w = ipywidgets.Checkbox(\n", | ||
| " value=True,\n", | ||
| " description=\"Filter Enabled\",\n", | ||
| ")\n", | ||
| "\n", | ||
| "\n", | ||
| "def on_filter_enabled_change(change): # noqa\n", | ||
| " # when we change the checkbox, toggle filtering on the layer\n", | ||
| " point_layer.filter_enabled = filter_enabled_w.value\n", | ||
| "\n", | ||
| "\n", | ||
| "filter_enabled_w.observe(on_filter_enabled_change, names=\"value\")\n", | ||
| "\n", | ||
| "cat_selector = ipywidgets.SelectMultiple( # make a select multiple so we can see interaction on the map\n", | ||
| " options=list(gdf[cat_col].unique()),\n", | ||
| " value=[list(gdf[cat_col].unique())[0]],\n", | ||
| " description=\"Category\",\n", | ||
| " disabled=False,\n", | ||
| ")\n", | ||
| "\n", | ||
| "\n", | ||
| "def on_cat_selector_change(change) -> None: # noqa\n", | ||
| " # when we change the selector, update the filter on the layer.\n", | ||
| " point_layer.filter_categories = cat_selector.value\n", | ||
| "\n", | ||
| "\n", | ||
| "cat_selector.observe(on_cat_selector_change, names=\"value\")\n", | ||
| "\n", | ||
| "ipywidgets.VBox([m, filter_enabled_w, cat_selector])" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ce25544c", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "point_layer2 = lonboard.ScatterplotLayer.from_geopandas(\n", | ||
| " gdf,\n", | ||
| " get_fill_color=(0, 255, 0),\n", | ||
| " radius_min_pixels=10,\n", | ||
| " extensions=[\n", | ||
| " DataFilterExtension(filter_size=1, category_size=0),\n", | ||
| " ], # no category filter, just a range\n", | ||
| " get_filter_value=gdf[\"int_col\"], # use the int_col for the filter category\n", | ||
| ")\n", | ||
| "\n", | ||
| "m2 = lonboard.Map(layers=[point_layer2], basemap_style=CartoBasemap.DarkMatter)\n", | ||
| "point_layer2.filter_range = [0, 5]\n", | ||
| "m2" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ef71f006", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "point_layer2.filter_range = [1, 4]" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "10e27c5d", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "point_layer3 = lonboard.ScatterplotLayer.from_geopandas(\n", | ||
| " gdf,\n", | ||
| " get_fill_color=(0, 255, 0),\n", | ||
| " radius_min_pixels=10,\n", | ||
| " extensions=[\n", | ||
| " DataFilterExtension(filter_size=1, category_size=1),\n", | ||
| " ], # no category filter, just a range\n", | ||
| " get_filter_category=gdf[\n", | ||
| " \"float_col\"\n", | ||
| " ], # use the float column for the filter category\n", | ||
| " get_filter_value=gdf[\"int_col\"], # use the int column for the filter category\n", | ||
| ")\n", | ||
| "\n", | ||
| "point_layer3.filter_categories = [1.5]\n", | ||
| "point_layer3.filter_range = [0, 3]\n", | ||
| "m3 = lonboard.Map(layers=[point_layer3], basemap_style=CartoBasemap.DarkMatter)\n", | ||
| "m3" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "c3f48195", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "point_layer3.filter_range = [0, 5]" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "lonboard_category_filter", | ||
| "language": "python", | ||
| "name": "lonboard_category_filter" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.8" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Can you add some tests for this? There are some example tests in
test_traits.pyand you can look at #917 for more examples.It might be worth making
test_traitsinto a folder and having a file specifically fortest_traits/test_filter_extension.pyThere 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.
ran out of time tonight, but I'll see what I can do in the next couple evenings, or maybe this weekend