Skip to content

Commit a874c07

Browse files
committed
updates in carto to mapbox migration notebook
1 parent 5082b4f commit a874c07

File tree

1 file changed

+300
-0
lines changed

1 file changed

+300
-0
lines changed

ResourceWatch/data_management/migration/Cartocss_mapbox_migration.ipynb

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
"More info can be found on the ````cartocssParser-VLSCompiler notebook````."
2626
]
2727
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 932,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"PRODUCTION_SERVER = 'https://api.resourcewatch.org'\n",
35+
"API_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjU5ZGI0ZWFjZTljMTM4MDAwMWQ2ZTRjMyIsInJvbGUiOiJBRE1JTiIsInByb3ZpZGVyIjoibG9jYWwiLCJlbWFpbCI6ImFkYW0ucGFpbkB2aXp6dWFsaXR5LmNvbSIsImV4dHJhVXNlckRhdGEiOnsiYXBwcyI6WyJydyIsImdmdyIsInByZXAiLCJhcXVlZHVjdCIsImZvcmVzdC1hdGxhcyIsImRhdGE0c2RncyIsImdmdy1jbGltYXRlIiwiZ2Z3LXBybyIsImdoZy1nZHAiLCJuZyJdfSwiY3JlYXRlZEF0IjoxNTcxOTMxNzI5MTMyLCJpYXQiOjE1NzE5MzE3Mjl9.h8WPxtaItHm20eThQd7ZcyXPoDrzO3a2Q2TiYrPci50'\n",
36+
"STAGING_SERVER = 'https://staging-api.globalforestwatch.org'\n",
37+
"STAGING_API_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjU5ZGI0ZWFjZTljMTM4MDAwMWQ2ZTRjMyIsInJvbGUiOiJBRE1JTiIsInByb3ZpZGVyIjoibG9jYWwiLCJlbWFpbCI6ImFkYW0ucGFpbkB2aXp6dWFsaXR5LmNvbSIsImV4dHJhVXNlckRhdGEiOnsiYXBwcyI6WyJuZyIsImdmdyIsInJ3IiwicHJlcCIsImFxdWVkdWN0IiwiZm9yZXN0LWF0bGFzIl19LCJjcmVhdGVkQXQiOjE1NzE5MzI4NDYxMTIsImlhdCI6MTU3MTkzMjg0Nn0.FZn70gN1RSlGsv_otmbhltm6qyonbTYcpEft3lEWTi0'"
38+
]
39+
},
2840
{
2941
"cell_type": "code",
3042
"execution_count": 563,
@@ -7698,6 +7710,294 @@
76987710
"source": [
76997711
"len(failed)"
77007712
]
7713+
},
7714+
{
7715+
"cell_type": "markdown",
7716+
"metadata": {},
7717+
"source": [
7718+
"# QA on updated layers:"
7719+
]
7720+
},
7721+
{
7722+
"cell_type": "code",
7723+
"execution_count": null,
7724+
"metadata": {},
7725+
"outputs": [],
7726+
"source": []
7727+
},
7728+
{
7729+
"cell_type": "code",
7730+
"execution_count": 1083,
7731+
"metadata": {},
7732+
"outputs": [
7733+
{
7734+
"data": {
7735+
"text/html": [
7736+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919?includes=vocabulary,metadata target='_blank'><b>2014 Global Conflict Risk Index—Food Insecurity</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-02-14T08:38:46.197Z<br><a href='https://api.resourcewatch.org/v1/fields/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7737+
],
7738+
"text/plain": [
7739+
"Layer cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919 2014 Global Conflict Risk Index—Food Insecurity"
7740+
]
7741+
},
7742+
"execution_count": 1083,
7743+
"metadata": {},
7744+
"output_type": "execute_result"
7745+
}
7746+
],
7747+
"source": [
7748+
"layer = lmi.Layer('cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919')\n",
7749+
"layer"
7750+
]
7751+
},
7752+
{
7753+
"cell_type": "code",
7754+
"execution_count": 1084,
7755+
"metadata": {},
7756+
"outputs": [
7757+
{
7758+
"data": {
7759+
"text/plain": [
7760+
"{'account': 'wri-rw',\n",
7761+
" 'body': {'maxzoom': 18,\n",
7762+
" 'minzoom': 3,\n",
7763+
" 'layers': [{'type': 'mapnik',\n",
7764+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.food FROM soc_055_global_conflict_risk_index data LEFT OUTER JOIN wri_countries_a wri ON wri.iso_a3=data.rw_country_code WHERE year=2014 AND data.food IS NOT NULL',\n",
7765+
" 'cartocss': '#soc_055_global_conflict_risk_index {polygon-opacity:1; line-width:0.3; line-color:#adadad; line-opacity:1;} [food>=8]{polygon-fill:#0868ac;} [food>=6][food<8]{polygon-fill:#43a2ca;} [food>=4][food<6]{polygon-fill:#7bccc4;} [food>=2][food<4]{polygon-fill:#bae4bc;} [food<2]{polygon-fill:#f0f9e8;}',\n",
7766+
" 'cartocss_version': '2.3.0'}}],\n",
7767+
" 'vectorLayers': [{'paint': {'line-width': 0.3,\n",
7768+
" 'line-color': '#adadad',\n",
7769+
" 'line-opacity': 1},\n",
7770+
" 'source-layer': 'layer0',\n",
7771+
" 'type': 'line',\n",
7772+
" 'filter': ['all']},\n",
7773+
" {'paint': {'fill-opacity': 1},\n",
7774+
" 'source-layer': 'layer0',\n",
7775+
" 'type': 'fill',\n",
7776+
" 'filter': ['all']},\n",
7777+
" {'paint': {'fill-color': '#0868ac'},\n",
7778+
" 'source-layer': 'layer0',\n",
7779+
" 'type': 'fill',\n",
7780+
" 'filter': ['all', ['>=', 'food', 8]]},\n",
7781+
" {'paint': {'fill-color': '#43a2ca'},\n",
7782+
" 'source-layer': 'layer0',\n",
7783+
" 'type': 'fill',\n",
7784+
" 'filter': ['all', ['>=', 'food', 6], ['<', 'food', 8]]},\n",
7785+
" {'paint': {'fill-color': '#7bccc4'},\n",
7786+
" 'source-layer': 'layer0',\n",
7787+
" 'type': 'fill',\n",
7788+
" 'filter': ['all', ['>=', 'food', 4], ['<', 'food', 6]]},\n",
7789+
" {'paint': {'fill-color': '#bae4bc'},\n",
7790+
" 'source-layer': 'layer0',\n",
7791+
" 'type': 'fill',\n",
7792+
" 'filter': ['all', ['>=', 'food', 2], ['<', 'food', 4]]},\n",
7793+
" {'paint': {'fill-color': '#f0f9e8'},\n",
7794+
" 'source-layer': 'layer0',\n",
7795+
" 'type': 'fill',\n",
7796+
" 'filter': ['all', ['<', 'food', 2]]}]},\n",
7797+
" 'layerType': 'vector'}"
7798+
]
7799+
},
7800+
"execution_count": 1084,
7801+
"metadata": {},
7802+
"output_type": "execute_result"
7803+
}
7804+
],
7805+
"source": [
7806+
"layer.attributes['layerConfig']"
7807+
]
7808+
},
7809+
{
7810+
"cell_type": "code",
7811+
"execution_count": 1089,
7812+
"metadata": {},
7813+
"outputs": [],
7814+
"source": [
7815+
"payload = {\n",
7816+
" 'layerConfig':{'account': 'wri-rw',\n",
7817+
" 'body': {'maxzoom': 18,\n",
7818+
" 'minzoom': 3,\n",
7819+
" 'layers': [{'type': 'mapnik',\n",
7820+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.food FROM soc_055_global_conflict_risk_index data LEFT OUTER JOIN wri_countries_a wri ON wri.iso_a3=data.rw_country_code WHERE year=2014 AND data.food IS NOT NULL',\n",
7821+
" 'cartocss': '#soc_055_global_conflict_risk_index {polygon-opacity:1; line-width:0.3; line-color:#adadad; line-opacity:1;} [food>=8]{polygon-fill:#0868ac;} [food>=6][food<8]{polygon-fill:#43a2ca;} [food>=4][food<6]{polygon-fill:#7bccc4;} [food>=2][food<4]{polygon-fill:#bae4bc;} [food<2]{polygon-fill:#f0f9e8;}',\n",
7822+
" 'cartocss_version': '2.3.0'}}],\n",
7823+
" 'vectorLayers': [{'paint': {'line-width': 0.3,\n",
7824+
" 'line-color': '#adadad',\n",
7825+
" 'line-opacity': 1},\n",
7826+
" 'source-layer': 'layer0',\n",
7827+
" 'type': 'line',\n",
7828+
" 'filter': ['all']},\n",
7829+
" {'paint': {'fill-opacity': 1},\n",
7830+
" 'source-layer': 'layer0',\n",
7831+
" 'type': 'fill',\n",
7832+
" 'filter': ['all']},\n",
7833+
" {'paint': {'fill-color': '#0868ac'},\n",
7834+
" 'source-layer': 'layer0',\n",
7835+
" 'type': 'fill',\n",
7836+
" 'filter': ['all', ['>=', 'food', '8']]},\n",
7837+
" {'paint': {'fill-color': '#43a2ca'},\n",
7838+
" 'source-layer': 'layer0',\n",
7839+
" 'type': 'fill',\n",
7840+
" 'filter': ['all', ['>=', 'food', '6'], ['<', 'food', '8']]},\n",
7841+
" {'paint': {'fill-color': '#7bccc4'},\n",
7842+
" 'source-layer': 'layer0',\n",
7843+
" 'type': 'fill',\n",
7844+
" 'filter': ['all', ['>=', 'food', '4'], ['<', 'food', '6']]},\n",
7845+
" {'paint': {'fill-color': '#bae4bc'},\n",
7846+
" 'source-layer': 'layer0',\n",
7847+
" 'type': 'fill',\n",
7848+
" 'filter': ['all', ['>=', 'food', '2'], ['<', 'food', '4']]},\n",
7849+
" {'paint': {'fill-color': '#f0f9e8'},\n",
7850+
" 'source-layer': 'layer0',\n",
7851+
" 'type': 'fill',\n",
7852+
" 'filter': ['all', ['<', 'food', '2']]}]},\n",
7853+
" 'layerType': 'vector'}\n",
7854+
"}"
7855+
]
7856+
},
7857+
{
7858+
"cell_type": "code",
7859+
"execution_count": 1086,
7860+
"metadata": {},
7861+
"outputs": [],
7862+
"source": [
7863+
"payload = {\n",
7864+
" 'layerConfig':{'account': 'wri-rw',\n",
7865+
" 'body': {'maxzoom': 18,\n",
7866+
" 'minzoom': 3,\n",
7867+
" 'layers': [{'type': 'mapnik',\n",
7868+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.food FROM soc_055_global_conflict_risk_index data LEFT OUTER JOIN wri_countries_a wri ON wri.iso_a3=data.rw_country_code WHERE year=2014 AND data.food IS NOT NULL',\n",
7869+
" 'cartocss': '#soc_055_global_conflict_risk_index {polygon-opacity:1; line-width:0.3; line-color:#adadad; line-opacity:1;} [food>=8]{polygon-fill:#0868ac;} [food>=6][food<8]{polygon-fill:#43a2ca;} [food>=4][food<6]{polygon-fill:#7bccc4;} [food>=2][food<4]{polygon-fill:#bae4bc;} [food<2]{polygon-fill:#f0f9e8;}',\n",
7870+
" 'cartocss_version': '2.3.0'}}],\n",
7871+
" 'vectorLayers': []},\n",
7872+
" 'layerType': 'vector'}\n",
7873+
"}"
7874+
]
7875+
},
7876+
{
7877+
"cell_type": "code",
7878+
"execution_count": 1090,
7879+
"metadata": {},
7880+
"outputs": [
7881+
{
7882+
"data": {
7883+
"text/html": [
7884+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919?includes=vocabulary,metadata target='_blank'><b>2014 Global Conflict Risk Index—Food Insecurity</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-03-25T17:50:13.268Z<br><a href='https://api.resourcewatch.org/v1/fields/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7885+
],
7886+
"text/plain": [
7887+
"Layer cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919 2014 Global Conflict Risk Index—Food Insecurity"
7888+
]
7889+
},
7890+
"execution_count": 1090,
7891+
"metadata": {},
7892+
"output_type": "execute_result"
7893+
}
7894+
],
7895+
"source": [
7896+
"layer"
7897+
]
7898+
},
7899+
{
7900+
"cell_type": "code",
7901+
"execution_count": 1091,
7902+
"metadata": {},
7903+
"outputs": [
7904+
{
7905+
"data": {
7906+
"text/html": [
7907+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919?includes=vocabulary,metadata target='_blank'><b>2014 Global Conflict Risk Index—Food Insecurity</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-03-25T17:50:21.309Z<br><a href='https://api.resourcewatch.org/v1/fields/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7908+
],
7909+
"text/plain": [
7910+
"Layer cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919 2014 Global Conflict Risk Index—Food Insecurity"
7911+
]
7912+
},
7913+
"execution_count": 1091,
7914+
"metadata": {},
7915+
"output_type": "execute_result"
7916+
}
7917+
],
7918+
"source": [
7919+
"layer.update(update_params=payload, token=API_TOKEN)"
7920+
]
7921+
},
7922+
{
7923+
"cell_type": "code",
7924+
"execution_count": 1092,
7925+
"metadata": {},
7926+
"outputs": [
7927+
{
7928+
"data": {
7929+
"text/html": [
7930+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/f12a4fb3-943b-4124-aba5-59e8c4a55e3c?includes=vocabulary,metadata target='_blank'><b>2016 Gini Index</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-03-11T04:04:42.158Z<br><a href='https://api.resourcewatch.org/v1/fields/f12a4fb3-943b-4124-aba5-59e8c4a55e3c' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7931+
],
7932+
"text/plain": [
7933+
"Layer f12a4fb3-943b-4124-aba5-59e8c4a55e3c 2016 Gini Index"
7934+
]
7935+
},
7936+
"execution_count": 1092,
7937+
"metadata": {},
7938+
"output_type": "execute_result"
7939+
}
7940+
],
7941+
"source": [
7942+
"gini = lmi.Layer(\"f12a4fb3-943b-4124-aba5-59e8c4a55e3c\")\n",
7943+
"gini"
7944+
]
7945+
},
7946+
{
7947+
"cell_type": "code",
7948+
"execution_count": 1093,
7949+
"metadata": {},
7950+
"outputs": [
7951+
{
7952+
"data": {
7953+
"text/plain": [
7954+
"{'account': 'wri-rw',\n",
7955+
" 'timelineLabel': '2016',\n",
7956+
" 'order': 2016,\n",
7957+
" 'timeline': True,\n",
7958+
" 'body': {'maxzoom': 18,\n",
7959+
" 'minzoom': 3,\n",
7960+
" 'layers': [{'type': 'mapnik',\n",
7961+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.rw_country_code, data.datetime, data.yr_data FROM soc_020_gini data LEFT OUTER JOIN wri_countries_a wri ON data.rw_country_code = wri.iso_a3 WHERE EXTRACT(YEAR FROM data.datetime) = 2016 and data.yr_data IS NOT NULL',\n",
7962+
" 'cartocss': '#soc_020_gini {polygon-opacity: 1; line-width: 0.5; line-color: #FFF; line-opacity: 1;} [yr_data>=50]{polygon-fill:#63589f;} [yr_data>=40][yr_data<50]{polygon-fill:#9178c4;} [yr_data>=35][yr_data<40]{polygon-fill:#b998dd;} [yr_data<35]{polygon-fill:#dbbaed;}',\n",
7963+
" 'cartocss_version': '2.3.0'}}],\n",
7964+
" 'vectorLayers': [{'paint': {'fill-color': ['step',\n",
7965+
" ['to-number', ['get', 'yr_data']],\n",
7966+
" '#dbbaed',\n",
7967+
" 35,\n",
7968+
" '#b998dd',\n",
7969+
" 40,\n",
7970+
" '#9178c4',\n",
7971+
" 50,\n",
7972+
" '#63589f',\n",
7973+
" 60,\n",
7974+
" '#fff'],\n",
7975+
" 'fill-opacity': 1},\n",
7976+
" 'source-layer': 'layer0',\n",
7977+
" 'type': 'fill',\n",
7978+
" 'filter': ['all']},\n",
7979+
" {'paint': {'line-width': 0.5, 'line-color': '#fff', 'line-opacity': 0.8},\n",
7980+
" 'source-layer': 'layer0',\n",
7981+
" 'type': 'line',\n",
7982+
" 'filter': ['all']}]},\n",
7983+
" 'layerType': 'vector'}"
7984+
]
7985+
},
7986+
"execution_count": 1093,
7987+
"metadata": {},
7988+
"output_type": "execute_result"
7989+
}
7990+
],
7991+
"source": [
7992+
"gini.attributes['layerConfig']"
7993+
]
7994+
},
7995+
{
7996+
"cell_type": "code",
7997+
"execution_count": null,
7998+
"metadata": {},
7999+
"outputs": [],
8000+
"source": []
77018001
}
77028002
],
77038003
"metadata": {

0 commit comments

Comments
 (0)