# Build a dataset from your own raster and your own areas

> Turn a grid of values and area polygons into a map layer and a number per area with geolith dataset: config, inputs, normals, build.

::info
**Status: live on the Scale plan.** The hosted datasets are served by the Datasets API. The engine that builds them, `geolith dataset`, is also yours to run: it is one local binary, and it uploads only when you run `upload` yourself, to a store you name.
::

The engine is not tied to rainfall. Any grid of values with a period, and any set of polygons, works. This page walks a made-up dataset called `demo`: two 4×4 rasters over the same small box, and two polygons side by side.

## 1. The config

`demo.json` describes the dataset. Unknown keys are an error, so a typo fails instead of being ignored.

```json
{
  "id": "demo",
  "name": "Demo",
  "unit": "mm",
  "period": "pentad",
  "scale": 1.0,
  "offset": 0.0,
  "valid_min": 0.0,
  "valid_max": 100.0,
  "nodata": -9999.0,
  "crs_epsg": 4326,
  "file_template": "demo.{year}.{month}.{pentad}.tif",
  "max_zoom": 4,
  "tile_size": 256,
  "stale_after_days": 30,
  "attribution": "Demo: made-up numbers for this guide.",
  "source_url": "https://example.com/demo",
  "licence": "CC BY 4.0"
}
```

- `period` is `pentad` (5 days, 72 slots a year) or `dekad` (10 days, 36 slots). `file_template` names the files and fixes which `{year}`, `{month}` and `{pentad}`/`{dekad}` the engine reads from each name; `prelim_file_template` is the optional second shape, for preliminary files.
- `scale` and `offset` convert the raster's numbers: `value = raw × scale + offset`. `valid_min`, `valid_max` and `nodata` say what is a value and what is a gap.
- `attribution` and `licence` are written into every file the build produces, so an area file always carries its source.
- `stale_after_days` sets the date the built pages go stale; `max_zoom` and `tile_size` set the map layer.
- Optional: `classes` turns values and their comparison with the normal into colour classes (rainfall ships `{ "value": [1, 5, 10, 25, 50, 100, 200], "comparison": [25, 50, 80, 120, 150, 200], "comparison_kind": "pct_of_normal" }`), `layer_periods` keeps the last n periods as separate layers, and `ramp` is the colour ramp of the map layer.

## 2. Your rasters

One file per period, named by the template, under a `final/` directory (and `prelim/` for preliminary files):

```text
raster/final/demo.2025.10.1.tif
raster/final/demo.2025.10.2.tif
```

Every file must be the same grid: same CRS (`crs_epsg`), same extent, same cell size. The engine reads the grid from the first file and refuses the ones that differ. `geolith dataset inspect <file>` prints a raster's layout and whether each read path decodes it, before a build finds out the hard way.

## 3. Your areas

One `GeoJSON` feature collection. Each feature needs `id`, `name`, `country` and `level`, and a polygon or multipolygon:

```json
{
  "type": "FeatureCollection",
  "boundary_release": "2026-10-21.0",
  "attribution": "Demo areas, made up for this guide.",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "id": "demo-north",
        "name": "North",
        "country": "FR",
        "level": "county"
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [0, 42],
            [4, 42],
            [4, 44],
            [0, 44],
            [0, 42]
          ]
        ]
      }
    }
  ]
}
```

`boundary_release` and `attribution` are members of the collection, not of a feature, and both are required: they name the polygons' release and say where they came from. Optional per-feature keys are `parent_id`, `parent_name`, `region_code` and `code`.

If you have no polygons of your own, `geolith dataset areas --overture <dir> --countries IN --out <dir>` cuts them from Overture Maps divisions, and writes `areas.geojson` beside `gaps.geojson`, `areas-report.json` and `areas.pmtiles`.

## 4. The normal for each slot

Area values compared with the normal for that time of year need the normal first. Give `normals` the baseline rasters and the slots you want:

```bash
geolith dataset normals --config demo.json --rasters baseline \
    --areas areas.geojson --baseline 2010-2010 --slots 10-1,10-2 \
    --out normals.csv
```

It writes one row per area and slot (`area_id,slot,normal,years,baseline,attribution`) and `normals-stats.json` beside it. `--baseline` is a year range and every year of it must have its rasters, unless the values cache (`--cache <dir>`) already holds them: then the normals run with the rasters deleted. A dataset with no normal simply has no comparison; the build still works.

## 5. Build

```bash
geolith dataset build --config demo.json --rasters raster \
    --areas areas.geojson --normals normals.csv --out out
```

The last line is the build directory, named after the newest period and the build time:

```text
out/2025-10-10.20261122T1215Z/
  index.json      period, areas, attribution
  numbers.csv     one row per area and period: value, normal, anomaly, coverage
  areas/<id>.json one area's series
  tiles.pmtiles   the map layer
  manifest.json   what the build wrote, and its inputs
```

`numbers.csv` is the part most people want: for each area and period, `value`, `normal`, `anomaly_pct`, `anomaly_abs`, `coverage_pct`, `cells` and the attribution. Nothing is overwritten: a new build is a new directory.

## 6. From a build to a served file

`build` writes engine directories. `stage` turns one of them into the upload-ready tree of keys, with a pointer that names the current build:

```bash
geolith dataset stage out/2025-10-10.20261122T1215Z --dataset demo
geolith dataset verify <stage-dir>
```

`verify` checks the tree before anything leaves the machine. Uploading and publishing are separate steps you run yourself, and need your bucket and its credentials; nothing in the pipeline uploads for you. The stage and its file names are documented in the geolith/geolith repo's README.

## 7. Upload to your own store

The binary holds no bucket, no key prefix and no host. Every setting has an environment name, and you keep the values in a git-ignored `.env` file. Copy `.env.example` from the geolith/geolith repo, fill in your own values and make it readable by you alone:

```bash
cp .env.example .env && chmod 600 .env
```

The storage part of `.env` (placeholders; any S3-compatible store works: Cloudflare R2 with region `auto`, AWS S3, MinIO, Backblaze B2):

```bash
DATASETS_R2_ENDPOINT=https://s3.example.com
DATASETS_R2_REGION=us-east-1
DATASETS_BUCKET=my-datasets
DATASETS_KEY_PREFIX=datasets/
GEOLITH_STORAGE_ACCESS_KEY_ID=replace-me
GEOLITH_STORAGE_SECRET_ACCESS_KEY=replace-me

# Optional: the live check after a publish ({dataset}, {country}, {build_id} are filled)
DATASETS_POINTER_URL=https://api.example.com/datasets/{dataset}/{country}/current.json
DATASETS_PAGE_URL=https://example.com/data/{country}/{dataset}
DATASETS_API_KEY=replace-me
```

`geolith dataset` reads the file named by `GEOLITH_ENV_FILE`, else `.env` in the current directory. No `.env` is fine; a file that `GEOLITH_ENV_FILE` names but that does not exist is an error, and a file whose mode is wider than 600 is refused. Nothing under your home directory is read by default.

Each setting is taken from the first place that has it: a flag, then the process environment, then the `.env` file, then an optional JSON file, then the default. The JSON file (copy `geolith.example.json`; keys such as `storage.bucket` and `publish.pointer_url`) is read only when you name it: `geolith dataset --config <file> <step>` (before the step) or `GEOLITH_CONFIG`. It holds no secret; its `credentials_file` fields can name mode-600 env files that do.

```bash
geolith dataset upload <build-id> --dry-run
geolith dataset upload <build-id>
geolith dataset publish <build-id>
```

The guards run first, also under `--dry-run`: only the configured bucket (`DATASETS_BUCKET`) is written, a dated key is never overwritten, and every key sits under the key prefix (`DATASETS_KEY_PREFIX`, default `datasets/`). If the endpoint or the bucket is missing, the command stops and names it.

`DATASETS_POINTER_URL` and `DATASETS_PAGE_URL` are optional. They are templates with `{dataset}`, `{country}` and `{build_id}`. The unattended `geolith dataset refresh` reads them after a publish to check the site names the new build, and rolls back if it does not. With neither set, that check is skipped and passes. `geolith dataset schedule install` writes the daily job and puts the path of the `.env` file it read into the job's environment as `GEOLITH_ENV_FILE` (and a JSON file it read as `GEOLITH_CONFIG`); the job's arguments carry no value.

## What this does not do

No hosted upload of your raster, and no CSV/Parquet/GeoParquet served over the API. The build is local and the files are static: serve them yourself, or stop at `numbers.csv`.
