Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/use dagster #22

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deforestation_api/dependencies/deforestationdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions deforestation_api/routers/deforestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions deforestation_api/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic_settings import BaseSettings
from os import environ


class Settings(BaseSettings):
Expand All @@ -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 <a href="https://glad.umd.edu/">Global Land Analysis and Discovery (GLAD)</a> laboratory at the University of Maryland, in partnership with <a href="https://www.globalforestwatch.org/">Global Forest Watch (GFW)</a>. The data are freely available for use under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.<br/><i>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: <a href="https://glad.earthengine.app/view/global-forest-change">https://glad.earthengine.app/view/global-forest-change</a></i>.<br/><br/>The data provided by the `basin` endpoint are aggregated over river basin polygons provided by <a href="https://www.hydrosheds.org/products/hydrobasins">HydroSHEDS</a>. The basin data are feely available for non-commercial and commercial use under a licence agreement included in the <a href="https://data.hydrosheds.org/file/technical-documentation/HydroSHEDS_TechDoc_v1_4.pdf">HydroSHEDS Technical Documentation</a>.'
Expand Down
4 changes: 2 additions & 2 deletions deployment/kubernetes/deforestation-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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
env:
- name: API_ROOT_PATH
value: "/deforestation"
- name: VERSION
value: 0.3.0
value: 0.3.1
- name: API_DOMAIN
valueFrom:
configMapKeyRef:
Expand Down
Loading