You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on integrating xarray support into Lumen, building on the proof-of-concept in #1434 and the request in #1508. This issue outlines my plan to deliver this in 3 incremental PRs, each independently mergeable and useful.
Motivation
Lumen currently handles tabular data (CSV, Parquet, SQL) via DuckDB. Researchers working with N-dimensional scientific data (climate, satellite, microscopy) stored in NetCDF/Zarr/HDF5 formats cannot use Lumen AI to explore their data. The xarray-sql library (Apache DataFusion backend) makes it possible to expose xarray datasets as SQL-queryable tables, bridging this gap.
Plan: 3 PRs
PR 1: Add XArraySQLSource (core source class)
Status: Ready for review
New lumen/sources/xarray_sql.py - XArraySQLSource(BaseSQLSource)
Uses xarray-sql (Apache DataFusion) for SQL queries over xarray datasets
Each data variable becomes a separate SQL table with coordinate columns
DataFusion uses postgres-compatible dialect for sqlglot translation
Supports NetCDF, Zarr, HDF5, GRIB with auto-engine detection
Rich metadata from xarray attributes (units, dimensions, coordinates)
Dimension info API for UI controls and AI context
Async execute/get for non-blocking AI agents
Shared DataFusion context via create_sql_expr_source
Full to_spec/from_spec serialization
Optional dependency: pip install lumen[xarray]
50 tests passing
PR 2: Add xarray scientific transforms
DimensionSlice - slice along any dimension by range or values
SpatialBBox - filter to lat/lon bounding box
DimensionAggregate - reduce dimensions via groupby (mean, sum, etc.)
TimeResample - resample time series at different frequencies
Anomaly - compute deviations from climatological mean
RollingWindow - moving average/sum/std smoothing
These work on any DataFrame with coordinate columns, useful even without XArraySQLSource.
PR 3: Wire xarray into Lumen AI
Add .nc/.zarr/.h5 to TABLE_EXTENSIONS in ai/controls/base.py
Add xarray file reader in _add_table()
Resolve .nc/.zarr paths in _resolve_data() for lumen-ai serve data.nc CLI
Upload flow: user drags NetCDF into Lumen AI chat, data becomes queryable
What to expect after all 3 PRs
A scientist can:
Run lumen-ai serve climate_data.nc from the command line
Or drag-and-drop a .nc file into Lumen AI chat
Ask natural language questions like "What's the average temperature by latitude?"
The SQL agent generates valid DataFusion SQL against the xarray data
Scientific transforms enable dimension slicing, spatial filtering, time resampling, and anomaly detection
Further work
After these 3 PRs establish the foundation, I plan to move forward with:
Remote Zarr support via fsspec (S3, GCS, Azure)
xarray DataTree support (hierarchical multi-resolution data)
Overview
I'm working on integrating xarray support into Lumen, building on the proof-of-concept in #1434 and the request in #1508. This issue outlines my plan to deliver this in 3 incremental PRs, each independently mergeable and useful.
Motivation
Lumen currently handles tabular data (CSV, Parquet, SQL) via DuckDB. Researchers working with N-dimensional scientific data (climate, satellite, microscopy) stored in NetCDF/Zarr/HDF5 formats cannot use Lumen AI to explore their data. The xarray-sql library (Apache DataFusion backend) makes it possible to expose xarray datasets as SQL-queryable tables, bridging this gap.
Plan: 3 PRs
PR 1: Add XArraySQLSource (core source class)
Status: Ready for review
lumen/sources/xarray_sql.py-XArraySQLSource(BaseSQLSource)create_sql_expr_sourceto_spec/from_specserializationpip install lumen[xarray]PR 2: Add xarray scientific transforms
DimensionSlice- slice along any dimension by range or valuesSpatialBBox- filter to lat/lon bounding boxDimensionAggregate- reduce dimensions via groupby (mean, sum, etc.)TimeResample- resample time series at different frequenciesAnomaly- compute deviations from climatological meanRollingWindow- moving average/sum/std smoothingThese work on any DataFrame with coordinate columns, useful even without XArraySQLSource.
PR 3: Wire xarray into Lumen AI
.nc/.zarr/.h5toTABLE_EXTENSIONSinai/controls/base.py_add_table().nc/.zarrpaths in_resolve_data()forlumen-ai serve data.ncCLIWhat to expect after all 3 PRs
A scientist can:
lumen-ai serve climate_data.ncfrom the command line.ncfile into Lumen AI chatFurther work
After these 3 PRs establish the foundation, I plan to move forward with:
xr.open_mfdataset()Related