A benchmarking and analysis toolkit for sparse vector-field reconstruction, HelioSwarm sampling, and downstream turbulence diagnostics.
This repository started as a reconstruction benchmark framework and now supports a broader workflow:
- sparse reconstruction benchmarks on synthetic or simulation-backed fields
- HelioSwarm-driven sampling geometries for static reconstructions
- moving-observatory HelioSwarm time-series generation through a static simulation box
- downstream structure-function, space-time decorrelation, and lag-tetrahedra analyses
The main onboarding doc is this README. For a more operational view of the run modes, inputs, outputs, and workflow chaining, see docs/workflows.md.
For a simple local install in this workspace:
cd /home/kgklein/Codes/sparse-field-reconstruction
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .For full development and notebook extras:
git clone https://github.com/kgklein/sparse-field-reconstruction.git
cd sparse-field-reconstruction
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev,notebooks]"Most example runs in this repo use:
PYTHONPATH=srcso the package can be imported directly from the checkoutMPLCONFIGDIR=/tmp/mplso Matplotlib has a writable config/cache directory
The current codebase supports four main workflow families:
- Reconstruction benchmarks via
scripts/run_baseline.py - Moving-observatory HelioSwarm time-series generation via
scripts/run_hs_timeseries.py - Structure-function analysis via
scripts/run_structure_functions.py - Space-time decorrelation and lag-tetrahedra analysis via
scripts/run_space_time_correlation.pyandscripts/run_lag_tetrahedra.py
- Use
scripts/run_baseline.pyif you want to compare reconstruction methods on synthetic fields or a static simulation snapshot. - Use
scripts/run_baseline.pywith--hs-pathand--hs-timeif you want a static HelioSwarm sampling geometry for a reconstruction benchmark. - Use
scripts/run_hs_timeseries.pyif you want a 9-spacecraft moving-observatory time series through a simulation box. - Use
scripts/run_structure_functions.py --input-mode interpolated_timeseriesif you want structure functions from an existing HelioSwarm time-series CSV. - Use
scripts/run_structure_functions.py --input-mode simulation_cubeif you want structure functions sampled directly from a simulation cube. - Use
scripts/run_space_time_correlation.pyif you want a multipoint decorrelation map from an existing HelioSwarm time series. - Use
scripts/run_lag_tetrahedra.pyif you want lag-tetrahedra and Yaglom-style diagnostics from saved Elsasser pair products.
The repo includes small worked examples as shell scripts:
quick_run.sh: 2D synthetic smoke runquick_run_3d.sh: 3D synthetic smoke runquick_run_3d_hs.sh: 3D synthetic field with HelioSwarm samplingquick_run_3d_sim_hs.sh: simulation-backed reconstruction with HelioSwarm samplingquick_run_hs_timeseries.sh: magnetic-field time-series sampling runquick_run_hs_timeseries_velocity.sh: velocity-focused time-series run that also writes Elsasser pair productsquick_run_structure_functions.sh: structure functions from an existing time-series productquick_run_structure_functions_cube.sh: structure functions sampled directly from a simulation cubequick_run_space_time_correlation.sh: multipoint space-time decorrelation analysisquick_run_lag_tetrahedra.sh: lag-tetrahedra analysis from saved Elsasser pair products
You can run them directly, for example:
./quick_run.sh
./quick_run_3d.sh
./quick_run_hs_timeseries.sh
./quick_run_hs_timeseries_velocity.sh
./quick_run_structure_functions.sh
./quick_run_space_time_correlation.sh
./quick_run_lag_tetrahedra.sh2D synthetic smoke run:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_baseline.py \
--methods rbf \
--sample-counts 24 \
--geometries random \
--noise-levels 0.0 \
--nx 24 \
--ny 24 \
--output-dir /tmp/sparse_recon_smoke3D synthetic smoke run:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_baseline.py \
--field-kind smooth_3d \
--methods rbf \
--sample-counts 48 \
--geometries random,multi_probe_like \
--noise-levels 0.0 \
--nx 10 \
--ny 9 \
--nz 8 \
--output-dir /tmp/sparse_recon_3d_smoke3D synthetic field with HelioSwarm sampling:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_baseline.py \
--field-kind smooth_3d \
--methods rbf \
--noise-levels 0.0 \
--nx 10 \
--ny 9 \
--nz 8 \
--hs-path /path/to/HelioSwarm/HS-RT/PhB_SRD5B_0x75b \
--hs-time "2029-06-26 00:00:00" \
--output-dir /tmp/sparse_recon_hs_smoke3D simulation snapshot with HelioSwarm sampling:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_baseline.py \
--data-source simulation \
--simulation-path /path/to/ot3D_field_75.npy \
--methods rbf \
--noise-levels 0.0 \
--hs-path /path/to/HelioSwarm/DRM \
--hs-time "2029-09-26 00:00:00" \
--rho-p-km 100 \
--sim-box-x 314.15926 \
--sim-box-y 314.15926 \
--sim-box-z 1570.79632 \
--include-hub \
--output-dir /tmp/sparse_recon_sim_hsMoving-observatory magnetic-field time-series run:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_hs_timeseries.py \
--simulation-path /path/to/ot3D_field_75.npy \
--hs-path /path/to/HelioSwarm/DRM \
--hs-time "2029-09-26 00:00:00" \
--rho-p-km 100 \
--sim-box-x 314.15926 \
--sim-box-y 314.15926 \
--sim-box-z 1570.79632 \
--vx-kms 250 \
--vy-kms 120 \
--vz-kms 150 \
--dt-seconds 0.03125 \
--n-steps 10000 \
--sampling-method trilinear \
--plot-timeseries \
--output-dir figsVelocity/Elsasser time-series run:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_hs_timeseries.py \
--simulation-path /path/to/ot3D_field_75.bp \
--ion-moments-path /path/to/ot3D_ion_75.bp \
--background-b-lua-path /path/to/ot3D.lua \
--simulation-vector-vars nux,nuy,nuz \
--simulation-density-var n \
--geometry-vector-vars bx,by,bz \
--secondary-timeseries-vector-vars bx,by,bz \
--secondary-timeseries-component-labels "B_x,B_y,B_z" \
--simulation-component-labels "u_x,u_y,u_z" \
--hs-path /path/to/HelioSwarm/DRM \
--hs-time "2029-09-26 00:00:00" \
--rho-p-km 100 \
--sim-box-x 314.15926 \
--sim-box-y 314.15926 \
--sim-box-z 1570.79632 \
--vx-kms 250 \
--vy-kms 120 \
--vz-kms 150 \
--dt-seconds 0.03125 \
--n-steps 10000 \
--sampling-method trilinear \
--plot-timeseries \
--output-dir figs_velocityThis velocity-focused mode can write both the sampled primary time series and the saved Elsasser pair products needed by the lag-tetrahedra workflow.
Structure-function analysis from an existing moving-observatory time-series product:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_structure_functions.py \
--input-mode interpolated_timeseries \
--timeseries-csv figs/helioswarm_timeseries.csv \
--timeseries-metadata figs/helioswarm_timeseries_metadata.json \
--max-order 6 \
--n-lambda-bins 20 \
--undersampled-fraction 0.01 \
--plot \
--output-dir figsStructure-function analysis directly from a simulation cube:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_structure_functions.py \
--input-mode simulation_cube \
--simulation-path /path/to/ot3D_field_75.npy \
--sim-box-x 314.15926 \
--sim-box-y 314.15926 \
--sim-box-z 1570.79632 \
--max-order 6 \
--n-lambda-bins 20 \
--cube-candidate-pairs 20000 \
--cube-target-pairs-per-bin 256 \
--cube-random-seed 0 \
--cube-diagnostics \
--cube-compare-local-reference \
--cube-reference-max-offset 1 \
--plot \
--output-dir /tmp/sparse_recon_structure_functions_cubeSpace-time decorrelation analysis from an existing moving-observatory time-series product:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_space_time_correlation.py \
--timeseries-csv figs/helioswarm_timeseries.csv \
--timeseries-metadata figs/helioswarm_timeseries_metadata.json \
--spacecraft-labels H,N1,N2,N3,N4,N5,N6,N7,N8 \
--n-r-bins 24 \
--max-tau-seconds 60 \
--plot \
--plot-contour \
--output-dir figsLag-tetrahedra analysis from saved Elsasser pair products:
PYTHONPATH=src MPLCONFIGDIR=/tmp/mpl python3 scripts/run_lag_tetrahedra.py \
--timeseries-metadata figs_velocity/helioswarm_timeseries_metadata.json \
--elsasser-pairs-npz figs_velocity/helioswarm_timeseries_elsasser_pairs.npz \
--elsasser-pairs-json figs_velocity/helioswarm_timeseries_elsasser_pairs.json \
--time-index 0 \
--dep-max 0.85 \
--max-arrows 400 \
--highlight-tetrahedron-index 120 \
--plot \
--output-dir figs_lag_tetrahedraThe synthetic field generator supports these benchmark families:
smoothhigh_frequencynoisy_smoothsmooth_3dhigh_frequency_3d
Simulation-backed workflows support structured snapshots such as:
.npyvector fields shaped(nx, ny, nz, 3).bpfield snapshots when variable names are supplied.bppacked ion-moment snapshots for velocity/density workflows
See data/README.md for local data expectations.
HelioSwarm sampling can be driven from either:
- a single
.cdffile - a directory containing monthly
.cdfsummary files
Accepted --hs-time formats include:
YYYY-MM-DD HHYYYY-MM-DD HH:MMYYYY-MM-DD HH:MM:SS- the same forms with
Tinstead of a space
The reader selects the nearest available timestamp in the CDF data.
Simulation-backed HelioSwarm workflows use two coordinate systems:
- HelioSwarm spacecraft positions start in physical
km - simulation boxes are specified in proton gyroradius units
rho_p
For simulation-backed reconstruction and moving-observatory runs, the current transform pipeline is:
- Load HelioSwarm positions from CDF files in
km. - Convert them to hub-relative coordinates in
km. - Divide by
--rho-p-kmto convert the formation fromkmtorho_p. - Use
--sim-box-x,--sim-box-y, and--sim-box-zas the full simulation-box lengths inrho_p. - Translate the HelioSwarm formation so its centroid sits at the center of that simulation box.
This simulation-backed transform is recorded in metadata as km_to_rho_p_centered_box.
Common outputs across workflows include:
- baseline benchmark outputs such as
results.jsonl, per-experimentmetrics.json, andoverview.png - time-series products such as
helioswarm_timeseries.csvandhelioswarm_timeseries_metadata.json - optional Elsasser pair products such as
helioswarm_timeseries_elsasser_pairs.npzandhelioswarm_timeseries_elsasser_pairs.json - structure-function outputs such as
structure_functions.json,structure_functions.png, and optional diagnostics files - space-time decorrelation outputs such as
space_time_correlation.jsonandspace_time_correlation.png - lag-tetrahedra outputs such as
lag_tetrahedra.json,lag_tetrahedra_ep_scatter.png,lag_tetrahedra_yaglom_flux.png,lag_tetrahedra_epsilon_diagnostics.png,lag_tetrahedra_epsilon_diagnostics_log_km.png, andlag_tetrahedra_baseline_projections.png
The exact inputs and outputs for each run mode are documented in docs/workflows.md.
sparse-field-reconstruction/
|- quick_run*.sh
|- scripts/
|- src/sparse_recon/
|- tests/
|- docs/
`- data/
Important directories:
scripts/: runnable entrypointssrc/sparse_recon/: package code for datasets, sampling, methods, analysis, and visualizationtests/: unit and integration testsdocs/: workflow documentation
- Baseline reconstruction methods currently available are
nearest,linear, andrbf. - Moving-observatory time-series runs are simulation-only and require all 9 valid HelioSwarm spacecraft including hub
H. - Space-time decorrelation currently requires a spacecraft label list that includes the hub.
- Lag-tetrahedra analysis depends on saved Elsasser pair outputs plus the matching time-series metadata file.
- Large simulation-backed runs can be expensive compared with the quick-run examples.
See CONTRIBUTING.md for contribution and testing guidance.
MIT.