FOXES / docs /workflows.md
griffingoodwin04's picture
Fixed dependency issues and notebook errors.
57e33cc
|
Raw History Blame Contribute Delete
7.79 kB

Command-Line Workflows

For single observations or short time ranges, the Python Guide is the easier route. The scripts on this page are for heavier jobs: building datasets, running batch predictions, evaluating results, and training. Each script reads a YAML config, so open and edit the config before running anything. Run all commands from the repository root.

Set Up a Checkout

git clone https://github.com/griffin-goodwin/FOXES.git
cd FOXES
conda create -n helio-foxes-dev python=3.12 pip -y
conda activate helio-foxes-dev
python -m pip install -e ".[data,dev,evaluation,training]"
git lfs pull

Each extra enables a checkout workflow. data supplies the raw dataset builder and Hugging Face downloader, evaluation supplies metrics, and training supplies Weights & Biases logging. dev adds pytest and a notebook kernel. python -m pip install -r requirements.txt installs the non-editable checkout with all three workflow extras. Pick the environment's kernel when working in a notebook and restart it after editing imported code. Run python -m pytest -q to check your changes.

Paths in a YAML config are resolved relative to the config file itself, not to wherever your terminal or notebook happens to be. The bundled configs set path_root: .., which makes ./foxes_data/ and ./foxes_outputs/ point to folders in the repository root. If your data lives somewhere else, point path_root at it or use absolute paths; ~ and environment variables like ${FOXES_DATA} work too. If you launch a script from a different directory, give the full paths to both the script and its --config. The data folders in the example configs need to exist, so create them or swap in your own paths.

Get Data

To download the released dataset as paired AIA/SXR .npy files:

python download/hugging_face_data_download.py --config download/hf_download_config.yaml

Set the output directories and the splits you want in download/hf_download_config.yaml. If you already have the Parquet files locally, set local_parquet_dir in that config to skip the download.

To build the dataset from raw AIA and GOES data instead, edit the matching configs and run:

python download/download_sdo.py --config download/sdo_download_config.yaml
python download/download_sxr.py --config download/sxr_download_config.yaml
python data/build_dataset.py --config data/build_dataset_config.yaml

AIA downloads need a registered JSOC email. The build script cleans and processes the AIA images, then lines the GOES measurements up with them.

Run Inference

In forecasting/inference_config.yaml, set data.aia_dir, data.sxr_dir, data.checkpoint_path, and output_path. The AIA files should be processed (7, 512, 512) -> (C, H, W) arrays, and each matching SXR file holds a single flux value under the same timestamp filename. If you don't have SXR targets, set prediction_only: "true".

By default the config uses model_assets/UncertaintyModel.ckpt with legacy_model: false. Leave data.sxr_norm_path: null so it uses the normalization stored in the checkpoint. Other weights are listed under Models and Checkpoints.

python forecasting/inference.py --config forecasting/inference_config.yaml

The script writes a CSV of predictions. Whether it also saves flux maps and patch uncertainty maps depends on the output paths and model_params in the config. Inference runs on the single device set by device; with CUDA, that's the first visible GPU.

To run inference across multiple CUDA GPUs, launch one process per GPU:

python forecasting/run_parallel_inference.py \
  --config forecasting/inference_config.yaml --gpus 0,1,2,3

Each worker uses the configured batch size and handles a disjoint share of the timestamps after the sampling step. It writes a shard CSV and log beside output_path; after every worker succeeds, the launcher merges all columns in timestamp order into the configured CSV. Gaussian intervals and legacy calibration columns are preserved. Optional maps keep their timestamp-based filenames in the configured folders. Paths still resolve from the YAML's path_root. The launcher explicitly selects CUDA for its workers, overriding the YAML's device setting. Keep the selected sample count at least as large as the number of GPUs.

Evaluate Predictions

Point forecasting/evaluation_config.yaml at your prediction CSV and an output directory, then run:

python forecasting/evaluation.py --config forecasting/evaluation_config.yaml

You'll get regression metrics and figures, plus interval coverage and calibration plots if the predictions include Gaussian uncertainty. The Results page is an example of the output.

Train a Model

Training expects paired AIA/SXR files split into train/, val/, and test/ folders. If you're building from raw data, turn on steps.split and sxr_normalization.compute in data/build_dataset_config.yaml to set those up.

Edit the data paths, model, and training settings, then run:

python training/train.py --config training/train_coupled_gaussian.yaml

The Gaussian config is an editable training preset. For the released checkpoint's architecture and uncertainty head, see Models and Checkpoints; the preset is not a complete reproduction recipe. For a deterministic model, use training/train_deterministic.yaml instead.

To train the Gaussian model using only the patch-level flux head, set vit_architecture.global_patch_adjustment: false in the training YAML. This omits initialization and computation of the global correction branch while preserving optional uncertainty training. The setting is saved in the checkpoint and also applies at inference. It defaults to true when omitted.

vit_architecture.mask_mode is passed to each patch attention block and accepts local, inverted, or none (full attention), with either setting of global_patch_adjustment. local_window sets the window size for the two masked modes.

uncertainty.uncertainty_input chooses what the uncertainty head sees. logit (the training preset's default) gives it each patch's local logit. context (used by the updated released checkpoint) gives it the globally corrected logit plus the patch's features, raw AIA token projection, and the global summary. Without the global branch, context uses the local logit and patch features. To fit only the uncertainty head on an existing model, set:

finetune:
  checkpoint_path: model_assets/UncertaintyModel.ckpt
  train_only_uncertainty_head: true
  reset_uncertainty_head: true

vit_architecture and data.sxr_norm_path must match the checkpoint; learning rate and dropout may differ. The flux predictions stay exactly as in the checkpoint, and the training loss is the Gaussian NLL alone. reset_uncertainty_head: true starts the head fresh even when checkpoint weights would match. It uses seeded random hidden weights and the configured uncertainty.initial_relative_std for its initial output. The default is false, which loads compatible uncertainty weights; an incompatible head starts fresh.

On the training set the flux model's errors are smaller than on new data, so a head fitted there learns too small a spread. To fit it on held-out data instead, also set finetune.val_fit_fraction, for example 0.8. The earliest 80% of val (in time) then trains the head, the last 20% selects checkpoints, and train/ is not read. With 1, all of val trains the head, validation is off, early stopping is not allowed, and every epoch is saved. Keep test/ for checking interval coverage afterwards.