Reduce Regions#
Setup#
Ecoscope#
[ ]:
ECOSCOPE_RAW = "https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master"
!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/ecoscope@v1.8.8' &> /dev/null
[ ]:
import os
import sys
import geopandas as gpd
import numpy as np
import ecoscope
ecoscope.init()
Google Drive#
[ ]:
output_dir = "Ecoscope-Outputs"
if "google.colab" in sys.modules:
from google.colab import drive
drive.mount("/content/drive/", force_remount=True)
output_dir = os.path.join("/content/drive/MyDrive/", output_dir)
os.makedirs(output_dir, exist_ok=True)
Load AOI#
[ ]:
ecoscope.io.download_file(
f"{ECOSCOPE_RAW}/tests/sample_data/vector/maec_4zones_UTM36S.gpkg",
os.path.join(output_dir, "maec_4zones_UTM36S.gpkg"),
)
AOI_FILE = os.path.join(output_dir, "maec_4zones_UTM36S.gpkg")
regions_gdf = gpd.GeoDataFrame.from_file(AOI_FILE).to_crs(4326).set_index("ZONE")
Visualize AOI#
[ ]:
regions_gdf.explore()
Apply Mean Reduction#
[ ]:
raster_name = os.path.join(output_dir, "mara_dem.tif")
ecoscope.io.download_file(f"{ECOSCOPE_RAW}/tests/sample_data/raster/mara_dem.tif", raster_name)
ecoscope.io.raster.reduce_region(gdf=regions_gdf, raster_path_list=[raster_name], reduce_func=np.mean)