5.8. Generating the YAML of a feature

The metadata of each feature stored by junifer has the DataGrabber, preprocessors and marker that computed it, with their parameters. From it, generate_yaml() generates the YAML to compute the feature again, with the same results (and the same MD5) if the data and the versions of the dependencies are the same.

The metadata of the features is listed by the storage (see analysing results):

from junifer.api import generate_yaml
from junifer.storage import HDF5FeatureStorage
from junifer.utils import yaml

storage = HDF5FeatureStorage(uri="/path/to/features.hdf5")
features = storage.list_features()
# The metadata of a feature, by its MD5
meta = features["<feature md5>"]
yaml.dump(generate_yaml(meta), "feature.yaml")

The YAML has a single marker, the one of the feature, and comments with the versions of the dependencies used to compute it and the issues found, for example:

# Auto-generated by junifer 0.0.9 on 2026-10-20 10:04:27 UTC from the
# metadata of the feature BOLD_tian_mean_aggregation
#
# Computed with:
#   junifer==0.0.9
#   nilearn==0.14.1
#   numpy==2.4.6
#
# To set:
#   - workdir: the working directory
#   - storage.uri: the file to store the features
workdir: ''

with:
  - junifer.testing.registry

datagrabber:
  kind: PartlyCloudyTestingDataGrabber
  n_timepoints: 5

preprocess:
  - kind: TemporalSlicer
    start: 0
    stop: 4.0

markers:
  - kind: ParcelAggregation
    method: mean
    name: tian_mean
    parcellation:
      - TianxS1x3TxMNInonlinear2009cAsym

storage:
  kind: HDF5FeatureStorage
  uri: ''

5.8.1. What the YAML contains

  • datagrabber, datareader, preprocess and markers: the components that computed the feature, each with only the parameters that were set in the original YAML (the defaults are left out). datareader is left out if it is the default one, DefaultDataReader without parameters. markers has a single marker, the one of the feature, with its name in the original YAML.

  • with: the modules that loaded the components that are not built-in, as in the original YAML. The files loaded with with are written with their absolute path.

Each component is created with its parameters to check that they are still valid. The modules of the components that are not loaded are imported first, as with with when running the YAML: besides their components, they can register what the built-in components need (e.g., a data type for a DataGrabber). If a module cannot be imported, its components are not checked, and an issue in the comments says so. If a component fails to be created (e.g., because it changed in another version of junifer), the YAML gets all the parameters stored in the metadata for that component, and an issue in the comments to check them.

5.8.2. What you need to set

The working directory and the storage are not part of the metadata, so they are left empty in the YAML:

  • workdir: the working directory.

  • storage: the uri of the file to store the features. The kind is HDF5FeatureStorage unless another one is given with storage_kind.

The datadir of the DataGrabber, if it was set, is the one used to compute the feature. If the data is now somewhere else, change it too. Note that, for the DataGrabbers that are not based on DataLad, datadir is part of the MD5 of the features, so a different datadir gives a different MD5.

5.8.3. Notes and issues in the comments

The comments at the start of the YAML list what to check before using it:

  • Notes: the versions of the dependencies that computed the feature, a reminder to check the components if the feature was computed with another version of junifer, and the ID and commit of the DataLad dataset, if any.

  • Issues: the components that are not built-in and whose module is unknown (to add to with), the modules that could not be imported, the components that failed to be created with their parameters, and a DataLad dataset that was dirty (had local changes), in which case the same results are not guaranteed.

Note

The parameters set to create the components, the modules to load them and the name of the marker are only stored by junifer > 0.0.8, so generate_yaml() raises an error for the features computed with previous versions.