Skip to content

Commit

Permalink
Correcting zonal stats for pyjeo (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
kempenep authored Nov 3, 2023
1 parent c484028 commit 3047dca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"""
Module to benchmark zonalstats.
"""

import os
from datetime import datetime
import logging
from pathlib import Path
from typing import List

import pandas as pd
import geopandas as gpd
import pyjeo as pj

Expand All @@ -27,11 +28,15 @@


def _get_package() -> str:
return "pygeoprocessing"
return "pyjeo"


def _get_version() -> str:
return f"{pj.__version__}".replace("v", "")
nproc = os.environ.get("OMP_NUM_THREADS")
if nproc is not None:
return f"{pj.__version__} {nproc} threads".replace("v", "")
else:
return f"{pj.__version__}".replace("v", "")


def zonalstats_1band(tmp_dir: Path) -> List[RunResult]:
Expand All @@ -55,12 +60,13 @@ def zonalstats_1band(tmp_dir: Path) -> List[RunResult]:
stats = pj.geometry.extract(
vector_data,
jim,
rule=["mean", "stdev", "count"],
# rule=["mean", "stdev", "count"],
rule=["mean", "stdev", "sum"],
output="/vsimem/pj.json",
oformat="GeoJSON",
)

print(stats)
print(pd.DataFrame(stats.dict()))

secs_taken = (datetime.now() - start_time).total_seconds()
results.append(
Expand All @@ -76,7 +82,10 @@ def zonalstats_1band(tmp_dir: Path) -> List[RunResult]:
)
)

logger.info(f"took {secs_taken:.2f}s for {nb_poly} polygons, {len(stats)} results")
logger.info(
f"took {secs_taken:.2f}s for {nb_poly} polygons, "
f"{stats.properties.getFeatureCount()} results"
)

# Return
return results
Binary file modified results_zonalstats/GeoBenchmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions results_zonalstats/benchmark_results.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
run_datetime,package,package_version,operation,operation_descr,secs_taken,run_details
2023-03-22 22:51:12.810491,pygeoprocessing,2.4.0,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,52.998522,{}
2023-03-22 22:52:01.739550,rasterstats,0.18.0,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,46.805364,{}
2023-03-23 15:42:53.890171,geowombat,2.1.6,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,83.593633,{}
2023-03-23 18:48:59.459963,pyqgis,3.28.2-Firenze,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,4.282287,{}
2023-11-01 21:32:20.485871,pyjeo,1.1.6 1 threads,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,20.261884,{}
2023-11-01 21:33:43.207416,pyjeo,1.1.6 2 threads,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,18.131106,{}
2023-11-01 21:35:01.359175,pyjeo,1.1.6 3 threads,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,16.00101,{}
2023-11-01 22:05:48.873225,pyjeo,1.1.6 4 threads,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,15.466929,{}
2023-11-01 22:06:50.164708,rasterstats,0.19.0,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,58.699413,{}
2023-11-01 22:06:58.247831,pyqgis,3.28.10-Firenze,zonalstats_1band,zonalstats of agri parcels (5000 polygons) + S2 NDVI BEFL,4.808703,{}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3047dca

Please sign in to comment.