Skip to content

Emission Import ​

This section outlines instructions on how to import data into the platform using helper scripts and the input format for the data.

GitHub Repository ​

Location of the scripts: github.com/aerscape/data-pipelines

Getting Started ​

Clone the repository ​

bash
git clone git@github.com:/aerscape/data-pipelines

Install dependencies ​

Install the requests library via pip:

bash
pip install requests

Getting the latest code ​

Before running, make sure to have the latest code and cd into the dataimport-scripts folder:

bash
git pull
cd dataimport-scripts

Quick Reference ​

Before running any script:

bash
cd {PROJECTS_ROOT}/data-pipelines/
git pull
cd dataimport-scripts

Common command examples:

bash
# Emissions Bridger
python -m importers.emissions.bridger --environment dev --api_key {API_KEY_VALUE} --data_path {PATH_TO_FOLDER} --data_source SELF_REPORTED

# Emissions Generic (Any data provider)
python -m importers.emissions.generic --environment staging --api_key {API_KEY_VALUE} --data_path {PATH_TO_FOLDER} --data_provider "Existing Data Provider" --contains_no_detects 1 --data_source SELF_REPORTED

# Aerial Images
python -m importers.infrastructure.aerial_images --environment prod --api_key {API_KEY_VALUE} --data_path {PATH_TO_FOLDER}

# Pipelines
python -m importers.infrastructure.pipelines --environment prod --api_key {API_KEY_VALUE} --data_path {PATH_TO_FOLDER} --owner {OWNER_NAME}

# ChampionX surveys
python -m importers.extra_data.championx --environment staging --api_key {API_KEY_VALUE} --data_path {PATH_TO_FOLDER}

Available Import Scripts ​

Emission Imports ​

Survey / Extra Data Imports ​

  • ChampionX - ChampionX flight survey data (DataSurvey)

Infrastructure Imports ​

Common Script Arguments ​

The following arguments are required for each script:

  • --environment - Environment to import to: local, dev, prod-testing, or prod
  • --api_key - Retrieved from the platform data_import admin view
  • --data_path - Full path to the folder containing data import files

Preparing the Data ​

Each script expects a path to a folder containing a data package. The package must contain:

  • Exactly one CSV file formatted to the script specification. If there is no CSV file found or if there are multiple CSV files found, the script will fail.
  • Referenced files: If a TIFF image or other file is referenced in the CSV file, it must be present in the data package, otherwise the script will fail.

Exception: The ChampionX importer takes a multi-CSV folder (a surveys.csv manifest plus one point CSV per survey), not a single CSV.

Important: CSV files cannot have byte order mark (Excel adds by default). Use :set nobomb in vim to remove.

Updating Existing Records ​

Imports can update detections that are already in the platform, not just create new ones. A row is treated as an update when it carries a record_id column matching a detection already stored for the same data provider.

Identity is record_id scoped by owner:

  • If the row resolves to an owner (an owner column, or the import's --owner), it can only update a point belonging to that same owner. The same record_id under a different owner is a different detection and is imported as a new point.
  • If the row resolves to no owner, it matches on record_id alone.

When a row updates an existing point:

  • The point is updated in place, a history entry is written with the previous values, and its version is bumped (ORIGINAL → V2 → V3 …).
  • The point stays in its original data batch — it is not moved into the new import's batch.
  • The data field is replaced wholesale, so an update row must carry all of the extra columns the original import supplied, or they are lost. Only tracked data keys keep their previous values in history.
  • Plume images are not replaced by default. Pass --overwrite-plumes-on-update to replace them.

Note: matching against infrastructure is not re-run for points that already have an emission record. An update that changes latitude/longitude will not move an existing match to a different site.

Detection timestamps can't change ​

A detection is identified by its record_id and detection timestamp, so in production an update row may not change an existing point's timestamp: a vendor that restates it is reporting a different detection. Each such row fails, the whole import is rolled back, and it ends in the SAFEGUARD_TRIGGERED state, shown as failed in the pipeline tracker:

Would change the detection timestamp of data point 'abc-123' from 2019-06-28T00:00:00+00:00 to 2019-07-01T00:00:00+00:00. Set `allow_detection_timestamp_changes: true` in import_params to allow it.

To let a legitimate correction through, re-run the import with "allow_detection_timestamp_changes": true in its import_params (only a JSON true counts). The check applies only while the protect_detection_timestamps waffle switch is on.

Volume limits ​

A vendor that re-keys or re-sends its records shows up as an import that touches a large share of what we already have. In production an import fails, before anything is written, when it would:

  • update more than 10% of the provider's existing data points (plume images are replaced along with updated points when --overwrite-plumes-on-update is set), or
  • create more than 10% of the provider's existing data points, for automated imports only (created by the platform user). Manual uploads are reviewed by a person.
Would update 1200 of 9000 existing CarbonMapper data points, more than 10%.
Set `allow_large_import: true` in import_params to allow it.

The import ends in the SAFEGUARD_TRIGGERED state, shown as failed in the pipeline tracker. Providers with fewer than 1000 data points aren't limited, so a new provider can load its backlog. To let a legitimate large import through, re-run it with "allow_large_import": true in its import_params (only a JSON true counts).

The external validate-csv endpoint doesn't check these limits: it only validates the file, and the limits are checked when the import saves. A file that passes validate-csv can still end in SAFEGUARD_TRIGGERED once the import runs.

Each limit has its own waffle switch and applies only while it's on: limit_emission_import_updates for updates, limit_emission_import_new_points for new points. The limits come from the DATA_IMPORT_MAX_UPDATED_RATIO, DATA_IMPORT_MAX_CREATED_RATIO and DATA_IMPORT_RATIO_MIN_BASELINE settings (environment variables of the same names).

Tracked data keys ​

A provider can list keys of the data field whose changes are recorded in history, like the typed fields (rate, location, timestamp …). This is the history_tracked_data_keys import parameter, set in the provider's import task.

ProviderTracked keys
CaliforniaSMPoperator, sector, event_status

Keys are the cleaned CSV column names (lowercase, spaces replaced by _), so CARB's Event Status column is tracked as event_status.

When a tracked key changes:

  • The history entry stores the previous values of the changed keys only, e.g. {"operator": "Old Operator LLC"}. A key the point didn't have before is stored as null.
  • Whitespace-only changes, and an empty value replacing a missing one, are not changes.
  • The version is bumped like for any other change, even when nothing else changed.

Providers without tracked keys behave as before: data changes are not recorded.

The changes are shown in the data point's history: the Details column of the emission's Data Point History table (the current row shows today's values for the same keys) and the History section of the map sidebar. They're also in the history API (history[].data) and the History column of the emission data export.

When the change happened ​

A history entry's changed_at is taken from the row's modified value, when it has one. For S3 providers that publish an _index.json (CaliforniaSMP, CarbonMapper), the S3 transformer copies each record's modified from the index into the record, unless the record already has its own.

  • Entries imported before this was in place have no changed_at. This includes all earlier CaliforniaSMP history.
  • The index modified can reflect when the record's file was last written to the bucket rather than when the source changed it, so changed_at can be later than the actual change.
  • Independently of changed_at, an entry's created_at is when the platform imported the change.

After Starting an Import ​

The platform processes an import in steps after the script uploads it: the import itself, then (depending on the data) image processing, matching and non-detects. The import's status tells you where it is:

StatusMeaning
READY_FOR_PROCESSINGUploaded, waiting for the antivirus scan
IMPORTINGBeing imported, or one of the steps after the import is running
COMPLETEEvery step finished: the data is imported, matched and its non-detects computed
ERRORA step failed. import_errors says which one and why. When a safeguard refused the import, state is SAFEGUARD_TRIGGERED
TIMED_OUTA step took too long. import_errors names the step

COMPLETE comes once the whole pipeline has finished, so an import can stay IMPORTING well after its rows are saved.

Note: helpers/query.py --wait stops on COMPLETE and ERROR, but not on TIMED_OUT yet, so stop it by hand if the status shows TIMED_OUT.

How the steps work is described in Data Import Pipeline.

Error Handling ​

The import process follows an all-or-nothing rule - it'll try to process the operations sequentially, and if anything fails, it rolls back the entire process.

The messages are all being stored in the database. For common errors and solutions, see the Troubleshooting guide.