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.1.3.tar.gz (20.4 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.1.3-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: biodata_enricher-0.1.3.tar.gz
  • Upload date:
  • Size: 20.4 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.1.3.tar.gz
Algorithm Hash digest
SHA256 b86b8cd0a9a1f51780cd8d7bdc2617889972ce434c31c4a2949abc1920bb33bf
MD5 b606eeb847f8a3e86049a6ca3d4d331a
BLAKE2b-256 ed41d81b176fbcb19d540cfe32fe1e001a49d129af7121c1ae260fe1b3832853

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for biodata_enricher-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eac12c13e5c68917aa376d4a28d69353f976fcb6f25ca79990e011e366a2128b
MD5 92a8bdcdeb07b5e67bca7d5ba6471fe7
BLAKE2b-256 4c9104026e5396c9944bddf71baec9ce8b05e3c7a3a72a48a011a95ca400f0f0

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