axon_synthesis.utils

Some utils for the AxonSynthesis package.

Functions

add_camera_sync(fig_path)

Update the HTML file to synchronize the cameras between the two plots.

build_layout_properties(pts[, ...])

Build a dictionary with layout properties for Plotly figures.

cols_from_json(df, cols)

Transform the given columns to Python objects from JSON strings.

cols_to_json(df, cols)

Transform the given columns from Python objects to JSON strings.

compute_aspect_ratios(bbox)

Compute the aspect ratios of a bounding box.

compute_bbox(points[, relative_buffer, ...])

Compute the bounding box of the given points and optionally apply a buffer to it.

create_dask_dataframe(data, npartitions[, ...])

Ensure all rows of the same group belong to the same partition.

create_random_morphologies(atlas, ...[, ...])

Create some random source points.

disable_distributed_loggers()

A context manager that will disable logging messages from the 'distributed' library.

disable_loggers(*logger_names)

A context manager that will disable logging messages triggered during the body.

export_morph_edges(morph, output_path[, ...])

Export the morphology as DataFrame for later analysis.

export_to_tecplot(voxcell_data, filename[, ...])

Export a 3D vector field to a Tecplot binary file.

fill_diag(mat[, val])

Fill the diagonal of the given matrix.

get_axons(morph[, axon_ids])

Get axons of the given morphology.

get_code_location([back_frames])

Return the current file name and line number in the program.

get_layers(atlas, pos)

Get layer data.

get_morph_pts(morph)

Return the points of a morphology and handle empty morphologies.

get_morphology_paths(morph_dir, *[, max_level])

Get all morphology paths from a given directory.

get_nested_morphology_paths(morph_dir, *[, ...])

Get all morphology paths from a given directory and sub directories.

ignore_warnings(*ignored_warnings)

A context manager that will ignore warnings raised during the body.

keep_only_neurites(morph[, neurite_type, ...])

Delete neurites except the ones with a given type or index.

load_morphology(path, *[, recenter])

Load a morphology a optionally recenter it.

merge_json_files(*files)

Merge several JSON files together.

neurite_to_graph(neurite[, graph_cls, ...])

Transform a neurite into a graph.

neurite_to_graph_old(neurite[, graph_cls])

Transform a neurite into a graph.

neurite_to_pts(neurite, *[, ...])

Extract points and segments from a neurite.

parallel_evaluator(data, func, ...[, ...])

Create a local cluster and process the given function on the given DataFrame.

permanently_disable_distributed_loggers()

Permanently disable logging messages from the 'distributed' library.

recursive_to_str(data)

Cast all Path objects into str objects in a given dict.

recursive_update(data, updates)

Update a dictionary with another with nested values.

save_morphology(morph, morph_path[, msg, logger])

Export the given morphology to the given path.

seed_from_name(name)

Build a seed from the name hash.

setup_logger([level, prefix, suffix])

Setup application logger.

sublogger(logger, name)

Get a sub-logger with specific name.

temp_dir(*args, **kwargs)

Create a temporary directory.

Classes

CleanableDirectory(dir_name, *[, parents, ...])

A class to create a directory that can be cleaned up.

MorphNameAdapter(logger[, extra])

Add the morphology name and optionally the axon ID to the log entries.

ParallelConfig([nb_processes, dask_config, ...])

Class to store the parallel configuration.

TemporaryDirectory(*args[, delete])

Backport of delete parameter for TemporaryDirectory.

class axon_synthesis.utils.CleanableDirectory(dir_name, *, parents=True, exist_ok=False)

Bases: object

A class to create a directory that can be cleaned up.

cleanup()

Clean up the directory.

class axon_synthesis.utils.MorphNameAdapter(logger, extra=None)

Bases: LoggerAdapter

Add the morphology name and optionally the axon ID to the log entries.

process(msg: str, kwargs: MutableMapping[str, object]) tuple[str, MutableMapping[str, object]]

Add extra information to the log entry.

class axon_synthesis.utils.ParallelConfig(nb_processes: int = 0, dask_config: dict | None = None, progress_bar: bool = False, use_mpi: bool = False)

Bases: object

Class to store the parallel configuration.

nb_processes

The number of processes.

Type:

int

dask_config

The dask configuration to use.

Type:

dict | None

progress_bar

If set to True, a progress bar is displayed during computation.

Type:

bool

use_mpi

Trigger the use of MPI.

Type:

bool

class axon_synthesis.utils.TemporaryDirectory(*args, delete=True, **kwargs)

Bases: TemporaryDirectory

Backport of delete parameter for TemporaryDirectory.

axon_synthesis.utils.add_camera_sync(fig_path)

Update the HTML file to synchronize the cameras between the two plots.

axon_synthesis.utils.build_layout_properties(pts, relative_buffer: float | None = None, absolute_buffer: float | None = None) dict

Build a dictionary with layout properties for Plotly figures.

axon_synthesis.utils.cols_from_json(df, cols)

Transform the given columns to Python objects from JSON strings.

axon_synthesis.utils.cols_to_json(df, cols)

Transform the given columns from Python objects to JSON strings.

axon_synthesis.utils.compute_aspect_ratios(bbox)

Compute the aspect ratios of a bounding box.

axon_synthesis.utils.compute_bbox(points, relative_buffer=None, absolute_buffer=None)

Compute the bounding box of the given points and optionally apply a buffer to it.

axon_synthesis.utils.create_dask_dataframe(data: DataFrame, npartitions: int, group_col='morphology')

Ensure all rows of the same group belong to the same partition.

axon_synthesis.utils.create_random_morphologies(atlas, nb_morphologies: int, brain_regions: int | str | list[int | str] | None = None, output_morphology_dir: str | PathLike | None = None, output_cell_collection: str | PathLike | None = None, morphology_prefix: str | None = None, rng: None | int | Sequence[int] | SeedSequence | BitGenerator | Generator = None, logger: Logger | LoggerAdapter | None = None)

Create some random source points.

axon_synthesis.utils.disable_distributed_loggers()

A context manager that will disable logging messages from the ‘distributed’ library.

axon_synthesis.utils.disable_loggers(*logger_names)

A context manager that will disable logging messages triggered during the body.

Parameters:

*logger_names (str) – The names of the loggers to be disabled.

axon_synthesis.utils.export_morph_edges(morph, output_path, neurite_filter=None, logger=None)

Export the morphology as DataFrame for later analysis.

axon_synthesis.utils.export_to_tecplot(voxcell_data, filename, title='Default Title')

Export a 3D vector field to a Tecplot binary file.

axon_synthesis.utils.fill_diag(mat, val=1)

Fill the diagonal of the given matrix.

axon_synthesis.utils.get_axons(morph, axon_ids=None)

Get axons of the given morphology.

axon_synthesis.utils.get_code_location(back_frames=1)

Return the current file name and line number in the program.

axon_synthesis.utils.get_layers(atlas, pos)

Get layer data.

axon_synthesis.utils.get_morph_pts(morph)

Return the points of a morphology and handle empty morphologies.

axon_synthesis.utils.get_morphology_paths(morph_dir, *, max_level=None)

Get all morphology paths from a given directory.

axon_synthesis.utils.get_nested_morphology_paths(morph_dir, *, max_level=None)

Get all morphology paths from a given directory and sub directories.

axon_synthesis.utils.ignore_warnings(*ignored_warnings)

A context manager that will ignore warnings raised during the body.

Parameters:

*ignored_warnings (Warning) – The classes of the warnings to be ignored.

axon_synthesis.utils.keep_only_neurites(morph, neurite_type=None, neurite_idx=None, *, copy=False)

Delete neurites except the ones with a given type or index.

Note

If both the type and index are given, the index is only applied for the neurites of the given type.

axon_synthesis.utils.load_morphology(path, *, recenter=False)

Load a morphology a optionally recenter it.

axon_synthesis.utils.merge_json_files(*files)

Merge several JSON files together.

The order is important: the files will be updated by all the next files in the list.

axon_synthesis.utils.neurite_to_graph(neurite, graph_cls=<class 'networkx.classes.digraph.DiGraph'>, *, keep_section_segments=False, **graph_kwargs)

Transform a neurite into a graph.

axon_synthesis.utils.neurite_to_graph_old(neurite, graph_cls=<class 'networkx.classes.digraph.DiGraph'>, **graph_kwargs)

Transform a neurite into a graph.

axon_synthesis.utils.neurite_to_pts(neurite, *, keep_section_segments=False, edges_with_coords=False)

Extract points and segments from a neurite.

axon_synthesis.utils.parallel_evaluator(data, func, parallel_config: ParallelConfig | None, new_columns: list, *, func_args=None, func_kwargs=None, startup_func=None, shuffle_rows: bool = True, progress_bar: bool = False, logger: Logger | LoggerAdapter | None = None)

Create a local cluster and process the given function on the given DataFrame.

axon_synthesis.utils.permanently_disable_distributed_loggers()

Permanently disable logging messages from the ‘distributed’ library.

axon_synthesis.utils.recursive_to_str(data)

Cast all Path objects into str objects in a given dict.

axon_synthesis.utils.recursive_update(data, updates)

Update a dictionary with another with nested values.

axon_synthesis.utils.save_morphology(morph: Morphology, morph_path: str | PathLike, msg: str | None = None, logger: Logger | LoggerAdapter | None = None)

Export the given morphology to the given path.

axon_synthesis.utils.seed_from_name(name)

Build a seed from the name hash.

axon_synthesis.utils.setup_logger(level: str = 'info', prefix: str = '', suffix: str = '')

Setup application logger.

axon_synthesis.utils.sublogger(logger: Logger | LoggerAdapter | None, name: str) Logger | LoggerAdapter

Get a sub-logger with specific name.

axon_synthesis.utils.temp_dir(*args, **kwargs)

Create a temporary directory.