Skip to content

Commit

Permalink
Initial restructuring and addition of simple test for each layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
kcartier-wri committed Aug 8, 2024
1 parent 9be92e3 commit f594c97
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
71 changes: 50 additions & 21 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ee
import numpy as np
import pytest

from city_metrix.layers import (
Expand All @@ -8,30 +6,25 @@
AverageNetBuildingHeight,
EsaWorldCover,
EsaWorldCoverClass,
HighLandSurfaceTemperature,
LandsatCollection2,
LandSurfaceTemperature,
NasaDEM,
NaturalAreas,
OpenBuildings,
OpenStreetMap,
OpenStreetMapClass,
OvertureBuildings,
Sentinel2Level2,
SmartSurfaceLULC,
TreeCanopyHeight,
TreeCover,
UrbanLandUse,
WorldPop
)
from city_metrix.layers.esa_ndvi import EsaNdvi
from tests.fixtures.bbox_constants import BBOX_BRAZIL_LAURO_DE_FREITAS_1


def test_tree_cover():
actual = TreeCover().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()
expected = 54.0
tolerance = 0.1
assert (
pytest.approx(expected, rel=tolerance) == actual
)


def test_albedo():
assert Albedo().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()

Expand All @@ -45,7 +38,7 @@ def test_average_net_building_height():
assert AverageNetBuildingHeight().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()


def test_esa():
def test_esa_world_cover():
count = (
EsaWorldCover(land_cover_class=EsaWorldCoverClass.BUILT_UP)
.get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1)
Expand All @@ -54,16 +47,37 @@ def test_esa():
assert count


def test_lst():
mean = LandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()
assert mean
def test_high_land_surface_temperature():
data = HighLandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1)
assert data.any()


def test_land_surface_temperature():
mean_lst = LandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()
assert mean_lst


def test_landsat_collection_2():
bands = ['green']
data = LandsatCollection2(bands).get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1)
assert data.any()


def test_nasa_dem():
mean = NasaDEM().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()
assert mean


def test_natural_areas():
data = NaturalAreas().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1)
assert data.any()


def test_openbuildings():
count = OpenBuildings().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).count().sum()
assert count


def test_open_street_map():
count = (
OpenStreetMap(osm_class=OpenStreetMapClass.ROAD)
Expand All @@ -74,16 +88,17 @@ def test_open_street_map():
assert count


def test_openbuildings():
count = OpenBuildings().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).count().sum()
assert count


def test_overture_buildings():
count = OvertureBuildings().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).count().sum()
assert count


def test_sentinal_2_level2():
sentinal_2_bands = ["green"]
data = Sentinel2Level2(sentinal_2_bands).get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1)
assert data.any()


def test_smart_surface_lulc():
count = SmartSurfaceLULC().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).count()
assert count
Expand All @@ -94,5 +109,19 @@ def test_tree_canopy_hight():
assert count


def test_tree_cover():
actual = TreeCover().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()
expected = 54.0
tolerance = 0.1
assert (
pytest.approx(expected, rel=tolerance) == actual
)


def test_urban_land_use():
assert UrbanLandUse().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).count()


def test_world_pop():
data = WorldPop().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1)
assert data.any()
2 changes: 0 additions & 2 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import ee
import numpy as np
import pytest

from city_metrix.layers.layer import get_image_collection

from .conftest import (
LARGE_ZONES,
ZONES,
Expand Down

0 comments on commit f594c97

Please sign in to comment.