Create an Ingest Template
This guide walks you through creating a template file to map your dataset structure to Flywheel's project hierarchy.
Before you begin: If you are new to templates, read Understanding Ingest Templates to learn when and why to use them.
Prerequisites
- Flywheel CLI installed and configured (installation guide)
- A plain text editor (TextEdit, Notepad, Sublime, VS Code, etc.)
- Your dataset organized in folders on your local machine
- Understanding of your dataset's folder structure and naming conventions
Before You Begin
Ensure you have:
CLI Setup:
- Flywheel CLI installed on your computer
- Valid API key and authenticated CLI - verify with
fw status - Stable internet connection for data upload
Permissions:
You need the following project-level permissions in the target group/project:
- Single File Upload/Create or Bulk File Upload - Required for CLI ingest commands
- Create Container - Required if creating new subjects, sessions, or acquisitions
To check your permissions, navigate to the project in the web UI and check your role. Learn more about user roles and permissions.
Data and Template Requirements:
- Dataset organized in consistent folder structure on your local machine
- Understanding of your dataset's folder naming patterns and hierarchy
- Template file saved as
.yaml(e.g.,my-template.yaml) - For DICOM data: Files must be valid DICOM format
- For non-DICOM data: Specify appropriate
packfile_typein template (e.g.,nifti,zip)
Template Validation:
Before running ingest:
- Validate YAML syntax at yamllint.com
- Test template on a small subset of data first
- Use
--dry-runflag to preview what will be imported without uploading
For PHI/Sensitive Data:
If your data contains Protected Health Information (PHI), configure de-identification before upload:
- Create a de-identification profile to remove PHI during import
- Test your profile with
fw deid testbefore uploading - See De-identifying Data During Ingest for template integration
For Automated Processing (Optional):
To automatically process data as it arrives, set up gear rules before uploading:
- Configure gear rules to run analysis automatically on new data
- Test rules on a small dataset first to verify they work as expected
Step 1: Start with a Basic Template
Every template must define labels for subjects, sessions, and acquisitions. Create a new file in your text editor and start with this basic structure:
This is the simplest template for uploading DICOM files with a three-level folder structure.
Step 2: Define the First Pattern
The first - pattern: line maps your dataset's top-level folder. Choose one of these approaches:
Option A: Use entire folder name as label
Example:
| Folder name | Result |
|---|---|
sub-01 | Subject label: sub-01 |
Option B: Extract part of folder name
Example:
| Folder name | Result |
|---|---|
001-subject-Nov-2021 | Subject label: 001 |
002-subject-Nov-2021 | Subject label: 002 |
Option C: Add custom metadata from folder name
Example:
| Folder name | Result |
|---|---|
001-subject-Nov-2021 | Adds metadata dataset: Nov-2021 to session |
Option D: Skip this folder level
Use regex .* to skip a folder level and move to the next.
Option E: Extract from filename
Example:
| Filename | Result |
|---|---|
SAG T1.dicom | Acquisition label: SAG T1 |
Tip
Use angled brackets <> instead of curly brackets {} when using regex to assign variables. This is a Python regex requirement.
Step 3: Add Patterns for Subfolders
Add a - pattern: line for each subfolder level in your dataset. Use any of the methods from Step 2.
Example:
Step 4: Package Files for Upload
At the deepest folder level containing your files, specify how to package them:
For DICOM files
When scan: dicom is used:
- Flywheel parses all
.dcmfiles - Metadata is extracted from DICOM headers
- Files are compressed into a zip for upload
- Invalid DICOM files stop the import (use
--ignore-scanflag to skip invalid files)
For non-DICOM files
Replace jpg with your file extension. This compresses all files in the folder into a single zip.
For mixed folders (select specific files)
This example only processes files ending in .dcm.
Step 5: Review and Validate
- Verify you have included each required variable exactly once:
{subject}{session}-
{acquisition} -
Check your YAML syntax using YAML Lint
-
Save your template file with a
.yamlextension (e.g.,my_template.yaml)
Step 6: Use Your Template
Run the ingest command with your template:
For additional options and flags, see the fw ingest template command reference.
Common Template Patterns
Three-level hierarchy with metadata
Skip middle folder level
Complex metadata extraction
Verify Success
After the ingest completes, verify your template worked correctly:
1. Check the CLI Output
Look for confirmation messages in the terminal:
- Number of files processed
- Containers created (subjects, sessions, acquisitions)
- Any warnings about pattern mismatches or skipped files
2. View Data in Flywheel Web UI
- Sign in to your Flywheel site
- Navigate to your project: Groups → [Your Group] → [Your Project]
- Verify:
- Subject labels match template pattern extraction
- Session labels are correct
- Acquisition labels are as expected
- File counts match what you uploaded
3. Check Metadata Extraction
If your template extracts custom metadata:
- Click on a subject, session, or acquisition
- View the "Info" tab
- Verify custom fields were populated correctly (e.g.,
{session.info.visit_date})
4. Validate File Organization
Check that files are organized correctly:
- Files are in the correct acquisitions
- File types are set correctly (DICOM, NIfTI, etc.)
- No files were skipped unexpectedly
5. Review Audit Logs (if enabled)
If you used the --save-audit-logs flag:
- Review the audit log file for any errors or warnings
- Check for pattern matching issues
- Verify all expected files were processed
Next Steps
- Explore more examples: See Additional Template Examples
- Review full syntax reference: See Ingest Template Reference
- Use a config file: Simplify complex commands with Configuration Files
- Apply de-identification: See De-identifying Data During Ingest
- Run analysis gears: Process your imported data with Flywheel gears
Troubleshooting
Issue: Template syntax errors
- Solution: Validate YAML at yamllint.com
- Check for proper indentation (use spaces, not tabs)
Issue: Missing subjects, sessions, or acquisitions in Flywheel
- Solution: Verify each variable (
{subject},{session},{acquisition}) appears exactly once in your template
Issue: Invalid DICOM files stop ingest
- Solution: Add
--ignore-scanflag to skip invalid files and continue processing
Issue: Metadata not appearing in Flywheel
- Solution: Use dot notation syntax:
{container.info.fieldname}(e.g.,{session.info.visit_date})