NeuroMorphoCache#

class braincell.io.NeuroMorphoCache(root)[source]#

First-class cache over locally-downloaded NeuroMorpho.Org neurons.

Owns a NeuroMorphoCacheLayout and provides discovery and loading operations. Replaces the loose find_standard_swc and load_cached_metadata helpers from previous versions.

Parameters:

root (str | Path) – Directory containing one subfolder per cached neuron. The directory is created lazily on first write.

Variables:

Examples

>>> cache = NeuroMorphoCache("~/data/neuromorpho")
>>> for neuron_id in cache.list_neurons():
...     morph = cache.load(neuron_id)
clear()[source]#

Delete every per-neuron folder under root.

Does not delete files at the root level that are not neuron folders.

Returns:

Number of folders that were removed.

Return type:

int

contains(neuron_id)[source]#

Return True if a folder for neuron_id exists on disk.

Return type:

bool

list_neurons()[source]#

Return the sorted ids of every cached neuron.

Returns:

Empty tuple when the cache directory does not exist.

Return type:

tuple[int, ...]

load(neuron_id, *, mode='neuromorpho', return_report=False)[source]#

Load a cached neuron as a Morphology.

Parses the cached standardized SWC file with Morphology.from_swc().

Parameters:
  • neuron_id (int)

  • mode (str | None) – SWC import mode forwarded to Morphology.from_swc(). Defaults to "neuromorpho".

  • return_report (bool) – If True, also return the SwcReport.

Return type:

Morphology | tuple[Morphology, SwcReport]

Raises:

FileNotFoundError – If no standardized SWC file is cached for neuron_id.

measurement(neuron_id)[source]#

Return the typed measurement for neuron_id, if cached.

Parameters:

neuron_id (int)

Returns:

None when no metadata file is present or it does not contain a measurement block.

Return type:

NeuroMorphoMeasurement | None

metadata(neuron_id)[source]#

Return the parsed metadata.json for neuron_id.

Parameters:

neuron_id (int)

Return type:

Mapping[str, Any]

Raises:

FileNotFoundError – If the metadata file does not exist.

original_file_path(neuron_id)[source]#

Return the path of the cached original (Source-Version) file.

Parameters:

neuron_id (int)

Returns:

None if no original file is present in the folder.

Return type:

Path | None

remove(neuron_id)[source]#

Delete the on-disk folder for neuron_id.

Parameters:

neuron_id (int)

Returns:

True if a folder was removed, False if there was nothing to remove.

Return type:

bool

standard_swc_path(neuron_id)[source]#

Return the path of the cached standardized SWC file.

Resolves the path by reading metadata.json for the neuron name when available, otherwise falls back to *.CNG.swc then *.swc glob inside the per-neuron folder.

Parameters:

neuron_id (int)

Returns:

None if no SWC file can be located.

Return type:

Path | None

status(neuron_id)[source]#

Return a NeuroMorphoCacheStatus snapshot for neuron_id.

Parameters:

neuron_id (int)

Return type:

NeuroMorphoCacheStatus