An Airflow pipeline that downloads NASA's near-Earth-object close-approach data week by week, models it with dbt, reconstructs each asteroid's flyby trajectory past Earth from its orbit, and renders the result on a 3D globe.
The asteroids orbit the Sun, not Earth: none of them hit us. Each one sweeps past on a nearly straight line and keeps going. The globe draws those paths over the 3 days before and after closest approach, with a dot riding along each one as the time slider plays.
15 April 2026, as (2013 GM3) makes the closest pass in the dataset, 0.68 lunar distances (about 260,000 km): the bright hooked curve just west of Africa. Around it are a month of other flybys. Lines brighten in the direction of travel; squares mark asteroids passing at that moment (red = potentially hazardous); the dashed ring is the Moon's distance. The panel on the left filters by time window, position accuracy, hazard and size.
It runs fully locally (Docker, Postgres, files on disk). Pointing it at Google Cloud (GCS + BigQuery) is a configuration change, see Going to GCP.
flowchart LR
A[NASA NeoWs /feed<br/>weekly windows] -->|neows_feed| B[(Lake<br/>raw JSON per week)]
B --> C[(Warehouse raw<br/>neo_observation, close_approach)]
J[JPL SBDB<br/>orbital elements] -->|neows_orbits| D[(raw.sbdb_orbit)]
C --> E{{neows_publish}}
D --> E
E -->|dbt| F[(marts: dim_asteroid,<br/>fct_close_approach, weekly summary)]
F -->|orbit maths| G[(fct_approach_geo)]
G -->|export + flyby paths| H[viz/data/approaches.js]
H --> I[viz/index.html<br/>3D globe]
Requires Docker with Compose.
cd airflow cp .env.example .env # set NASA_API_KEY (free at https://api.nasa.gov), AIRFLOW_UID=$(id -u), and the secrets docker compose up -d --build
Open Airflow at http://localhost:8081 (no login in local mode). The DAGs are unpaused, so:
neows_feedbackfills every week since 2024-01-01 (one API request per week; two weeks run in parallel).DEMO_KEYallows only 30 requests per hour, so use a real key for the backfill.neows_orbitspulls the orbital elements of every known NEO in a single request.- When both have run,
neows_publishbuilds the dbt models, computes the overhead points and writesviz/data/approaches.js.
Then open viz/index.html in a browser. A snapshot is committed so the page works
before you run anything.
Without Docker, the same steps run from the command line (see .env.example for the variables):
python -m neows backfill --start 2024-01-01, orbits, geo, export.
NeoWs gives a miss distance and a time, not a position. For each approach:
- take the asteroid's orbital elements from JPL SBDB and propagate them with a two-body (Keplerian) solution to every 6 hours from 3 days before to 3 days after closest approach,
- subtract Earth's position (astropy's built-in ephemeris) to get where the asteroid is relative to Earth: a direction (right ascension/declination) and a distance,
- draw the samples against the stars as they stood at the moment of closest approach. The nearest
point then floats directly above the place on Earth the asteroid was overhead at that instant
(
fct_approach_geostores that point). An Earth-fixed frame would wind every path into a spiral, because the planet rotates underneath.
Distance is drawn on a log scale so that flybys at 0.7 and at 70 lunar distances both fit, which makes the straight paths look gently curved. A dashed ring marks the Moon's distance for scale.
Planetary perturbations are ignored, so every approach is checked against NASA's own miss
distance and labelled good (< 5 % off), rough (< 25 %) or poor. On the 2024-2026 data
(5,236 approaches), 95.6 % are good (median error 0.2 %); spot checks against JPL Horizons agree to
about 0.1 degrees. The globe lets you filter by this accuracy.
| Layer | Object | Notes |
|---|---|---|
| lake | raw/feed/start_date=YYYY-MM-DD/feed.json |
scrubbed API response (the API key is stripped); rerunning a week overwrites it |
| raw | neo_observation, close_approach, sbdb_orbit |
loaded by Python, one weekly interval replaced atomically per run |
| marts | dim_asteroid |
latest attributes + orbital elements, one row per asteroid |
| marts | fct_close_approach |
one row per (asteroid, approach instant); partitioned/clustered on BigQuery |
| marts | mart_weekly_summary |
approaches, hazardous count, closest pass, largest object per week |
| marts | fct_approach_geo |
overhead point at closest approach, computed distance, accuracy label |
NeoWs asteroid ids are not JPL SPK-IDs, so orbits are joined on the provisional designation
(2015 XB128), which matches about 99 % of asteroids.
The code path is identical; only configuration changes.
- Create a GCP project and a service account with Storage Admin and BigQuery Admin (or narrower).
Save its key as
airflow/credentials/gcp.json(the folder is gitignored). - Create the bucket and datasets:
cd terraform export GOOGLE_APPLICATION_CREDENTIALS=$PWD/../airflow/credentials/gcp.json terraform init && terraform apply -var project=YOUR_PROJECT terraform output -raw env_snippet >> ../airflow/.env
docker compose up -dagain. The lake is nowgs://..., loads go to BigQuery, and dbt runs with--target gcp.
The Postgres container still hosts Airflow's own metadata; only the data moves.
airflow/
dags/ neows_feed, neows_orbits, neows_publish
neows/ the package the DAGs call: client, parse, lake, warehouse, sbdb, geo, pipeline
dbt/neows/ staging views, marts, tests; targets `local` (Postgres) and `gcp` (BigQuery)
tests/ pytest (no Docker or network needed)
terraform/ optional GCP infrastructure
viz/ the globe page and its exported data
uv run pytest # unit tests; DAG parse tests run too if Airflow is installed
uv run ruff check airflow- Secrets live in
airflow/.envandairflow/credentials/, both gitignored. Stored raw responses have the NeoWslinksblocks removed, because NASA echoes your API key in them. - Local services bind to
127.0.0.1only. Local mode disables the Airflow login screen; removeSIMPLE_AUTH_MANAGER_ALL_ADMINSfromdocker-compose.ymlbefore exposing it anywhere.
Data: NASA NeoWs and JPL SBDB.
