Skip to content

Commit

Permalink
Merge branch 'master' into chore-update-datasdk
Browse files Browse the repository at this point in the history
  • Loading branch information
abstractalgo authored Jul 29, 2024
2 parents 8575dc3 + 44ac797 commit ca29bb8
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 227 deletions.
38 changes: 20 additions & 18 deletions python-notebooks/01 - Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"# If in Colab, install this notebook's required dependencies\n",
"import sys\n",
"if \"google.colab\" in sys.modules:\n",
" !pip install 'foursquare.map_sdk>=1.0' sidecar pandas"
" !pip install 'foursquare.map_sdk>=3.0.1' sidecar pandas"
]
},
{
Expand All @@ -68,7 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"from foursquare.map_sdk import create_map\n",
"import foursquare.map_sdk as map_sdk\n",
"from sidecar import Sidecar\n",
"import pandas as pd"
]
Expand Down Expand Up @@ -96,7 +96,9 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map = create_map()"
"map = map_sdk.create_map(\n",
" api_key=\"<your-api-key>\"\n",
")"
]
},
{
Expand All @@ -114,7 +116,7 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map"
"map"
]
},
{
Expand All @@ -134,7 +136,7 @@
"source": [
"sc = Sidecar(title='Studio Map', anchor='split-right')\n",
"with sc:\n",
" display(unfolded_map)"
" display(map)"
]
},
{
Expand All @@ -160,14 +162,14 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.add_dataset({\n",
" 'data': pd.DataFrame({\n",
" 'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],\n",
" 'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],\n",
" 'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],\n",
" 'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]\n",
" })\n",
"})"
"map.add_dataset(map_sdk.LocalDatasetCreationProps(\n",
" data=pd.DataFrame({\n",
" 'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],\n",
" 'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],\n",
" 'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],\n",
" 'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]\n",
"})\n",
"))"
]
},
{
Expand All @@ -193,11 +195,11 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.set_view({\n",
" 'longitude': -60, \n",
" 'latitude': -20,\n",
" 'zoom': 2\n",
"})"
"map.set_view(map_sdk.PartialView(\n",
" longitude=-60,\n",
" latitude=-20,\n",
" zoom=2\n",
"))"
]
},
{
Expand Down
26 changes: 14 additions & 12 deletions python-notebooks/02 - Local maps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"# If in Colab, install this notebook's required dependencies\n",
"import sys\n",
"if \"google.colab\" in sys.modules:\n",
" !pip install 'foursquare.map_sdk>=1.0' requests pandas"
" !pip install 'foursquare.map_sdk>=3.0.1' requests pandas"
]
},
{
Expand All @@ -68,7 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"from foursquare.map_sdk import create_map\n",
"import foursquare.map_sdk as map_sdk\n",
"from uuid import uuid4\n",
"import pandas as pd\n",
"import requests"
Expand All @@ -89,8 +89,10 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map = create_map()\n",
"unfolded_map"
"map = map_sdk.create_map(\n",
" api_key=\"<your-api-key>\"\n",
")\n",
"map"
]
},
{
Expand Down Expand Up @@ -147,11 +149,11 @@
"outputs": [],
"source": [
"url = 'https://4sq-studio-public.s3.us-west-2.amazonaws.com/sdk/examples/sample-data/earthquakes.csv'\n",
"unfolded_map.add_dataset({\n",
" 'id': dataset_id,\n",
" 'label': 'Earthquakes dataset',\n",
" 'data': pd.read_csv(url)\n",
"})"
"map.add_dataset(map_sdk.LocalDatasetCreationProps(\n",
" id=dataset_id,\n",
" label='Earthquakes dataset',\n",
" data=pd.read_csv(url)\n",
"))"
]
},
{
Expand All @@ -169,7 +171,7 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.remove_dataset(dataset_id)"
"map.remove_dataset(dataset_id)"
]
},
{
Expand Down Expand Up @@ -198,7 +200,7 @@
"url = 'https://4sq-studio-public.s3.us-west-2.amazonaws.com/sdk/examples/sample-data/nyc-census.json'\n",
"r = requests.get(url)\n",
"census_tracts_geojson = r.json()\n",
"unfolded_map.add_dataset({'data': census_tracts_geojson})"
"map.add_dataset(map_sdk.LocalDatasetCreationProps(data=census_tracts_geojson))"
]
},
{
Expand Down Expand Up @@ -238,7 +240,7 @@
"metadata": {},
"outputs": [],
"source": [
"added_dataset = unfolded_map.add_dataset({'data': earthquakes_csv})"
"added_dataset = map.add_dataset(map_sdk.LocalDatasetCreationProps(data=earthquakes_csv))"
]
}
],
Expand Down
73 changes: 40 additions & 33 deletions python-notebooks/03 - Layers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"# If in Colab, install this notebook's required dependencies\n",
"import sys\n",
"if \"google.colab\" in sys.modules:\n",
" !pip install 'foursquare.map_sdk>=1.0' pandas"
" !pip install 'foursquare.map_sdk>=3.0.1' pandas"
]
},
{
Expand All @@ -62,12 +62,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "020d1aa5",
"metadata": {},
"outputs": [],
"source": [
"from foursquare.map_sdk import create_map\n",
"import foursquare.map_sdk as map_sdk\n",
"import pandas as pd\n",
"from uuid import uuid4"
]
Expand Down Expand Up @@ -95,8 +95,10 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map = create_map()\n",
"unfolded_map"
"map = map_sdk.create_map(\n",
" api_key=\"<your-api-key>\"\n",
")\n",
"map"
]
},
{
Expand Down Expand Up @@ -153,12 +155,11 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.add_dataset(\n",
" {\n",
" 'id': dataset_id,\n",
" 'label': 'Earthquakes',\n",
" 'data': earthquakes_data\n",
" },\n",
"map.add_dataset(map_sdk.LocalDatasetCreationProps(\n",
" id=dataset_id,\n",
" label='Earthquakes',\n",
" data=earthquakes_data\n",
" ),\n",
" auto_create_layers = False\n",
")"
]
Expand Down Expand Up @@ -186,23 +187,19 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.add_layer({\n",
" 'id': 'earthquake_points',\n",
" 'type': 'point',\n",
" 'data_id': dataset_id,\n",
" 'label': 'Earthquakes',\n",
" 'fields': {\n",
" 'lat': 'Latitude',\n",
" 'lng': 'Longitude'\n",
" },\n",
" 'is_visible': True,\n",
" 'config': {\n",
" 'visual_channels': {\n",
" 'colorField': {'name': 'Depth', 'type': 'real'}\n",
" }\n",
" \n",
" }\n",
"})"
"layer = map_sdk.PointLayer(\n",
" id='earthquake_points',\n",
" data_id=dataset_id,\n",
" columns=map_sdk.PointLayerNeighborsColumns(\n",
" lat='Latitude',\n",
" lng='Longitude'\n",
" ),\n",
" label='Earthquakes',\n",
" color_column='Depth',\n",
" color_column_type='real'\n",
")\n",
"\n",
"map.add_layer_from_config(layer.to_json())"
]
},
{
Expand Down Expand Up @@ -230,7 +227,7 @@
"metadata": {},
"outputs": [],
"source": [
"layers = unfolded_map.get_layers()"
"layers = map.get_layers()"
]
},
{
Expand Down Expand Up @@ -275,7 +272,12 @@
"outputs": [],
"source": [
"# Hide layer\n",
"unfolded_map.update_layer(layers[0].id, is_visible=False)"
"map.update_layer(\n",
" layer_id=layers[0].id,\n",
" values=map_sdk.LayerUpdateProps(\n",
" is_visible=False\n",
" )\n",
")"
]
},
{
Expand All @@ -286,7 +288,12 @@
"outputs": [],
"source": [
"# Show layer again\n",
"unfolded_map.update_layer(layers[0].id, is_visible=True)"
"map.update_layer(\n",
" layer_id=layers[0].id,\n",
" values=map_sdk.LayerUpdateProps(\n",
" is_visible=True\n",
" )\n",
")"
]
},
{
Expand All @@ -312,7 +319,7 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.remove_layer('earthquake_points')"
"map.remove_layer('earthquake_points')"
]
},
{
Expand All @@ -330,7 +337,7 @@
"metadata": {},
"outputs": [],
"source": [
"unfolded_map.remove_dataset(dataset_id)"
"map.remove_dataset(dataset_id)"
]
}
],
Expand Down
Loading

0 comments on commit ca29bb8

Please sign in to comment.