Axon Simulations

The axon_simulations module provides several high-level functions to facilitate simulation and exploration at the axon level.

Search Threshold Functions

NRV provides two main functions to estimate axon thresholds:

These functions use a binary search approach to efficiently estimate the required threshold. They require at least three arguments:

  • An axon object (pre-configured) on which the threshold search is performed.

  • max_amp: A float specifying the maximum amplitude (in µA) for the search.

  • A callable object to update the stimulation of the axon between each iteration. This object must take at least two arguments: the axon object and the new stimulation amplitude.

Example usage:

def my_update_function(axon, amp, pw, some_args):
    my_new_stim = nrv.stimulus()
    my_new_stim.any_stim(amp)
    axon.change_stimulus_from_electrode(elec_id, my_new_stim)

my_arg_stim = {'pw': 100, 'other_param': value}

my_threshold = nrv.axon_AP_threshold(
    axon=my_axon,
    amp_max=my_max_amp,
    update_func=my_update_function,
    args_update=my_arg_stim
)

See also

Example 16 - Practical applications of axon_AP_threshold().

Search Threshold Dispatching Functions

NRV also includes the function search_threshold_dispatcher(), which enables parallelized execution of threshold searches over multiple CPU cores. This is useful for evaluating the effect of varying one parameter across a range of values.

This function requires:

  • A callable object to be dispatched to each core. This function must take at least one argument, representing the parameter of interest to be varied.

  • A list of parameter values to test.

  • Optionally, the number of CPU cores to allocate. If not provided, all available cores will be used.

Example usage:

def my_process_threshold(my_param):
    my_arg['my_param'] = my_param
    return nrv.axon_AP_threshold(
        axon=my_axon,
        amp_max=my_amp_max,
        update_func=my_update_function,
        args_update=my_arg,
        verbose=False
    )

if __name__ == '__main__':
    my_thresholds = nrv.threshold_search_dispatcher(
        my_process_threshold,
        my_param_list
    )

See also

Example 17 - Demonstration of search_threshold_dispatcher().

Warning

Always enclose the call to search_threshold_dispatcher() within the if __name__ == '__main__': block. Otherwise, each core may redundantly execute the full parameter list.

Warning

The function search_threshold_dispatcher() may be unstable when executed from Jupyter notebooks. It can hang or never return, depending on the multiprocessing backend and platform. For best results, run this function from a standalone script (e.g., .py file executed via terminal).