Skip to main content

Enrich points with environmental predictors from local/remote sources (MVP).

Project description

biodata-enricher — Python usage

Enrich a Pandas DataFrame of points (id, lat, lon, optional date) with features sampled from local GeoTIFF rasters.
Outputs model-ready Parquet plus QA columns and provenance (metadata JSON).


Install

make install
make test

Sampling policy

Current behavior includes all pixels in the pixel-aligned window. We plan to expose a sampling_policy (e.g., centroid, all_touched, fractional) to control edge inclusion.

Recommended: groups mode (one call → multiple features + QA + metadata)

import pandas as pd
from biodata.enrich import enrich

df = pd.read_csv("data/points_sample.csv")

# One run, two groups, multiple reducers
cfg = {
    "groups": [
        {
            "name": "dem_100m",
            # catalog keys (can be local rasters or GEE-backed)
            "predictors": ["dem_mini"],
            "output": {
                "kind": "tabular",
                # any subset of the registered reducers:
                # mean, median, std, var, min, max, q10, q90, count, sum
                "reducers": ["mean", "std", "q10", "q90"],
                "window_m": 100,
            },
        },
        {
            "name": "site_stats",
            "predictors": ["dem_mini"],
            "output": {
                "kind": "tabular",
                "reducers": ["mean", "min", "max", "count"],
                "window_m": 500,
            },
        },
    ],
    "min_coverage_pct": 80,          # QA threshold
    "project_crs": "EPSG:3006",      # working CRS for meter-based windows
}

outputs = enrich(
    df,
    groups=cfg,
    catalog="configs/catalog.yml",          # base catalog shipped with the library
    extra_catalog="configs/local_catalog.yml",  # optional: user’s own extra sources
    out_dir="out",
)

# Parquet paths (per group)
print(outputs["dem_100m"])   # -> out/dem_100m.parquet
print(outputs["site_stats"]) # -> out/site_stats.parquet
# Each has a matching metadata JSON:
# out/dem_100m_metadata.json, out/site_stats_metadata.json

What you’ll see in the Parquet

Reducer columns: dem_mini_mean, dem_mini_std, dem_mini_q10, dem_mini_q90

QA columns: dem_mini_in_extent, dem_mini_n_pixels, dem_mini_had_nodata, dem_mini_coverage_pct

Catalog (tell the library where rasters live)

configs/catalog.yml:

datasets:
  dem_mini:
    type: raster
    source: local_raster
    path: tests/data/mini_dem.tif   # any GeoTIFF with a valid CRS
    crs: EPSG:4326
    default_reducer: mean

Add more predictors by adding more entries to datasets: and listing them in your predictors/features.

Re-run previous runs (History)

Every enrich run writes a manifest with all the knobs you used (input CSV, catalog, groups/predictors, reducers, window, etc.):

  • Latest run: out/last_run.json
  • Archive of all runs: out/runs/run_<YYYYMMDD_HHMMSS>.json

CLI

# Run once (writes out/last_run.json and out/runs/run_*.json)
biodata enrich \
  --in data/points_sample.csv \
  --out out \
  --catalog configs/catalog.yml \
  --groups configs/run.yml

# Re-run the latest
biodata rerun --from out/last_run.json

# Re-run a specific past run
biodata rerun --from out/runs/run_20251113_121530.json

Python

from biodata.history import replay_last_run

outputs = replay_last_run()  # or replay_last_run("out/runs/run_20251113_121530.json")
print(outputs)

Where do the TIFF files go?

out/tiles/<group>/<feature>/b<buffer>/id<point_id>.tif
# e.g. out/tiles/terrain_features/dem_elev/b100/id42.tif

Notes & limits

  • Windows are in meters using EPSG:3006 internally (robust for Sweden; reprojected to the raster CRS when sampling).

  • Works with GeoTIFFs readable by rasterio and having a valid CRS; assumes numeric single-band by default.

  • Low coverage is flagged, not fatal; filter by *_coverage_pct as needed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

biodata_enricher-0.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

biodata_enricher-0.2.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file biodata_enricher-0.2.0.tar.gz.

File metadata

  • Download URL: biodata_enricher-0.2.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for biodata_enricher-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c172c68a241b515dd05f771658e344a19d6990cdcb53bdd63de6b3f2bdce2745
MD5 d2bca877b78cb64f7f2932fdaf83d56f
BLAKE2b-256 13570d5b10ed8b21fd42ffe7bc93745384a2029f52178ff9f62b8410f89bc2cd

See more details on using hashes here.

File details

Details for the file biodata_enricher-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for biodata_enricher-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c2443353f0959ca20635d227079be8df4bc06201e2b78e6bb9440468437b0b4
MD5 cb97d34d2375703bc659bf6a5fa8c8a3
BLAKE2b-256 c918bf8071d9c176e833dc26c571fdcd0a13ed375b1eeae0117270a89649fe15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page