Skip to content

Commit

Permalink
add test and notebook section for tree canopy hight layer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrowe committed May 29, 2024
1 parent e33f688 commit 39a4d8b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 39 deletions.
108 changes: 70 additions & 38 deletions notebooks/tutorial/get layers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"| Natural Areas | `NaturalAreas()` | `none` | |\n",
"| Open Street Map | `OpenStreetMap()` | `osm_class=None`; `OpenStreetMapClass`: Groupings of OSM Tags for various land uses | |\n",
"| Building Hight | `AverageNetBuildingHeight()` | `none` | |\n",
"| Building Footprints | `OpenBuildings()` | `country='USA'` | |"
"| Building Footprints | `OpenBuildings()` | `country='USA'` | |\n",
"| 1m Global Tree Canopy Height | `TreeCanopyHeight()` | | |"
]
},
{
Expand All @@ -47,43 +48,20 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": 1,
"id": "7ed2c665-e6d8-4e98-95ac-41aab749493f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <style>\n",
" .geemap-dark {\n",
" --jp-widgets-color: white;\n",
" --jp-widgets-label-color: white;\n",
" --jp-ui-font-color1: white;\n",
" --jp-layout-color2: #454545;\n",
" background-color: #383838;\n",
" }\n",
"\n",
" .geemap-dark .jupyter-button {\n",
" --jp-layout-color3: #383838;\n",
" }\n",
"\n",
" .geemap-colab {\n",
" background-color: var(--colab-primary-surface-color, white);\n",
" }\n",
"\n",
" .geemap-colab .jupyter-button {\n",
" --jp-layout-color3: var(--colab-primary-surface-color, white);\n",
" }\n",
" </style>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"ename": "ModuleNotFoundError",
"evalue": "No module named 'rasterio'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mgeopandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mgpd\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mrasterio\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mplot\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m show\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mrasterio\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m \n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'rasterio'"
]
}
],
"source": [
Expand All @@ -96,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 67,
"execution_count": null,
"id": "602a6217-fd80-4cec-b40b-20de68b8f62b",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -4641,13 +4619,67 @@
"Map\n"
]
},
{
"cell_type": "markdown",
"id": "a875211e",
"metadata": {},
"source": [
"# 1m Global Tree Canopy Height"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2417058",
"metadata": {},
"outputs": [],
"source": [
"from city_metrix.layers import TreeCanopyHeight"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80a05bdf",
"metadata": {},
"outputs": [],
"source": [
"# Load 1m Global Tree Canopy Hight layer\n",
"city_TreeCanopyHeight = TreeCanopyHeight().get_data(city_centroid_buffer.total_bounds)\n",
"city_TreeCanopyHeight"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aabb9dbe",
"metadata": {},
"outputs": [],
"source": [
"city_TreeCanopyHeight.plot()"
]
},
{
"cell_type": "markdown",
"id": "1276883d",
"metadata": {},
"source": [
"# Development"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95c9221e",
"id": "81786aad",
"metadata": {},
"outputs": [],
"source": []
"source": [
"import sys\n",
"sys.dont_write_bytecode=True\n",
"\n",
"%load_ext autoreload\n",
"%autoreload"
]
}
],
"metadata": {
Expand All @@ -4666,7 +4698,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
6 changes: 5 additions & 1 deletion tests/layers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ee

from city_metrix.layers import LandsatCollection2, Albedo, LandSurfaceTemperature, EsaWorldCover, EsaWorldCoverClass, TreeCover, AverageNetBuildingHeight, OpenStreetMap, OpenStreetMapClass, UrbanLandUse, OpenBuildings
from city_metrix.layers import LandsatCollection2, Albedo, LandSurfaceTemperature, EsaWorldCover, EsaWorldCoverClass, TreeCover, AverageNetBuildingHeight, OpenStreetMap, OpenStreetMapClass, UrbanLandUse, OpenBuildings, TreeCanopyHeight
from city_metrix.layers.layer import get_image_collection
from .conftest import MockLayer, MockMaskLayer, ZONES, LARGE_ZONES, MockLargeLayer

Expand Down Expand Up @@ -90,3 +90,7 @@ def test_urban_land_use():
def test_openbuildings():
count = OpenBuildings().get_data(SAMPLE_BBOX).count().sum()
assert count

def test_tree_canopy_hight():
count = TreeCanopyHeight().get_data(SAMPLE_BBOX).count()
assert count

0 comments on commit 39a4d8b

Please sign in to comment.