Bulk Import - Customizing Import Rules
Overview
While Flywheel provides automatic import behavior that works well for many scenarios, you may need to customize how files are organized during import.
The new CLI provides extensive options for customizing:
- Filtering - Control which files are imported
- Mapping - Define how files are organized into Flywheel's hierarchy
- Grouping - Control how DICOM files are packaged into ZIP archives
- File Naming - Customize ZIP archive and individual file names
All customization options are available when using the flyw import run command.
Pattern Syntax Documentation
For comprehensive pattern syntax documentation and practical examples, see:
- Filtering and Mapping Guide - Practical examples and common use cases
- Pattern Quick Reference - Quick lookup for common patterns
- Pattern Syntax Reference - Complete syntax documentation
- Rule Files - Define complex rules in reusable YAML format
Scan Parameters
When importing from a cloud storage location that contains a very large number of items (for example, millions of files in a single storage prefix), you can use server-side prefix filtering to improve performance. Rather than listing all items and filtering client-side, prefix filtering tells the system to scan only the specified paths.
Prefix Filtering via the CLI
Use the --scan-params-prefix option to specify one or more path prefixes:
Multiple --scan-params-prefix values can be provided in a single import run. Each prefix is scanned independently, and the results are combined.
Prefix Filtering via Rule Files
Prefixes can also be defined in a rule file or managed rule set using the scan_params.prefixes field:
The rule file approach is recommended for recurring imports because it keeps the prefix configuration alongside the rest of the import rules.
Filtering Files
Filters control which files are included or excluded from import based on file properties like name, size, path, or depth.
Include Filters
Include filters specify which files should be processed. At least one include filter must match for a file to be imported.
Exclude Filters
Exclude filters specify which files should be skipped. If any exclude filter matches, the file is not imported.
Combining Include and Exclude
For more filtering examples and available fields, see the Filtering and Mapping Guide.
Mapping Files to Flywheel Hierarchy
Mapping patterns define how source file paths are transformed into Flywheel's hierarchy structure (Subject, Session, Acquisition) and how container labels are derived.
Path-Based Mapping
Extract container labels from file path structure:
DICOM Metadata Mapping
For DICOM files, derive container labels from DICOM headers:
Default Values
Set default values when mappings don't extract a value:
Override Values
Force specific values regardless of extracted data:
For more mapping examples and available DICOM fields, see the Filtering and Mapping Guide.
Per-File Values from a Manifest
Mapping rules derive values from patterns that apply to many files at once. When values cannot be derived from paths or headers, supply them file by file in a manifest file.
Rules and a manifest work together in the same import:
Each part of a rule plays a different role, and the manifest affects only one of them:
- Filters (
includeandexclude) are applied while Flywheel scans the source location. They decide which files are imported, and the matching rule sets each file's hierarchy level. The manifest is not used at this stage, so it cannot bring in a file that the filters skip. - Grouping of files into archives, such as the files of a DICOM series, also happens without the manifest.
- Mappings, including
defaultsandoverrides, derive each file's labels and metadata. This is the only stage where the manifest applies. For each file the manifest lists, its non-empty values replace the values that the mappings derived, including values set byoverrides. For files the manifest does not list, and for fields that a manifest row leaves empty, the mappings' values are used.
In other words, the filters always apply, and for the files they select, manifest entries take precedence over the mappings, which act as the fallback. Keep as much as possible in the rules, and use the manifest only for what the rules cannot derive. See Bulk Import - Default Behavior for how values are derived when no manifest is supplied.
DICOM-Specific Customizations
Custom Grouping Logic
Control how DICOM files are grouped into ZIP archives using the --dicom-group-by option:
Disable Zipping Single Files
By default, even single DICOM files are zipped. Use --no-zip-single to disable this:
Configuring File Names
Control the naming of files during import using the file.name mapping field. This applies to both ZIP archives created from DICOM files and non-DICOM files:
Configuring Individual DICOM File Names
Control how individual DICOM files are named within ZIP archives using --dicom-instance-name:
Note
The --dicom-instance-name option only affects DICOM files packaged into ZIP archives. To customize the names of loose DICOM files when --no-zip-single is used, use the file.name mapping field instead (see Configuring File Names).
Using Rule Sets or Rule Files
For complex import scenarios with multiple sets of rules, you have two options:
Managed Rule Sets (Recommended)
Use a centrally managed import rule set stored in Flywheel. Rule sets can be shared across your organization, are automatically versioned, and provide a full audit trail.
See Import and Export Rule Sets for details on creating and managing rule sets.
Local Rule Files
Alternatively, define rules in a local YAML file:
Rule files support:
- Multiple rules with first-match-wins logic
- All filtering and mapping options
- DICOM-specific configurations
- Reusable configurations across imports
See Rule Files for complete documentation on the YAML format and examples.
Complete Example
Here's a comprehensive example combining multiple customization options:
This command:
- Imports DICOM files larger than 1MB
- Excludes localizer and scout images
- Derives container labels from DICOM headers
- Groups files by study and series
- Customizes individual DICOM file naming within archives
Testing Your Configuration
Before running a full import, test your configuration using:
See Also
- Bulk Import - Default Behavior - Understanding automatic import processing
- Bulk Import - How-To (CLI) - Step-by-step import process
- Pattern Syntax Reference - Complete pattern syntax documentation
- Rule Files - Define complex rules in YAML format
- flyw CLI Documentation - Complete CLI reference