V-System: Vascular Lindenmayer Systems for Synthetic Vessel Generation
V-System generates synthetic 3D vascular networks with stochastic, parametric
Lindenmayer systems (L-systems) and renders them as binary image volumes for
training and validating vessel segmentation methods.
The grammars, the turtle interpreter and the bifurcation model follow
Galarreta-Valverde’s 2012 dissertation and the SPIE 2013 paper by
Galarreta-Valverde et al.; daughter diameters
obey Murray’s law and bifurcation angles follow Zamir’s minimum-volume rule.

Pipeline
- Grammar generation (
vSystem.py): the tree rule F is expanded for a
chosen number of drawn generations into a string of turtle instructions.
- Interpretation (
analyseGrammar.py): the string is executed by a 3D turtle
that keeps a direction vector and a perpendicular vector, giving the centreline
points and diameters.
- Interpolation (
utils.py): each stem is smoothed with a cubic B-spline.
- Voxelisation (
computeVoxel.py): the network is mapped into the volume
with a single isotropic scale factor and every segment is drawn as a tapered
capsule, so calibre and bifurcation angles survive into the image, plus the
face-connected chain of voxels it passes through, so a vessel thinner than a
voxel stays unbroken.
Steps 1–3 produce the centreline, which is saved alongside the volume. The
centreline is the source of truth for the geometry and the TIFF is one
rasterisation of it, so step 4 can be repeated at any resolution without
regenerating the network.
Three optional stages shape the geometry between steps 2 and 4 without changing
what the grammar decides: a persistent random walk that bends each stem
smoothly (--tortuosity walk), collision avoidance between branches
(--avoid-collisions) and anastomosis, which joins tips into loops
(--anastomose). --family bundles them, and describe.py measures what
they change. See Geometry below.
Units
One grammar unit is one micrometre. Nothing in the code enforces this — the
generator is scale free — but every output declares it, so that a dataset cannot
be silently mis-scaled:
--d0 and --d-min are vessel diameters in micrometres;
--voxel-size is grammar units per voxel, and therefore a modality’s
physical voxel size in micrometres per voxel;
epsilon (the length-to-diameter ratio) is dimensionless, so segment lengths
follow the diameters;
- every JSON sidecar records
"units": "um".
A vessel of diameter d rendered with --fit voxel_size --voxel-size v is
d / v voxels across, so calibre in voxels scales as 1 / v and the same
centreline rendered at two voxel sizes gives two correctly scaled datasets.
Rasterising once and resampling the binary volume afterwards does not: it
destroys vessels a voxel wide. Render each modality from the centreline instead.
The 1 / v law holds down to the grid: a vessel below one voxel across is drawn
at the one-voxel connectivity floor rather than scaled, so its rendered calibre
is overstated. That is the honest rendering of an unresolvable vessel, but it
means a network must be chosen against the voxel size it will be rendered at —
see Rendering one network for several modalities below.
To work in another unit, keep the convention self-consistent — interpret --d0
and --voxel-size in the same unit — and declare it with --units mm. The flag
labels the data; it rescales nothing.
Installation
Python 3.10 or newer.
git clone https://github.com/psweens/V-System.git
cd V-System
pip install -e . # numpy and tifffile only
pip install -e ".[viz]" # plus matplotlib, for plotting
pip install -e ".[preprocess]" # plus OpenCV, for resize_volume
Usage
Generate five networks into ./output, reproducibly:
python main.py --count 5 --out ./output --seed 1
Each network is written as three files sharing the stem
Lnet_i<generations>_s<seed>:
| File |
Contents |
.tiff |
a uint8 volume of 0 and 255 whose pages are z, rows y and columns x |
.npz |
the centreline: nodes, the (4, N) array of x, y, z and diameter in grammar units with NaN column separators; edges, the (2, E) graph of column indices; node_kind and tree, per-column labels; program, the grammar string; and metadata, the sidecar record |
.json |
the seed, the unit convention and every parameter used |
Network i of a run uses seed + i, and the same seed and parameters reproduce
the same volume. The default volume is an imaging slab, fitted in x and y and
clipped in z, so vessels leave and re-enter it and a deep network renders as
several pieces; see Connectivity below for what that means and how to change
it. The centreline archive grows with the number of drawn
generations rather than with the volume — tens of kilobytes at four generations
and about seven megabytes at twelve, against 37 MB for a 512 × 512 × 140
volume whatever the network inside it. Its arrays are exact; being a zip, its
entries carry a modification time, so compare the arrays rather than the bytes.
Useful options (python main.py --help lists them all):
| Option |
Default |
Meaning |
--volume NX NY NZ |
512 512 140 |
volume shape in voxels |
--iterations MIN MAX |
4 12 |
drawn generations, drawn uniformly |
--d0 MEAN STD |
20 5 |
root diameter, grammar units, truncated at --d0-min |
--d-min |
none |
smallest drawn vessel diameter; a branch stops bifurcating below it |
--capillary-generations M |
0 |
replace a daughter that --d-min would end by a capillary tree of M symmetric generations drawn at --d-min; needs --d-min |
--capillary-runs E |
1 |
draw every capillary stem, and every stem whose daughters both end, as E consecutive stem blocks |
--epsilon MIN MAX |
4 10 |
length-to-diameter ratio of a segment |
--randmarg MIN MAX |
0.1 0.3 |
relative half-width of the segment-length distribution |
--sigma |
5 |
d_opt / sigma is the spread of the first daughter diameter |
--roll-angle |
70 |
roll of the bifurcation plane after each daughter turn, degrees |
--stem-angle |
25 |
turn between the five sub-segments of a stem, degrees |
--aneurysm-prob, --stenosis-prob |
0.02 |
per sub-segment probability of a local ×1.5 dilation or ×0.5 constriction |
--fit |
isotropic |
isotropic, voxel_size (fixed --voxel-size) or stretch (legacy per-axis fill) |
--voxel-size |
none |
grammar units per voxel for --fit voxel_size: the modality’s voxel size |
--clip-axes |
z |
axes left out of the isotropic fit and clipped, as an imaging slab would |
--grow-in-volume |
off |
confine growth to the volume’s proportions so no vessel is cut |
--no-connect |
off |
rasterise bare capsules, leaving sub-voxel vessels dotted |
--units |
um |
the unit one grammar unit stands for, recorded in the sidecar |
--family |
tree |
preset bundle of the geometry options: tree, mesh, tumour, aligned, aligned_tight, aligned_bed, capillary_bed, foam (the last five need --d-min) |
--tortuosity |
stems |
stems: five sub-segments smoothed by a B-spline; walk: a persistent random walk of the same arc length |
--persistence |
none |
persistence length of the walk in vessel diameters; required by walk |
--avoid-collisions |
off |
keep branches apart by at least --collision-margin (default 1 µm), redrawing or shortening, and count what could not be placed |
--anastomose |
off |
join --anastomosis-fraction (0.5) of the tips to partners within --anastomosis-radius (25) tip diameters, never closer kin than --anastomosis-min-separation (3) segments, by bridges routed clear of the network at --collision-margin; --anastomose-mode arteriovenous grows a second tree from the opposite face |
--guidance JSON |
none |
steer the walk towards an axis or a plane per calibre class: a list of rules, each with a bound below in d_min (null for none), a field (axis, plane or null), its axis or normal, a length G in diameters, an onset (2) and, for an axis, a sense and polarity, for a plane bank; needs --tortuosity walk |
--root-offsets JSON |
none |
move the roots from their default positions on the faces of the growth box, staying inside it: one [x, y, z] per tree in units of d_min; needs --grow-in-volume and --d-min |
--cross-connect / --no-cross-connect |
off |
after anastomosis, join capillary vessels side to side by rungs at gaps of about --rung-spacing (20) diameters, to partners within --rung-radius (8) site diameters whose chord stands at least --rung-lateral-deg (60°) off the vessel (or off --rung-axis); vessels below --rung-below (2) d_min are capillaries; needs --d-min |
--bed JSON |
none |
grow an explicit capillary bed between the tips of two feeder trees in the mesh layout instead of anastomosing them: a JSON object of bed settings (kind, spacing, girth, min_angle, reach, diameter, persistence, feeder_stop, tip_edges, stretch, density, jitter, step), the ones left out at their defaults; null turns a preset’s bed off; needs --grow-in-volume and --d-min |
--d-min and --iterations are both stopping criteria and whichever comes first
wins. --d-min is the one a modality states directly, as its smallest resolvable
calibre; with --deterministic daughters, diameters fall by exactly 2^(-1/k) a
generation and it is reached after log(d0 / d_min) / log(2^(1/k)) of them.
Under the default stochastic daughter diameters that is only an estimate, and
the two daughters of a bifurcation reach it at different depths, so the tree
terminates unevenly. Either way, raise --iterations above the estimate to let
--d-min decide. It bounds the diameter a branch is drawn at, not the
diameter after a local anomaly: a stenosis still narrows a drawn sub-segment by
--stenosis-prob’s factor of 0.5, so set --stenosis-prob 0 for a hard floor.
Connectivity
A capsule sets only the voxels whose centres it contains. A vessel thinner than
a voxel contains no centre along much of its length, so on its own it rasterises
as a dotted line and a connected tree falls apart into fragments — with the
default parameters, more than a third of the centreline is that thin and a
single tree renders as dozens of pieces. Every segment is therefore also drawn
as the chain of voxels it passes through, walked one face at a time
(Amanatides & Woo, 1987), which renders a sub-voxel vessel one voxel wide
instead of dotted. It is not a dilation: every voxel the chain sets lies within
sqrt(3)/2 of the centreline, so for a radius of 0.866 voxels or more it is
already inside the capsule and calibre is untouched. --no-connect restores the
bare capsule rasterisation.
The chain is face-connected (6-connected), not merely 26-connected. The
distinction matters downstream: a chain of voxels touching only at edges or
corners is one piece to a 26-connected label but shatters under the
six-connected flood fill, label or morphological operation most tools default
to — scipy.ndimage.label among them — and looks like a string of beads in a
viewer. Face connectivity is the weakest assumption any of them makes, so it is
the one the rasteriser guarantees.
check_connectivity.py answers the question for a given network. It reports the
components of a volume under both 6- and 26-connectivity and, for every piece
but the largest, whether that piece touches a face of the volume — a piece that
does is a branch the volume cut, a piece that does not is a real break. It also
checks a saved .npz centreline as pure geometry, independently of any volume,
where anything but one component is a defect. --generate N makes fresh
networks to check instead of reading files, passing every other option through
to the generator, and the exit status is 1 only for a break the volume boundary
does not explain:
python check_connectivity.py --generate 10 --seed 1
python check_connectivity.py output/*.npz output/*.tiff
Two ways of looking can still suggest breaks that are not there. A thin vessel
running obliquely through a stack shows up in any single slice as isolated
voxels even though it is unbroken in three dimensions, so judge connectivity
with a 3-D component count rather than slice by slice. And a rendered network
does still fall into several genuine pieces under two conditions, neither of
them a defect:
- Clipping. A branch that leaves a slab and re-enters it is two vessels in
the image, exactly as it would be in a real acquisition.
--grow-in-volume
removes this at the source: growth is confined to a box with the volume’s
proportions and a branch that would leave it is terminated along with its
subtree, so the tree takes the volume’s shape and no vessel is ever cut part
way along. On a 512 × 512 × 140 slab at twelve generations that turns 43
pieces into one while raising the vessel count, because branches that used to
grow out of the slab and be discarded now stay inside it. --clip-axes is
unused when it is set, and it is off by default so existing output is
unchanged. A volume with equal axes needs none of this: the grammar grows a
roughly cubical tree, so --volume 512 512 512 --clip-axes none is one
connected piece at the same calibre. The default volume
is such a slab — fitted in x and y, clipped in z — so this is what the
quickstart command produces: its deepest network, at twelve generations,
renders as 48 pieces, every one of them touching the top or bottom face of
the slab, with 95% of the vessel voxels in the largest. --clip-axes and
the volume shape control this. With --clip-axes none each of the five
quickstart networks renders as a single connected component, at the cost of
scaling the whole tree into 140 slices and so shrinking every vessel.
- Resolution. A vessel the modality cannot resolve is still drawn, one voxel
wide. To stop generating them instead, set
--d-min to the smallest
resolvable calibre.
--clip-axes is read by the isotropic fit only; voxel_size and stretch
ignore it. The command line clips z by default because the default volume is an
imaging slab, whereas the library functions computeVoxel.process_network and
fit_to_volume default to clipping nothing, so that a direct call fits the whole
network unless told otherwise. Axes may be named or indexed in either place, and
an axis that is neither raises.
From Python:
from main import generate_network, save_network
volume, program, nodes = generate_network(
niter=8, d0=20.0, properties={"epsilon": 7.0, "randmarg": 0.2}, tVol=(512, 512, 140))
save_network("Lnet.npz", nodes, program=program)
volume is a uint8 array of 0 and 1 indexed (x, y, z); program is the grammar
string; nodes is the (4, N) centreline of x, y, z and diameter with NaN columns
separating branches. nodes is in grammar units and independent of tVol, fit
and voxel_size, so it is the artefact worth keeping.
Anti-aliased rendering
A capsule sets the voxels whose centres it contains, and at small calibres how
many it contains depends on where its centre line falls among them. A vessel
two voxels across is one voxel wide where its centre line passes near a voxel
centre and 2 × 2 where it passes between four, so a straight vessel at an
oblique angle renders beaded, and an axis-aligned one has an area anywhere
from 36 % below to 59 % above π r², depending on its sub-voxel offset. A
segmentation model trained on such masks learns the beads. The library
functions take antialias=True to draw each vessel with the cross-section
its geometry asks for instead:
from computeVoxel import process_network, rasterise_segments
volume = process_network(nodes, shape, fit="voxel_size", voxel_size=2.0, antialias=True)
volume = rasterise_segments(points, radii, shape, connect=True, antialias=True)
Every voxel at least half a voxel inside a capsule is drawn. Across each
vessel, in every lattice plane perpendicular to its dominant axis, the voxels
near the surface then get a count: the plane’s share of the capsule’s volume,
from a coverage ramp one voxel wide, rounded by error diffusion along the
vessel (half of each plane’s rounding remainder carried into the next). The
count is filled with the voxels nearest the surface from inside out, chain
voxels first. In a vessel below 2.45 voxels across the count never completes
a 2 × 2 × 2 cube. A voxel outside a capsule is drawn only where it cannot
touch a vessel more than √3 voxels away. That distance is measured from each
capsule’s axis less its larger radius, so it holds along steep tapers too.
The face-connected chain is unioned in as by default (connect), and a
voxel enclosed by six drawn neighbours is set.
The full rule is in computeVoxel._rasterise_antialiased.
Smoothing the capsules’ coverage and thresholding it, the obvious
band-limit-then-sample rule, was measured and does not help. On a straight
vessel it still sets the voxel centres inside a smooth tube, so it beads
exactly as the default does: at two voxels across, the CV along the tube is
0.101 against 0.103, and on the foam network below it gives 3 to 9 short
necks per mm, depending on the threshold.
Measured on straight tubes in 20 directions (axis-aligned, face and body
diagonals, 12 random) at 3 random sub-voxel offsets each. The area of a tube
is the number of its voxels in each lattice plane across its dominant axis k,
times |u_k|, averaged over the planes of its central part; its CV is that
area’s coefficient of variation along the tube. Short necks are counted on
the oblique tubes and on tortuous ones, at 2 µm voxels (a thin voxel belongs
to no all-foreground 2 × 2 × 2 cube; a neck is a run of thin voxels touching
two or more pieces of the 2 × 2 × 2 opening, short if it has at most 5
voxels):
| diameter (voxels) |
worst tube’s area error, default / anti-aliased |
mean CV along the tube |
short necks per mm, oblique / tortuous |
| 1.5 |
60 % / 13 % |
0.192 / 0.140 |
0 / – |
| 2 |
55 % / 6.5 % |
0.105 / 0.078 |
0.80 → 0 / 4.06 → 0 |
| 2.2 (tortuous only) |
– |
– |
– / 12.5 → 0 |
| 2.5 |
22 % / 3.0 % |
0.092 / 0.041 |
0 / 0 |
| 3 |
13 % / 2.0 % |
0.056 / 0.020 |
0 / 0 |
| 4 |
13 % / 3.5 % |
0.039 / 0.019 |
0 / 0 |
| 8 |
4.5 % / 0.5 % |
0.014 / 0.005 |
0 / 0 |
The mean area over the tubes of a diameter is within 1.5 % of π r² either
way (the default’s errors cancel out across offsets). A foam network grown
at --d-min 4 and rendered at 2 µm in 256³ (98 % of its centre line two
voxels across) goes from 4.92 short necks per mm to none. Its volume is
within 0.1 % of the capsules’ union, its 26-components are unchanged, it has
2 face-connected pieces instead of 5, and it renders in 0.6 to 0.9 times
the default’s time. A capillary_bed network goes from 0.95 to none, also
with its components unchanged.
What the mode guarantees, and where it stops:
- Calibre. Every straight tube two voxels across or more keeps its area
within 6.5 % at every orientation and offset measured. The per-plane count
is an integer, though. A vessel whose planes each ask for n + ½ voxels must
either alternate between n and n + 1 or be off by half a voxel. Carrying half
the remainder settles a plane that asks for n + 0.2 on n, at a bias of at
most a quarter voxel per plane, and leaves the alternation for targets near
n + ½. That is why the worst tube’s CV at two voxels across stays 0.144 while
the mean falls.
- Topology. A voxel outside the capsules is drawn only where it cannot
touch another capsule more than √3 voxels away. Two vessels that far apart
surface to surface, which includes the 2-voxel separation in the
acceptance tests, therefore touch only where the default has them touch.
Vessels √3 voxels across or more never touch at that distance; thinner ones
touch only through their chains, which reach past their surfaces as by
default. Rendered whole, the fixture networks have the same 26-components as by
default. Where a volume face cuts vessels, the pieces touching that face
can differ: a vessel running just outside a slab shows its edge in the face
plane, and the default may break that edge in two where the mode keeps it
whole, or the mode may show a one-voxel piece the default leaves out. The
pieces that touch no face are as many as by default (measured on 48
clipped renders of the fixtures).
- Necks. Below 2.45 voxels across, a smooth vessel holds no 2 × 2 × 2
cube. One can appear only where a voxel enclosed at a sharp kink is filled,
or where the vessel meets another polyline. So a smooth thin vessel has no
opening to pinch and no necks of any length (tortuous two-voxel
vessels: 38.8 per mm of any length by default, none anti-aliased). Above
that, a vessel is too thin for an unbroken 2 × 2 × 2 opening (one costs about
four voxels per unit length, 27 % over π r² at two voxels across) yet thick
enough to hold cubes. Around 2.6 voxels it keeps longer necks, all over 5
voxels: 9.6 per mm of any length against the default’s 4.6 on tortuous
vessels, and 4.6 against 17.9 at 2.45. Short necks are none at every
diameter measured.
- Order and determinism. The result involves no random numbers and does
not depend on the order of the polylines. It does depend on the order of the
points within a polyline, since the counts are carried along it: reversing
every polyline of a foam network changes about 4 % of its voxels.
- Cost. Segments more than 8 voxels beyond their reach outside the volume
are skipped, and only the voxels near the volume are examined. So a window
of a large network, or a long segment through a small volume, costs what
the window holds: 0.1 to 0.4 times the default’s time on 64³ and 128³
windows of the foam network. Such a window matches the crop of the whole
rendering except within the run-in of a vessel cut by its margin: none of
the fixture windows tested differs, 0.4 % of a foam window does.
- On whole networks at 2 µm it takes 0.4 to 1.3 times the default’s time.
- Thick vessels sampled every fraction of a voxel cost 1.7 to 2.2 times.
- Renders of 28 µm vessels cost about 2 times at 1 µm and 3 times at
0.5 µm.
- Besides the volume, it needs 35 to 50 MB on 256³ windows at 2 µm,
where the default needs the volume alone. A single polyline of 50,000
points needs about 0.2 GB.
The command line does not expose the mode; vsystem writes what 3.9 wrote.
antialias=False is the default, and with it both functions draw what 3.9
drew, bit for bit.
Rendering one network for several modalities
Because the mapping from grammar units to voxels happens at rasterisation time, a
saved centreline can be rendered at each modality’s own voxel size. The field of
view is shape * voxel_size, so shape has to follow the voxel size to keep it
fixed; deriving it from the network’s own extent does that:
import numpy as np
from computeVoxel import process_network
from main import load_network
# written by: python main.py --count 1 --seed 1 --iterations 8 8 --out output
network = load_network("output/Lnet_i8_s1.npz")
nodes = network["nodes"]
extent = np.nanmax(nodes[:3], axis=1) - np.nanmin(nodes[:3], axis=1) # micrometres
for modality, voxel_size in [("two-photon", 1.0), ("light-sheet", 2.0)]:
shape = np.ceil(extent / voxel_size).astype(int) + 8 # same field of view, finer grid
volume = process_network(nodes, shape, fit="voxel_size", voxel_size=voxel_size)
Only the sampling changes between the two, so each result carries the vessel
calibre distribution at that modality’s resolution. A 20 µm vessel is 20 voxels
across at 1 µm and 10 voxels across at 2 µm.
Holding shape fixed instead would render the same network into two different
fields of view. That is the mistake to avoid: at 20 µm/voxel a
512 × 512 × 140 volume covers 10 240 × 10 240 × 2800 µm, and the network above
occupies 37 × 33 × 21 of its 36.7 million voxels.
One centreline serves a modality only while that modality can resolve it.
Every vessel thinner than a voxel is drawn at the one-voxel connectivity floor,
so once most of the network is sub-voxel its calibre distribution collapses to a
spike at 1 voxel instead of matching anything. Check before trusting a render:
d = nodes[3][~np.isnan(nodes[3])] / voxel_size # diameters in voxels
print(np.percentile(d, [50, 90]), (d < 1.0).mean()) # ... and the sub-voxel fraction
For a modality whose voxel size approaches the network’s finest vessels,
generate a network for it — a larger --d0, or --d-min set to its smallest
resolvable calibre — rather than rendering an existing one more coarsely.
To target a fixed acquisition geometry instead, a 512 × 512 × 140 slab at
2 µm say, choose --d0, --epsilon and --iterations (or --d-min) so that
the network spans the field of view shape * voxel_size: under voxel_size the
network is centred and clipped rather than scaled to fit.
Geometry
The grammar fixes the tree’s topology, calibres, segment lengths and
bifurcation angles. What a segmentation model trained on these volumes also
learns is the local geometry — how smoothly vessels curve, whether they cross,
how often they end — and the plain grammar has three properties real
vasculature lacks: stems are zig-zags of five straight pieces, branches pass
through one another, and every terminal branch ends in a free tip. Three
opt-in stages address them. None is used unless asked for, and the default
command line writes the same nodes, program and TIFF as before for a given
seed (tests/fixtures pins this).
The graph in the archive
Every archive carries edges, a (2, E) array of column indices into nodes:
one edge between consecutive points of a polyline and, because a daughter
polyline starts on a bitwise copy of its parent’s branch point, one shared
vertex wherever polylines meet. Coincident columns (within graph.DEFAULT_TOL,
10⁻⁶ µm) are one vertex, represented by the lowest column index. node_kind
labels every column interior (degree 2), junction (degree 3 or more) or tip
(degree 1; the root counts as a tip), and tree labels the tree a column
belongs to (0, 1) or marks it as an anastomosis bridge (2). graph.py rebuilds
all of this from nodes alone — edges_from_nodes, node_kind, betti,
segments — so an archive written before this version gains a graph when read
with load_network. The rasteriser ignores the graph.
Smooth tortuosity: --tortuosity walk --persistence P
A stem is normally the grammar’s five straight sub-segments with alternating
turns of --stem-angle, smoothed by an approximating B-spline; its arc/chord
ratio is fixed by the stem angle and does not vary. With walk, the path of
each stem is a persistent random walk on the unit tangent: at every step of
length h (a sub-segment divided into 2^--subdivisions steps) the tangent is
rotated by an angle drawn from N(0, √(h / l_p)) about a random perpendicular
axis, with persistence length l_p = P × the local diameter. Total arc length
equals the grammar’s, the daughters leave from where the walk actually ends
and at the grammar’s angles relative to the walk’s final direction, and the
walk draws from its own random stream seeded from the run seed, so the
grammar’s draws are untouched. Lower P is more tortuous; docs/geometry
tabulates arc/chord and curvature against P. Under --grow-in-volume a step
that would leave the box is redrawn up to a budget, turning more sharply each
time, then the branch terminates and the sidecar counts it.
The rotation rule gives a tangent autocorrelation of exp(−s / 2 l_p) in three
dimensions, so P is a shape parameter calibrated against measured arc/chord
ratios rather than a literal persistence length; tortuosity.py documents the
factor of two.
Collision avoidance: --avoid-collisions
Every accepted point is stored in a spatial index (--collision-index grid or
kdtree; auto is the grid hash, which was faster than the k-d tree at both
10⁵ and 10⁶ points: 1.3 s against 1.8 s, and 16 s against 60 s, for the
insert-and-query mix of python spatial.py --benchmark). A proposed point
collides when it lies closer than the sum of the two radii plus
--collision-margin to a stored point that is not on its own stem within an
arc-length window, nor on its parent or sibling close to their common junction
(the two distances to the junction, measured along the vessels, summing to
less than 1.7 times the collision threshold, which is how far tubes meeting at
Zamir’s angles overlap; collisions.py derives the bound). A colliding walk step is redrawn up to
--collision-attempts times, each redraw turning more sharply than the last
(the rotation’s spread grows by one multiple of its base per attempt) so the
walk steers away from what it hit rather than repeating almost the same step;
a spline stem is shortened to its longest clear prefix of control points; a
branch that cannot be placed terminates. The
sidecar counts redraws, shortened stems and terminations. Terminated branches
are new tips, so avoidance raises tip density unless anastomosis absorbs them.
The check is on centreline points, so keep the margin at or above the point
spacing of the finest vessels. describe.py verifies the result independently
as the minimum surface clearance over the whole network.
Anastomosis: --anastomose
After growth, a seeded random fraction of the tips (--anastomosis-fraction)
each search within --anastomosis-radius tip diameters for a partner: another
tip first, otherwise an interior point of a segment that is not their own,
nearest first, never a junction, a root, or a point inside a junction’s
overlap zone, and never closer kin than --anastomosis-min-separation
segments along the tree (default 3, which rules out the parent stem and the
sister stem, two segments away). Without that rule the commonest bridge joins
a tip to its sister’s tip, usually the nearest, closing the two sister stems
into a small triangle. The nearest partner beyond the sister lies about
2 ε tip diameters away (8 at ε = 4, 14 at ε = 7, 20 at ε = 10), which is why
the default radius is 25; a radius in multiples of the segment length would
be self-scaling and is an open question.
A branch that avoidance or the growth box terminated within a step or two of
its junction leaves a stub whose tip sits inside that zone; such stubs are
neither sources nor partners, and are counted. Partners are sought ahead of the tip, within 120° of its
direction, as a sprouting tip fuses with what it grows towards rather than
doubling back. A bridge of diameter min(d_tip, d_partner) is traced by the
pinned form of the walk: it leaves the tip along the tip’s direction, arrives
into a partner tip along that vessel’s direction (so the two tips become one
continuous vessel) or into the side of a vessel along the chord, and carries
the walk’s curvature at --persistence diameters, or at 8 when the stems are
not walked, so that it is a vessel rather than a straight strut. Every
bridge is routed clear of the network at --collision-margin, whether or not
the tree was grown with --avoid-collisions, redrawn on a collision and
abandoned (and counted) when no candidate clears. It is appended as a new
polyline whose end columns copy the two joined points, so the graph gains a
cycle (β₁ = E − V + C rises by one) or joins two components. --anastomose-mode arteriovenous grows a second tree from the
opposite face of the volume, heading back towards the first, and ranks partners
in the other tree first — the arteriole → capillary → venule design of a
capillary bed; it works best with --grow-in-volume, which the mesh preset
turns on. The second root is placed at the nearest spot on its face that is
clear of the first tree, and both root positions are recorded in the sidecar. Tips that found no partner, or whose every candidate bridge collided,
are counted. The rasteriser draws polylines independently, so cycles need no
special handling.
Directional guidance: --guidance and --root-offsets
The walk can be steered. Before every step’s random turn, the heading h is
turned deterministically towards a target t by
ω = min(θ, r sin θ cos θ) for a nematic axis or a plane,
ω = min(θ, r sin θ) for a polar axis,
where θ is the angle from h to t and r = min(1, step / (G d)) with G the
guidance length in local diameters d. The drift draws nothing: with guidance
off the walk draws exactly what it drew before, and with guidance on it still
draws two numbers per attempt, each redraw turning about the steered frame.
The target depends on the field of the rule that governs the stem: for a
nematic axis a it is the nearer of a and −a; for a polar axis it is s a with
a sense s fixed per tree, +1 (fixed), the sign of the tree’s root heading
along a (root), or the sign along a of the partner tree’s root offset
minus this tree’s (partner, from the --root-offsets entries, so it
points towards the partner root when the axis lies in the roots’ faces, as
in aligned); for a plane with normal n it is the
projection of h onto the plane, undefined when h lies along n. A plane rule
may also bank: after the turn the frame’s perpendicular is turned towards
the normal by the same rule, so that the branching turns the grammar writes
about the perpendicular stay in the plane despite the roll of 70° before
every daughter.
The rules are a JSON list, each governing the stems whose diameter at the
first move lies below below × d_min and above the bound of the rule before
it, so the rules partition the calibres from the finest upwards; the last
rule may have below null and a rule with field null leaves its class
unguided. A stem is not steered while the arc walked along it is below
onset × its diameter, so that daughters clear their sisters before being
pulled into line; the rule is chosen once per walked polyline, from the
diameter of its first move, and held, so a local anomaly does not switch
class part way along. Bare moves and spline stems are never steered, so
--guidance needs --tortuosity walk, and a finite bound needs --d-min.
--root-offsets adds one vector per tree, in units of d_min, to the roots’
default positions on the faces of the growth box before the second root is
cleared of the first tree; a component along a face’s normal moves its root
into the box. It needs --grow-in-volume and --d-min, and a root moved
outside the box is refused. Every refusal fires before the network it
concerns is written; a malformed rule or offset is refused before anything
is written, but without --fit voxel_size the box comes from each grown
tree, so a root outside it is refused when that network grows, after the
earlier networks of a --count run have been written.
The law. The walk diffuses the heading with D = 1 / (4 P d) per unit length
and the drift descends Φ = −cos²θ / 2 (nematic), −cos θ (polar) or
sin²β / 2 (plane, β the angle out of the plane), so on a stem much longer
than G d the heading settles into a stationary law: Watson exp(K cos²θ) with
K = 2P / G for a nematic axis, Fisher exp(κ cos θ) with κ = 4P / G for a
polar axis, and the girdle exp(−K sin²β) with K = 2P / G for a plane; the
small-angle rms angles are √(G / 2P) to an axis and √(G / 4P) out of a plane.
G follows from a target K. The steps are finite, so the measured
concentration carries a discretisation bias of order step / (G d):
tests/test_guidance.py grows one stem of 2000 sub-segments at P 10 and
step 0.175 d and measures, over seeds 1 to 4 at G 3, ⟨cos²θ⟩ = 0.821,
⟨cos θ⟩ = 0.922 and ⟨sin²β⟩ = 0.078 against 0.830, 0.925 and 0.0747 from
the laws: the laws’ moments at 0.96 of their concentrations, at
step / (G d) = 0.058. The nematic law is
Watson, not Fisher-axial: Fisher-axial is exp(K |cos θ|), whose ⟨|cos θ|⟩ is
1 / (1 − e^−K) − 1 / K, which approaches the polar law’s ⟨cos θ⟩ at κ = K,
coth K − 1 / K, as K grows, the two differing by the polar law’s backward
mass.
Every run counts its steering: guided_steps, guidance_onset_steps,
unguided_steps and guidance_undefined_steps partition the walk’s steps,
guidance_sense_flips counts the changes of the nearer end of a nematic axis
between consecutive guided steps of one polyline, and guidance_bank_steps
counts bank rotations. Guidance costs about 90 µs per guided step on an
Intel Xeon Gold 5220 workstation (Linux, Python 3.12, numpy 2.5), and a bank
about 45 µs more (tests/test_topology_benchmark.py): that doubles the cost
of a bare walk step (89 µs there), but adds about 7% to a network grown with
avoidance and anastomosis, the aligned preset taking 1.38 ms per point at
R 8 against 1.29 ms with guidance None (seeds 1 to 3, 87 thousand points in
all either way).
Every network grown from 3.5 records its frame in the sidecar and in the
archive’s metadata: the kind of the field rule with the smallest bound
(none, axis or plane), its axis or normal, the sense and, for a polar
rule, the +1 or −1 of each tree, every rule normalised, the growth frame
(grow_direction, grow_perpendicular) and an origin (the centre of the
growth box, else the first root), all in the coordinates and unit of nodes.
With guidance off the kind is none and the rules are empty. frames.py
places networks by their frame (below), and describe.py measures against
it.
Capillary fill: --capillary-generations and --capillary-runs
A grammar tree ends every branch once its diameter falls below d_min, so it
keeps only a small, fixed share of its length and volume in its finest
calibres. The fill extends each such branch into a capillary bed of its own.
With --capillary-generations M (M > 0, which needs --d-min), a daughter
that d_min would end becomes a capillary tree instead: M generations of
symmetric bifurcations, every stem drawn at d_min, turned by the Zamir angle
of a bifurcation into equal daughters (acos 2^(−1/3), about 37.5°, the angle
the grammar itself would draw for them) and rolled by the roll angle, so that
the substitution draws nothing for its turns. The iteration count is checked
first, so a daughter that --iterations ends stays ended, and the M capillary
generations do not count against it; a root thinner than d_min is still
drawn as nothing. With --capillary-runs E, every capillary stem, and every
stem whose two daughters both end, is drawn as E consecutive stem blocks,
each with its own length, mirror and anomaly draws, in one pair of braces, so
the finest vessels run E times as far before they branch or stop. Every
drawn diameter stays at or above d_min, apart from the middle of a stenosis.
With both options at their defaults (0 and 1) the grammar is the released one,
string for string and draw for draw (the tests compare it with the 3.5
modules); the fill draws only on its own path: each capillary stem block and
each extra run block takes the six random.random and five
np.random.uniform calls of one stem, and nothing else. On the command line
the fill applies only where --d-min ends a branch before --iterations
does, so give an iteration range above the depth at which d_min is reached.
With stochastic parameters, randomness margin and anomalies off and
ε 7, the length and volume shares of a filled program below 2 d_min follow a
closed form for symmetric Murray trees, which the tests check to 1e-9.
Cross-connections: --cross-connect
Anastomosis closes a tree into loops only at its tips; a capillary bed is a
mesh whose capillaries also meet side to side. --cross-connect adds such
connections (“rungs”) after anastomosis, on a random stream of their own
(tag 5), so that turning them on changes nothing drawn before them. The
vessels are the segments of the trees between branch points and tips; a
vessel whose median vertex diameter lies below --rung-below (2) × d_min is
a capillary. Along each capillary, sites are drawn as a Poisson process with
mean gap --rung-spacing (20, at least 1) vessel diameters and snapped to a
vertex, then taken in random order. Each site is joined to the nearest
capillary point of another vessel within --rung-radius (8) site diameters
that is not touching it, not on its own vessel (or, with
--rung-min-separation 3, not on a vessel meeting it either), not near a
junction, and whose chord stands at least --rung-lateral-deg (60°) off the
site’s vessel tangent, or off --rung-axis when one is given. The rung has
the smaller of the two diameters, is traced along the chord by the walk of
an anastomosis bridge, keeps --collision-margin from the network and the
rungs before it, and is redrawn up to --collision-attempts times. It joins
both vessels at new junctions with bitwise shared end points, carries the
bridge label, and is listed under rungs in the return, the sidecar (a
count) and the library metadata; no existing column moves. Every site has
exactly one outcome: rung_sites = rung_sites_near_junction +
rung_sites_consumed + rung_no_partner + rung_collision_failed +
rung_bridges, with rung_bridges_cross_tree, rung_kin_skipped,
rung_angle_skipped and rung_bridge_redraws beside them, appended to the
counters. With --cross-connect off no generator is created and every
counter stays at zero.
Explicit capillary bed: --bed
Anastomosis, the fill and the rungs make a capillary bed out of the trees’
own branches. --bed JSON builds one explicitly instead: two feeder trees
grow in the mesh layout, from opposite faces of the growth box, with their
grammar stopping below feeder_stop × d_min, and a bed of vessels
diameter × d_min across is built in the box and joined to their tips. The
construction is a greedy degree-3 graph with a girth bound, after Smith
2019’s organising requirements (not Smith’s Voronoi construction): a nearly
isotropic, connected, space-filling capillary mesh whose junctions mostly
join three vessels and whose tissue domains share one characteristic size
(Smith, Doyeux, Berg, Peyrounette, Haft-Javaherian, Larue, Slater, Lauwers,
Blinder, Tsai, Kleinfeld, Schaffer, Nishimura, Davit and Lorthois, Brain
capillary networks across species: a few simple organizational requirements
are sufficient to reproduce both structure and function, Frontiers in
Physiology 10:233 (2019),
DOI 10.3389/fphys.2019.00233).
The settings are a JSON object whose keys left out take their defaults,
given in brackets below, lengths in d_min unless stated; --bed null turns
a preset’s bed off. bed.py states every rule, draw and law in its
docstring.
Seeds. Seeds are placed by hard-core random sequential addition, one
proposal at a time, uniformly in the growth box inset by half a bed
diameter d. A proposal is refused when it lies within a feeder column’s
vertex radius plus d / 2 plus --collision-margin of that column, and
otherwise when it lies within h = spacing (7.5) of a seed already placed;
the placement stops at the target count N_t = ⌊density (0.5) × V / h³⌋,
V the volume of the inset box, which is known before anything is drawn. A
placement that has considered ⌈64 V / h³⌉ proposals short of N_t is refused
(bed.SeedsNotPlaced); nothing is shrunk. With stretch s above 1 (1, at
most 4), distances between seeds are taken with their component along the
growth direction divided by s, so that seeds and candidate edges stand up
to s times further apart along it, V is divided by s, and the network’s
frame is recorded with kind axis along that direction (nematic, with no
rules); at s = 1 the frame is that of an unguided pair, of kind none.
Tips and candidates. A feeder tip is a vertex of degree one other than
a root. A tip inside the overlap zone of a junction of its own polyline is a
stub, as in anastomosis, and takes no edge; every other tip is eligible,
whatever its calibre. Every pair of seeds, and every pair of a seed and an
eligible tip, closer than reach (2.5) × h is a candidate edge; two tips
never are, since that would be an anastomosis. The candidates form one list,
taken shortest first with jitter: in increasing order of the chord × (1 +
jitter (0.25) × u), u one uniform draw per pair.
The greedy pass. A candidate becomes an edge unless it fails one of four
rules, and is counted under the first it fails, in this order: the degree
cap (three bed edges at a seed, tip_edges (2) at a tip, whose feeder stem
makes it three); the angle (the edge would make less than min_angle (60°)
with an edge already at either end, or at a tip with the feeder’s direction
into its vessel); the girth (the ends are already joined within girth − 2
edges, so the edge would close a cycle shorter than girth (8, at most 16),
counted in edges of the bed together with the feeders, each feeder path
between junctions and tips one edge); and the clearance (two bed edges
meeting at an end at less than 72.06°, a chord passing within d +
--collision-margin of a bed chord it shares no end with, or a point of the
chord, sampled every step (0.5) bed diameters, colliding with a feeder).
Two straight chords meeting below 2 asin(1 / 1.7) = 72.06° overlap beyond
the junction excuse of collisions.py, so the smallest angle between two
bed edges is in effect 72.06° at min_angle 60, and the candidates refused
between the two count as clearance, in bed_refused_clearance_at_end; at a
tip the feeder is a curved vessel, not a chord, and the angle against it is
min_angle’s. Seeds are not obstacles to chords: a seed that an accepted
chord passes close to may be left with no edge that clears it, and is
pruned.
Pruning and the walk. Every seed with at most one edge is removed with
its edge until none is left (dead ends), then every component that holds no
feeder tip (islands). Tips are never removed, so a bed that reaches one tree
only is kept. What remains is cut into chains, each running through seeds of
degree two between vertices of other degree or tips, and each chain is
walked as one vessel: one tortuosity.bridge_path per edge, the pinned walk
of an anastomosis bridge, at a persistence of persistence (8) bed
diameters and a step of step bed diameters, through each interior seed
along the direction from the seed before it to the seed after it, and
leaving and reaching the chain’s ends along the chord. A walk is checked
against the feeders, the chains placed before it, the chords of those not
yet placed and itself, and redrawn up to --collision-attempts times; when
every attempt collides, the straight chain the greedy pass checked is placed
instead (a chord), and when that collides too the chain is dropped, its
edges removed and the bed pruned again. The check is the rule of
describe.clearance, as the rungs apply it, so that a bed that passes it
passes describe.py’s clearance; a chain that returns to its junction (a
lasso) is written from its middle seed, so that its closing points are
excused at the junction. Walked chains are not confined to the growth box,
as bridges and rungs are not.
Attachment and records. The feeders’ columns are kept as they are, and
each placed chain is appended after a NaN separator, d across and labelled 2
in tree, as bridges and rungs are, with its end and seed columns written
from the stored coordinates, so that the graph rebuilt from coordinates
joins it bitwise to the feeder tips and to the other chains; a tip with k
bed edges ends with degree 1 + k. bridges in the return, the sidecar and
the library index stays anastomose’s, empty (0) for a bed, and the sidecar’s
bridge_persistence stays that of anastomosis bridges: the bed’s
persistence, like each of its settings, is in the shaping key bed, which
the sidecar, the archive’s metadata and a library member’s kwargs record
normalised, all thirteen values whichever were given. No return, describe or
index key is added.
Draws. The feeders’ two programs, F(niter, d0, feeder_stop (2) ×
d_min), are the only draws from the global generators. The bed draws on
sub-streams of its own, numpy.random.default_rng([seed, 7, k]): k = 1 the
proposals, k = 2 the jitter and k = 3 the walks, each created only when it
draws. Tag 7 is bed.RNG_TAG, kept in bed.py as join’s 3 and the
library’s 4 are kept in theirs, so main.RNG_STREAMS is unchanged; the
sidecar of a run with a bed records "bed": [seed, 7] under rng_streams,
and no other sidecar does. With the feeders fixed, changing the bed’s
persistence or the walk’s redraws (bed.build’s attempts) leaves the
seeds and the edges of the greedy pass as they were, and changing the
jitter or the step leaves the seeds. --collision-attempts also sets the
redraws of the feeders’ collision avoidance, which foam turns on, so
changing it changes the feeders, and with them the seeds and the edges.
Every distance and dot product the seeds, the candidates and the greedy
pass decide on is computed elementwise
(np.linalg.norm(..., axis=1), and products summed in order), never through
@, np.dot or a one-dimensional np.linalg.norm, whose last bit depends
on the BLAS kernel, so the seeds, the candidates and the greedy pass of a
bed alone are the same on every kernel; the walks and the greedy pass’s
test against the feeders go through bridge_path, which depends on the
kernel as every walked vessel does.
Refusals. bed.parse_settings refuses an unknown key, a kind other
than foam, a spacing, diameter or persistence that is not positive,
a reach not above 1, a girth that is not a whole number in [3, 16], a
min_angle outside [0, 120], a tip_edges other than 1 or 2, a
feeder_stop below 1, a stretch outside [1, 4], a density outside
(0, 0.6], a negative jitter and a step below 0.1; bed.check_settings
refuses a spacing that does not exceed the diameter plus the margin, at
which seeds would touch. With a bed, grow_network and the command line
also refuse anastomosis, --cross-connect, a capillary fill, --guidance,
a run without --grow-in-volume or --d-min, a negative seed (the bed’s
streams take none; grow_network also refuses a missing one) and a
collision margin that is not finite and at least 0, all before anything is
drawn or written. A root diameter below feeder_stop × d_min, which would
grow feeders without a tip, is refused when it is sampled. Under
--fit voxel_size the box is known, so a --voxel-size that is not
positive and finite, a box that holds no seed (main.BedBoxTooSmall, a
ValueError beside RootOutsideBox) and a root offset outside the box are
refused before the feeders’ grammar draws; under the other fits (isotropic
or stretch) the box is the first feeder’s, so the last two are refused
once the grammar has drawn, after the earlier networks of a --count run
have been written. bed.SeedsNotPlaced comes after the seeds have drawn.
On the command line
the refusals that depend on a network’s sampled root or grown feeders (a
root below feeder_stop × d_min, a box too small or an offset outside it
under the other fits, and bed.SeedsNotPlaced) exit naming the seed, and
the others exit before anything is written; with --generate,
check_connectivity.py skips a seed whose root lies below feeder_stop ×
d_min, as it skips one below d_min.
Counters. Twenty-nine counters are appended to the events after the
rung counters, all zero without a bed. bed_proposals =
bed_proposals_on_feeders + bed_proposals_overlapping + bed_seeds, and
bed_seeds is N_t. bed_tips counts the feeder vertices of degree one
other than roots, bed_tips_inside_junction the stubs among them.
bed_candidates = bed_refused_degree + bed_refused_angle +
bed_refused_girth + bed_refused_clearance + bed_edges, bed_edges
being the edges the greedy pass accepted; bed_candidates_tip counts the
candidates with a tip and bed_refused_clearance_at_end the clearance
refusals at a shared end. bed_edges = the kept edges +
bed_edges_dead_end + bed_edges_island + bed_edges_dropped, and
bed_seeds = the kept seeds + bed_seeds_dead_end + bed_seeds_island.
bed_segments, the chains whose walk was attempted, =
bed_segments_walked + bed_segments_chord + bed_segments_dropped;
bed_segments_removed counts placed chains that the pruning after a later
drop removed, and bed_walk_redraws is at most --collision-attempts per
chain. bed_tips_attached counts the eligible
tips with a kept edge and bed_tip_edges their kept edges; bed_components
counts the components of the kept bed and bed_components_one_tree those
whose tips all belong to one tree.
The girth bounds cycles in edges of the bed graph. describe.py counts
loops in segments, and a chain merges its seeds of degree two into one
segment, so loops shorter than the girth in segments do occur: in foam
networks at R 4, 8 and 16 (seeds 1 to 3 pooled), 71%, 43% and 28% of the
loops through a segment are shorter than 8 segments (the shortest has 3),
while no cycle of a bed is shorter than 8 edges. A pair whose feeders have
few eligible tips may stay unjoined: when no kept component reaches both
trees, as bed_components_one_tree shows, check_connectivity.py reports
the network as two components. Over these nine networks, 513 of the 535
eligible tips (96%) attach, 432 of them by two bed edges, and the bed joins
both trees in 8 of them. At R 4, 8 and 16 (means over the seeds) their
bed’s capillary segments have a median length of 11.6, 10.1 and 9.8 d_min
(10th to 90th percentiles 8.3 to 30.7, 8.2 to 22.9 and 8.1 to 20.6 d_min,
coefficients of variation 0.64, 0.55 and 0.50), the mean distance from
tissue in the growth box to the nearest vessel wall is 3.37, 3.08 and
2.98 d_min (3.61, 3.26 and 3.15 d_min to the bed’s vessels alone), and the
median smallest, middle and largest angles at junctions of three vessels
are 83°, 107° and 139° at R 4, 84°, 107° and 138° at R 8 and 85°, 107° and
138° at R 16 (tests/test_topology_benchmark.py).
Fibre beds: "kind": "fibre"
A bed of kind fibre is made of capillaries that run nearly parallel to
one axis a, with short cross-connections between neighbours; its density
across a, its alignment and its cross-connections are set independently,
so alignment costs no density. Its keys, bed.FIBRE_SETTING_KEYS, are
lengths in d_min unless stated, and every default is provisional except
axis and layout: spacing h (5), the lanes’ hard core across a;
density (0.5), ρ h², in (0, 0.6]; girth (8), min_angle (60),
reach (2, the longest tip edge in spacings), diameter d (1),
persistence (16), feeder_stop (2), tip_edges (2), jitter (0.25)
and step (0.5), as foam’s; axis (null: the frame’s axis, else its
growth direction); knot ℓ (4), the axial spacing of a lane’s knots;
sway σ (1), the standard deviation of each transverse knot offset;
link_spacing λ (20), the planned mean axial spacing of cross-connection
ends along one capillary, null for none; link_reach (1.75 spacings);
run, the mean axial distance between lane breaks, null for unbroken
lanes (it needs link_spacing: without links a broken lane peels away
entirely); layout, pair or sheets; and, for the sheets layout,
unit (60) and sheet_length (2). A key of the other kind is refused,
stretch with fibre and knot with foam, and foam’s settings are 3.7’s
byte for byte.
The rules (F0-F8 of bed.py’s docstring): N = ⌊density A / h²⌋ lane points,
A the inset box’s area projected along a, are placed by a two-dimensional
hard core in the plane through the box centre across a, each lane its line
clipped to the box; a lane carries a knot on each face it meets and
interior knots every ℓ from a random phase, each offset across a by a
Gaussian of σ per component cut radially at w = (h − d − margin) / 2, so
that two lanes’ chords never come within d + margin; breaks remove lane
edges at exponential gaps; a share ℓ / (2λ) of the interior knots are
link sites, each joined to the knot nearest in t of a neighbouring lane
within link_reach h, drawn among the neighbours whose link clears
max(min_angle, 72.06°) at both ends against the lane edges there, so that
no link is refused by the angle or at a shared end against a lane. Lane
edges, then tip edges, then links pass foam’s greedy pass; dead ends are
peeled with the face knots anchored, islands removed, and the chains walked
and attached as foam’s. The counters from bed_proposals_outside on are
the fibre bed’s (0 for foam), and their laws F1-F9 are in the docstring.
On a bed alone along a coordinate axis without breaks every plane across a
inside the lanes’ common extent meets each lane’s chord path once, whatever
the sway or the link rate, so the chord graph’s crossings are N plus the
links that span the plane; bed.chord_crossing_ratio(settings) gives the
lane chords’ length-weighted crossing ratio J(β) = 1 + β √(π/2)
exp(1/(2β²)) erfc(1/(√2 β)), β = √2 σ / ℓ, for offsets well below w.
planned_seeds and planned_candidates (N (⌈E/ℓ⌉ + 1) + ⌈N ⌈E/ℓ⌉ ℓ /
(2λ)⌉, E the inset box’s extent along a) take the axis as a keyword when
the settings have none, and frame_record gives a fibre bed an axis record
about the domain’s centre even without a frame.
Layouts. pair grows foam’s feeder pair. sheets grows n = max(2,
⌊B / (unit d_min) + 1/2⌋) feeder trees, B the box’s side along a, in planes
across a at s_k = (k + 1/2) B / n: tree k is arterial from the face at
the low end of the growth direction (y = 0 on the command line) for even k
and venous from the opposite face for odd k, its root at s_k
and the box centre, labelled k + (k ≥ 2) so that labels skip the bridge
label, each steered by a plane rule of normal a and length sheet_length.
It needs a bed axis of ±x or ±z, the growth direction ±y and the walk,
holds at most 126 sheets, and takes no root offsets: it places its own
roots. The sidecar and archive metadata list the trees under
feeder_trees (label, role, sheet, root).
Measured (tests/test_fibre_benchmark.py, beds alone along x, d_min 1,
margin 1). In a cube of side 96 at the defaults (seeds 1-10) 0.83 of the
link candidates and 0.70 of the link sites become links; no lane edge is
refused and no chain dropped. A dense bed (spacing 3.2, density 0.6, links
on) in a cube of side 256, 246,663 knots and 1.09 × 10⁶ d_min of walked
chain, took 363 s and 995 MB on one core: 1.06 times foam’s cost per unit
of placed chain length on the same machine.
A field of view can be filled between a forest’s tips with bed.build
directly and a settings axis:
import bed
result = bed.build((low, high), {"kind": "fibre", "axis": [1.0, 0.0, 0.0]}, d_min=1.0, seed=1,
collision_margin=1.0, feeders=(nodes, tree))
With one feeder label every end of degree one but the first column of the
label is a tip, so ends cut at the box faces are tips too.
Families: --family
tree is the plain grammar. mesh is walk (P = 10) + collision avoidance +
arteriovenous anastomosis of half the tips, grown in the volume. tumour is a
low-persistence walk (P = 3), avoidance, anastomosis of 80% of the tips within
one tree, a root calibre of 20 ± 10 µm and aneurysm and stenosis probabilities
of 0.1. aligned is an arteriovenous pair in the mesh layout whose roots are
moved by −15 and +15 d_min along x, 30 d_min apart (root_offsets), and whose
vessels below 2 d_min are steered along x towards the other tree’s root (a
polar axis with polarity partner, G 4.9, so κ = 4P / G ≈ 8.2, after an onset
of 2 diameters) while the larger vessels are kept in planes perpendicular to x
(a plane with normal x, G 5, girdle K = 4): each tree feeds one sheet and the
capillaries run from sheet to sheet, with 80% of the tips seeking an
arteriovenous partner. It imitates capillaries running along muscle fibres
from terminal arterioles to collecting venules with cross-connections (Skalak
and Schmid-Schönbein 1986; Sarelius 1986; Emerson and Segal 1997), whose
orientation has been fitted with a Fisher-axial law (Mathieu et al. 1983;
Mathieu-Costello 1987). It needs --d-min, and its guidance values are
provisional. aligned_tight is aligned with its capillaries steered harder
and from their first step (G 2, so κ = 4P / G = 20, and an onset of 0 for
both rules) and its roots moved by −20 and +20 d_min along x, 40 d_min apart,
in a cube of side 20 R in a library; it also needs --d-min, and its values
are provisional too. aligned_bed is aligned_tight filled and
cross-connected: capillary trees of two generations whose stems run as four
blocks, and rungs at a spacing of 40 diameters whose chords stand at least 60°
off x, for capillaries running along fibres with transverse connections
(Skalak and Schmid-Schönbein 1986; Kassab and Fung 1994). capillary_bed is
an unguided arteriovenous pair grown in the volume, every tip seeking a
partner of the other tree, filled with capillary trees of three generations
whose stems run as two blocks and cross-connected at a spacing of 20 diameters
off the vessel tangent, for a homogeneous capillary mesh fed and drained by
trees (Lorthois and Cassot 2010; Blinder et al. 2013; Ji et al. 2021). Both
need --d-min; their fill and rung values are provisional. foam is two
feeder trees in the mesh layout, walked (P = 10) with collision avoidance and
grown in the volume, whose grammar stops below 2 d_min, joined by the
explicit bed of the section above, a greedy degree-3 graph with a girth
bound after the organising requirements of Smith et al. (2019), with every
bed setting written out in the preset: spacing 7.5, girth 8, min_angle 60,
reach 2.5, diameter 1, persistence 8, feeder_stop 2, tip_edges 2, stretch 1,
density 0.5, jitter 0.25 and step 0.5. Its frame is of kind none, about
the centre of the growth box, and a library grows it in a cube of side
15 R. It needs --d-min; its bed values are provisional. Released presets
are frozen, so a changed value takes a new family name. Options given
explicitly override the preset. The persistence
values of the presets are provisional calibrations from the sweep in
docs/geometry. A preset listed as None in main.FAMILIES is a family this
version does not offer, and is refused.
fibre is feeder trees in the sheets layout, walked (P = 10) with
collision avoidance and grown in the volume, their grammar stopping below
2 d_min, joined by a fibre bed along x with every bed setting written out:
spacing 5, girth 8, min_angle 60, reach 2, diameter 1, persistence 16,
feeder_stop 2, tip_edges 2, density 0.5, jitter 0.25, step 0.5, axis x,
knot 4, sway 1, link_spacing 20, link_reach 1.75, run null, layout sheets,
unit 60 and sheet_length 2. It imitates the capillary bed of striated
muscle, capillaries running along the fibres between terminal arterioles
and collecting venules in alternating sheets, with cross-connections
(Plyley and Groom 1975, American Journal of Physiology,
doi:10.1152/ajplegacy.1975.228.5.1376; Bassingthwaighte et al. 1974,
Microvascular Research, doi:10.1016/0026-2862(74)90008-9; Potter and
Groom 1983, Microvascular Research, doi:10.1016/0026-2862(83)90044-4;
Skalak and Schmid-Schönbein 1986, Microvascular Research,
doi:10.1016/0026-2862(86)90069-5; Sarelius 1986, American Journal of
Physiology, doi:10.1152/ajpheart.1986.250.6.H899; Kassab and Fung 1994,
American Journal of Physiology, doi:10.1152/ajpheart.1994.267.1.H319;
Emerson and Segal 1997, Journal of Applied Physiology,
doi:10.1152/jappl.1997.82.1.42), whose orientation has been fitted with a
Fisher-axial law (Mathieu et al. 1983, Journal of Microscopy,
doi:10.1111/j.1365-2818.1983.tb04240.x; Mathieu-Costello 1987,
Microvascular Research, doi:10.1016/0026-2862(87)90010-0). Its frame is of
kind axis along x; a library grows it in a cube of side 15 R. It needs
--d-min, --bed null turns its bed off, and its numeric values are
provisional.
Cost
The default command line is unchanged in what it draws and about 8% slower at
twelve generations (21 s against 20 s for a 512 × 512 × 140 volume on one
core), the difference being the graph built for the archive; shallow trees
take the same 1.5 s as before. The opt-in stages are Python loops over walk
steps: at twelve generations the walk adds a quarter, stems-mode avoidance a
half, walk with avoidance takes 2.5×, with anastomosis 4×, and the two-tree
mesh preset 7× (146 s). docs/geometry/audit.md has the table. The
aligned preset of 3.5 costs about what a mesh costs: grown as the library
grows it on an Intel Xeon Gold 5220 workstation, it takes 8.8, 49 and 185 s
at R 4, 8 and 16 (means over seeds 1 to 3, 6.6, 28 and 87 thousand points)
and 600 s at R 25 (298 thousand points,
README 内容过长,已截取前 64 KB。完整内容请前往 GitHub 仓库查看。
评论