Skip to content

About

Dockerized Python package for processing Level 0 -> Level 1 data in the FDRI project

Resources

Contributing

Stars

1 star

Watchers

7 watching

Forks

Repository files navigation

Time Series Data Processing Pipeline

A pipeline for processing environmental time series data from monitoring networks. The system performs corrections, quality control, infilling, aggregation, and derivation operations on meteorological and hydrological measurements.

Overview

This pipeline processes time series data through a metadata-driven approach:

  1. Fetches metadata from the FDRI Metadata API to build a dependency graph of datasets
  2. Processes datasets in topological order, ensuring dependencies are satisfied
  3. Applies operations corrections > quality control > infilling > aggregation/derivation
  4. Writes results to S3 storage as partitioned parquet files

Basic usage

The processor CLI is invoked using:

python -m dritimeseriesprocessor ...

Use one of four (mutually exclusive) processing modes, or the utility command:

  1. Explicit: from-selection

    • Individual sets of processing arguments
    python -m dritimeseriesprocessor from-selection
     --network NETWORK
     [--lookback DURATION | --start-date YYYY-MM-DD]
     [--end-date YYYY-MM-DD]
     --selection SITE VARIABLE PERIODICITY
     [--selection SITE2 VARIABLE2 PERIODICITY2 ...]

    Example:

    python -m dritimeseriesprocessor from-selection
     --network cosmos
     --lookback P2D
     --selection cosmos-alic1 TA PT30M
     --selection cosmos-bunny PA PT30M
     --selection cosmos-bunny PRECIP P1D
  2. Cross-product: from-cross-product

    • Bulk processing across processing dimensions
    python -m dritimeseriesprocessor from-cross-product
     --network NETWORK
     [--lookback DURATION | --start-date YYYY-MM-DD]
     [--end-date YYYY-MM-DD]
     [--sites SITE1 SITE2 ...]
     [--variables VAR1 VAR2 ...]
     [--periodicities PER1 PER2 ...]

    Example:

    python -m dritimeseriesprocessor from-cross-product
     --network cosmos
     --lookback P2D
     --sites cosmos-alic1 cosmos-bunny
     --variables TA PA
     --periodicities PT30M
  3. From datasets: from-datasets

    • Request one or more datasets directly by their metadata API ID
    • Works for both TimeSeriesDataset and ObservationDataset records
    • Does not require --network
    python -m dritimeseriesprocessor from-datasets
     [--lookback DURATION | --start-date YYYY-MM-DD]
     [--end-date YYYY-MM-DD]
     --datasets DATASET_ID [DATASET_ID2 ...]

    Example:

    python -m dritimeseriesprocessor from-datasets
     --datasets flux-plynl-processed
     --start-date 2024-08-14
     --end-date 2024-08-15
  4. Historic: historic

    • Processes everything for a network's sites over each site's full operating dates, one calendar year at a time
    • No dataset or date options: start and end dates come from each site's metadata (end date is today if still open)
    • Optionally pass --sites to limit the run to a specific set of sites
    python -m dritimeseriesprocessor historic
     --network NETWORK
     [--sites SITE [SITE ...]]

    Example:

    python -m dritimeseriesprocessor historic --network cosmos --sites cosmos-alic1
  5. List sites: list-sites

    • Writes a JSON array of active site IDs for a network to /tmp/sites.json
    • Sites not open during the requested date window are excluded
    • Pass --historic instead of any date arguments to list every site the network has ever had
    • Optionally pass --sites to limit the result to a specific set of sites (still checked against the network and date window)
    python -m dritimeseriesprocessor list-sites
     --network NETWORK
     [--sites SITE [SITE ...]]
     [--historic | [--lookback DURATION | --start-date YYYY-MM-DD] [--end-date YYYY-MM-DD]]

    Example:

    python -m dritimeseriesprocessor list-sites --network cosmos --lookback P2D

See CLI Usage for more info.

Developer Setup

This is for active development on the processing package itself.

Requirements

Install uv

Official instructions

Clone the repository

git clone https://github.com/NERC-CEH/dri-timeseries-processor.git
cd dri-timeseries-processor

Setting up and activating a virtual environment

uv sync
source .venv/bin/activate

Docker Compose

Build the Docker container to set up LocalStack (local AWS services):

docker compose up -d

This initialises:

  • LocalStack S3 buckets with sample data
  • Prometheus Pushgateway for metrics (accessible at localhost:9091)

Common commands

Run make help to list all available targets. The most commonly used ones:

Command Description
make qa Format, lint, type check, and test
make test Run tests
make ruff Run ruff format and lint checks
make type-check Type check with pyright
make docker-build Build the Docker image locally
make docker-run Run the Docker image locally
make install-hooks Configure git to use .githooks/

Test data is automatically loaded into LocalStack S3 on container initialization.

Detecting tests using VSCode

VSCode has a useful test runner, allowing running and debugging of all tests within the repository. To allow VSCode to detect the tests, use the Configure Tests option accessed either via the help menu (select "Show All Commands" and type "Configure Tests" in the search bar), or via the test runner panel and select the "Configure Tests" button if it is available. To configure the tests, select pytest as the test runner framework and testing as the directory containing the tests.

Pre-commit hooks

Run the following to set up the pre-commit hooks:

make install-hooks

The hook runs ruff format --check and ruff check to prevent commits that are not formatted correctly or have errors. The hook intentionally does not alter files, but tells you which command to run.

Versioning and Releases

This project follows Semantic Versioning (major.minor.patch). The patch component is used as an auto-incrementing build number: a local pre-push git hook bumps it on every push that doesn't already include a version change. Install the hook once per clone with make install-hooks. major and minor are bumped by hand with make bump-minor or make bump-major when you want a new release line. Every merge to production automatically builds the production Docker image, tags the commit, and creates a GitHub release.

See Versioning and Releases for the full flow, examples, and the workflows involved.

Configuration

Configuration is environment-aware, loading from different sources based on the environment variable:

  • Local: __assets__/env.cfg file
  • Staging/Production: Environment variables directly

Required configuration keys:

  • AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  • metadata_api_url
  • endpoint_url (LocalStack only)

Metrics

The pipeline exports Prometheus metrics to a Pushgateway:

  • Pipeline timing: Total runtime, per-operation timings
  • Success/failure counts: Datasets processed successfully or failed
  • Data availability: Datasets with no data available

Locally accessible at http://localhost:9091

Documentation

Available in docs folder.

About

Dockerized Python package for processing Level 0 -> Level 1 data in the FDRI project

Resources

Contributing

Stars

1 star

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages