neurocarto.util.edit.checking

neurocarto.util.edit.checking.use_probe(probe=<class 'neurocarto.probe.ProbeDesp'>, code=None, *, create=None, check=True)

Decorate a blueprint script (BlueprintScript) to indicate this function request a particular probe type.

@use_probe('npx', 24) # checking and creating probe if necessary
def my_probe(bp: BlueprintFunctions):
    bp.check_probe('npx', 24) # no need anymore in common case.

It also allows BlueprintScriptView to filter suitable scripts for a probe.

Parameters:
  • probe (str | type[ProbeDesp]) – probe type or its name. It is omitted, just check a probe is existed.

  • code (int | tuple[int, ...] | None) – channelmap code

  • create (bool | None) – create the probe if there is no probe in the main figure. If True, it requires code should be not None. Force False if probe is omitted.

  • check – check the current probe type automatically before entering the script.

See:

get_use_probe()

See:

BlueprintFunctions. check_probe()

neurocarto.util.edit.checking.check_probe(self, probe=None, code=None)

check request probe type and channelmap code.

Parameters:
Raises:

RequestChannelmapTypeError – when check failed.

neurocarto.util.edit.checking.get_use_probe(func)

Get RequestChannelmapType.

Parameters:

func – blueprint script function

Returns:

Return type:

RequestChannelmapType | None

class neurocarto.util.edit.checking.RequestChannelmapType

An annotation data to indicate the probe request for a blueprint script.

Do not create by yourself. In order to use this, use use_probe() and get_use_probe() instead.

probe: str | type[ProbeDesp] | None

request probe name or type.

code: int | tuple[int, ...] | None

request channelmap code.

create: bool

create a channelmap when it is missing.

check: bool

check it is existed and match to the request. raise error when mis-match

property probe_name: str

Probe name

match_probe(probe, chmap=None)

Does probe and chmap match this request?

Parameters:
  • probe (ProbeDesp | None)

  • chmap (Any | None)

Returns:

Return type:

bool

static __new__(_cls, probe, code, create=True, check=True)

Create new instance of RequestChannelmapType(probe, code, create, check)

Parameters:
  • probe (str | type[ProbeDesp] | None)

  • code (int | tuple[int, ...] | None)

  • create (bool)

  • check (bool)

exception neurocarto.util.edit.checking.RequestChannelmapTypeError
__init__(request)
Parameters:

request (RequestChannelmapType) – request probe type.

neurocarto.util.edit.checking.use_view(view)

Decorate a blueprint script (BlueprintScript) to indicate this function request a particular ViewBase to work.

@use_view('AtlasView')
def my_function(bp: BlueprintFunctions):
    if (atlas := bp.use_view('AtlasView')) is None:
        raise RuntimeError('AtlasView is not loaded')

It also allows BlueprintScriptView to filter suitable scripts, which depends on existed views.

Parameters:

view (str | type[neurocarto.views.base.ViewBase]) – request view name or type.

Returns:

See:

get_use_view()

See:

BlueprintFunctions. use_view()

neurocarto.util.edit.checking.get_use_view(func)

Get RequestView.

Parameters:

func – blueprint script function

Returns:

Return type:

RequestView | None

class neurocarto.util.edit.checking.RequestView

An annotation data to indicate the view dependency for a blueprint script.

Do not create by yourself. In order to use this, use use_view() and get_use_view() instead.

static __new__(_cls, view_type)

Create new instance of RequestView(view_type,)

Parameters:

view_type (str | type[ViewBase])

view_type: str | type[neurocarto.views.base.ViewBase]

request view name or type.