Run your first workflow
One way to process data with DEFAIR — and probably the first that comes to mind — is by writing Python code that calls its functions. Run that code as a script or in a Jupyter notebook, using a Python environment where DEFAIR is installed.
You can also define a workflow in a YAML file. This is a plain text configuration file that specifies which data to read, which processing steps to apply and where to save the results. When you run the workflow from the terminal, DEFAIR reads these settings and carries out the steps in order.
The choice depends on how you want to work:
Advantages of workflows: You can save, share and reuse a processing sequence without writing a Python script for the supported operations. Change the input paths, processing parameters or output settings in the YAML file, then run it with the same command. You can also include that command in a scheduled job.
Limitations of workflows: The YAML file uses the operations and options supported by DEFAIR’s workflow system. Custom calculations may still require Python functions or plugins. Python is more flexible when you need conditional logic or want to inspect intermediate results interactively. To run someone else’s workflow, you need a compatible DEFAIR environment and access to its input data.
In the example below, you will create and run a workflow that reads an MSG SEVIRI product, selects one channel over a region and saves the result as Zarr.
Prerequisites
No. 1 DEFAIR and the sample product
Install DEFAIR by following Install DEFAIR. Then follow Read your first product to download and extract the sample product. Keep the extracted .nat file in a folder where you have permission to create files.
Write the workflow file
In the folder containing the extracted sample, create a file named first-workflow.yaml. Copy the following YAML configuration into it and save the file:
name: First workflow
description: One MSG SEVIRI channel over Iberia, written to Zarr
inputs:
- reader:
name: msg15nat
use_channel_names: true
source:
fs_type: local
path: MSG3-SEVI-MSG15-0100-NA-20251016172744.081000000Z-NA.nat
transformations:
- operation: content_filter
include_vars: [IR_108]
- operation: spatial_filter
lat_min: 35
lat_max: 45
lon_min: -10
lon_max: 5
outputs:
- writer: zarrv2
path: output/first-workflow.zarr
mode: w
The configuration has three sections:
inputsspecifies the reader and the path to the sample file.transformationslists the processing steps in execution order: select theIR_108channel, then crop it to the specified region.outputsspecifies the Zarr writer and the destination,output/first-workflow.zarr. This path is relative to the folder from which you run DEFAIR.
Reader, transformation and writer options use the same names as in Python.
Preview the plan
Open a terminal in the folder containing the sample and first-workflow.yaml, and activate your DEFAIR environment. Run the following command to preview the processing steps:
defair run --config first-workflow.yaml --dry-run
2026-09-24 00:14:04 | INFO | [774116ba] defair.cli.run:run_cmd:82 - Successfully loaded workflow: First workflow
First workflow
One MSG SEVIRI channel over Iberia, written to Zarr
1. Input Stage
┏━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ # ┃ ID ┃ Reader ┃ Source ┃ Configuration ┃
┡━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ input_0 │ msg15nat │ local://MSG3-SEVI-MSG15-0100-NA-20251016172744.081000000Z-NA.nat │ Reader: use_channel_names=True │
└─────┴─────────┴──────────┴──────────────────────────────────────────────────────────────────┴────────────────────────────────┘
2. Transformation Stage
┏━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ # ┃ Operation ┃ Routing ┃ Parameters ┃
┡━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ content_filter │ - │ include_vars=['IR_108'] │
│ 2 │ spatial_filter │ - │ lat_min=35, lat_max=45, lon_min=-10, lon_max=5 │
└─────┴────────────────┴─────────┴────────────────────────────────────────────────┘
3. Output Stage
┏━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ # ┃ Writer ┃ Destination ┃ Configuration ┃
┡━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ 1 │ zarrv2 │ output/first-workflow.zarr │ Writer: mode=w │
└─────┴────────┴────────────────────────────┴────────────────┘
The first line is a log message, with a date and a code that change from run to run. DEFAIR checks the file against the plugins it names and prints what it would do. A mistake, such as an option a plugin does not accept, is reported here rather than part-way through a run.
Run it
Run the following command from the same folder to process the sample and write the result:
defair run --config first-workflow.yaml
DEFAIR logs each processing step, including the warning that the HRV channel is excluded by default, and ends with:
Workflow completed successfully!
After a successful run, the Zarr result is saved at output/first-workflow.zarr inside your working folder. The result is equivalent to the one produced by the Python example.
The defair run command returns exit code 0 on success, 1 when processing fails and 2 when the configuration file is invalid. A shell script or scheduler can use this code to check whether the command succeeded.
Change it
Try one of these edits and run the file again:
Put the region on a latitude and longitude grid: add a third transformation,
operation: reprojectionwithtarget: EPSG:4326andresolution: 0.05.Build a time series: replace
pathwith a list of files, or a pattern such asdata/*.nat.Write NetCDF instead: change the writer to
netcdf4and the path tooutput/first-workflow.nc, and removemode: w.
What to do next
Continue with Where to go next to choose your next task. To adapt the YAML structure for more inputs or processing steps, follow Create a workflow file.