crantpy.utils.cave.helpers module

crantpy.utils.cave.helpers module#

This module provides utility functions for cave-related helpers.

crantpy.utils.cave.helpers.is_latest_roots(x, timestamp=None, dataset=None, progress=True, batch_size=100000, validate_ids=True, use_http_session=True)[source]#

Check if the given root IDs are the latest based on the timestamp.

Parameters:
  • x (IDs = str | int | np.int64) – The root IDs to check.

  • timestamp (Timestamp = str | int | np.int64 | datetime | np.datetime64 | pd.Timestamp) – The timestamp to compare against. Can also be β€œmat” for the latest materialization timestamp.

  • dataset (str, optional) – The dataset to use.

  • progress (bool, default True) – Whether to show progress bar for large batches.

  • batch_size (int, default 100_000) – Batch size for processing large numbers of IDs.

  • validate_ids (bool, default True) – Whether to validate root IDs before processing.

  • use_http_session (bool, default True) – Whether to use direct HTTP session for better performance.

Returns:

A boolean array indicating whether each root ID is the latest.

Return type:

np.ndarray

Examples

>>> from crantpy.utils.cave.helpers import is_latest_roots
>>> is_latest_roots([123456789, 987654321])
array([ True, False])
>>> # Check against latest materialization
>>> is_latest_roots([123456789], timestamp="mat")
array([ True])
crantpy.utils.cave.helpers.is_valid_root(x, dataset=None, raise_exc=False)[source]#

Check if ID is (potentially) valid root ID.

Parameters:
  • x (IDs = str | int | np.int64) – The root IDs to check.

  • dataset (str, optional) – The dataset to use.

  • raise_exc (bool, default False) – Whether to raise an exception if invalid IDs are found.

Returns:

A boolean array indicating whether each root ID is valid.

Return type:

np.ndarray

Raises:

ValueError – If raise_exc is True and invalid IDs are found.

crantpy.utils.cave.helpers.is_valid_supervoxel(x, dataset=None, raise_exc=False)[source]#

Check if ID is (potentially) valid supervoxel ID.

Parameters:
  • x (IDs = str | int | np.int64) – The supervoxel IDs to check.

  • dataset (str, optional) – The dataset to use.

  • raise_exc (bool, default False) – Whether to raise an exception if invalid IDs are found.

Returns:

If x is a single ID, returns bool. If x is iterable, returns array.

Return type:

bool or np.ndarray

Raises:

ValueError – If raise_exc is True and invalid IDs are found.

See also

is_valid_root

Use this function to check if a root ID is valid.

crantpy.utils.cave.helpers.parse_root_ids(x)[source]#

Parse root IDs from various input formats to a list of np.int64.

Parameters:

x (Neurons = str | int | np.int64 | navis.BaseNeuron | Iterables of previous types | navis.NeuronList | NeuronCriteria) – The input to parse. Can be a single ID, a list of IDs, or a navis neuron object.

Returns:

A numpy array of root IDs as np.int64.

Return type:

np.ndarray