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

[Bug] H3ClusterLayer failing to use get_fill_color #7618

Closed
1 of 6 tasks
ckrapu opened this issue Feb 4, 2023 · 4 comments
Closed
1 of 6 tasks

[Bug] H3ClusterLayer failing to use get_fill_color #7618

ckrapu opened this issue Feb 4, 2023 · 4 comments

Comments

@ckrapu
Copy link

ckrapu commented Feb 4, 2023

Description

I ran the example script for the H3ClusterLayer and was unable to reproduce the yellow-to-red color variation as shown in the docs. My results look more like this:

Screen Shot 2023-02-04 at 4 19 04 PM

Calling %watermark gives the following:

The watermark extension is already loaded. To reload it, use:
  %reload_ext watermark
Python implementation: CPython
Python version       : 3.9.13
IPython version      : 7.31.1

pandas           : 1.4.4
pydeck           : 0.8.0
pydeck_s3_parquet: not installed

Compiler    : Clang 12.0.0 
OS          : Darwin
Release     : 20.4.0
Machine     : x86_64
Processor   : i386
CPU cores   : 12
Architecture: 64bit

Flavors

  • React
  • Python/Jupyter notebook
  • MapboxLayer
  • GoogleMapsOverlay
  • CartoLayer
  • DeckLayer/DeckRenderer for ArcGIS

Expected Behavior

image

Steps to Reproduce

Start a fresh Jupyter notebook and run the following code:

"""
H3ClusterLayer
==============

Data grouped by H3 geohash, as an example of one of the geohash schemes supported by pydeck.

This layer joins contiguous regions into the same color. Data format is as follows:

    [
      {
        "mean": 73.333,
        "count": 440,
        "hexIds": [
          "88283082b9fffff",
          "88283082b1fffff",
          "88283082b5fffff",
          "88283082b7fffff",
          "88283082bbfffff",
          "882830876dfffff"
        ]
      },
      {
        "mean": 384.444,
        "count": 3460,
        "hexIds": [
          "8828308281fffff",
          "8828308287fffff",
          "88283082abfffff",
          "88283082a3fffff",
          "8828308289fffff",
          "88283082c7fffff",
          "88283082c3fffff",
          "88283082c1fffff",
          "88283082d5fffff"
        ]
      },
      ...

If you'd simply like to plot a value at an H3 hex ID, see the H3HexagonLayer.

This example is adapted from the deck.gl documentation.
"""

import pydeck as pdk
import pandas as pd

H3_CLUSTER_LAYER_DATA = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.h3clusters.json"  # noqa

df = pd.read_json(H3_CLUSTER_LAYER_DATA)

# Define a layer to display on a map
layer = pdk.Layer(
    "H3ClusterLayer",
    df,
    pickable=True,
    stroked=True,
    filled=True,
    extruded=False,
    get_hexagons="hexIds",
    get_fill_color="[255, (1 - mean / 500) * 255, 0]",
    get_line_color=[255, 255, 255],
    line_width_min_pixels=2,
)

# Set the viewport location
view_state = pdk.ViewState(latitude=37.7749295, longitude=-122.4194155, zoom=11, bearing=0, pitch=30)


# Render
r = pdk.Deck(layers=[layer], initial_view_state=view_state, tooltip={"text": "Density: {mean}"})
r.to_html("h3_cluster_layer.html")

Environment

  • Framework version:
  • Browser: reproducible in both Chrome via Streamlit app and VSCode via Jupyter
  • OS: macOS Big Sur, 11.3.1

Logs

No relevant messages

@Jesus89
Copy link
Collaborator

Jesus89 commented Apr 1, 2023

This seems to be a bug in deck.gl. I was able to reproduce it in the playground. Not a pydeck issue so I will update the labels.

{
  "initialViewState": {
    "longitude": -122.4194155,
    "latitude": 37.7749295,
    "zoom": 11,
    "pitch": 30,
    "bearing": 0
  },
  "views": [
    {
      "@@type": "MapView",
      "controller": true,
      "mapStyle": "https://basemaps.cartocdn.com/gl/dark-matter-nolabels-gl-style/style.json"
    }
  ],
  "layers": [
    {
      "@@type": "H3ClusterLayer",
      "data": "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.h3clusters.json",
      "pickable": true,
      "stroked": true,
      "filled": true,
      "getHexagons": "@@=hexIds",
      "getFillColor": "@@=[255, (1 - mean / 500) * 255, 0]",
      "getLineColor": "@@=[255, 255, 255]",
      "lineWidthMinPixels": 2
    }
  ]
}

@Pessimistress
Copy link
Collaborator

The underlying issue has been fixed in v8.9.7. I believe pydeck is pinned to 8.8.x, though. @Jesus89

@ckrapu
Copy link
Author

ckrapu commented Apr 5, 2023

Awesome, thank you!

@Jesus89
Copy link
Collaborator

Jesus89 commented Apr 7, 2023

Nice @Pessimistress. We will prepare a release of pydeck pointing to v8.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants