A collection of scripts that checks the masks generated by aligning images to the Allen Brain Atlas
The Brain Atlas Checker is a Python tool designed to recursively scan directories for TIFF files within atlaslabel_def_origspace
folders and compare their unique values against a reference CSV file. This tool is particularly useful for validating atlas label files against a known set of valid IDs.
The atlas_info.csv file in atlases/atlas_v3
was derived from the atlas_info.txt file from Snehashish Roy's CATNIP GitHub Repo.
- Recursive directory scanning for
atlaslabel_def_origspace
folders - TIFF file parsing to extract unique values
- CSV parsing for reference IDs
- Identification of values present in TIFF files but missing from the reference CSV
- JSON output support
- Verbose mode for detailed progress tracking
click
tifffile
- Clone this repository
- Install required packages:
pip install click tifffile
python tiff_scanner.py /path/to/root/directory
# Save results to JSON file
python tiff_scanner.py /path/to/root/directory -o results.json
# Use verbose mode
python tiff_scanner.py /path/to/root/directory -v
# Specify custom CSV path
python tiff_scanner.py /path/to/root/directory --csv-path /path/to/custom/atlas_info.csv
# Combine options
python tiff_scanner.py /path/to/root/directory -o results.json -v --csv-path /path/to/custom/atlas_info.csv
root_directory
: (Required) The starting directory for the recursive search--output
,-o
: Output JSON file path (optional)--verbose
,-v
: Enable detailed progress information--csv-path
: Path to atlas info CSV file (defaults to "/atlases/atlas_v3/atlas_info.csv")
The tool generates a JSON output with the following structure:
{
"/absolute/path/to/directory1": [1, 2, 3],
"/absolute/path/to/directory2": [4, 5, 6]
}
Each key is an absolute path to a processed directory, and the corresponding value is a list of integer IDs that were found in the TIFF files but not in the reference CSV.
The tool expects a CSV file with the following structure:
id,name,acronym,red,green,blue,structure_order,parent_id,parent_acronym
1,Structure1,STR1,255,78,86,75500,557,STR
2,Structure2,STR2,137,205,161,6200,345,STR
The id
column is used as the reference for valid values.
- Invalid CSV files or missing directories will raise appropriate errors
- Individual TIFF file processing errors are logged but won't stop the overall process
- Non-integer values in TIFF files are automatically filtered out
The module can also be imported and used programmatically:
from tiff_scanner import scan_for_label_directories
# Scan directories and get results
results = scan_for_label_directories(
root_path="/path/to/root/directory",
csv_path="/path/to/atlas_info.csv"
)
# Process results
for directory, missing_ids in results.items():
print(f"Directory: {directory}")
print(f"Missing IDs: {missing_ids}")
Feel free to open issues or submit pull requests for any improvements or bug fixes.