Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions applications/pipeline/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# VFB precomputed pipeline: precomputed.zip per image folder (see README.md, vfb_pipeline.py).
# Built for the VFB cluster, whose VMs expose a qemu64 CPU without SSE4.2/POPCNT: no x86-64-v2 wheels
# (numpy < 2.4, scipy < 1.15) and nothing compiled with -march.
FROM python:3.12-slim-bookworm

RUN apt-get update && apt-get install -y --no-install-recommends build-essential ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Pin the two packages whose newer wheels assume x86-64-v2 first, so the rest resolve against them.
RUN pip install --no-cache-dir "numpy<2.4" "scipy<1.15"

WORKDIR /app
COPY requirements.txt /app/requirements.txt
# igneous/zmesh/DracoPy (multires_draco) and navis are optional for the production path (legacy meshes;
# volume_man.obj or tube meshes from SWC) and are left out of the cluster image.
RUN grep -vE '^(igneous|zmesh|DracoPy|navis)' requirements.txt > /tmp/req.txt \
&& pip install --no-cache-dir -r /tmp/req.txt
COPY . /app
RUN python -c "import numpy, scipy, skimage, trimesh, nrrd, cloudvolume, vfb_pipeline; print('numpy', numpy.__version__)"
# cloud-volume writes ~/.cloudfiles and ~/.cloudvolume; uid 1000 has no home in the image.
ENV PYTHONUNBUFFERED=1 HOME=/tmp
USER 1000:1000
ENTRYPOINT ["python", "/app/vfb_pipeline.py"]
73 changes: 58 additions & 15 deletions applications/pipeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,69 @@

## Overview

This repository contains scripts and documentation for converting Virtual Fly Brain (VFB) image files into [Neuroglancer precomputed format](https://github.com/google/neuroglancer/tree/master/src/datasource/precomputed) for use in Neuroglancer/Neuroglass viewers.
This folder converts Virtual Fly Brain (VFB) image files into [Neuroglancer precomputed format](https://github.com/google/neuroglancer/tree/master/src/datasource/precomputed) for the Neuroglancer/Neuroglass viewer.

VFB image data lives at `https://www.virtualflybrain.org/data/VFB/i/{first4}/{last4}/{template_id}/` and contains several file types per image:

| File | Format | Description |
|------|--------|-------------|
| `volume.nrrd` | NRRD | 3D volumetric voxel data |
| `volume_man.obj` | OBJ mesh | Manually curated or generated mesh (vertices + faces) |
| `volume.nrrd` | NRRD | 3D volumetric voxel data (uint8, X Y Z, microns) |
| `volume_man.obj` | OBJ mesh | Manually curated or generated mesh (vertices + faces, X Y Z, microns) |
| `volume.obj` | OBJ point cloud | Auto-generated point cloud (vertices only, no faces) |
| `volume.swc` | SWC | Neuron skeleton/morphology tracing |
| `volume.swc` | SWC | Neuron skeleton/morphology tracing (microns) |
| `volume.wlz` | Woolz | Format for the IIP3D slice viewer |

## The production pipeline: `vfb_pipeline.py`

`vfb_pipeline.py` is what runs against the image store. For each image folder it writes **one file**, `precomputed.zip`, next to the source files: a precomputed dataset (`info`, `0/` chunks, `mesh/`) zipped as a single archive that Neuroglancer reads through its zip kvstore with HTTP Range requests:

```
https://www.virtualflybrain.org/data/VFB/i/0010/1567/VFB_00101567/precomputed.zip|zip:|neuroglancer-precomputed:
```

What is written depends on what the image **is** (its VFB category, from the KB), because every VFB NRRD is uint8 and the dtype cannot tell a template from a neuron:

| category | KB rule | layer | chunks (`0/`) | mesh |
|---|---|---|---|---|
| template | `:Template` individual | `image` | intensities | none |
| expression | typed by a `VFBexp_*` (GAL4 / split pattern) or `VFBext_*` (fragment) class | `image` | intensities | none |
| object | everything else: `FBbt_*`-typed neurons, clones, painted domains | `segmentation` | `{0,1}`, segment 1 | `volume_man.obj` if it has faces, else generated from `volume.swc`, else marching cubes on the NRRD |

Without a KB category (filesystem scan, `--ids`) the same decision is made from the data: a `volume_man.obj` with faces or a `volume.swc` means an object; a single-valued mask is an object; intensities are an image.

Axes and units: everything stays X, Y, Z as pynrrd returns it — no transposes, no swaps (OBJ and SWC vertices were checked against the NRRD voxel extents of templates, domains, FlyWire/hemibrain neurons and LM neurons). Source files are in microns; `resolution`, `voxel_offset` (voxel units) and mesh vertices are written in **nanometres**, the unit the precomputed spec defines, so VFB datasets compose with other precomputed sources.

The zip also carries `provenance.json` (pipeline version, category, mesh source, size+mtime of the source files). A re-run skips a folder whose zip was made by the current `PIPELINE_VERSION` from unchanged sources, so the job is idempotent and resumable; bump `PIPELINE_VERSION` to regenerate everything.

Each dataset is built in `--work-dir` (local scratch; a template-sized volume is ~120 MB of raw chunks) and only the finished zip is copied into the image folder, as `precomputed.zip.tmp-<pid>` then renamed — a reader never sees a partial file.

```bash
# What would be done for everything on JRC2018U, live images only (KB)
python vfb_pipeline.py --image-root /data --use-kb --template VFB_00101567 --dry-run

# A few folders, building on local scratch
python vfb_pipeline.py --image-root /data --ids VFB_00101567 VFB_00102107 VFB_jrchk0ew --template VFB_00101567 --work-dir /scratch

# A batch file (one id per line), e.g. one Argo task
python vfb_pipeline.py --image-root /data --ids-file batch.txt --template VFB_00101567 --work-dir /scratch
```

For a planned run (one plan pod, many workers): `--use-kb --list-targets targets.tsv` writes the discovered targets with their category (40 s for the 680k JRC2018U images); split that into batches and give each worker `--targets-file batch.tsv --results results.jsonl` — no KB access in the workers, one JSON line per image for the report.

`--template` is required (except with `--targets-file`): space is limited, so only the alignments you name get a `precomputed.zip`. Hemibrain (`VFB_00101384`) alignments are never converted.

`--layer-type image|segmentation` overrides the per-image decision; `--mask/--mesh-percentile/--decimate-fraction/--mesh-format` only affect the marching-cubes path (objects with no mesh); `--no-compress` leaves an uncompressed `precomputed/` folder for debugging. Discovery needs only HTTP access to `kb.virtualflybrain.org` (read-only, published credentials).

Measured on JRC2018U samples (one core): template 29 MB in 5 s; neurons and painted domains 0.3–0.9 MB in ~2 s; a dense GAL4 line 16 MB in 5 s; an MCFO fragment 6 MB in 3.5 s.

## VFB Image Categories & Conversion Strategies

There are four distinct categories of VFB images, each requiring a different conversion approach:

---

(The standalone scripts below predate `vfb_pipeline.py` and are kept for experiments; the production pipeline does not call `convert_templates.py` or `convert_all.py`.)

### Category A: Templates with Painted Domains (Index Regions)

**What they are:** Reference brain templates (e.g., JRC2018Unisex `VFB_00101567`) that contain a segmentation label field — an integer-indexed NRRD volume where each voxel value maps to a specific anatomical region (neuropil).
Expand Down Expand Up @@ -171,21 +216,19 @@ For each VFB image:

## Output: Neuroglancer Precomputed Format

All conversion paths produce the same output structure:
`vfb_pipeline.py` writes `precomputed.zip` (see above) whose entries are:

```
output/{vfb_id}/
├── info # JSON metadata (type, data_type, scales, resolution)
├── mesh/
│ ├── info # Mesh metadata (@type: neuroglancer_legacy_mesh)
│ ├── {seg_id} # Binary mesh data per segment
│ └── {seg_id}:0 # Fragment manifest
├── segment_properties/
│ └── info # Segment labels and descriptions
└── 0/ # Scale level 0 volume chunks (for segmentation types)
└── 0-64_0-64_0-64 # Chunk files
info # JSON metadata (type image|segmentation, uint8, one scale, resolution in nm)
provenance.json # pipeline version, category, mesh source, source-file stamps
0/ # scale-0 chunks, 64^3, raw (absent for a mesh-only object with no NRRD)
mesh/info # {"@type": "neuroglancer_legacy_mesh"} (segmentation only)
mesh/1:0 # fragment manifest for segment 1
mesh/1:0:1 # the mesh
```

No `segment_properties/`: a VFB image is one object, so there is nothing to label.

## Requirements

```bash
Expand Down
2 changes: 1 addition & 1 deletion applications/pipeline/convert_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def process_image(vfb_id: str, template_id: str, category: str,
download_file(url, tmp_path)
convert_nrrd(
tmp_path, output_dir, vfb_id,
merge_segments=True, verbose=verbose,
layer_type="auto", verbose=verbose,
)
finally:
os.unlink(tmp_path)
Expand Down
Loading
Loading