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

color and PMTiles utils #97

Merged
merged 115 commits into from
Dec 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
77cabc0
Add color utils
Jul 12, 2024
7edf0b4
Add save method to map
Jul 12, 2024
21a3981
Add maplibre express CoreLayer
Jul 12, 2024
c9ccb41
Support numeric color columns
Jul 12, 2024
fcd3b98
Fix color expressions
Jul 12, 2024
1e0a299
Add vancouver blocks express example
Jul 12, 2024
88850cc
Create color expression from quantiles
Jul 13, 2024
eb688dc
Refactor color utils
Jul 13, 2024
71d6f9a
Add quantiles as q parameter
Jul 13, 2024
49051ce
Add method to list cmaps
Jul 13, 2024
bf25dfd
Add default color and refactor
Jul 14, 2024
df50922
Add outline color
Jul 14, 2024
15bec27
Refactor and add helper to get pmtile meta data
Jul 15, 2024
8b2363a
Move pmtiles utils to separate file
Jul 15, 2024
8391b97
PMTiles class
Jul 15, 2024
cdc34cc
Add PMTiles header class
Jul 16, 2024
d72bc12
Fix test
Jul 16, 2024
ad67f34
Create source based on tile type
Jul 16, 2024
81969a8
Return vector source
Jul 16, 2024
b4ec856
Fix missing h3 dep for geo layers
Jul 16, 2024
2784de3
Create basemap from pmtiles
Jul 17, 2024
6587bda
Refactor
Jul 17, 2024
45e8426
Merge branch 'dev' into feature/color-utils
Jul 18, 2024
57653b1
Refactor
Jul 18, 2024
5c671bd
Use fixed h3 version
Jul 18, 2024
3959490
Support h3 deck layers in shiny apps
Jul 18, 2024
49a243c
Extract maplibre version
Jul 18, 2024
d152b0f
Support deck.gl geo layers
Jul 18, 2024
ea6ff10
Merge pull request #102 from eodaGmbH/feature/deck-geolayers-ipywidget
crazycapivara Jul 18, 2024
619f17c
Catch error
Jul 19, 2024
851b870
Get pmtiles header from local file
Jul 19, 2024
b25d819
Support metadata from local pmtiles
Jul 19, 2024
103b500
Refactor
Jul 19, 2024
b1b5f97
Add simple features source
Jul 20, 2024
e4486b8
Allow geopandas sources
Jul 21, 2024
94eb3ba
Add optinal to layer attributes
Jul 21, 2024
40a8c83
Extract BaseModel to _core
Jul 21, 2024
d6ebbe0
Rename BaseModel to MapLibreBaseModel
Jul 21, 2024
4c51361
Allow arbitrary types
Jul 21, 2024
a1a080d
Allow geopandas source for layers
Jul 21, 2024
219151f
Add test for SimpleFeatures
Jul 21, 2024
f81f8d4
Remove dead code
Jul 21, 2024
9b4f6cf
Add layers and sources parameter to Map
Jul 21, 2024
fb97161
Add simple layers
Jul 22, 2024
4a0fa33
Add bounds property to layer
Jul 22, 2024
a74dfc7
Add position param to controls
Jul 24, 2024
3c2b7c3
Add controls param to map
Jul 24, 2024
3014796
Add interpolate expression
Jul 25, 2024
0fa4e7d
Add step expression
Jul 25, 2024
9200b04
Add example using pydeck.Layer
Jul 25, 2024
013fb16
Support pydeck layers
Jul 25, 2024
401c866
Add comment
Jul 25, 2024
a146587
Allow GeoDataFrame in set Data
Jul 25, 2024
90ef826
Update changelog
Jul 25, 2024
40ab30a
Add additional params to MapWidget
Jul 25, 2024
75349b5
color_match_expr
Jul 25, 2024
b2628db
Add quantiles expression
Jul 26, 2024
b316144
Add _future
Jul 26, 2024
da93408
Add py.typed
Jul 26, 2024
75c136f
Move color expressions to expressions
Jul 26, 2024
c182855
Refactor expressions
Jul 26, 2024
e70256d
Refactor expressions
Jul 26, 2024
eff3d3d
Add example datasets
Jul 27, 2024
448c997
Add filter example
Jul 27, 2024
cda034f
Add filter expressions
Jul 27, 2024
2a3b555
Update docs
Jul 27, 2024
2c5cce2
Refactor __future__ code
Jul 27, 2024
c96ba4b
Add dataset
Jul 27, 2024
dad061e
Add urban areas dataset
Jul 27, 2024
c081be2
Add fit_bounds method
Jul 27, 2024
a3c2935
Update changelog
Jul 27, 2024
5117006
Add new express implementation
Jul 28, 2024
dbccf38
Store path
Jul 28, 2024
0ba1196
Use url as source if possible
Jul 28, 2024
72623b4
Add earthquakes dataset
Jul 28, 2024
fc2b3e2
Add circle express layer
Jul 28, 2024
d14d6d6
Add color bin expression
Jul 28, 2024
8b444dd
Add map_this
Jul 29, 2024
6c6e1d1
Add Wes Anderson color palettes
Jul 31, 2024
4267202
Update settings
Jul 31, 2024
0a8f371
Set default fill_outline_color
Jul 31, 2024
6a8d8ea
Fix settings
Jul 31, 2024
d0b417f
Move color_utils to _deprecated
Jul 31, 2024
f826cbc
Move current express to _deprecated
Jul 31, 2024
451109d
Use fill_outline_color from settings
Jul 31, 2024
86f7ee6
Move express from __future__ to root
Jul 31, 2024
e03bd95
Typo
Jul 31, 2024
5b6150f
Add default layer styles
Jul 31, 2024
d52b917
Add test
Jul 31, 2024
1d18d72
Add maptiler support
Aug 29, 2024
2b1e0ec
Typo
Aug 29, 2024
1bce806
Update docs
Aug 29, 2024
4820dd2
Update changelog
Aug 29, 2024
0796929
Fix express
Aug 29, 2024
bc0e99d
Use model_post_init
Aug 29, 2024
1cc130e
Refactor simple layer
Aug 29, 2024
b446877
Update docs
Aug 29, 2024
f7a514d
Add height param to ipywidget
Aug 29, 2024
4ce3f11
Rename Maptiler to MapTiler
Sep 2, 2024
1f91856
Add basemap demotiles constant
Sep 2, 2024
08ea1c9
Add extrusion layer to express
Sep 2, 2024
d7b5226
Use specific maplibre version in html template
Sep 2, 2024
f460279
Refactor
Sep 2, 2024
ba4373b
Rename settings.py to config.py
Sep 2, 2024
4579225
Rename settings to options
Sep 2, 2024
a00fc27
Import options in init
Sep 2, 2024
ae010bb
Add TODO
Sep 2, 2024
00bab7b
Add TODO
Sep 2, 2024
f80327a
Remove dead code
Sep 2, 2024
9de16ba
Refactor fit_bounds
Sep 2, 2024
8b33025
Update docs
Sep 2, 2024
36381c1
Add data
Sep 6, 2024
fa78654
Add comments
Sep 6, 2024
cde470d
Merge branch 'dev' into feature/color-utils
Oct 31, 2024
93d1ef1
v0.2.7
Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create color expression from quantiles
  • Loading branch information
Stefan Kuethe committed Jul 13, 2024
commit 88850cc928aa899c2d656cbb6cac2bb124197fb7
14 changes: 14 additions & 0 deletions maplibre/color_utils.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ def create_numeric_color_expression(
) -> tuple | None:
step = (max(values) - min(values)) / n
breaks = [min(values) + i * step for i in range(n)]
# return create_numeric_color_expression_from_breaks(column_name, breaks, cmap)
colors = color_brewer(cmap, n + 1)

expression = (
@@ -79,3 +80,16 @@ def create_numeric_color_expression(
)

return expression, breaks, colors


def create_numeric_color_expression_from_quantiles(
values: Any, q: list, column_name: str, cmap: str = "viridis"
):
try:
import numpy as np
except ImportError as e:
print(e)
return

breaks = np.quantile(values, q)
return create_numeric_color_expression_from_breaks(column_name, breaks, cmap)
25 changes: 25 additions & 0 deletions tests/test_color_expressions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from maplibre.color_utils import (
create_categorical_color_expression,
create_numeric_color_expression_from_breaks,
create_numeric_color_expression_from_quantiles,
)


@@ -50,3 +51,27 @@ def test_numeric_color_expression_from_breaks():
6,
"#fde725",
]


def test_numeric_color_expression_from_quantiles():
# Prepare
values = [1, 4, 2, 8, 9, 2, 3, 4]
column_name = "test"
quantiles = [0.25, 0.75]

# Act
expression = create_numeric_color_expression_from_quantiles(
values, q=quantiles, column_name=column_name
)
print(expression)

# Assert
assert expression == [
"step",
["get", "test"],
"#440154",
2.0,
"#21908c",
5.0,
"#fde725",
]