diff --git a/ResourceWatch/Api_definition/layer_definition.ipynb b/ResourceWatch/Api_definition/layer_definition.ipynb index 9d5016b..cbfcf11 100644 --- a/ResourceWatch/Api_definition/layer_definition.ipynb +++ b/ResourceWatch/Api_definition/layer_definition.ipynb @@ -805,7 +805,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -816,6 +816,8 @@ "text": [ "builtins==None\n", "builtins==None\n", + "sys==None\n", + "os==None\n", "requests_toolbelt.sessions==None\n", "types==None\n", "json==2.0.9\n", @@ -857,10 +859,10 @@ { "data": { "text/markdown": [ - "**Layer**: [Intact Forest Landscapes - 2000-2016](https://api.resourcewatch.org/v1/dataset/b29f48ff-dd92-4cb4-a37f-82080ed80da0/layer/af4e9e0b-cbf9-437b-80cb-9b0f795161ca)" + "**Layer**: [June 30, 2022 04:00 CT NO₂ Concentration (ppb)](https://api.resourcewatch.org/v1/dataset/918ba6bc-69ed-44fb-9b29-5fb445fdfef6/layer/ca17eef5-b750-472c-87bb-167e7d3fcbab)" ], "text/plain": [ - "Layer(id=UUID('af4e9e0b-cbf9-437b-80cb-9b0f795161ca'), type='layer', attributes=LayerAttributes(name='Intact Forest Landscapes - 2000-2016', description='IFL including reduction in extent 2013-2016', application=['gfw'], iso=[], provider='vector', type=None, default=False, protected=True, published=True, env='production', layerConfig=LayerConfigV4(type='vector', lmMetadata={'version': '4.0'}, source={'type': 'vector', 'provider': {'type': 'carto', 'account': 'wri-01', 'layers': [{'options': {'sql': 'SELECT * FROM ifl_2000_2013_2016 {{where}}', 'type': 'cartodb'}}]}}, render={'layers': [{'paint': {'fill-color': '#5C8C50', 'fill-opacity': 0.9}, 'source-layer': 'layer0', 'type': 'fill'}, {'filter': ['all', ['==', 'class', 'IFL2000']], 'paint': {'fill-color': '#969904'}, 'source-layer': 'layer0', 'type': 'fill'}, {'filter': ['all', ['==', 'class', 'IFL2013']], 'paint': {'fill-color': '#635731'}, 'source-layer': 'layer0', 'type': 'fill'}]}, deck=None, version='3.0', sql_config=[{'key': 'where', 'key_params': [{'key': 'class', 'required': True, 'default': ['IFL2016', 'IFL2013', 'IFL2000'], 'items': [{'key': 2000, 'value': ['IFL2016', 'IFL2013', 'IFL2000']}, {'key': 2013, 'value': ['IFL2016', 'IFL2013']}, {'key': 2016, 'value': ['IFL2016']}]}]}]), legendConfig={'items': [{'color': '#5C8C50', 'name': 'Intact Forest Landscapes'}, {'color': '#969904', 'name': 'Reduction in extent 2000-2013'}, {'color': '#635731', 'name': 'Reduction in extent 2013-2016'}], 'type': 'basic'}, interactionConfig={}, applicationConfig={'active': True, 'dataset_slug': 'intact-forest-landscapes', 'default': True, 'global': True, 'menuPosition': 3, 'metadata': 'intact_forest_landscapes_change', 'slug': 'intact-forest-landscapes', 'v2_id': 'fd44b976-62e6-4072-8218-8abf6e254ed8'}, staticImageConfig={}, createdAt='2020-03-12T11:36:53.788Z', updatedAt='2021-01-14T16:37:09.934Z'), _url='https://api.resourcewatch.org/v1/dataset/b29f48ff-dd92-4cb4-a37f-82080ed80da0/layer/af4e9e0b-cbf9-437b-80cb-9b0f795161ca')" + "Layer(id=UUID('ca17eef5-b750-472c-87bb-167e7d3fcbab'), type='layer', attributes=LayerAttributes(name='June 30, 2022 04:00 CT NO₂ Concentration (ppb)', description='Air quality forecast for nitrogen dioxide (NO₂) concentrations at Earth’s surface on indicated date, expressed in parts per billion (ppb).', application=['rw'], iso=[], provider='gee', type=None, default=False, protected=False, published=True, env='production', layerConfig=LayerConfigV4(type='raster', lmMetadata={'version': '4.0', 'legacy-keys': ['timeline', 'timelineLabel', 'order', 'body', 'assetId']}, source={'provider': {'type': 'gee', 'options': {}}, 'type': 'raster', 'tiles': [], 'minzoom': 3, 'maxzoom': 12}, render=None, deck=None, body={'sldValue': ' b1 ', 'styleType': 'sld'}, order=28, assetId='projects/resource-watch-gee/loc_mcaqf_mexico_city_aq_forecast/NO2/loc_mcaqf_mexico_city_aq_forecast_NO2_20220629_28', timeline=True, timelineLabel='028'), legendConfig={'items': [{'color': '#08519c', 'name': '0', 'id': 0}, {'color': '#3182bd', 'name': '10', 'id': 1}, {'color': '#6baed6', 'name': '20', 'id': 2}, {'color': '#9ecae1', 'name': '30', 'id': 3}, {'color': '#c6dbef', 'name': '40', 'id': 4}, {'color': '#eff3ff', 'name': '≥50', 'id': 5}], 'type': 'gradient'}, interactionConfig={'type': 'intersection', 'config': {'url': 'https://api.resourcewatch.org/v1/query/ca17eef5-b750-472c-87bb-167e7d3fcbab?sql=select st_summarystats(rast, \\'b1\\', false) as x from \\'projects/resource-watch-gee/loc_mcaqf_mexico_city_aq_forecast/NO2/loc_mcaqf_mexico_city_aq_forecast_NO2_20220629_28\\' where ST_INTERSECTS(ST_SetSRID(ST_GeomFromGeoJSON(\\'{\"type\":\"Point\",\"coordinates\":[{{lng}},{{lat}}]}\\'),4326),the_geom)'}, 'output': [{'column': 'x.b1.mean', 'property': 'Nitrogen dioxide concentration', 'type': 'number', 'format': '0.00', 'prefix': ' ', 'suffix': ' ppb'}]}, applicationConfig={}, staticImageConfig={}, createdAt='2020-09-22T23:46:01.111Z', updatedAt='2022-06-29T17:24:03.393Z'), _url='https://api.resourcewatch.org/v1/dataset/918ba6bc-69ed-44fb-9b29-5fb445fdfef6/layer/ca17eef5-b750-472c-87bb-167e7d3fcbab')" ] }, "execution_count": 3, @@ -884,34 +886,22 @@ { "data": { "text/plain": [ - "{'type': 'vector',\n", - " 'lmMetadata': {'version': '4.0'},\n", - " 'source': {'type': 'vector',\n", - " 'provider': {'type': 'carto',\n", - " 'account': 'wri-01',\n", - " 'layers': [{'options': {'sql': 'SELECT * FROM ifl_2000_2013_2016 {{where}}',\n", - " 'type': 'cartodb'}}]}},\n", - " 'render': {'layers': [{'paint': {'fill-color': '#5C8C50',\n", - " 'fill-opacity': 0.9},\n", - " 'source-layer': 'layer0',\n", - " 'type': 'fill'},\n", - " {'filter': ['all', ['==', 'class', 'IFL2000']],\n", - " 'paint': {'fill-color': '#969904'},\n", - " 'source-layer': 'layer0',\n", - " 'type': 'fill'},\n", - " {'filter': ['all', ['==', 'class', 'IFL2013']],\n", - " 'paint': {'fill-color': '#635731'},\n", - " 'source-layer': 'layer0',\n", - " 'type': 'fill'}]},\n", + "{'type': 'raster',\n", + " 'lmMetadata': {'version': '4.0',\n", + " 'legacy-keys': ['timeline', 'timelineLabel', 'order', 'body', 'assetId']},\n", + " 'source': {'provider': {'type': 'gee', 'options': {}},\n", + " 'type': 'raster',\n", + " 'tiles': [],\n", + " 'minzoom': 3,\n", + " 'maxzoom': 12},\n", + " 'render': None,\n", " 'deck': None,\n", - " 'version': '3.0',\n", - " 'sql_config': [{'key': 'where',\n", - " 'key_params': [{'key': 'class',\n", - " 'required': True,\n", - " 'default': ['IFL2016', 'IFL2013', 'IFL2000'],\n", - " 'items': [{'key': 2000, 'value': ['IFL2016', 'IFL2013', 'IFL2000']},\n", - " {'key': 2013, 'value': ['IFL2016', 'IFL2013']},\n", - " {'key': 2016, 'value': ['IFL2016']}]}]}]}" + " 'body': {'sldValue': ' b1 ',\n", + " 'styleType': 'sld'},\n", + " 'order': 28,\n", + " 'assetId': 'projects/resource-watch-gee/loc_mcaqf_mexico_city_aq_forecast/NO2/loc_mcaqf_mexico_city_aq_forecast_NO2_20220629_28',\n", + " 'timeline': True,\n", + " 'timelineLabel': '028'}" ] }, "execution_count": 4, @@ -925,72 +915,49 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "decode_function = '''\n", - " // First 6 bits Alpha channel used to individual alert confidence\n", - " // First two bits (leftmost) are GLAD-L\n", - " // Next, 3rd and 4th bits are GLAD-S2\n", - " // Finally, 5th and 6th bits are RADD\n", - " // Bits are either: 00 (0, no alerts), 01 (1, low conf), or 10 (2, high conf)\n", - " // e.g. 00 10 01 00 --> no GLAD-L, high conf GLAD-S2, low conf RADD\n", "\n", - " float agreementValue = alpha * 255.;\n", + "// values for creating power scale, domain (input), and range (output)\n", + " float day = color.r * 255. * 255. + (color.g * 255.);\n", + " float confidence = color.b * 255.;\n", "\n", - " float r = color.r * 255.;\n", - " float g = color.g * 255.;\n", - " float b = color.b * 255.;\n", - "\n", - " float day = r * 255. + g;\n", - " float confidence = floor(b / 100.) - 1.;\n", - " float intensity = mod(b, 100.) * 50.;\n", - "\n", - " if (\n", - " day > 0. &&\n", - " day >= startDayIndex &&\n", - " day <= endDayIndex &&\n", - " agreementValue > 0.\n", - " )\n", - " {\n", - " if (intensity > 255.) {\n", - " intensity = 255.;\n", - " }\n", - " // get high and highest confidence alerts\n", - " float confidenceValue = 0.;\n", - "\n", - " if (agreementValue == 4. || agreementValue == 16. || agreementValue == 64.) {\n", - " // ONE ALERT LOW CONF: 4,8,16,32,64,128 i.e. 2**(2+n) for n<8\n", - "\n", - " color.r = 237. / 255.;\n", - " color.g = 164. / 255.;\n", - " color.b = 194. / 255.;\n", - " alpha = (intensity -confidenceValue) / 255.;\n", - " } else if (agreementValue == 8. || agreementValue == 32. || agreementValue == 128.){\n", - " // ONE HIGH CONF ALERT: 8,32,128 i.e. 2**(2+n) for n<8 and odd\n", - "\n", - " color.r = 220. / 255.;\n", - " color.g = 102. / 255.;\n", - " color.b = 153. / 255.;\n", - " alpha = intensity / 255.;\n", - " } else {\n", - " // MULTIPLE ALERTS: >0 and not 2**(2+n)\n", - "\n", - " color.r = 201. / 255.;\n", - " color.g = 42. / 255.;\n", - " color.b = 109. / 255.;\n", - " alpha = intensity / 255.;\n", - " }\n", - " } else {\n", - " alpha = 0.;\n", - " }\n", + " if (\n", + " day > 0. &&\n", + " day >= startDayIndex &&\n", + " day <= endDayIndex\n", + " ) {\n", + " // get intensity\n", + " float intensity = mod(confidence, 100.) * 50.;\n", + " if (intensity > 255.) {\n", + " intensity = 255.;\n", + " }\n", + " if (confidence < 200.) {\n", + " color.r = 237. / 255.;\n", + " color.g = 164. / 255.;\n", + " color.b = 194. / 255.;\n", + " alpha = intensity / 255.;\n", + " } else {\n", + " color.r = 220. / 255.;\n", + " color.g = 102. / 255.;\n", + " color.b = 153. / 255.;\n", + " alpha = intensity / 255.;\n", + " }\n", + " } else {\n", + " alpha = 0.;\n", + " }\n", + " \n", + " \n", + " \n", " '''" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -1014,7 +981,7 @@ " \"minZoom\": 3,\n", " \"maxZoom\": 12\n", " },\n", - " \"data\": \"https://tiles.globalforestwatch.org/gfw_integrated_alerts/latest/default/{z}/{x}/{y}.png\",\n", + " \"data\": \"https://tiles.globalforestwatch.org/glad_prod/tiles/{z}/{x}/{y}.png\",\n", " \"subtype\": \"DecodedRasterLayer\"\n", " }]\n", " }\n", @@ -1024,84 +991,88 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 35, "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "**Layer**: test_layer" - ], - "text/plain": [ - "Layer(id=None, type='layer', attributes=LayerAttributes(name='test_layer', description='test layer', application=['rw'], iso=[], provider=None, type='raster', default=False, protected=False, published=False, env='staging', layerConfig=LayerConfigV4(type='deck', lmMetadata={'version': '4.0'}, source=None, render=None, deck=[{'type': 'TileLayer', 'params': {'decodeFunction': '\\n // First 6 bits Alpha channel used to individual alert confidence\\n // First two bits (leftmost) are GLAD-L\\n // Next, 3rd and 4th bits are GLAD-S2\\n // Finally, 5th and 6th bits are RADD\\n // Bits are either: 00 (0, no alerts), 01 (1, low conf), or 10 (2, high conf)\\n // e.g. 00 10 01 00 --> no GLAD-L, high conf GLAD-S2, low conf RADD\\n\\n float agreementValue = alpha * 255.;\\n\\n float r = color.r * 255.;\\n float g = color.g * 255.;\\n float b = color.b * 255.;\\n\\n float day = r * 255. + g;\\n float confidence = floor(b / 100.) - 1.;\\n float intensity = mod(b, 100.) * 50.;\\n\\n if (\\n day > 0. &&\\n day >= startDayIndex &&\\n day <= endDayIndex &&\\n agreementValue > 0.\\n )\\n {\\n if (intensity > 255.) {\\n intensity = 255.;\\n }\\n // get high and highest confidence alerts\\n float confidenceValue = 0.;\\n\\n if (agreementValue == 4. || agreementValue == 16. || agreementValue == 64.) {\\n // ONE ALERT LOW CONF: 4,8,16,32,64,128 i.e. 2**(2+n) for n<8\\n\\n color.r = 237. / 255.;\\n color.g = 164. / 255.;\\n color.b = 194. / 255.;\\n alpha = (intensity -confidenceValue) / 255.;\\n } else if (agreementValue == 8. || agreementValue == 32. || agreementValue == 128.){\\n // ONE HIGH CONF ALERT: 8,32,128 i.e. 2**(2+n) for n<8 and odd\\n\\n color.r = 220. / 255.;\\n color.g = 102. / 255.;\\n color.b = 153. / 255.;\\n alpha = intensity / 255.;\\n } else {\\n // MULTIPLE ALERTS: >0 and not 2**(2+n)\\n\\n color.r = 201. / 255.;\\n color.g = 42. / 255.;\\n color.b = 109. / 255.;\\n alpha = intensity / 255.;\\n }\\n } else {\\n alpha = 0.;\\n }\\n ', 'decodeParams': {'startDayIndex': 0, 'endDayIndex': 1150}, 'minZoom': 3, 'maxZoom': 12}, 'data': 'https://tiles.globalforestwatch.org/gfw_integrated_alerts/latest/default/{z}/{x}/{y}.png', 'subtype': 'DecodedRasterLayer'}]), legendConfig={}, interactionConfig={}, applicationConfig={}, staticImageConfig={}, createdAt=None, updatedAt=None), _url=None)" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "new_layer = Layer.parse_obj(lconfig)\n", + "\n", + "# add provider\n", + "new_layer.attributes.provider = 'vector'\n", "new_layer\n" ] }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "def createAsset(session: Session, path: str, asset: APIRESOURCE):\n", " payload = asset.attributes.json(exclude={'createdAt': True, 'updatedAt': True})\n", " print(payload)\n", - " response = session.post(path, json=payload )\n", + " response = session.post(path, data=payload)\n", " return response.json()" ] }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{\"name\": \"test_layer\", \"description\": \"test layer\", \"application\": [\"rw\"], \"iso\": [], \"provider\": null, \"type\": \"raster\", \"default\": false, \"protected\": false, \"published\": false, \"env\": \"staging\", \"layerConfig\": {\"type\": \"deck\", \"lmMetadata\": {\"version\": \"4.0\"}, \"source\": null, \"render\": null, \"deck\": [{\"type\": \"TileLayer\", \"params\": {\"decodeFunction\": \"\\n // First 6 bits Alpha channel used to individual alert confidence\\n // First two bits (leftmost) are GLAD-L\\n // Next, 3rd and 4th bits are GLAD-S2\\n // Finally, 5th and 6th bits are RADD\\n // Bits are either: 00 (0, no alerts), 01 (1, low conf), or 10 (2, high conf)\\n // e.g. 00 10 01 00 --> no GLAD-L, high conf GLAD-S2, low conf RADD\\n\\n float agreementValue = alpha * 255.;\\n\\n float r = color.r * 255.;\\n float g = color.g * 255.;\\n float b = color.b * 255.;\\n\\n float day = r * 255. + g;\\n float confidence = floor(b / 100.) - 1.;\\n float intensity = mod(b, 100.) * 50.;\\n\\n if (\\n day > 0. &&\\n day >= startDayIndex &&\\n day <= endDayIndex &&\\n agreementValue > 0.\\n )\\n {\\n if (intensity > 255.) {\\n intensity = 255.;\\n }\\n // get high and highest confidence alerts\\n float confidenceValue = 0.;\\n\\n if (agreementValue == 4. || agreementValue == 16. || agreementValue == 64.) {\\n // ONE ALERT LOW CONF: 4,8,16,32,64,128 i.e. 2**(2+n) for n<8\\n\\n color.r = 237. / 255.;\\n color.g = 164. / 255.;\\n color.b = 194. / 255.;\\n alpha = (intensity -confidenceValue) / 255.;\\n } else if (agreementValue == 8. || agreementValue == 32. || agreementValue == 128.){\\n // ONE HIGH CONF ALERT: 8,32,128 i.e. 2**(2+n) for n<8 and odd\\n\\n color.r = 220. / 255.;\\n color.g = 102. / 255.;\\n color.b = 153. / 255.;\\n alpha = intensity / 255.;\\n } else {\\n // MULTIPLE ALERTS: >0 and not 2**(2+n)\\n\\n color.r = 201. / 255.;\\n color.g = 42. / 255.;\\n color.b = 109. / 255.;\\n alpha = intensity / 255.;\\n }\\n } else {\\n alpha = 0.;\\n }\\n \", \"decodeParams\": {\"startDayIndex\": 0, \"endDayIndex\": 1150}, \"minZoom\": 3, \"maxZoom\": 12}, \"data\": \"https://tiles.globalforestwatch.org/gfw_integrated_alerts/latest/default/{z}/{x}/{y}.png\", \"subtype\": \"DecodedRasterLayer\"}]}, \"legendConfig\": {}, \"interactionConfig\": {}, \"applicationConfig\": {}, \"staticImageConfig\": {}}\n" + "{\"name\": \"test_layer\", \"description\": \"test layer\", \"application\": [\"rw\"], \"iso\": [], \"provider\": \"vector\", \"type\": \"raster\", \"default\": false, \"protected\": false, \"published\": false, \"env\": \"staging\", \"layerConfig\": {\"type\": \"deck\", \"lmMetadata\": {\"version\": \"4.0\"}, \"source\": null, \"render\": null, \"deck\": [{\"type\": \"TileLayer\", \"params\": {\"decodeFunction\": \"\\n\\n// values for creating power scale, domain (input), and range (output)\\n float day = color.r * 255. * 255. + (color.g * 255.);\\n float confidence = color.b * 255.;\\n\\n if (\\n day > 0. &&\\n day >= startDayIndex &&\\n day <= endDayIndex\\n ) {\\n // get intensity\\n float intensity = mod(confidence, 100.) * 50.;\\n if (intensity > 255.) {\\n intensity = 255.;\\n }\\n if (confidence < 200.) {\\n color.r = 237. / 255.;\\n color.g = 164. / 255.;\\n color.b = 194. / 255.;\\n alpha = intensity / 255.;\\n } else {\\n color.r = 220. / 255.;\\n color.g = 102. / 255.;\\n color.b = 153. / 255.;\\n alpha = intensity / 255.;\\n }\\n } else {\\n alpha = 0.;\\n }\\n \\n \\n \\n \", \"decodeParams\": {\"startDayIndex\": 0, \"endDayIndex\": 1150}, \"minZoom\": 3, \"maxZoom\": 12}, \"data\": \"https://tiles.globalforestwatch.org/glad_prod/tiles/{z}/{x}/{y}.png\", \"subtype\": \"DecodedRasterLayer\"}]}, \"legendConfig\": {}, \"interactionConfig\": {}, \"applicationConfig\": {}, \"staticImageConfig\": {}}\n" ] }, { - "ename": "HTTPError", - "evalue": "400 Client Error: Bad Request for url: https://api.resourcewatch.org/v1/dataset/e663eb09-04de-4f39-b871-35c6c2ed10b5/layer", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/alicitita/Projects/notebooks/notebooks-wri/ResourceWatch/Api_definition/layer_definition.ipynb Cell 46'\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m url \u001b[39m=\u001b[39m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m/v1/dataset/\u001b[39m\u001b[39m{\u001b[39;00mnew_layer\u001b[39m.\u001b[39mattributes\u001b[39m.\u001b[39m_datasetId\u001b[39m}\u001b[39;00m\u001b[39m/layer\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m----> 2\u001b[0m createAsset(session, url, new_layer)\n", - "\u001b[1;32m/home/alicitita/Projects/notebooks/notebooks-wri/ResourceWatch/Api_definition/layer_definition.ipynb Cell 45'\u001b[0m in \u001b[0;36mcreateAsset\u001b[0;34m(session, path, asset)\u001b[0m\n\u001b[1;32m 2\u001b[0m payload \u001b[39m=\u001b[39m asset\u001b[39m.\u001b[39mattributes\u001b[39m.\u001b[39mjson(exclude\u001b[39m=\u001b[39m{\u001b[39m'\u001b[39m\u001b[39mcreatedAt\u001b[39m\u001b[39m'\u001b[39m: \u001b[39mTrue\u001b[39;00m, \u001b[39m'\u001b[39m\u001b[39mupdatedAt\u001b[39m\u001b[39m'\u001b[39m: \u001b[39mTrue\u001b[39;00m})\n\u001b[1;32m 3\u001b[0m \u001b[39mprint\u001b[39m(payload)\n\u001b[0;32m----> 4\u001b[0m response \u001b[39m=\u001b[39m session\u001b[39m.\u001b[39;49mpost(path, json\u001b[39m=\u001b[39;49mpayload )\n\u001b[1;32m 5\u001b[0m \u001b[39mreturn\u001b[39;00m response\u001b[39m.\u001b[39mjson()\n", - "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/sessions.py:577\u001b[0m, in \u001b[0;36mSession.post\u001b[0;34m(self, url, data, json, **kwargs)\u001b[0m\n\u001b[1;32m 566\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mpost\u001b[39m(\u001b[39mself\u001b[39m, url, data\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, json\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 567\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Sends a POST request. Returns :class:`Response` object.\u001b[39;00m\n\u001b[1;32m 568\u001b[0m \n\u001b[1;32m 569\u001b[0m \u001b[39m :param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 574\u001b[0m \u001b[39m :rtype: requests.Response\u001b[39;00m\n\u001b[1;32m 575\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 577\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrequest(\u001b[39m'\u001b[39;49m\u001b[39mPOST\u001b[39;49m\u001b[39m'\u001b[39;49m, url, data\u001b[39m=\u001b[39;49mdata, json\u001b[39m=\u001b[39;49mjson, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", - "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests_toolbelt/sessions.py:64\u001b[0m, in \u001b[0;36mBaseUrlSession.request\u001b[0;34m(self, method, url, *args, **kwargs)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[39m\"\"\"Send the request after generating the complete URL.\"\"\"\u001b[39;00m\n\u001b[1;32m 63\u001b[0m url \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcreate_url(url)\n\u001b[0;32m---> 64\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39;49m(BaseUrlSession, \u001b[39mself\u001b[39;49m)\u001b[39m.\u001b[39;49mrequest(\n\u001b[1;32m 65\u001b[0m method, url, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m 66\u001b[0m )\n", - "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/sessions.py:529\u001b[0m, in \u001b[0;36mSession.request\u001b[0;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[1;32m 524\u001b[0m send_kwargs \u001b[39m=\u001b[39m {\n\u001b[1;32m 525\u001b[0m \u001b[39m'\u001b[39m\u001b[39mtimeout\u001b[39m\u001b[39m'\u001b[39m: timeout,\n\u001b[1;32m 526\u001b[0m \u001b[39m'\u001b[39m\u001b[39mallow_redirects\u001b[39m\u001b[39m'\u001b[39m: allow_redirects,\n\u001b[1;32m 527\u001b[0m }\n\u001b[1;32m 528\u001b[0m send_kwargs\u001b[39m.\u001b[39mupdate(settings)\n\u001b[0;32m--> 529\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(prep, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msend_kwargs)\n\u001b[1;32m 531\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n", - "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/sessions.py:652\u001b[0m, in \u001b[0;36mSession.send\u001b[0;34m(self, request, **kwargs)\u001b[0m\n\u001b[1;32m 649\u001b[0m r\u001b[39m.\u001b[39melapsed \u001b[39m=\u001b[39m timedelta(seconds\u001b[39m=\u001b[39melapsed)\n\u001b[1;32m 651\u001b[0m \u001b[39m# Response manipulation hooks\u001b[39;00m\n\u001b[0;32m--> 652\u001b[0m r \u001b[39m=\u001b[39m dispatch_hook(\u001b[39m'\u001b[39;49m\u001b[39mresponse\u001b[39;49m\u001b[39m'\u001b[39;49m, hooks, r, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 654\u001b[0m \u001b[39m# Persist cookies\u001b[39;00m\n\u001b[1;32m 655\u001b[0m \u001b[39mif\u001b[39;00m r\u001b[39m.\u001b[39mhistory:\n\u001b[1;32m 656\u001b[0m \n\u001b[1;32m 657\u001b[0m \u001b[39m# If the hooks create history then we want those cookies too\u001b[39;00m\n", - "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/hooks.py:31\u001b[0m, in \u001b[0;36mdispatch_hook\u001b[0;34m(key, hooks, hook_data, **kwargs)\u001b[0m\n\u001b[1;32m 29\u001b[0m hooks \u001b[39m=\u001b[39m [hooks]\n\u001b[1;32m 30\u001b[0m \u001b[39mfor\u001b[39;00m hook \u001b[39min\u001b[39;00m hooks:\n\u001b[0;32m---> 31\u001b[0m _hook_data \u001b[39m=\u001b[39m hook(hook_data, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 32\u001b[0m \u001b[39mif\u001b[39;00m _hook_data \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 33\u001b[0m hook_data \u001b[39m=\u001b[39m _hook_data\n", - "File \u001b[0;32m/tmp/ipykernel_410/3342181247.py:7\u001b[0m, in \u001b[0;36mrwApiSession..\u001b[0;34m(response, *args, **kwargs)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[39m'''\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[39mCreates a sesion object for making calls to the RW api.\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[39m'''\u001b[39;00m\n\u001b[1;32m 5\u001b[0m retries \u001b[39m=\u001b[39m Retry(total\u001b[39m=\u001b[39m\u001b[39m3\u001b[39m, backoff_factor\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m, status_forcelist\u001b[39m=\u001b[39m[\u001b[39m429\u001b[39m, \u001b[39m500\u001b[39m, \u001b[39m502\u001b[39m, \u001b[39m503\u001b[39m, \u001b[39m504\u001b[39m])\n\u001b[0;32m----> 7\u001b[0m assert_status_hook \u001b[39m=\u001b[39m \u001b[39mlambda\u001b[39;00m response, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: response\u001b[39m.\u001b[39;49mraise_for_status()\n\u001b[1;32m 9\u001b[0m httpsSession \u001b[39m=\u001b[39m sessions\u001b[39m.\u001b[39mBaseUrlSession(base_url \u001b[39m=\u001b[39m serverUrl )\n\u001b[1;32m 11\u001b[0m httpsSession\u001b[39m.\u001b[39mmount(\u001b[39m\"\u001b[39m\u001b[39mhttps://\u001b[39m\u001b[39m\"\u001b[39m, TimeoutHTTPAdapter(max_retries\u001b[39m=\u001b[39mretries))\n", - "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/models.py:960\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 957\u001b[0m http_error_msg \u001b[39m=\u001b[39m \u001b[39mu\u001b[39m\u001b[39m'\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m Server Error: \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m for url: \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39m%\u001b[39m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstatus_code, reason, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39murl)\n\u001b[1;32m 959\u001b[0m \u001b[39mif\u001b[39;00m http_error_msg:\n\u001b[0;32m--> 960\u001b[0m \u001b[39mraise\u001b[39;00m HTTPError(http_error_msg, response\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m)\n", - "\u001b[0;31mHTTPError\u001b[0m: 400 Client Error: Bad Request for url: https://api.resourcewatch.org/v1/dataset/e663eb09-04de-4f39-b871-35c6c2ed10b5/layer" - ] + "data": { + "text/plain": [ + "{'data': {'id': 'e6406b35-d58d-4e04-843f-7741eea4bc56',\n", + " 'type': 'layer',\n", + " 'attributes': {'name': 'test_layer',\n", + " 'slug': 'test_layer_6',\n", + " 'dataset': 'e663eb09-04de-4f39-b871-35c6c2ed10b5',\n", + " 'description': 'test layer',\n", + " 'application': ['rw'],\n", + " 'iso': [],\n", + " 'provider': 'vector',\n", + " 'type': 'raster',\n", + " 'userId': '61c2fbbecdc846001a774ddc',\n", + " 'default': False,\n", + " 'protected': False,\n", + " 'published': False,\n", + " 'env': 'staging',\n", + " 'layerConfig': {'type': 'deck',\n", + " 'lmMetadata': {'version': '4.0'},\n", + " 'source': None,\n", + " 'render': None,\n", + " 'deck': [{'type': 'TileLayer',\n", + " 'params': {'decodeFunction': '\\n\\n// values for creating power scale, domain (input), and range (output)\\n float day = color.r * 255. * 255. + (color.g * 255.);\\n float confidence = color.b * 255.;\\n\\n if (\\n day > 0. &&\\n day >= startDayIndex &&\\n day <= endDayIndex\\n ) {\\n // get intensity\\n float intensity = mod(confidence, 100.) * 50.;\\n if (intensity > 255.) {\\n intensity = 255.;\\n }\\n if (confidence < 200.) {\\n color.r = 237. / 255.;\\n color.g = 164. / 255.;\\n color.b = 194. / 255.;\\n alpha = intensity / 255.;\\n } else {\\n color.r = 220. / 255.;\\n color.g = 102. / 255.;\\n color.b = 153. / 255.;\\n alpha = intensity / 255.;\\n }\\n } else {\\n alpha = 0.;\\n }\\n \\n \\n \\n ',\n", + " 'decodeParams': {'startDayIndex': 0, 'endDayIndex': 1150},\n", + " 'minZoom': 3,\n", + " 'maxZoom': 12},\n", + " 'data': 'https://tiles.globalforestwatch.org/glad_prod/tiles/{z}/{x}/{y}.png',\n", + " 'subtype': 'DecodedRasterLayer'}]},\n", + " 'legendConfig': {},\n", + " 'interactionConfig': {},\n", + " 'applicationConfig': {},\n", + " 'staticImageConfig': {},\n", + " 'createdAt': '2022-07-01T09:43:08.907Z',\n", + " 'updatedAt': '2022-07-01T09:43:08.907Z'}}}" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "url = f'/v1/dataset/{new_layer.attributes._datasetId}/layer'\n", "createAsset(session, url, new_layer)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {