diff --git a/deforestation_api/dependencies/deforestationdata.py b/deforestation_api/dependencies/deforestationdata.py
index 07545b1..13d0a8d 100644
--- a/deforestation_api/dependencies/deforestationdata.py
+++ b/deforestation_api/dependencies/deforestationdata.py
@@ -33,6 +33,7 @@ def fetch_parquet(path) -> pd.DataFrame:
path,
storage_options={"anon": True},
)
+ df = df.rename(columns={"HYBAS_ID": "id"})
logger.info(f"Done reloading data from %s", path)
return df
diff --git a/deforestation_api/routers/deforestation.py b/deforestation_api/routers/deforestation.py
index 06da9f7..da2a80b 100644
--- a/deforestation_api/routers/deforestation.py
+++ b/deforestation_api/routers/deforestation.py
@@ -55,6 +55,22 @@ def add_treecover_loss_data(
) -> None:
basin_loss = treecover_loss[treecover_loss["id"] == feature["id"]]
basin_loss = basin_loss.loc[basin_loss["year"].between(start_year, end_year)]
+
+ basin_loss = (
+ basin_loss.groupby(["id", "year"])
+ .agg(
+ tree_loss_incidents=("tree_loss_incidents", "sum"),
+ first_cell_area=("first_cell_area", "first"),
+ )
+ .reset_index()
+ )
+ basin_loss["area"] = (
+ basin_loss["tree_loss_incidents"] * basin_loss["first_cell_area"]
+ )
+ basin_loss["relative_area"] = (
+ basin_loss["area"] / feature["properties"]["basin_area"]
+ )
+
total_loss = basin_loss["area"].sum()
relative_loss = basin_loss["relative_area"].sum()
loss_per_year = basin_loss.drop(columns="id").to_json(orient="records")
diff --git a/deforestation_api/settings.py b/deforestation_api/settings.py
index fbd96ef..b7262c7 100644
--- a/deforestation_api/settings.py
+++ b/deforestation_api/settings.py
@@ -1,4 +1,5 @@
from pydantic_settings import BaseSettings
+from os import environ
class Settings(BaseSettings):
@@ -7,9 +8,10 @@ class Settings(BaseSettings):
uvicorn_host: str = "0.0.0.0"
uvicorn_reload: bool = True
uvicorn_proxy_headers: bool = False
- basin_data_path: str = "s3://databricks-data-openepi/deforestation/basins.parquet"
+ dagster_data_bucket: str = environ.get("dagster_data_bucket", "placeholder-bucket")
+ basin_data_path: str = f"s3://{dagster_data_bucket}/basin/basins.parquet"
lossyear_data_path: str = (
- "s3://databricks-data-openepi/deforestation/lossyear.parquet"
+ f"s3://{dagster_data_bucket}/deforestation/treeloss_per_basin/"
)
api_root_path: str = ""
api_description: str = 'This is a RESTful service that provides aggregated deforestation data over the period from 2001 to 2022 based on data provided by Global Land Analysis and Discovery (GLAD) laboratory at the University of Maryland, in partnership with Global Forest Watch (GFW). The data are freely available for use under a Creative Commons Attribution 4.0 International License.
Citation: Hansen, M. C., P. V. Potapov, R. Moore, M. Hancher, S. A. Turubanova, A. Tyukavina, D. Thau, S. V. Stehman, S. J. Goetz, T. R. Loveland, A. Kommareddy, A. Egorov, L. Chini, C. O. Justice, and J. R. G. Townshend. 2013. High-Resolution Global Maps of 21st-Century Forest Cover Change. Science 342 (15 November): 850-53. Data available on-line from: https://glad.earthengine.app/view/global-forest-change.
The data provided by the `basin` endpoint are aggregated over river basin polygons provided by HydroSHEDS. The basin data are feely available for non-commercial and commercial use under a licence agreement included in the HydroSHEDS Technical Documentation.'
diff --git a/deployment/kubernetes/deforestation-api.yaml b/deployment/kubernetes/deforestation-api.yaml
index f624bc5..4120cf7 100644
--- a/deployment/kubernetes/deforestation-api.yaml
+++ b/deployment/kubernetes/deforestation-api.yaml
@@ -18,7 +18,7 @@ spec:
prometheus.io/path: "/metrics"
spec:
containers:
- - image: ghcr.io/openearthplatforminitiative/deforestation-api:0.3.0
+ - image: ghcr.io/openearthplatforminitiative/deforestation-api:0.3.1
name: deforestation-api
ports:
- containerPort: 8080
@@ -26,7 +26,7 @@ spec:
- name: API_ROOT_PATH
value: "/deforestation"
- name: VERSION
- value: 0.3.0
+ value: 0.3.1
- name: API_DOMAIN
valueFrom:
configMapKeyRef: