Key concepts
DEFAIR has four kinds of building block. Each is a plugin, a piece of code DEFAIR loads by name, so you choose one by naming it.
Readers
A reader opens one kind of product. DEFAIR includes 50 readers, and some
of them open several related products. Dataset is where you start.
Dataset.from_source("my-file.nat") looks at the file and chooses the
right reader for you, so you rarely name one yourself.
from defair_data import Dataset
dataset = Dataset.from_source("my-file.nat")
print(dataset.data)
dataset.data is an xarray dataset, the standard Python container for
labelled arrays. Its arrays are Dask arrays: nothing is read from the
file until you ask for values, so opening a product is quick whatever
its size.
Transformations
Transformations change data you have already read. For example, you can:
Crop data to a region.
Keep only the channels you need.
Move data onto a different map grid.
Put data from several satellites on a shared grid.
Average data over time.
These are just some of the available transformations. Each returns a dataset that you can pass directly to the next transformation.
For example, use spatial_filter to crop the dataset to a region:
region = dataset.transform("spatial_filter", lat_min=35, lat_max=45, lon_min=-10, lon_max=5)
Writers
A writer saves a dataset to a file. Zarr is the usual choice for machine learning: it splits one large array into many small files, so a training job can read the part it needs without loading all of it. NetCDF, HDF5, Parquet, CSV, GeoTIFF, PNG and JPEG are also available. Writers save to your disk, and the Zarr writers also save to cloud storage.
region.to_file("region.zarr", writer="zarrv2")
Workflows
A workflow is a whole job written in a YAML file, a plain text settings file. It says which products to read, what to do to them, and where to write the result. Run it with:
defair run --config my-workflow.yaml
Add --dry-run to preview the plan:
defair run --config my-workflow.yaml --dry-run
You can save the file, review changes, and run the same job again.
Lazy loading and chunks
DEFAIR uses lazy loading and chunks to process datasets larger than the available memory.
Lazy loading delays reading and processing data until the values are needed. Dask manages this work throughout the pipeline, from reading the input to writing the output.
Chunks are smaller blocks of a large array that can be read and processed separately. Readers choose default chunk sizes, which you can adjust.
What to do next
Continue to DEFAIR packages on PyPI to learn what each package contains and which packages you need for the tutorials. Then choose the local or JupyterHub installation guide.
For details and examples of the building blocks introduced here, explore these articles:
Reader catalogue lists the readers and the products they read.
Transform data describes the built-in transformations with examples of how to use them.
Write outputs lists the built-in writers, their output formats and when to use them.
Run your first workflow combines reading, filtering and writing in a YAML workflow.