Skip to Content
Developer DocsServicesFlaring Monitor

Flaring Monitor

The Flaring Monitor is a comprehensive flaring compliance service that tracks flare event volumes, validates Form R-32 filings, calculates emissions (CO2e), forecasts authorization exceedances, manages repair obligations, handles operational events with deduplication and submission guards, and provides burn rate projections.

Overview

Texas operators that flare or vent natural gas must comply with RRC Rule 32 (Statewide Rule 32). The flaring monitor provides the data backbone for this compliance workflow:

  • Volume tracking — Ingest flaring events, compute cumulative volumes, and assess compliance against authorization limits
  • Pre-filing validation — Validate Form R-32 data completeness before submission
  • Emissions calculation — Compute CO2, CH4, and CO2-equivalent emissions for flaring and venting, assess EPA OOOOb applicability
  • Predictive analysis — Forecast when an authorization will be exceeded using decline curve analysis and model infrastructure delay impacts
  • Audit trail — Tag events with applicable regulatory frameworks (RRC, EPA, GHGRP) and write HMAC-signed audit entries
  • Flare event CRUD — Full lifecycle management of individual flare events with correlation
  • Burn rate projections — Calculate daily burn rates and project authorization exhaustion dates
  • Repair obligations — Track repair commitments triggered by flare events
  • Operational events — Unified event system for 5+ event types with deduplication rules, custom event types, and submission guards

Port & Language

PropertyValue
Port8007
LanguagePython 3.12
FrameworkFastAPI
Entry pointsrc/flaring/main.py

Key Endpoints

Volume Tracking & Compliance

MethodPathDescription
POST/flaring/ingestIngest flaring events and compute compliance status.
POST/flaring/assessAssess current flaring volumes against authorization limits.
POST/flaring/validateValidate Form R-32 data before submission.

Emissions & Audit

MethodPathDescription
POST/flaring/emissionsCalculate CO2e emissions from flaring/venting volumes.
POST/flaring/tag-frameworksTag a flaring event with applicable regulatory frameworks.
POST/flaring/form-prGenerate Form PR-ready data from flaring events.

Predictive Analysis

MethodPathDescription
POST/flaring/forecastForecast authorization exceedance using decline curve analysis.
POST/flaring/infrastructure-delayModel infrastructure delay impact on flaring compliance.

Flare Events CRUD

MethodPathDescription
POST/flare-eventsCreate a new flare event.
GET/flare-eventsList flare events with filtering.
GET/flare-events/{event_id}Get a single flare event.
PUT/flare-events/{event_id}Update a flare event.
POST/flare-events/{event_id}/correlateCorrelate a flare event with another event.

Burn Rate & Projections

MethodPathDescription
GET/authorizations/{auth_id}/burn-rateGet burn rate data for an authorization.
GET/authorizations/{auth_id}/projectionProject authorization exhaustion date.

Repair Obligations

MethodPathDescription
GET/repair-obligationsList repair obligations (overdue, upcoming, completed).
PUT/repair-obligations/{id}Update repair status (completion date, narrative).

Operational Events (Unified)

MethodPathDescription
POST/eventsCreate an operational event (any type). Runs deduplication and guard rules.
GET/eventsList operational events with filtering, pagination, sorting.
GET/events/{event_id}Get a single operational event.
PUT/events/{event_id}Update an operational event.
PUT/events/{event_id}/statusTransition event status.
POST/events/agent-draftCreate an agent-assisted draft event.

Duplication Rules

MethodPathDescription
GET/events/duplication-rulesList deduplication rules.
POST/events/duplication-rulesCreate a deduplication rule.
PUT/events/duplication-rules/{id}Update a deduplication rule.

Custom Event Types

MethodPathDescription
GET/events/typesList custom event type definitions.
POST/events/typesCreate a custom event type.
PUT/events/types/{id}Update a custom event type.

Submission Guard Rules

MethodPathDescription
GET/events/guard-rulesList submission guard rules.
POST/events/guard-rulesCreate a guard rule.
PUT/events/guard-rules/{id}Update a guard rule.

Dashboard & Seeding

MethodPathDescription
GET/flaring/dashboard/{operator_id}Dashboard summary for an operator’s flaring compliance.
POST/seed-eventsSeed demo events, duplication rules, and custom event types.
GET/healthHealth check.

Architecture

Module Breakdown

src/flaring/ ├── main.py # FastAPI app, core endpoint definitions, background tasks ├── config.py # Settings and emission factor constants ├── schemas.py # Pydantic request/response models ├── volume_tracker.py # Flaring volume processing and compliance assessment ├── validation.py # Form R-32 pre-filing validation ├── prediction.py # Decline curve forecasting and infra delay modeling ├── audit_tagging.py # Regulatory framework tagging, Form PR generation, audit writes ├── burn_rate.py # Burn rate calculation and alert thresholds ├── burn_rate_routes.py # Burn rate API routes ├── event_routes.py # Flare event CRUD routes ├── repair_routes.py # Repair obligation routes ├── operational_event_routes.py # Unified operational event CRUD ├── duplication_engine.py # Event deduplication rule engine ├── duplication_rule_routes.py # Deduplication rule CRUD routes ├── event_type_service.py # Custom event type management ├── event_type_routes.py # Custom event type routes ├── submission_guard_engine.py # Pre-submission validation guard engine ├── guard_rule_service.py # Guard rule management service ├── guard_rule_routes.py # Guard rule routes ├── compliance_triggers.py # Event-driven compliance trigger logic ├── correlation.py # Event correlation logic ├── event_number.py # Sequential event number generation ├── override_capture.py # Override tracking for guard acknowledgments ├── seed_events.py # Demo operational event seeder ├── seed_duplication_rules.py # Demo deduplication rule seeder └── seed_event_types.py # Demo custom event type seeder

Emissions Calculation

The /flaring/emissions endpoint computes emissions using EPA-standard factors:

FactorValueUnit
CO2 per MCF flared0.054metric tons
CH4 slip per MCF (flared)0.00038metric tons
CH4 per MCF vented0.019metric tons
CH4 GWP (global warming potential)28CO2e multiplier
GHGRP threshold25,000metric tons CO2e/year

EPA OOOOb applicability: Wells spudded after November 15, 2021 are subject to OOOOb methane emission standards.

Alert Thresholds

MetricWarningCritical
Volume vs. authorization limit80%90%
Authorization days remaining150 days180 days (max)

Nightly Burn Rate Recalculation

A background task runs every 24 hours (with a 60-second startup delay) that recalculates burn rates for all active authorizations:

  1. Query all distinct authorization_id values from flare_events
  2. For each authorization, aggregate daily volumes
  3. Recalculate the burn rate and update projections

Operational Event Deduplication

When creating an operational event, the DuplicationRulesEngine checks the new event against configurable rules to detect potential duplicates:

  • Rules define matching criteria (entity, time window, event type, severity)
  • If a potential duplicate is detected, the API returns a warning
  • The caller can acknowledge the duplication and proceed by setting duplication_acknowledged: true

Submission Guards

The SubmissionGuardEngine evaluates pre-submission rules before an event can be created:

  • Rules define conditions that must be met (e.g., required fields, minimum data quality)
  • If a guard rule fails, the API returns the failing conditions
  • The caller can acknowledge and override by setting guard_acknowledged: true

Dependencies

Python Packages

PackageVersionPurpose
fastapi^0.115Web framework
uvicorn^0.34ASGI server
asyncpg^0.29PostgreSQL async driver
httpx^0.28HTTP client for KG queries
aegis-sharedlocalShared models, events, DB helpers

Service Dependencies

ServiceProtocolPurpose
Knowledge Graph Service (8003)HTTPWell and authorization data for dashboard
PostgreSQLTCPFlare events, operational events, repair obligations

Configuration

Environment VariableDefaultDescription
FLARING_HOST0.0.0.0Bind address
FLARING_PORT8007Bind port
DATABASE_URLpostgresql://aegis:aegis_local@localhost:5432/aegisPostgreSQL connection
KNOWLEDGE_GRAPH_SERVICE_URLhttp://localhost:8003Knowledge graph service URL
HMAC_SIGNING_KEYaegis-local-hmac-key-change-in-productionKey for audit trail HMAC signatures
DB_SCHEMAag_catalogDatabase schema prefix

Hardcoded emission factors and thresholds are in config.py. See the Emissions Calculation section above for values.

Running Locally

cd services/flaring-monitor poetry install poetry run uvicorn flaring.main:app --reload --port 8007

Seeding Demo Data

# Seed operational events, duplication rules, and custom event types curl -X POST http://localhost:8007/seed-events

The flaring monitor requires PostgreSQL for event storage. The knowledge graph service is only needed for the dashboard endpoint. All volume tracking, validation, and emissions calculation endpoints are self-contained.

Last updated on