def test_warning(): """Verify that a warning is emitted when no Mapbox API key is set""" _environ = dict(os.environ) try: if os.environ.get("MAPBOX_API_KEY"): del os.environ["MAPBOX_API_KEY"] with pytest.warns(UserWarning) as record: d = Deck() # noqa: F841 os.environ["MAPBOX_API_KEY"] = "pk.xx" d = Deck() # noqa: F841 # Assert that only one warning has been raised assert len(record) == 1 finally: os.environ.clear() os.environ.update(_environ)
def create_minimal_test_object(): lights = LightSettings( lights_position=[ -0.144528, 49.739968, 8000, -3.807751, 54.104682, 8000 ], ambient_ratio=0.4, diffuse_ratio=0.6, ) layer = Layer( "HexagonLayer", "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv", id="heatmap", elevation_scale=50, elevation_range=[0, 3000], extruded=True, coverage=1, light_settings=lights, ) view_state = ViewState( longitude=-1.4157267858730052, latitude=52.232395363869415, zoom=6.6, min_zoom=5, max_zoom=15, pitch=40.5, bearing=-27.396674584323023, ) view = View(type="MapView", controller=True) return Deck(layers=[layer], initial_view_state=view_state, views=[view])
def test_constructor_binary_transport(): test_layer = Layer( "ScatterplotLayer", data=df, id="test-layer", use_binary_transport=True, get_position="position", radius=10, ) EXPECTED_DATUM = { "layer_id": "test-layer", "column_name": "position", "accessor": "getPosition", "np_data": np.array([[0, 0], [0, 0]]), } actual_datum = test_layer.get_binary_data()[0] assert test_layer.radius == 10 assert test_layer.use_binary_transport == True assert test_layer.data is None assert len(test_layer.get_binary_data()) == 1 assert EXPECTED_DATUM["layer_id"] == actual_datum["layer_id"] assert EXPECTED_DATUM["column_name"] == actual_datum["column_name"] assert EXPECTED_DATUM["accessor"] == actual_datum["accessor"] assert np.array_equal(EXPECTED_DATUM["np_data"], actual_datum["np_data"]) assert "0, 0" not in Deck( test_layer).to_json(), "Should not write data to JSON output"
def test_json_output(): lights = LightSettings( lights_position=[ -0.144528, 49.739968, 8000, -3.807751, 54.104682, 8000], ambient_ratio=0.4, diffuse_ratio=0.6) layer = Layer( 'HexagonLayer', 'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv', id='heatmap', elevation_scale=50, elevation_range=[0, 3000], extruded=True, coverage=1, light_settings=lights) view_state = ViewState( longitude=-1.4157267858730052, latitude=52.232395363869415, zoom=6.6, min_zoom=5, max_zoom=15, pitch=40.5, bearing=-27.396674584323023) view = View(type='MapView', controller=True) deck = Deck(layers=[layer], initial_view_state=view_state, views=[view]) assert str(deck) == json.dumps(json.loads(FIXTURE_STRING), sort_keys=True)
def create_heatmap_test_object(): DESCRIPTION = "HexagonLayer without a function string should fail but HeatmapLayer should succeed" # This actually shouldn't render # Tries to detect if strings are being interpreted by the # expression parser in @deck.gl/json failed_hexagon_layer = Layer( type="HexagonLayer", id="failed-heatmap", data=data, elevation_range=[0, 15], elevation_scale=1800, get_position="'[lon, lat]'", radius=10000, upper_percentile=100, color_range=color_range, ) # This will render successful_heatmap_layer = Layer( type="HeatmapLayer", id="successful-heatmap", data=data, get_position=["lon", "lat"], color_range=color_range, ) return Deck( description=DESCRIPTION, initial_view_state=ViewState( **{"longitude": 0, "latitude": 0, "zoom": 5, "pitch": 40.5, "bearing": -27.396674584323023} ), views=[View(type="MapView", controller=True)], layers=[failed_hexagon_layer, successful_heatmap_layer], map_style=None, )
def create_stacked_test_object(): view_state = ViewState(max_zoom=20, zoom=15) scatterplot = Layer( "ScatterplotLayer", data=data, get_position="position", get_radius=100, id="first", getColor="rgb", ) text_layer = Layer( "TextLayer", data=df, id="second", font_size=144, get_color=[0, 0, 255], get_position="position", get_text_anchor="`start`", font_family="`Times, Times New Roman, Georgia, serif`", ) return Deck( description="Test of plotting multiple layers at once", layers=[scatterplot, text_layer], initial_view_state=view_state, views=None, map_style=None, )
def create_scatterplot_test_object(): view_state = ViewState(latitude=0, longitude=0, zoom=12) layers = [ Layer( "ScatterplotLayer", id="scatterplot", data=[[0, 0], [0.01, 0.01]], get_position="-", get_radius=500, get_fill_color=[255, 0, 0], ) ] return Deck(layers=layers, initial_view_state=view_state, map_style=None, views=None)
def create_multi_layer_test_object(): view_state = ViewState(latitude=-122.45, longitude=37.8, zoom=12) scatterplot = Layer( "ScatterplotLayer", id='scatterplot', data=[{ "position": [-122.45, 37.8] }], get_position='position', get_fill_color=[255, 0, 0, 255], get_radius=1000, ) text_layer = Layer( "TextLayer", id='textlayer', data=[{ "position": [-122.45, 37.8], "text": "Hello World" }], get_position='position', get_text_anchor="end", ) geojson_layer = Layer( "GeoJsonLayer", id='geojsonlayer', data={ "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-122.42923736572264, 37.80544394934271], }, }], }, stroked=True, filled=True, get_position='features.geometry.coordinates', line_width_min_pixels=2, opacity=0.4, get_line_color=[255, 100, 100], get_fill_color=[200, 160, 0, 180], ) return Deck(layers=[scatterplot, text_layer, geojson_layer], initial_view_state=view_state)
def create_geojson_layer_test_object(): return Deck(description="Test of GeoJsonLayer", map_style=None, initial_view_state=ViewState(longitude=-122.45, latitude=37.8, zoom=0), layers=[ Layer( "GeoJsonLayer", id='geojson-layer', data=features, stroked=True, filled=True, line_width_min_pixels=2, opacity=0.4, get_line_color=[255, 100, 100], get_fill_color=[200, 160, 0, 180], ) ], views=None)
def create_geojson_layer_with_gmaps_test_object(): return Deck( description="Test of GeoJsonLayer, with Google Maps basemap", map_style="satellite", map_provider="google_maps", initial_view_state=ViewState(longitude=-122.45, latitude=37.8, zoom=0), layers=[ Layer( "GeoJsonLayer", id="geojson-layer", data=features, stroked=True, filled=True, line_width_min_pixels=2, opacity=0.4, get_line_color=[255, 100, 100], get_fill_color=[200, 160, 0, 180], ) ], views=None, )
}, { "rgb": [123, 159, 53], "position": [0.002, 0.002] }, ] d = Deck(layers=[ Layer( "ScatterplotLayer", data=scatterplot_data, get_radius=100, picking_radius=5, pickable=True, get_color="rgb", get_position="position", ), Layer( "TextLayer", data=text_data, picking_radius=5, get_color=[255, 255, 255], pickable=True, font_size=72, get_position="position", ), ]) v = ViewState(latitude=0, longitude=0, zoom=15) d.initial_view_state = v def has_pyppeteer(): try:
import pytest import os from pydeck import Deck, Layer, ViewState from ..const import FIXTURE_STRING from .screenshot_utils import go_to_page_and_screenshot text_data = [{'text': 'Test', 'position': [0.0, 0.0]}] d = Deck(layers=[ Layer( 'TextLayer', data=text_data, get_color=[0, 255, 255], font_size=72, get_position='position')]) v = ViewState(latitude=0, longitude=0, zoom=15) d.initial_view_state = v @pytest.mark.asyncio async def test_standalone_rendering(tmp_path): filename = d.to_html(str(tmp_path) + '/', open_browser=False) await go_to_page_and_screenshot('file://' + filename, filename, output_dir=tmp_path) @pytest.mark.skip(reason='Not yet implemented') @pytest.mark.asyncio async def test_notebook_iframe_rendering(): pass
'rgb': [45, 136, 45], 'position': [0.002, -0.002] }, { 'rgb': [123, 159, 53], 'position': [0.002, 0.002] }, ] d = Deck(layers=[ Layer('ScatterplotLayer', data=scatterplot_data, get_radius=100, picking_radius=5, pickable=True, get_color='rgb', get_position='position'), Layer('TextLayer', data=text_data, picking_radius=5, get_color=[255, 255, 255], pickable=True, font_size=72, get_position='position'), ]) v = ViewState(latitude=0, longitude=0, zoom=15) d.initial_view_state = v @pytest.mark.skipif(os.environ.get('TRAVIS') == 'true', reason='Skipping this test on Travis CI.') @pytest.mark.asyncio async def test_standalone_rendering(tmp_path):
def test_deck_layer_args(): """Verify layer argument null cases""" CASES = [({"layers": None}, []), ({"layers": []}, [])] for [args, expected_output] in CASES: r = Deck(**args) assert r.layers == expected_output
id='heatmap', elevation_scale=50, elevation_range=[0, 3000], extruded=True, coverage=1, light_settings=lights) view_state = ViewState( longitude=-1.4157267858730052, latitude=52.232395363869415, zoom=6.6, min_zoom=5, max_zoom=15, pitch=40.5, bearing=-27.396674584323023) view = View(type='MapView', controller=True) deck = Deck(layers=[layer], initial_view_state=view_state, views=[view]) def test_json_output(): """Verify that the JSON rendering produces an @deck.gl/json library-compliant JSON object""" assert str(deck) == json.dumps(json.loads(FIXTURE_STRING), sort_keys=True) def test_update(): """Verify that calling `update` changes the Deck object""" view_state.latitude, view_state.longitude = 0, 0 deck.update() # Create relevant results string expected_results = json.loads(FIXTURE_STRING) expected_results['initialViewState']['latitude'] = 0 expected_results['initialViewState']['longitude'] = 0
from pydeck import Layer, Deck from pydeck.data_utils import compute_view from pydeck.types import String DATA_URL = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/bart-stations.json" SCENEGRAPH_URL = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoxAnimated/glTF-Binary/BoxAnimated.glb" # Automatically fit viewport location based on data df = pd.read_json(DATA_URL) view = compute_view(df["coordinates"]) layer = Layer( type="ScenegraphLayer", id="scenegraph-layer", data=DATA_URL, pickable=True, scenegraph=SCENEGRAPH_URL, get_position="coordinates", get_orientation=[0, 180, 90], size_scale=500, _animations={"*": { "speed": 5 }}, _lighting=String("pbr"), ) # Render r = Deck(layer, initial_view_state=view) r.to_html("scenegraph_layer.html")