diff --git a/010_api_reference.html b/010_api_reference.html index 05b79126..4154f9f4 100644 --- a/010_api_reference.html +++ b/010_api_reference.html @@ -83,6 +83,7 @@
  • API Reference
  • Index
  • @@ -130,6 +131,13 @@

    API Reference + +

    iblatlas

    +

    A package for working with brain atlases.

    + + + diff --git a/_autosummary/brainbox.atlas.html b/_autosummary/brainbox.atlas.html index 114299a0..94488ad9 100644 --- a/_autosummary/brainbox.atlas.html +++ b/_autosummary/brainbox.atlas.html @@ -105,6 +105,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.behavior.dlc.html b/_autosummary/brainbox.behavior.dlc.html index a2b44c6f..8e25c515 100644 --- a/_autosummary/brainbox.behavior.dlc.html +++ b/_autosummary/brainbox.behavior.dlc.html @@ -108,6 +108,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.behavior.html b/_autosummary/brainbox.behavior.html index 80ed6c3a..0036dd22 100644 --- a/_autosummary/brainbox.behavior.html +++ b/_autosummary/brainbox.behavior.html @@ -108,6 +108,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • @@ -151,7 +152,7 @@

    (DEPRECATED) The psychofit toolbox contains tools to fit two-alternative psychometric data. The fitting is done using maximal likelihood estimation: one assumes that the responses of the subject are given by a binomial distribution whose mean is given by the psychometric function. The data can be expressed in fraction correct (from .5 to 1) or in fraction of one specific choice (from 0 to 1). To fit them you can use these functions: - weibull50: Weibull function from 0.5 to 1, with lapse rate - weibull: Weibull function from 0 to 1, with lapse rate - erf_psycho: erf function from 0 to 1, with lapse rate - erf_psycho_2gammas: erf function from 0 to 1, with two lapse rates Functions in the toolbox are: - mle_fit_psycho: Maximumum likelihood fit of psychometric function - neg_likelihood: Negative likelihood of a psychometric function For more info, see: - Examples: Examples of use of psychofit toolbox Matteo Carandini, 2000-2015.

    brainbox.behavior.training

    -

    +

    Computing and testing IBL training status criteria.

    brainbox.behavior.wheel

    Set of functions to handle wheel data.

    diff --git a/_autosummary/brainbox.behavior.pyschofit.html b/_autosummary/brainbox.behavior.pyschofit.html index 9cac8e05..e0b7c92b 100644 --- a/_autosummary/brainbox.behavior.pyschofit.html +++ b/_autosummary/brainbox.behavior.pyschofit.html @@ -108,6 +108,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.behavior.training.TRIALS_KEYS.html b/_autosummary/brainbox.behavior.training.TRIALS_KEYS.html new file mode 100644 index 00000000..396ed815 --- /dev/null +++ b/_autosummary/brainbox.behavior.training.TRIALS_KEYS.html @@ -0,0 +1,191 @@ + + + + + + + brainbox.behavior.training.TRIALS_KEYS — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    brainbox.behavior.training.TRIALS_KEYS

    +
    +
    +TRIALS_KEYS = ['contrastLeft', 'contrastRight', 'feedbackType', 'probabilityLeft', 'choice', 'response_times', 'stimOn_times']
    +

    The required keys in the trials object for computing training status.

    +
    +
    Type:
    +

    list of str

    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/brainbox.behavior.training.html b/_autosummary/brainbox.behavior.training.html index a89f8826..0a92d7a4 100644 --- a/_autosummary/brainbox.behavior.training.html +++ b/_autosummary/brainbox.behavior.training.html @@ -24,7 +24,7 @@ - + @@ -108,6 +108,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • @@ -142,6 +143,46 @@

    brainbox.behavior.training

    +

    Computing and testing IBL training status criteria.

    +

    For an in-depth description of each training status, see Appendix 2 of the IBL Protocol For Mice +Training.

    +

    Examples

    +

    Plot the psychometric curve for a given session.

    +
    >>> trials = ONE().load_object(eid, 'trials')
    +>>> fix, ax = plot_psychometric(trials)
    +
    +
    +

    Compute ‘response times’, defined as the duration of open-loop for each contrast.

    +
    >>> reaction_time, contrasts, n_contrasts = compute_reaction_time(trials)
    +
    +
    +

    Compute ‘reaction times’, defined as the time between go cue and first detected movement. +NB: These may be negative!

    +
    >>> reaction_time, contrasts, n_contrasts = compute_reaction_time(
    +...     trials, stim_on_type='goCue_times', stim_off_type='firstMovement_times')
    +
    +
    +

    Compute ‘response times’, defined as the time between first detected movement and response.

    +
    >>> reaction_time, contrasts, n_contrasts = compute_reaction_time(
    +...     trials, stim_on_type='firstMovement_times', stim_off_type='response_times')
    +
    +
    +

    Compute ‘movement times’, defined as the time between last detected movement and response threshold.

    +
    >>> import brainbox.behavior.wheel as wh
    +>>> wheel_moves = ONE().load_object(eid, 'wheeMoves')
    +>>> trials['lastMovement_times'] = wh.get_movement_onset(wheel_moves.intervals, trial_data.response_times)
    +>>> reaction_time, contrasts, n_contrasts = compute_reaction_time(
    +...     trials, stim_on_type='lastMovement_times', stim_off_type='response_times')
    +
    +
    +

    Module attributes

    + + + + + + +

    TRIALS_KEYS

    The required keys in the trials object for computing training status.

    Functions

    @@ -149,7 +190,7 @@ - + @@ -161,34 +202,34 @@ - + - + - + - + - + - + - + - + - + - + @@ -197,19 +238,19 @@ - + - + - + - + - + @@ -224,6 +265,17 @@

    Compute all relevant performance metrics for when subject is on biasedChoiceWorld

    compute_median_reaction_time

    Compute median reaction time on zero contrast trials from trials object

    Compute median response time on zero contrast trials from trials object

    compute_n_trials

    Compute number of trials in trials object

    Compute performance on easy trials (stimulus >= 50 %) from trials object

    compute_psychometric

    Compute psychometric fit parameters for trials object

    Compute psychometric fit parameters for trials object.

    compute_reaction_time

    Compute median reaction time for all contrasts

    Compute median response time for all contrasts.

    compute_training_info

    Compute all relevant performance metrics for when subject is on trainingChoiceWorld

    Compute all relevant performance metrics for when subject is on trainingChoiceWorld.

    concatenate_trials

    Concatenate trials from different training sessions

    Concatenate trials from different training sessions.

    criterion_1a

    Returns bool indicating whether criterion for trained_1a is met.

    Returns bool indicating whether criteria for status 'trained_1a' are met.

    criterion_1b

    Returns bool indicating whether criterion for trained_1b is met.

    Returns bool indicating whether criteria for trained_1b are met.

    criterion_delay

    Returns bool indicating whether criterion for ready4delay is met.

    Returns bool indicating whether criteria for 'ready4delay' is met.

    criterion_ephys

    Returns bool indicating whether criterion for ready4ephysrig or ready4recording is met.

    Returns bool indicating whether criteria for ready4ephysrig or ready4recording are met.

    display_status

    Display training status of subject to terminal

    Display training status of subject to terminal.

    get_lab_training_status

    Computes the training status of all alive and water restricted subjects in a specified lab

    Computes the training status of all alive and water restricted subjects in a specified lab.

    get_sessions

    Download and load in training data for a specified subject.

    Compute signed contrast from trials object

    get_subject_training_status

    Computes the training status of specified subject

    Computes the training status of specified subject and prints results to std out.

    get_training_status

    Compute training status of a subject from three consecutive training datasets

    Compute training status of a subject from consecutive training datasets.

    plot_psychometric

    Function to plot psychometric curve plots a la datajoint webpage

    Function to plot psychometric curve plots a la datajoint webpage.

    plot_reaction_time

    Function to plot reaction time against contrast a la datajoint webpage (inverted for some reason??)

    Function to plot reaction time against contrast a la datajoint webpage.

    plot_reaction_time_over_trials

    Function to plot reaction time with trial number a la datajoint webpage

    Function to plot reaction time with trial number a la datajoint webpage.

    query_criterion

    Get the session for which a given training criterion was met.

    +
    +
    +TRIALS_KEYS = ['contrastLeft', 'contrastRight', 'feedbackType', 'probabilityLeft', 'choice', 'response_times', 'stimOn_times']
    +

    The required keys in the trials object for computing training status.

    +
    +
    Type:
    +

    list of str

    +
    +
    +
    +
    class TrainingStatus(value)[source]
    @@ -240,17 +292,17 @@ ... assert TrainingStatus[status.upper()] in TrainingStatus.TRAINED ^ TrainingStatus.READY -

    # Get the next training status ->>> next(member for member in sorted(TrainingStatus) if member > TrainingStatus[status.upper()]) -<TrainingStatus.READY4RECORDING: 128>

    +

    Get the next training status

    +
    >>> next(member for member in sorted(TrainingStatus) if member > TrainingStatus[status.upper()])
    +<TrainingStatus.READY4RECORDING: 128>
    +
    +

    Notes

    • ~TrainingStatus.TRAINED means any status but trained 1a or trained 1b.

    • -
    • A subject may acheive both TRAINED_1A and TRAINED_1B within a single session, therefore it

    • +
    • A subject may acheive both TRAINED_1A and TRAINED_1B within a single session, therefore it +is possible to have skipped the TRAINED_1A session status.

    -
    -

    is possible to have skipped the TRAINED_1A session status.

    -
    UNTRAINABLE = 1
    @@ -311,41 +363,38 @@
    get_lab_training_status(lab, date=None, details=True, one=None)[source]
    -

    Computes the training status of all alive and water restricted subjects in a specified lab

    +

    Computes the training status of all alive and water restricted subjects in a specified lab.

    +

    The response are printed to std out.

    Parameters:
      -
    • lab (string) – lab name (must match the name registered on Alyx)

    • -
    • date – the date from which to compute training status from. If not specified will compute

    • +
    • lab (str) – Lab name (must match the name registered on Alyx).

    • +
    • date (str) – The ISO date from which to compute training status. If not specified will compute from the +latest date with available data. Format should be ‘YYYY-MM-DD’.

    • +
    • details (bool) – Whether to display all information about training status computation e.g. performance, +number of trials, psychometric fit parameters.

    • +
    • one (one.api.OneAlyx) – An instance of ONE.

    -

    from the latest date with available data -:type date: string of format ‘YYYY-MM-DD’ -:param details: whether to display all information about training status computation e.g -performance, number of trials, psychometric fit parameters -:type details: bool -:param one: instantiation of ONE class

    get_subject_training_status(subj, date=None, details=True, one=None)[source]
    -

    Computes the training status of specified subject

    +

    Computes the training status of specified subject and prints results to std out.

    Parameters:
      -
    • subj (string) – subject nickname (must match the name registered on Alyx)

    • -
    • date – the date from which to compute training status from. If not specified will compute

    • +
    • subj (str) – Subject nickname (must match the name registered on Alyx).

    • +
    • date (str) – The ISO date from which to compute training status. If not specified will compute from the +latest date with available data. Format should be ‘YYYY-MM-DD’.

    • +
    • details (bool) – Whether to display all information about training status computation e.g. performance, +number of trials, psychometric fit parameters.

    • +
    • one (one.api.OneAlyx) – An instance of ONE.

    -

    from the latest date with available data -:type date: string of format ‘YYYY-MM-DD’ -:param details: whether to display all information about training status computation e.g -performance, number of trials, psychometric fit parameters -:type details: bool -:param one: instantiation of ONE class

    @@ -357,127 +406,117 @@
    Parameters:
      -
    • subj (string) – subject nickname (must match the name registered on Alyx)

    • -
    • date – the date from which to compute training status from. If not specified will compute

    • +
    • subj (str) – Subject nickname (must match the name registered on Alyx).

    • +
    • date (str) – The ISO date from which to compute training status. If not specified will compute from the +latest date with available data. Format should be ‘YYYY-MM-DD’.

    • +
    • one (one.api.OneAlyx) – An instance of ONE.

    -
    -

    from the latest date with available data -:type date: string of format ‘YYYY-MM-DD’ -:param one: instantiation of ONE class -:returns:

    -
    -
      -
    • trials - dict of trials objects where each key is the session date

    • -
    • task_protocol - list of the task protocol used for each of the sessions

    • -
    • -
      ephys_sess_data - list of dates where training was conducted on ephys rig. Empty list if

      all sessions on training rig

      -
      -
      -
    • -
    • -
      n_delay - number of sessions on ephys rig that had delay prior to starting session

      > 15min. Returns 0 is no sessions detected

      +
      Returns:
      +

        +
      • iblutil.util.Bunch – Dictionary of trials objects where each key is the ISO session date string.

      • +
      • list of str – List of the task protocol used for each of the sessions.

      • +
      • list of str – List of ISO date strings where training was conducted on ephys rig. Empty list if all +sessions on training rig.

      • +
      • n_delay (int) – Number of sessions on ephys rig that had delay prior to starting session > 15min. +Returns 0 if no sessions detected.

      • +
      +

      -
    • -
    -
    get_training_status(trials, task_protocol, ephys_sess_dates, n_delay)[source]
    -

    Compute training status of a subject from three consecutive training datasets

    +

    Compute training status of a subject from consecutive training datasets.

    +

    For IBL, training status is calculated using trials from the last three consecutive sessions.

    Parameters:
      -
    • trials (Bunch) – dict containing trials objects from three consecutive training sessions

    • -
    • task_protocol – task protocol used for the three training session, can be ‘training’,

    • +
    • trials (dict of str) – Dictionary of trials objects where each key is the ISO session date string.

    • +
    • task_protocol (list of str) – Task protocol used for each training session in trials, can be ‘training’, ‘biased’ or +‘ephys’.

    • +
    • ephys_sess_dates (list of str) – List of ISO date strings where training was conducted on ephys rig. Empty list if all +sessions on training rig.

    • +
    • n_delay (int) – Number of sessions on ephys rig that had delay prior to starting session > 15min. +Returns 0 if no sessions detected.

    -
    -

    ‘biased’ or ‘ephys’ -:type task_protocol: list of strings -:param ephys_sess_dates: dates of sessions conducted on ephys rig -:type ephys_sess_dates: list of strings -:param n_delay: number of sessions on ephys rig with delay before start > 15 min -:type n_delay: int -:returns:

    -
    -
      -
    • status - training status of subject

    • -
    • -
      info - Bunch containing performance metrics that decide training status e.g performance

      on easy trials, number of trials, psychometric fit parameters, reaction time

      +
      Returns:
      +

        +
      • str – Training status of the subject.

      • +
      • iblutil.util.Bunch – Bunch containing performance metrics that decide training status i.e. performance on easy +trials, number of trials, psychometric fit parameters, reaction time.

      • +
      +

      -
    • -
    -
    display_status(subj, sess_dates, status, perf_easy=None, n_trials=None, psych=None, psych_20=None, psych_80=None, rt=None)[source]
    -

    Display training status of subject to terminal

    +

    Display training status of subject to terminal.

    Parameters:
      -
    • subj (string) – subject nickname

    • -
    • sess_dates (list of strings) – training session dates used to determine training status

    • -
    • status (string) – training status of subject

    • -
    • perf_easy (np.array) – performance on easy trials for each training sessions

    • -
    • n_trials (np.array) – number of trials for each training sessions

    • -
    • psych (np.array - bias, threshold, lapse high, lapse low) – parameters of psychometric curve fit to data from all training sessions

    • -
    • psych_20 – parameters of psychometric curve fit to data in 20 (probability left) block

    • +
    • subj (str) – Subject nickname (must match the name registered on Alyx).

    • +
    • sess_dates (list of str) – ISO date strings of training sessions used to determine training status.

    • +
    • status (str) – Training status of subject.

    • +
    • perf_easy (numpy.array) – Proportion of correct high contrast trials for each training session.

    • +
    • n_trials (numpy.array) – Total number of trials for each training session.

    • +
    • psych (numpy.array) – Psychometric parameters fit to data from all training sessions - bias, threshold, lapse +high, lapse low.

    • +
    • psych_20 (numpy.array) – The fit psychometric parameters for the blocks where probability of a left stimulus is 0.2.

    • +
    • psych_80 (numpy.array) – The fit psychometric parameters for the blocks where probability of a left stimulus is 0.8.

    • +
    • rt (float) – The median response time for zero contrast trials across all training sessions. NaN +indicates no zero contrast stimuli in training sessions.

    -

    from all training sessions -:type psych_20: np.array - bias, threshold, lapse high, lapse low -:param psych_80: parameters of psychometric curve fit to data in 80 (probability left) block -from all training sessions -:type psych_80: np.array - bias, threshold, lapse high, lapse low -:param rt: median reaction time on zero contrast trials across all training sessions (if nan -indicates no zero contrast stimuli in training sessions)

    concatenate_trials(trials)[source]
    -

    Concatenate trials from different training sessions

    +

    Concatenate trials from different training sessions.

    Parameters:
    -

    trials – dict containing trials objects from three consecutive training sessions,

    +

    trials (dict of str) – Dictionary of trials objects where each key is the ISO session date string.

    +
    +
    Returns:
    +

    Trials object with data concatenated over three training sessions.

    +
    +
    Return type:
    +

    one.alf.io.AlfBunch

    -

    keys are session dates -:type trials: Bunch -:return: trials object with data concatenated over three training sessions -:rtype: dict

    compute_training_info(trials, trials_all)[source]
    -

    Compute all relevant performance metrics for when subject is on trainingChoiceWorld

    +

    Compute all relevant performance metrics for when subject is on trainingChoiceWorld.

    Parameters:
    -

    trials – dict containing trials objects from three consecutive training sessions,

    +
      +
    • trials (dict of str) – Dictionary of trials objects where each key is the ISO session date string.

    • +
    • trials_all (one.alf.io.AlfBunch) – Trials object with data concatenated over three training sessions.

    • +
    -
    -

    keys are session dates -:type trials: Bunch -:param trials_all: trials object with data concatenated over three training sessions -:type trials_all: Bunch -:returns:

    -
    -
      -
    • perf_easy - performance of easy trials for each session

    • -
    • n_trials - number of trials in each session

    • -
    • psych - parameters for psychometric curve fit to all sessions

    • -
    • rt - median reaction time for zero contrast stimuli over all sessions

    • +
      Returns:
      +

        +
      • numpy.array – Proportion of correct high contrast trials for each session.

      • +
      • numpy.array – Total number of trials for each training session.

      • +
      • numpy.array – Array of psychometric parameters fit to all_trials - bias, threshold, lapse high, +lapse low.

      • +
      • float – The median response time for all zero-contrast trials across all sessions. Returns NaN if +no trials zero-contrast trials).

      -
    +

    +
    +
    @@ -559,132 +598,422 @@
    -compute_psychometric(trials, signed_contrast=None, block=None, plotting=False, compute_ci=False, alpha=0.32)[source]
    -

    Compute psychometric fit parameters for trials object

    +compute_psychometric(trials, signed_contrast=None, block=None, plotting=False, compute_ci=False, alpha=0.032)[source] +

    Compute psychometric fit parameters for trials object.

    Parameters:
      -
    • trials (dict) – trials object that must contain contrastLeft, contrastRight and probabilityLeft

    • -
    • signed_contrast (np.array) – array of signed contrasts in percent, where -ve values are on the left

    • -
    • block (float) – biased block can be either 0.2 or 0.8

    • +
    • trials (one.alf.io.AlfBunch) – An ALF trials object containing the keys {‘probabilityLeft’, ‘contrastLeft’, +‘contrastRight’, ‘feedbackType’, ‘choice’, ‘response_times’, ‘stimOn_times’}.

    • +
    • signed_contrast (numpy.array) – An array of signed contrasts in percent the length of trials, where left contrasts are -ve. +If None, these are computed from the trials object.

    • +
    • block (float) – The block type to compute. If None, all trials are included, otherwise only trials where +probabilityLeft matches this value are included. For biasedChoiceWorld, the +probabilityLeft set is {0.5, 0.2, 0.8}.

    • +
    • plotting (bool) – Which set of psychofit model parameters to use (see notes).

    • +
    • compute_ci (bool) – If true, computes and returns the confidence intervals for response at each contrast.

    • +
    • alpha (float, default=0.032) – Significance level for confidence interval. Must be in (0, 1). If compute_ci is false, +this value is ignored.

    Returns:
    -

    array of psychometric fit parameters - bias, threshold, lapse high, lapse low

    +

      +
    • numpy.array – Array of psychometric fit parameters - bias, threshold, lapse high, lapse low.

    • +
    • (tuple of numpy.array) – If compute_ci is true, a tuple of

    • +
    +

    +
    +

    See also

    +
    +
    statsmodels.stats.proportion.proportion_confint

    interval.

    +
    +
    +

    psychofit.mle_fit_psycho

    +
    +

    Notes

    +

    The psychofit starting parameters and model constraints used for the fit when computing the +training status (e.g. trained_1a, etc.) are sub-optimal and can produce a poor fit. To keep +the precise criteria the same for all subjects, these parameters have not changed. To produce a +better fit for plotting purposes, or to calculate the training status in a manner inconsistent +with the IBL training pipeline, use plotting=True.

    compute_median_reaction_time(trials, stim_on_type='stimOn_times', contrast=None, signed_contrast=None)[source]
    -

    Compute median reaction time on zero contrast trials from trials object

    +

    Compute median response time on zero contrast trials from trials object

    Parameters:
      -
    • trials (dict) – trials object that must contain response_times and stimOn_times

    • -
    • stim_on_type – feedback from which to compute the reaction time. Default is stimOn_times

    • +
    • trials (one.alf.io.AlfBunch) – An ALF trials object containing the keys {‘probabilityLeft’, ‘contrastLeft’, +‘contrastRight’, ‘feedbackType’, ‘choice’, ‘response_times’, ‘stimOn_times’}.

    • +
    • stim_on_type (str, default='stimOn_times') – The trials key to use when calculating the response times. The difference between this and +‘feedback_times’ is used (see notes).

    • +
    • contrast (float) – If None, the median response time is calculated for all trials, regardless of contrast, +otherwise only trials where the matching signed percent contrast was presented are used.

    • +
    • signed_contrast (numpy.array) – An array of signed contrasts in percent the length of trials, where left contrasts are -ve. +If None, these are computed from the trials object.

    +
    Returns:
    +

    The median response time for trials with contrast (returns NaN if no trials matching +contrast in trials object).

    +
    +
    Return type:
    +

    float

    +
    -

    i.e when stimulus is presented -:type stim_on_type: string (must be a valid key in trials object) -:param signed_contrast: array of signed contrasts in percent, where -ve values are on the left -:type signed_contrast: np.array -:return: float of median reaction time at zero contrast (returns nan if no zero contrast -trials in trials object)

    +

    Notes

    +
      +
    • The stim_on_type is ‘stimOn_times’ by default, however for IBL rig data, the photodiode is +sometimes not calibrated properly which can lead to inaccurate (or absent, i.e. NaN) stim on +times. Therefore, it is sometimes more accurate to use the ‘stimOnTrigger_times’ (the time of +the stimulus onset command), if available, or the ‘goCue_times’ (the time of the soundcard +output TTL when the audio go cue is played) or the ‘goCueTrigger_times’ (the time of the +audio go cue command).

    • +
    • The response/reaction time here is defined as the time between stim on and feedback, i.e. the +entire open-loop trial duration.

    • +
    compute_reaction_time(trials, stim_on_type='stimOn_times', stim_off_type='response_times', signed_contrast=None, block=None, compute_ci=False, alpha=0.32)[source]
    -

    Compute median reaction time for all contrasts

    +

    Compute median response time for all contrasts.

    Parameters:
      -
    • trials – trials object that must contain response_times and stimOn_times

    • -
    • stim_on_type

    • -
    • stim_off_type

    • -
    • signed_contrast

    • -
    • block

    • +
    • trials (one.alf.io.AlfBunch) – An ALF trials object containing the keys {‘probabilityLeft’, ‘contrastLeft’, +‘contrastRight’, ‘feedbackType’, ‘choice’, ‘response_times’, ‘stimOn_times’}.

    • +
    • stim_on_type (str, default='stimOn_times') – The trials key to use when calculating the response times. The difference between this and +stim_off_type is used (see notes).

    • +
    • stim_off_type (str, default='response_times') – The trials key to use when calculating the response times. The difference between this and +stim_on_type is used (see notes).

    • +
    • signed_contrast (numpy.array) – An array of signed contrasts in percent the length of trials, where left contrasts are -ve. +If None, these are computed from the trials object.

    • +
    • block (float) – The block type to compute. If None, all trials are included, otherwise only trials where +probabilityLeft matches this value are included. For biasedChoiceWorld, the +probabilityLeft set is {0.5, 0.2, 0.8}.

    • +
    • compute_ci (bool) – If true, computes and returns the confidence intervals for response time at each contrast.

    • +
    • alpha (float, default=0.32) – Significance level for confidence interval. Must be in (0, 1). If compute_ci is false, +this value is ignored.

    Returns:
    -

    +

      +
    • numpy.array – The median response times for each unique signed contrast.

    • +
    • numpy.array – The set of unique signed contrasts.

    • +
    • numpy.array – The number of trials for each unique signed contrast.

    • +
    • (numpy.array) – If compute_ci is true, an array of confidence intervals is return in the shape (n_trials, +2).

    • +
    +

    +

    Notes

    +
      +
    • The response/reaction time by default is the time between stim on and response, i.e. the +entire open-loop trial duration. One could use ‘stimOn_times’ and ‘firstMovement_times’ to +get the true reaction time, or ‘firstMovement_times’ and ‘response_times’ to get the true +response times, or calculate the last movement onset times and calculate the true movement +times. See module examples for how to calculate this.

    • +
    +
    +

    See also

    +

    scipy.stats.bootstrap

    +
    criterion_1a(psych, n_trials, perf_easy)[source]
    -

    Returns bool indicating whether criterion for trained_1a is met. All criteria documented here -(https://figshare.com/articles/preprint/A_standardized_and_reproducible_method_to_measure_ -decision-making_in_mice_Appendix_2_IBL_protocol_for_mice_training/11634729)

    +

    Returns bool indicating whether criteria for status ‘trained_1a’ are met.

    +
    +

    Criteria

    +
      +
    • Bias is less than 16

    • +
    • Threshold is less than 19

    • +
    • Lapse rate on both sides is less than 0.2

    • +
    • The total number of trials is greater than 200 for each session

    • +
    • Performance on easy contrasts > 80% for all sessions

    • +
    +
    +
    param psych:
    +

    The fit psychometric parameters three consecutive sessions. Parameters are bias, threshold, +lapse high, lapse low.

    +
    +
    type psych:
    +

    numpy.array

    +
    +
    param n_trials:
    +

    The number for trials for each session.

    +
    +
    type n_trials:
    +

    numpy.array of int

    +
    +
    param perf_easy:
    +

    The proportion of correct high contrast trials for each session.

    +
    +
    type perf_easy:
    +

    numpy.array of float

    +
    +
    returns:
    +

    True if the criteria are met for ‘trained_1a’.

    +
    +
    rtype:
    +

    bool

    +
    +
    +

    Notes

    +

    The parameter thresholds chosen here were originally determined by averaging the parameter fits +for a number of sessions determined to be of ‘good’ performance by an experimenter.

    +
    criterion_1b(psych, n_trials, perf_easy, rt)[source]
    -

    Returns bool indicating whether criterion for trained_1b is met.

    +

    Returns bool indicating whether criteria for trained_1b are met.

    +
    +

    Criteria

    +
      +
    • Bias is less than 10

    • +
    • Threshold is less than 20 (see notes)

    • +
    • Lapse rate on both sides is less than 0.1

    • +
    • The total number of trials is greater than 400 for each session

    • +
    • Performance on easy contrasts > 90% for all sessions

    • +
    • The median response time across all zero contrast trials is less than 2 seconds

    • +
    +
    +
    param psych:
    +

    The fit psychometric parameters three consecutive sessions. Parameters are bias, threshold, +lapse high, lapse low.

    +
    +
    type psych:
    +

    numpy.array

    +
    +
    param n_trials:
    +

    The number for trials for each session.

    +
    +
    type n_trials:
    +

    numpy.array of int

    +
    +
    param perf_easy:
    +

    The proportion of correct high contrast trials for each session.

    +
    +
    type perf_easy:
    +

    numpy.array of float

    +
    +
    param rt:
    +

    The median response time for zero contrast trials.

    +
    +
    type rt:
    +

    float

    +
    +
    returns:
    +

    True if the criteria are met for ‘trained_1b’.

    +
    +
    rtype:
    +

    bool

    +
    +
    +

    Notes

    +

    The parameter thresholds chosen here were originally chosen to be slightly stricter than 1a, +however it was decided to use round numbers so that readers would not assume a level of +precision that isn’t there (remember, these parameters were not chosen with any rigor). This +regrettably means that the maximum threshold fit for 1b is greater than for 1a, meaning the +slope of the psychometric curve may be slightly less steep than 1a.

    +
    criterion_ephys(psych_20, psych_80, n_trials, perf_easy, rt)[source]
    -

    Returns bool indicating whether criterion for ready4ephysrig or ready4recording is met.

    +

    Returns bool indicating whether criteria for ready4ephysrig or ready4recording are met.

    +

    NB: The difference between these two is whether the sessions were acquired ot a recording rig +with a delay before the first trial. Neither of these two things are tested here.

    +
    +

    Criteria

    +
      +
    • Lapse on both sides < 0.1 for both bias blocks

    • +
    • Bias shift between blocks > 5

    • +
    • Total number of trials > 400 for all sessions

    • +
    • Performance on easy contrasts > 90% for all sessions

    • +
    • Median response time for zero contrast stimuli < 2 seconds

    • +
    +
    +
    param psych_20:
    +

    The fit psychometric parameters for the blocks where probability of a left stimulus is 0.2. +Parameters are bias, threshold, lapse high, lapse low.

    +
    +
    type psych_20:
    +

    numpy.array

    +
    +
    param psych_80:
    +

    The fit psychometric parameters for the blocks where probability of a left stimulus is 0.8. +Parameters are bias, threshold, lapse high, lapse low.

    +
    +
    type psych_80:
    +

    numpy.array

    +
    +
    param n_trials:
    +

    The number of trials for each session (typically three consecutive sessions).

    +
    +
    type n_trials:
    +

    numpy.array

    +
    +
    param perf_easy:
    +

    The proportion of correct high contrast trials for each session (typically three +consecutive sessions).

    +
    +
    type perf_easy:
    +

    numpy.array

    +
    +
    param rt:
    +

    The median response time for zero contrast trials.

    +
    +
    type rt:
    +

    float

    +
    +
    returns:
    +

    True if subject passes the ready4ephysrig or ready4recording criteria.

    +
    +
    rtype:
    +

    bool

    +
    +
    +
    criterion_delay(n_trials, perf_easy)[source]
    -

    Returns bool indicating whether criterion for ready4delay is met.

    +

    Returns bool indicating whether criteria for ‘ready4delay’ is met.

    +
    +

    Criteria

    +
      +
    • Total number of trials for any of the sessions is greater than 400

    • +
    • Performance on easy contrasts is greater than 90% for any of the sessions

    • +
    +
    +
    param n_trials:
    +

    The number of trials for each session (typically three consecutive sessions).

    +
    +
    type n_trials:
    +

    numpy.array of int

    +
    +
    param perf_easy:
    +

    The proportion of correct high contrast trials for each session (typically three +consecutive sessions).

    +
    +
    type perf_easy:
    +

    numpy.array

    +
    +
    returns:
    +

    True if subject passes the ‘ready4delay’ criteria.

    +
    +
    rtype:
    +

    bool

    +
    +
    +
    -plot_psychometric(trials, ax=None, title=None, plot_ci=False, ci_aplha=0.32, **kwargs)[source]
    -

    Function to plot psychometric curve plots a la datajoint webpage

    +plot_psychometric(trials, ax=None, title=None, plot_ci=False, ci_alpha=0.032, **kwargs)[source] +

    Function to plot psychometric curve plots a la datajoint webpage.

    Parameters:
    -

    trials

    +
      +
    • trials (one.alf.io.AlfBunch) – An ALF trials object containing the keys {‘probabilityLeft’, ‘contrastLeft’, +‘contrastRight’, ‘feedbackType’, ‘choice’, ‘response_times’, ‘stimOn_times’}.

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • title (str) – An optional plot title.

    • +
    • plot_ci (bool) – If true, computes and plots the confidence intervals for response at each contrast.

    • +
    • ci_alpha (float, default=0.032) – Significance level for confidence interval. Must be in (0, 1). If plot_ci is false, +this value is ignored.

    • +
    • **kwargs – If ax is None, these arguments are passed to matplotlib.pyplot.subplots.

    • +
    Returns:
    -

    +

      +
    • matplotlib.pyplot.Figure – The figure handle containing the plot.

    • +
    • matplotlib.pyplot.Axes – The plotted axes.

    • +
    +

    +
    +
    +
    +

    See also

    +
    +
    statsmodels.stats.proportion.proportion_confint

    interval.

    +
    +
    +

    psychofit.mle_fit_psycho

    +
    +
    psychofit.erf_psycho_2gammas

    using the fit parameters.

    +
    plot_reaction_time(trials, ax=None, title=None, plot_ci=False, ci_alpha=0.32, **kwargs)[source]
    -

    Function to plot reaction time against contrast a la datajoint webpage (inverted for some reason??)

    +

    Function to plot reaction time against contrast a la datajoint webpage.

    +

    The reaction times are plotted individually for the following three blocks: {0.5, 0.2, 0.8}.

    Parameters:
    -

    trials

    +
      +
    • trials (one.alf.io.AlfBunch) – An ALF trials object containing the keys {‘probabilityLeft’, ‘contrastLeft’, +‘contrastRight’, ‘feedbackType’, ‘choice’, ‘response_times’, ‘stimOn_times’}.

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • title (str) – An optional plot title.

    • +
    • plot_ci (bool) – If true, computes and plots the confidence intervals for response at each contrast.

    • +
    • ci_alpha (float, default=0.32) – Significance level for confidence interval. Must be in (0, 1). If plot_ci is false, +this value is ignored.

    • +
    • **kwargs – If ax is None, these arguments are passed to matplotlib.pyplot.subplots.

    • +
    Returns:
    -

    +

      +
    • matplotlib.pyplot.Figure – The figure handle containing the plot.

    • +
    • matplotlib.pyplot.Axes – The plotted axes.

    • +
    +

    +
    +

    See also

    +

    scipy.stats.bootstrap

    +
    plot_reaction_time_over_trials(trials, stim_on_type='stimOn_times', ax=None, title=None, **kwargs)[source]
    -

    Function to plot reaction time with trial number a la datajoint webpage

    +

    Function to plot reaction time with trial number a la datajoint webpage.

    Parameters:
      -
    • trials

    • -
    • stim_on_type

    • -
    • ax

    • -
    • title

    • -
    • kwargs

    • +
    • trials (one.alf.io.AlfBunch) – An ALF trials object containing the keys {‘probabilityLeft’, ‘contrastLeft’, +‘contrastRight’, ‘feedbackType’, ‘choice’, ‘response_times’, ‘stimOn_times’}.

    • +
    • stim_on_type (str, default='stimOn_times') – The trials key to use when calculating the response times. The difference between this and +‘feedback_times’ is used (see notes for compute_median_reaction_time).

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • title (str) – An optional plot title.

    • +
    • **kwargs – If ax is None, these arguments are passed to matplotlib.pyplot.subplots.

    Returns:
    -

    +

      +
    • matplotlib.pyplot.Figure – The figure handle containing the plot.

    • +
    • matplotlib.pyplot.Axes – The plotted axes.

    • +
    +

    @@ -722,7 +1051,7 @@

    diff --git a/_autosummary/brainbox.behavior.wheel.html b/_autosummary/brainbox.behavior.wheel.html index 510f1fa3..e54864d7 100644 --- a/_autosummary/brainbox.behavior.wheel.html +++ b/_autosummary/brainbox.behavior.wheel.html @@ -25,7 +25,7 @@ - + @@ -108,6 +108,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • @@ -402,7 +403,7 @@
    diff --git a/_autosummary/brainbox.core.html b/_autosummary/brainbox.core.html index b32413d7..b87f559c 100644 --- a/_autosummary/brainbox.core.html +++ b/_autosummary/brainbox.core.html @@ -105,6 +105,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.ephys_plots.html b/_autosummary/brainbox.ephys_plots.html index 2d4238a2..8bf1d624 100644 --- a/_autosummary/brainbox.ephys_plots.html +++ b/_autosummary/brainbox.ephys_plots.html @@ -117,6 +117,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.html b/_autosummary/brainbox.html index 8301923c..7e5af8fe 100644 --- a/_autosummary/brainbox.html +++ b/_autosummary/brainbox.html @@ -102,6 +102,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.io.html b/_autosummary/brainbox.io.html index 9c517397..bab215c8 100644 --- a/_autosummary/brainbox.io.html +++ b/_autosummary/brainbox.io.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.io.one.html b/_autosummary/brainbox.io.one.html index f6b932bd..78d53f35 100644 --- a/_autosummary/brainbox.io.one.html +++ b/_autosummary/brainbox.io.one.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • @@ -234,7 +235,7 @@

  • channels – Bunch or dictionary of aligned channels containing at least keys ‘localCoordinates’

  • -
  • brain_regions

    None (default) or ibllib.atlas.BrainRegions object +

  • brain_regions

    None (default) or iblatlas.regions.BrainRegions object if None will return a dict with keys ‘localCoordinates’, ‘mlapdv’, ‘brainLocationIds_ccf_2017 if a brain region object is provided, outputts a dict with keys

    @@ -261,7 +262,7 @@
  • probe ([str, list of str]) – The probe label(s), e.g. ‘probe01’

  • one (one.api.OneAlyx) – An instance of ONE (shouldn’t be in ‘local’ mode)

  • aligned (bool) – Whether to get the latest user aligned channel when not resolved or use histology track

  • -
  • brain_atlas (ibllib.atlas.BrainAtlas) – Brain atlas object (default: Allen atlas)

  • +
  • brain_atlas (iblatlas.BrainAtlas) – Brain atlas object (default: Allen atlas)

  • Returns:
    @@ -297,7 +298,7 @@
  • dataset_types – additional spikes/clusters objects to add to the standard default list

  • spike_sorter – name of the spike sorting you want to load (None for default)

  • collection – name of the spike sorting collection to load - exclusive with spike sorter name ex: “alf/probe00”

  • -
  • brain_regions – ibllib.atlas.regions.BrainRegions object - will label acronyms if provided

  • +
  • brain_regions – iblatlas.regions.BrainRegions object - will label acronyms if provided

  • nested – if a single probe is required, do not output a dictionary with the probe name as key

  • return_collection – (False) if True, will return the collection used to load

  • @@ -329,7 +330,7 @@
  • probe – name of probe to load in, if not given all probes for session will be loaded

  • dataset_types – additional spikes/clusters objects to add to the standard default list

  • spike_sorter – name of the spike sorting you want to load (None for default)

  • -
  • brain_regions – ibllib.atlas.regions.BrainRegions object - will label acronyms if provided

  • +
  • brain_regions – iblatlas.regions.BrainRegions object - will label acronyms if provided

  • @@ -353,7 +354,7 @@
  • dataset_types (list of str) – Optional additional spikes/clusters objects to add to the standard default list

  • spike_sorter (str) – Name of the spike sorting you want to load (None for default which is pykilosort if it’s available otherwise the default MATLAB kilosort)

  • -
  • brain_atlas (ibllib.atlas.BrainAtlas) – Brain atlas object (default: Allen atlas)

  • +
  • brain_atlas (iblatlas.atlas.BrainAtlas) – Brain atlas object (default: Allen atlas)

  • return_collection (bool) – Returns an extra argument with the collection chosen

  • @@ -759,12 +760,19 @@
    -raster(spikes, channels, save_dir=None, br=None, label='raster', time_series=None)[source]
    +raster(spikes, channels, save_dir=None, br=None, label='raster', time_series=None, **kwargs)[source]
    Parameters:
      -
    • spikes – spikes dictionary

    • -
    • save_dir – optional if specified

    • +
    • spikes – spikes dictionary or Bunch

    • +
    • channels – channels dictionary or Bunch.

    • +
    • save_dir – if specified save to this directory as “{pid}_{probe}_{label}.png”. +Otherwise, plot.

    • +
    • br – brain regions object (optional)

    • +
    • label – label for saved image (optional, default=”raster”)

    • +
    • time_series – timeseries dictionary for behavioral event times (optional)

    • +
    • **kwargs

      kwargs passed to driftmap() (optional)

      +

    Returns:
    diff --git a/_autosummary/brainbox.io.spikeglx.html b/_autosummary/brainbox.io.spikeglx.html index 91f8a6e0..a5f28763 100644 --- a/_autosummary/brainbox.io.spikeglx.html +++ b/_autosummary/brainbox.io.spikeglx.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.lfp.html b/_autosummary/brainbox.lfp.html index bb1529a4..d9c24082 100644 --- a/_autosummary/brainbox.lfp.html +++ b/_autosummary/brainbox.lfp.html @@ -107,6 +107,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.metrics.electrode_drift.html b/_autosummary/brainbox.metrics.electrode_drift.html index edc83e19..46e478cc 100644 --- a/_autosummary/brainbox.metrics.electrode_drift.html +++ b/_autosummary/brainbox.metrics.electrode_drift.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.metrics.html b/_autosummary/brainbox.metrics.html index b361dc59..378a4c6e 100644 --- a/_autosummary/brainbox.metrics.html +++ b/_autosummary/brainbox.metrics.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.metrics.single_units.html b/_autosummary/brainbox.metrics.single_units.html index 420d7043..70d20cc8 100644 --- a/_autosummary/brainbox.metrics.single_units.html +++ b/_autosummary/brainbox.metrics.single_units.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.plot.html b/_autosummary/brainbox.plot.html index a68aff2f..aa81e0f0 100644 --- a/_autosummary/brainbox.plot.html +++ b/_autosummary/brainbox.plot.html @@ -113,6 +113,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.plot_base.html b/_autosummary/brainbox.plot_base.html index c02a1618..82de6eae 100644 --- a/_autosummary/brainbox.plot_base.html +++ b/_autosummary/brainbox.plot_base.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.population.cca.html b/_autosummary/brainbox.population.cca.html index 5b2d4a2a..0313ab6a 100644 --- a/_autosummary/brainbox.population.cca.html +++ b/_autosummary/brainbox.population.cca.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.population.decode.html b/_autosummary/brainbox.population.decode.html index e4b0a5bb..6eeccfab 100644 --- a/_autosummary/brainbox.population.decode.html +++ b/_autosummary/brainbox.population.decode.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.population.html b/_autosummary/brainbox.population.html index d6b1455a..c42955e0 100644 --- a/_autosummary/brainbox.population.html +++ b/_autosummary/brainbox.population.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.processing.html b/_autosummary/brainbox.processing.html index 27f2441a..18fbdc61 100644 --- a/_autosummary/brainbox.processing.html +++ b/_autosummary/brainbox.processing.html @@ -110,6 +110,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.quality.html b/_autosummary/brainbox.quality.html index 28fa9569..800eba56 100644 --- a/_autosummary/brainbox.quality.html +++ b/_autosummary/brainbox.quality.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.quality.lfp_qc.html b/_autosummary/brainbox.quality.lfp_qc.html index a6cf1813..4dea3a68 100644 --- a/_autosummary/brainbox.quality.lfp_qc.html +++ b/_autosummary/brainbox.quality.lfp_qc.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.quality.permutation_test.html b/_autosummary/brainbox.quality.permutation_test.html index 7a839f3c..65bcc284 100644 --- a/_autosummary/brainbox.quality.permutation_test.html +++ b/_autosummary/brainbox.quality.permutation_test.html @@ -106,6 +106,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.singlecell.html b/_autosummary/brainbox.singlecell.html index 34500892..d61fc924 100644 --- a/_autosummary/brainbox.singlecell.html +++ b/_autosummary/brainbox.singlecell.html @@ -109,6 +109,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.spike_features.html b/_autosummary/brainbox.spike_features.html index 45f2001b..dbcf909e 100644 --- a/_autosummary/brainbox.spike_features.html +++ b/_autosummary/brainbox.spike_features.html @@ -105,6 +105,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.task.closed_loop.html b/_autosummary/brainbox.task.closed_loop.html index 84cbc4d2..b92201ea 100644 --- a/_autosummary/brainbox.task.closed_loop.html +++ b/_autosummary/brainbox.task.closed_loop.html @@ -107,6 +107,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.task.html b/_autosummary/brainbox.task.html index 7df9eb10..7214a154 100644 --- a/_autosummary/brainbox.task.html +++ b/_autosummary/brainbox.task.html @@ -107,6 +107,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.task.passive.html b/_autosummary/brainbox.task.passive.html index 8162cd1c..542992ed 100644 --- a/_autosummary/brainbox.task.passive.html +++ b/_autosummary/brainbox.task.passive.html @@ -107,6 +107,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.task.trials.html b/_autosummary/brainbox.task.trials.html index 3c6b0717..23a1b03a 100644 --- a/_autosummary/brainbox.task.trials.html +++ b/_autosummary/brainbox.task.trials.html @@ -107,6 +107,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.html b/_autosummary/brainbox.tests.html index 3f43c10e..9c00a20f 100644 --- a/_autosummary/brainbox.tests.html +++ b/_autosummary/brainbox.tests.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_behavior.html b/_autosummary/brainbox.tests.test_behavior.html index a8d9e86a..7963907c 100644 --- a/_autosummary/brainbox.tests.test_behavior.html +++ b/_autosummary/brainbox.tests.test_behavior.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_cca.html b/_autosummary/brainbox.tests.test_cca.html index 09d26fd3..bcff5463 100644 --- a/_autosummary/brainbox.tests.test_cca.html +++ b/_autosummary/brainbox.tests.test_cca.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_io.html b/_autosummary/brainbox.tests.test_io.html index 00282828..18855807 100644 --- a/_autosummary/brainbox.tests.test_io.html +++ b/_autosummary/brainbox.tests.test_io.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_metrics.html b/_autosummary/brainbox.tests.test_metrics.html index 6bcc5b7e..310855be 100644 --- a/_autosummary/brainbox.tests.test_metrics.html +++ b/_autosummary/brainbox.tests.test_metrics.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_passive.html b/_autosummary/brainbox.tests.test_passive.html index 97a5d2e3..94ada2e0 100644 --- a/_autosummary/brainbox.tests.test_passive.html +++ b/_autosummary/brainbox.tests.test_passive.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_plot_base.html b/_autosummary/brainbox.tests.test_plot_base.html index 8a0b7e41..019afc07 100644 --- a/_autosummary/brainbox.tests.test_plot_base.html +++ b/_autosummary/brainbox.tests.test_plot_base.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_population.html b/_autosummary/brainbox.tests.test_population.html index 0d5724aa..79291afa 100644 --- a/_autosummary/brainbox.tests.test_population.html +++ b/_autosummary/brainbox.tests.test_population.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_processing.html b/_autosummary/brainbox.tests.test_processing.html index 809cf37b..632f8b28 100644 --- a/_autosummary/brainbox.tests.test_processing.html +++ b/_autosummary/brainbox.tests.test_processing.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_singlecell.html b/_autosummary/brainbox.tests.test_singlecell.html index 04f60805..4eb01636 100644 --- a/_autosummary/brainbox.tests.test_singlecell.html +++ b/_autosummary/brainbox.tests.test_singlecell.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_task.html b/_autosummary/brainbox.tests.test_task.html index d73cfc52..9d1990a6 100644 --- a/_autosummary/brainbox.tests.test_task.html +++ b/_autosummary/brainbox.tests.test_task.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_trials.html b/_autosummary/brainbox.tests.test_trials.html index 69a9c426..f4ee6307 100644 --- a/_autosummary/brainbox.tests.test_trials.html +++ b/_autosummary/brainbox.tests.test_trials.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.tests.test_video.html b/_autosummary/brainbox.tests.test_video.html index 911dd358..a1c825ad 100644 --- a/_autosummary/brainbox.tests.test_video.html +++ b/_autosummary/brainbox.tests.test_video.html @@ -116,6 +116,7 @@
  • brainbox.video
  • +
  • iblatlas
  • Index
  • diff --git a/_autosummary/brainbox.video.html b/_autosummary/brainbox.video.html index 5e1f447b..4c006362 100644 --- a/_autosummary/brainbox.video.html +++ b/_autosummary/brainbox.video.html @@ -24,7 +24,7 @@ - + @@ -107,6 +107,7 @@ +
  • iblatlas
  • Index
  • @@ -225,7 +226,7 @@

    diff --git a/_autosummary/iblatlas.atlas.ALLEN_CCF_LANDMARKS_MLAPDV_UM.html b/_autosummary/iblatlas.atlas.ALLEN_CCF_LANDMARKS_MLAPDV_UM.html new file mode 100644 index 00000000..814533ef --- /dev/null +++ b/_autosummary/iblatlas.atlas.ALLEN_CCF_LANDMARKS_MLAPDV_UM.html @@ -0,0 +1,195 @@ + + + + + + + iblatlas.atlas.ALLEN_CCF_LANDMARKS_MLAPDV_UM — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.atlas.ALLEN_CCF_LANDMARKS_MLAPDV_UM

    +
    +
    +ALLEN_CCF_LANDMARKS_MLAPDV_UM = {'bregma': array([5739, 5400,  332])}
    +

    The ML AP DV voxel coordinates of brain landmarks in the Allen atlas.

    +
    +
    Type:
    +

    dict

    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.atlas.PAXINOS_CCF_LANDMARKS_MLAPDV_UM.html b/_autosummary/iblatlas.atlas.PAXINOS_CCF_LANDMARKS_MLAPDV_UM.html new file mode 100644 index 00000000..808ea022 --- /dev/null +++ b/_autosummary/iblatlas.atlas.PAXINOS_CCF_LANDMARKS_MLAPDV_UM.html @@ -0,0 +1,195 @@ + + + + + + + iblatlas.atlas.PAXINOS_CCF_LANDMARKS_MLAPDV_UM — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.atlas.PAXINOS_CCF_LANDMARKS_MLAPDV_UM

    +
    +
    +PAXINOS_CCF_LANDMARKS_MLAPDV_UM = {'bregma': array([5700, 4460,  330])}
    +

    The ML AP DV voxel coordinates of brain landmarks in the Franklin & Paxinos atlas.

    +
    +
    Type:
    +

    dict

    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.atlas.S3_BUCKET_IBL.html b/_autosummary/iblatlas.atlas.S3_BUCKET_IBL.html new file mode 100644 index 00000000..d163a1b1 --- /dev/null +++ b/_autosummary/iblatlas.atlas.S3_BUCKET_IBL.html @@ -0,0 +1,195 @@ + + + + + + + iblatlas.atlas.S3_BUCKET_IBL — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.atlas.S3_BUCKET_IBL

    +
    +
    +S3_BUCKET_IBL = 'ibl-brain-wide-map-public'
    +

    The name of the public IBL S3 bucket containing atlas data.

    +
    +
    Type:
    +

    str

    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.atlas.html b/_autosummary/iblatlas.atlas.html new file mode 100644 index 00000000..827a8490 --- /dev/null +++ b/_autosummary/iblatlas.atlas.html @@ -0,0 +1,1427 @@ + + + + + + + iblatlas.atlas — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.atlas

    +

    Classes for manipulating brain atlases, insertions, and coordinates.

    +

    Module attributes

    + + + + + + + + + + + + +

    ALLEN_CCF_LANDMARKS_MLAPDV_UM

    The ML AP DV voxel coordinates of brain landmarks in the Allen atlas.

    PAXINOS_CCF_LANDMARKS_MLAPDV_UM

    The ML AP DV voxel coordinates of brain landmarks in the Franklin & Paxinos atlas.

    S3_BUCKET_IBL

    The name of the public IBL S3 bucket containing atlas data.

    +

    Functions

    + + + + + + + + + + + + + + + +

    MRITorontoAtlas

    The MRI Toronto brain atlas.

    NeedlesAtlas

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution using the IBL Bregma and coordinate system.

    cart2sph

    Converts cartesian to spherical coordinates.

    sph2cart

    Converts Spherical to Cartesian coordinates.

    +

    Classes

    + + + + + + + + + + + + + + + + + + + + + +

    AllenAtlas

    The Allan Common Coordinate Framework (CCF) brain atlas.

    BrainAtlas

    Objects that holds image, labels and coordinate transforms for a brain Atlas.

    BrainCoordinates

    Class for mapping and indexing a 3D array to real-world coordinates.

    FranklinPaxinosAtlas

    pathlib.PurePosixPath: The default relative path of the atlas file.

    Insertion

    Defines an ephys probe insertion in 3D coordinate.

    Trajectory

    3D Trajectory (usually for a linear probe), minimally defined by a vector and a point.

    +
    +
    +ALLEN_CCF_LANDMARKS_MLAPDV_UM = {'bregma': array([5739, 5400,  332])}
    +

    The ML AP DV voxel coordinates of brain landmarks in the Allen atlas.

    +
    +
    Type:
    +

    dict

    +
    +
    +
    + +
    +
    +PAXINOS_CCF_LANDMARKS_MLAPDV_UM = {'bregma': array([5700, 4460,  330])}
    +

    The ML AP DV voxel coordinates of brain landmarks in the Franklin & Paxinos atlas.

    +
    +
    Type:
    +

    dict

    +
    +
    +
    + +
    +
    +S3_BUCKET_IBL = 'ibl-brain-wide-map-public'
    +

    The name of the public IBL S3 bucket containing atlas data.

    +
    +
    Type:
    +

    str

    +
    +
    +
    + +
    +
    +cart2sph(x, y, z)[source]
    +

    Converts cartesian to spherical coordinates.

    +

    Returns spherical coordinates (r, theta, phi).

    +
    +
    Parameters:
    +
      +
    • x (numpy.array) – A 1D array of x-axis coordinates.

    • +
    • y (numpy.array) – A 1D array of y-axis coordinates.

    • +
    • z (numpy.array) – A 1D array of z-axis coordinates.

    • +
    +
    +
    Returns:
    +

      +
    • numpy.array – The radial distance of each point.

    • +
    • numpy.array – The polar angle.

    • +
    • numpy.array – The azimuthal angle.

    • +
    +

    +
    +
    +
    +

    See also

    +

    sph2cart

    +
    +
    + +
    +
    +sph2cart(r, theta, phi)[source]
    +

    Converts Spherical to Cartesian coordinates.

    +

    Returns Cartesian coordinates (x, y, z).

    +
    +
    Parameters:
    +
      +
    • r (numpy.array) – A 1D array of radial distances.

    • +
    • theta (numpy.array) – A 1D array of polar angles.

    • +
    • phi (numpy.array) – A 1D array of azimuthal angles.

    • +
    +
    +
    Returns:
    +

      +
    • x (numpy.array) – A 1D array of x-axis coordinates.

    • +
    • y (numpy.array) – A 1D array of y-axis coordinates.

    • +
    • z (numpy.array) – A 1D array of z-axis coordinates.

    • +
    +

    +
    +
    +
    +

    See also

    +

    cart2sph

    +
    +
    + +
    +
    +class BrainCoordinates(nxyz, xyz0=(0, 0, 0), dxyz=(1, 1, 1))[source]
    +

    Bases: object

    +

    Class for mapping and indexing a 3D array to real-world coordinates.

    +
      +
    • x = ml, right positive

    • +
    • y = ap, anterior positive

    • +
    • z = dv, dorsal positive

    • +
    +

    The layout of the Atlas dimension is done according to the most used sections so they lay +contiguous on disk assuming C-ordering: V[iap, iml, idv]

    +
    +
    Parameters:
    +
      +
    • nxyz (array_like) – Number of elements along each Cartesian axis (nx, ny, nz) = (nml, nap, ndv).

    • +
    • xyz0 (array_like) – Coordinates of the element volume[0, 0, 0] in the coordinate space.

    • +
    • dxyz (array_like, float) – Spatial interval of the volume along the 3 dimensions.

    • +
    +
    +
    +
    +
    +xyz0
    +

    The Cartesian coordinates of the element volume[0, 0, 0], i.e. the origin.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +x0
    +

    The x-axis origin coordinate of the element volume.

    +
    +
    Type:
    +

    int

    +
    +
    +
    + +
    +
    +y0
    +

    The y-axis origin coordinate of the element volume.

    +
    +
    Type:
    +

    int

    +
    +
    +
    + +
    +
    +z0
    +

    The z-axis origin coordinate of the element volume.

    +
    +
    Type:
    +

    int

    +
    +
    +
    + +
    +
    +property dxyz
    +

    Spatial interval of the volume along the 3 dimensions.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +property nxyz
    +

    Coordinates of the element volume[0, 0, 0] in the coordinate space.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +r2ix(r)[source]
    +
    + +
    +
    +r2iy(r)[source]
    +
    + +
    +
    +r2iz(r)[source]
    +
    + +
    +
    +x2i(x, round=True, mode='raise')[source]
    +

    Find the nearest volume image index to a given x-axis coordinate.

    +
    +
    Parameters:
    +
      +
    • x (float, numpy.array) – One or more x-axis coordinates, relative to the origin, x0.

    • +
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • +
    • mode ({'raise', 'clip', 'wrap'}, default='raise') – How to behave if the coordinate lies outside of the volume: raise (default) will raise +a ValueError; ‘clip’ will replace the index with the closest index inside the volume; +‘wrap’ will return the index as is.

    • +
    +
    +
    Returns:
    +

    The nearest indices of the image volume along the first dimension.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    Raises:
    +

    ValueError – At least one x value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to + keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    +
    +
    +
    + +
    +
    +y2i(y, round=True, mode='raise')[source]
    +

    Find the nearest volume image index to a given y-axis coordinate.

    +
    +
    Parameters:
    +
      +
    • y (float, numpy.array) – One or more y-axis coordinates, relative to the origin, y0.

    • +
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • +
    • mode ({'raise', 'clip', 'wrap'}) – How to behave if the coordinate lies outside of the volume: raise (default) will raise +a ValueError; ‘clip’ will replace the index with the closest index inside the volume; +‘wrap’ will return the index as is.

    • +
    +
    +
    Returns:
    +

    The nearest indices of the image volume along the second dimension.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    Raises:
    +

    ValueError – At least one y value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to + keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    +
    +
    +
    + +
    +
    +z2i(z, round=True, mode='raise')[source]
    +

    Find the nearest volume image index to a given z-axis coordinate.

    +
    +
    Parameters:
    +
      +
    • z (float, numpy.array) – One or more z-axis coordinates, relative to the origin, z0.

    • +
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • +
    • mode ({'raise', 'clip', 'wrap'}) – How to behave if the coordinate lies outside of the volume: raise (default) will raise +a ValueError; ‘clip’ will replace the index with the closest index inside the volume; +‘wrap’ will return the index as is.

    • +
    +
    +
    Returns:
    +

    The nearest indices of the image volume along the third dimension.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    Raises:
    +

    ValueError – At least one z value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to + keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    +
    +
    +
    + +
    +
    +xyz2i(xyz, round=True, mode='raise')[source]
    +

    Find the nearest volume image indices to the given Cartesian coordinates.

    +
    +
    Parameters:
    +
      +
    • xyz (array_like) – One or more Cartesian coordinates, relative to the origin, xyz0.

    • +
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • +
    • mode ({'raise', 'clip', 'wrap'}) – How to behave if any coordinate lies outside of the volume: raise (default) will raise +a ValueError; ‘clip’ will replace the index with the closest index inside the volume; +‘wrap’ will return the index as is.

    • +
    +
    +
    Returns:
    +

    The nearest indices of the image volume.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    Raises:
    +

    ValueError – At least one coordinate lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ + to keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    +
    +
    +
    + +
    +
    +i2x(ind)[source]
    +

    Return the x-axis coordinate of a given index.

    +
    +
    Parameters:
    +

    ind (int, numpy.array) – One or more indices along the first dimension of the image volume.

    +
    +
    Returns:
    +

    The corresponding x-axis coordinate(s), relative to the origin, x0.

    +
    +
    Return type:
    +

    float, numpy.array

    +
    +
    +
    + +
    +
    +i2y(ind)[source]
    +

    Return the y-axis coordinate of a given index.

    +
    +
    Parameters:
    +

    ind (int, numpy.array) – One or more indices along the second dimension of the image volume.

    +
    +
    Returns:
    +

    The corresponding y-axis coordinate(s), relative to the origin, y0.

    +
    +
    Return type:
    +

    float, numpy.array

    +
    +
    +
    + +
    +
    +i2z(ind)[source]
    +

    Return the z-axis coordinate of a given index.

    +
    +
    Parameters:
    +

    ind (int, numpy.array) – One or more indices along the third dimension of the image volume.

    +
    +
    Returns:
    +

    The corresponding z-axis coordinate(s), relative to the origin, z0.

    +
    +
    Return type:
    +

    float, numpy.array

    +
    +
    +
    + +
    +
    +i2xyz(iii)[source]
    +

    Return the Cartesian coordinates of a given index.

    +
    +
    Parameters:
    +

    iii (array_like) – One or more image volume indices.

    +
    +
    Returns:
    +

    The corresponding xyz coordinates, relative to the origin, xyz0.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +property xlim
    +
    + +
    +
    +property ylim
    +
    + +
    +
    +property zlim
    +
    + +
    +
    +lim(axis)[source]
    +
    + +
    +
    +property xscale
    +
    + +
    +
    +property yscale
    +
    + +
    +
    +property zscale
    +
    + +
    +
    +property mgrid
    +
    + +
    + +
    +
    +class BrainAtlas(image, label, dxyz, regions, iorigin=[0, 0, 0], dims2xyz=[0, 1, 2], xyz2dims=[0, 1, 2])[source]
    +

    Bases: object

    +

    Objects that holds image, labels and coordinate transforms for a brain Atlas. +Currently this is designed for the AllenCCF at several resolutions, +yet this class can be used for other atlases arises.

    +
    +
    +image = None
    +

    An annotation label volume.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +label = None
    +
    + +
    +
    +compute_surface()[source]
    +

    Get the volume top, bottom, left and right surfaces, and from these the outer surface of +the image volume. This is needed to compute probe insertions intersections.

    +

    NOTE: In places where the top or bottom surface touch the top or bottom of the atlas volume, the surface +will be set to np.nan. If you encounter issues working with these surfaces check if this might be the cause.

    +
    + +
    +
    +get_labels(xyz, mapping=None, radius_um=None, mode='raise')[source]
    +

    Performs a 3D lookup from real world coordinates to the volume labels +and return the regions ids according to the mapping

    +
    +
    Parameters:
    +
      +
    • xyz – [n, 3] array of coordinates

    • +
    • mapping – brain region mapping (defaults to original Allen mapping)

    • +
    • radius_um – if not null, returns a regions ids array and an array of proportion +of regions in a sphere of size radius around the coordinates.

    • +
    • mode – {‘raise’, ‘clip’} determines what to do when determined index lies outside the atlas volume

    • +
    +
    +
    +

    ‘raise’ will raise a ValueError (default) +‘clip’ will replace the index with the closest index inside the volume +:return: n array of region ids

    +
    + +
    +
    +tilted_slice(xyz, axis, volume='image')[source]
    +

    From line coordinates, extracts the tilted plane containing the line from the 3D volume

    +
    +
    Parameters:
    +

    xyz – np.array: points defining a probe trajectory in 3D space (xyz triplets)

    +
    +
    +

    if more than 2 points are provided will take the best fit +:param axis:

    +
    +

    0: along ml = sagittal-slice +1: along ap = coronal-slice +2: along dv = horizontal-slice

    +
    +
    +
    Parameters:
    +

    volume – ‘image’ or ‘annotation’

    +
    +
    Returns:
    +

    np.array, abscissa extent (width), ordinate extent (height),

    +
    +
    +

    squeezed axis extent (depth)

    +
    + +
    +
    +plot_tilted_slice(xyz, axis, volume='image', cmap=None, ax=None, return_sec=False, **kwargs)[source]
    +

    From line coordinates, extracts the tilted plane containing the line from the 3D volume

    +
    +
    Parameters:
    +

    xyz – np.array: points defining a probe trajectory in 3D space (xyz triplets)

    +
    +
    +

    if more than 2 points are provided will take the best fit +:param axis:

    +
    +

    0: along ml = sagittal-slice +1: along ap = coronal-slice +2: along dv = horizontal-slice

    +
    +
    +
    Parameters:
    +

    volume – ‘image’ or ‘annotation’

    +
    +
    Returns:
    +

    matplotlib axis

    +
    +
    +
    + +
    +
    +extent(axis)[source]
    +
    +
    Parameters:
    +

    axis – direction along which the volume is stacked: +(2 = z for horizontal slice) +(1 = y for coronal slice) +(0 = x for sagittal slice)

    +
    +
    Returns:
    +

    +
    +
    +
    + +
    +
    +slice(coordinate, axis, volume='image', mode='raise', region_values=None, mapping=None, bc=None)[source]
    +

    Get slice through atlas

    +
    +
    Parameters:
    +
      +
    • coordinate – coordinate to slice in metres, float

    • +
    • axis – xyz convention: 0 for ml, 1 for ap, 2 for dv +- 0: sagittal slice (along ml axis) +- 1: coronal slice (along ap axis) +- 2: horizontal slice (along dv axis)

    • +
    • volume

        +
      • ‘image’ - allen image volume

      • +
      • ’annotation’ - allen annotation volume

      • +
      • ’surface’ - outer surface of mesh

      • +
      • ’boundary’ - outline of boundaries between all regions

      • +
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • +
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • +
      +

    • +
    • mode – error mode for out of bounds coordinates +- ‘raise’ raise an error +- ‘clip’ gets the first or last index

    • +
    • region_values – custom values to plot +- if volume=’volume’, region_values must have shape ba.image.shape +- if volume=’value’, region_values must have shape ba.regions.id

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    +
    +
    Returns:
    +

    2d array or 3d RGB numpy int8 array

    +
    +
    +
    + +
    +
    +compute_boundaries(values)[source]
    +

    Compute the boundaries between regions on slice

    +
    +
    Parameters:
    +

    values

    +
    +
    Returns:
    +

    +
    +
    +
    + +
    +
    +plot_slices(xyz, *args, **kwargs)[source]
    +

    From a single coordinate, plots the 3 slices that intersect at this point in a single +matplotlib figure

    +
    +
    Parameters:
    +
      +
    • xyz – mlapdv coordinate in m

    • +
    • args – arguments to be forwarded to plot slices

    • +
    • kwargs – keyword arguments to be forwarded to plot slices

    • +
    +
    +
    Returns:
    +

    2 by 2 array of axes

    +
    +
    +
    + +
    +
    +plot_cslice(ap_coordinate, volume='image', mapping=None, region_values=None, **kwargs)[source]
    +

    Plot coronal slice through atlas at given ap_coordinate

    +
    +
    Param:
    +

    ap_coordinate (m)

    +
    +
    Parameters:
    +
      +
    • volume

        +
      • ‘image’ - allen image volume

      • +
      • ’annotation’ - allen annotation volume

      • +
      • ’surface’ - outer surface of mesh

      • +
      • ’boundary’ - outline of boundaries between all regions

      • +
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • +
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • +
      +

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • region_values – custom values to plot +- if volume=’volume’, region_values must have shape ba.image.shape +- if volume=’value’, region_values must have shape ba.regions.id

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • **kwargs

      matplotlib.pyplot.imshow kwarg arguments

      +

    • +
    +
    +
    Returns:
    +

    matplotlib ax object

    +
    +
    +
    + +
    +
    +plot_hslice(dv_coordinate, volume='image', mapping=None, region_values=None, **kwargs)[source]
    +

    Plot horizontal slice through atlas at given dv_coordinate

    +
    +
    Param:
    +

    dv_coordinate (m)

    +
    +
    Parameters:
    +
      +
    • volume

        +
      • ‘image’ - allen image volume

      • +
      • ’annotation’ - allen annotation volume

      • +
      • ’surface’ - outer surface of mesh

      • +
      • ’boundary’ - outline of boundaries between all regions

      • +
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • +
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • +
      +

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • region_values – custom values to plot +- if volume=’volume’, region_values must have shape ba.image.shape +- if volume=’value’, region_values must have shape ba.regions.id

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • **kwargs

      matplotlib.pyplot.imshow kwarg arguments

      +

    • +
    +
    +
    Returns:
    +

    matplotlib ax object

    +
    +
    +
    + +
    +
    +plot_sslice(ml_coordinate, volume='image', mapping=None, region_values=None, **kwargs)[source]
    +

    Plot sagittal slice through atlas at given ml_coordinate

    +
    +
    Param:
    +

    ml_coordinate (m)

    +
    +
    Parameters:
    +
      +
    • volume

        +
      • ‘image’ - allen image volume

      • +
      • ’annotation’ - allen annotation volume

      • +
      • ’surface’ - outer surface of mesh

      • +
      • ’boundary’ - outline of boundaries between all regions

      • +
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • +
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • +
      +

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • region_values – custom values to plot +- if volume=’volume’, region_values must have shape ba.image.shape +- if volume=’value’, region_values must have shape ba.regions.id

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • **kwargs

      matplotlib.pyplot.imshow kwarg arguments

      +

    • +
    +
    +
    Returns:
    +

    matplotlib ax object

    +
    +
    +
    + +
    +
    +plot_top(volume='annotation', mapping=None, region_values=None, ax=None, **kwargs)[source]
    +

    Plot top view of atlas

    +
    +
    Parameters:
    +
      +
    • volume

        +
      • ‘image’ - allen image volume

      • +
      • ’annotation’ - allen annotation volume

      • +
      • ’boundary’ - outline of boundaries between all regions

      • +
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • +
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • +
      +

    • +
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • +
    • region_values

    • +
    • ax

    • +
    • kwargs

    • +
    +
    +
    Returns:
    +

    +
    +
    +
    + +
    + +
    +
    +class Trajectory(vector: ndarray, point: ndarray)[source]
    +

    Bases: object

    +

    3D Trajectory (usually for a linear probe), minimally defined by a vector and a point.

    +

    Examples

    +

    Instantiate from a best fit from an n by 3 array containing xyz coordinates:

    +
    >>> trj = Trajectory.fit(xyz)
    +
    +
    +
    +
    +vector: ndarray
    +
    + +
    +
    +point: ndarray
    +
    + +
    +
    +static fit(xyz)[source]
    +

    Fits a line to a 3D cloud of points.

    +
    +
    Parameters:
    +

    xyz (numpy.array) – An n by 3 array containing a cloud of points to fit a line to.

    +
    +
    Returns:
    +

    A new trajectory object.

    +
    +
    Return type:
    +

    Trajectory

    +
    +
    +
    + +
    +
    +eval_x(x)[source]
    +

    given an array of x coordinates, returns the xyz array of coordinates along the insertion

    +
    +
    Parameters:
    +

    x – n by 1 or numpy array containing x-coordinates

    +
    +
    Returns:
    +

    n by 3 numpy array containing xyz-coordinates

    +
    +
    +
    + +
    +
    +eval_y(y)[source]
    +

    given an array of y coordinates, returns the xyz array of coordinates along the insertion

    +
    +
    Parameters:
    +

    y – n by 1 or numpy array containing y-coordinates

    +
    +
    Returns:
    +

    n by 3 numpy array containing xyz-coordinates

    +
    +
    +
    + +
    +
    +eval_z(z)[source]
    +

    given an array of z coordinates, returns the xyz array of coordinates along the insertion

    +
    +
    Parameters:
    +

    z – n by 1 or numpy array containing z-coordinates

    +
    +
    Returns:
    +

    n by 3 numpy array containing xyz-coordinates

    +
    +
    +
    + +
    +
    +project(point)[source]
    +

    projects a point onto the trajectory line

    +
    +
    Parameters:
    +

    point – np.array(x, y, z) coordinates

    +
    +
    Returns:
    +

    +
    +
    +
    + +
    +
    +mindist(xyz, bounds=None)[source]
    +

    Computes the minimum distance to the trajectory line for one or a set of points. +If bounds are provided, computes the minimum distance to the segment instead of an +infinite line.

    +
    +
    Parameters:
    +
      +
    • xyz – […, 3]

    • +
    • bounds – defaults to None. np.array [2, 3]: segment boundaries, inf line if None

    • +
    +
    +
    Returns:
    +

    minimum distance […]

    +
    +
    +
    + +
    +
    +exit_points(bc)[source]
    +

    Given a Trajectory and a BrainCoordinates object, computes the intersection of the +trajectory with the brain coordinates bounding box

    +
    +
    Parameters:
    +

    bc – BrainCoordinate objects

    +
    +
    Returns:
    +

    np.ndarray 2 y 3 corresponding to exit points xyz coordinates

    +
    +
    +
    + +
    + +
    +
    +class Insertion(x: float, y: float, z: float, phi: float, theta: float, depth: float, label: str = '', beta: float = 0)[source]
    +

    Bases: object

    +

    Defines an ephys probe insertion in 3D coordinate. IBL conventions.

    +

    To instantiate, use the static methods: Insertion.from_track and Insertion.from_dict.

    +
    +
    +x: float
    +
    + +
    +
    +y: float
    +
    + +
    +
    +z: float
    +
    + +
    +
    +phi: float
    +
    + +
    +
    +theta: float
    +
    + +
    +
    +depth: float
    +
    + +
    +
    +label: str = ''
    +
    + +
    +
    +beta: float = 0
    +
    + +
    +
    +static from_track(xyzs, brain_atlas=None)[source]
    +

    Define an insersion from one or more trajectory.

    +
    +
    Parameters:
    +
      +
    • xyzs (numpy.array) – An n by 3 array xyz coordinates representing an insertion trajectory.

    • +
    • brain_atlas (BrainAtlas) – A brain atlas instance, used to attain the point of entry.

    • +
    +
    +
    Return type:
    +

    Insertion

    +
    +
    +
    + +
    +
    +static from_dict(d, brain_atlas=None)[source]
    +

    Constructs an Insertion object from the json information stored in probes.description file.

    +
    +
    Parameters:
    +
      +
    • d (dict) – A dictionary containing at least the following keys {‘x’, ‘y’, ‘z’, ‘phi’, ‘theta’, +‘depth’}. The depth and xyz coordinates must be in um.

    • +
    • brain_atlas (BrainAtlas, default=None) – If provided, disregards the z coordinate and locks the insertion point to the z of the +brain surface.

    • +
    +
    +
    Return type:
    +

    Insertion

    +
    +
    +

    Examples

    +
    >>> tri = {'x': 544.0, 'y': 1285.0, 'z': 0.0, 'phi': 0.0, 'theta': 5.0, 'depth': 4501.0}
    +>>> ins = Insertion.from_dict(tri)
    +
    +
    +
    + +
    +
    +property trajectory
    +

    Gets the trajectory object matching insertion coordinates +:return: atlas.Trajectory

    +
    + +
    +
    +property xyz
    +
    + +
    +
    +property entry
    +
    + +
    +
    +property tip
    +
    + +
    +
    +static get_brain_exit(traj, brain_atlas)[source]
    +

    Given a Trajectory and a BrainAtlas object, computes the brain exit coordinate as the +intersection of the trajectory and the brain surface (brain_atlas.surface)

    +
    +
    Parameters:
    +

    brain_atlas

    +
    +
    Returns:
    +

    3 element array x,y,z

    +
    +
    +
    + +
    +
    +static get_brain_entry(traj, brain_atlas)[source]
    +

    Given a Trajectory and a BrainAtlas object, computes the brain entry coordinate as the +intersection of the trajectory and the brain surface (brain_atlas.surface)

    +
    +
    Parameters:
    +

    brain_atlas

    +
    +
    Returns:
    +

    3 element array x,y,z

    +
    +
    +
    + +
    + +
    +
    +class AllenAtlas(res_um=25, scaling=(1, 1, 1), mock=False, hist_path=None)[source]
    +

    Bases: BrainAtlas

    +

    The Allan Common Coordinate Framework (CCF) brain atlas.

    +

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution +using the IBL Bregma and coordinate system.

    +
    +
    +atlas_rel_path = PurePosixPath('histology/ATLAS/Needles/Allen')
    +

    A diffusion weighted imaging (DWI) image volume.

    +

    The Allen atlas DWI average template volume has with the shape (ap, ml, dv) and contains uint16 +values. FIXME What do the values represent?

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +image = None
    +

    An annotation label volume.

    +

    The Allen atlas label volume has with the shape (ap, ml, dv) and contains uint16 indices +of the Allen CCF brain regions to which each voxel belongs.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +label = None
    +
    + +
    +
    +xyz2ccf(xyz, ccf_order='mlapdv', mode='raise')[source]
    +

    Converts anatomical coordinates to CCF coordinates.

    +

    Anatomical coordinates are in meters, relative to bregma, which CFF coordinates are +assumed to be the volume indices multiplied by the spacing in micormeters.

    +
    +
    Parameters:
    +
      +
    • xyz (numpy.array) – An N by 3 array of anatomical coordinates in meters, relative to bregma.

    • +
    • ccf_order ({'mlapdv', 'apdvml'}, default='mlapdv') – The order of the CCF coordinates returned. For IBL (the default) this is (ML, AP, DV), +for Allen MCC vertices, this is (AP, DV, ML).

    • +
    • mode ({'raise', 'clip', 'wrap'}, default='raise') – How to behave if the coordinate lies outside of the volume: raise (default) will raise +a ValueError; ‘clip’ will replace the index with the closest index inside the volume; +‘wrap’ will return the index as is.

    • +
    +
    +
    Returns:
    +

      +
    • numpy.array – Coordinates in CCF space (um, origin is the front left top corner of the data

    • +
    • volume, order determined by ccf_order

    • +
    +

    +
    +
    +
    + +
    +
    +ccf2xyz(ccf, ccf_order='mlapdv')[source]
    +

    Convert anatomical coordinates from CCF coordinates.

    +

    Anatomical coordinates are in meters, relative to bregma, which CFF coordinates are +assumed to be the volume indices multiplied by the spacing in micormeters.

    +
    +
    Parameters:
    +
      +
    • ccf (numpy.array) – An N by 3 array of coordinates in CCF space (atlas volume indices * um resolution). The +origin is the front left top corner of the data volume.

    • +
    • ccf_order ({'mlapdv', 'apdvml'}, default='mlapdv') – The order of the CCF coordinates given. For IBL (the default) this is (ML, AP, DV), +for Allen MCC vertices, this is (AP, DV, ML).

    • +
    +
    +
    Returns:
    +

    The MLAPDV coordinates in meters, relative to bregma.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +compute_regions_volume(cumsum=False)[source]
    +

    Sums the number of voxels in the labels volume for each region. +Then compute volumes for all of the levels of hierarchy in cubic mm.

    +
    +
    Param:
    +

    cumsum: computes the cumulative sum of the volume as per the hierarchy (defaults to False)

    +
    +
    Returns:
    +

    +
    +
    +
    + +
    + +
    +
    +NeedlesAtlas(*args, **kwargs)[source]
    +

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution +using the IBL Bregma and coordinate system. The Needles atlas defines a stretch along AP +axis and a squeeze along the DV axis.

    +
    +
    Parameters:
    +
      +
    • res_um ({10, 25, 50} int) – The Atlas resolution in micrometres; one of 10, 25 or 50um.

    • +
    • **kwargs – See AllenAtlas.

    • +
    +
    +
    Returns:
    +

    An Allen atlas object with MRI atlas scaling applied.

    +
    +
    Return type:
    +

    AllenAtlas

    +
    +
    +

    Notes

    +

    The scaling was determined by manually transforming the DSURQE atlas [1]_ onto the Allen CCF. +The DSURQE atlas is an MRI atlas acquired from 40 C57BL/6J mice post-mortem, with 40um +isometric resolution. The alignment was performed by Mayo Faulkner. +The atlas data can be found here. +More information on the dataset and segmentation can be found +here.

    +

    References

    + +
    + +
    +
    +MRITorontoAtlas(*args, **kwargs)[source]
    +

    The MRI Toronto brain atlas.

    +

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution +using the IBL Bregma and coordinate system. The MRI Toronto atlas defines a stretch along AP +a squeeze along DV and a squeeze along ML. These are based on 12 p65 mice MRIs averaged [1]_.

    +
    +
    Parameters:
    +
      +
    • res_um ({10, 25, 50} int) – The Atlas resolution in micrometres; one of 10, 25 or 50um.

    • +
    • **kwargs – See AllenAtlas.

    • +
    +
    +
    Returns:
    +

    An Allen atlas object with MRI atlas scaling applied.

    +
    +
    Return type:
    +

    AllenAtlas

    +
    +
    +

    References

    + +
    + +
    +
    +class FranklinPaxinosAtlas(res_um=(10, 100, 10), scaling=(1, 1, 1), mock=False, hist_path=None)[source]
    +

    Bases: BrainAtlas

    +

    pathlib.PurePosixPath: The default relative path of the atlas file.

    +
    +
    +atlas_rel_path = PurePosixPath('histology/ATLAS/Needles/FranklinPaxinos')
    +
    + +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.flatmaps.html b/_autosummary/iblatlas.flatmaps.html new file mode 100644 index 00000000..d0e11843 --- /dev/null +++ b/_autosummary/iblatlas.flatmaps.html @@ -0,0 +1,307 @@ + + + + + + + iblatlas.flatmaps — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.flatmaps

    +

    Techniques to project the brain volume onto 2D images for visualisation purposes.

    +

    Functions

    + + + + + + + + + + + + +

    circles

    +
    param N:
    +

    number of circles

    +
    +
    +

    swanson

    FIXME Document! Which publication to reference? Are these specifically for flat maps?

    swanson_json

    Vectorized version of the swanson bitmap file.

    +

    Classes

    + + + + + + +

    FlatMap

    The Allen Atlas flatmap.

    +
    +
    +class FlatMap(flatmap='dorsal_cortex', res_um=25)[source]
    +

    Bases: AllenAtlas

    +

    The Allen Atlas flatmap.

    +
    +
    FIXME Document! How are these flatmaps determined? Are they related to the Swansan atlas or is

    that something else?

    +
    +
    +
    +
    +plot_flatmap(depth=0, volume='annotation', mapping='Allen', region_values=None, ax=None, **kwargs)[source]
    +

    Displays the 2D image corresponding to the flatmap.

    +

    If there are several depths, by default it will display the first one.

    +
    +
    Parameters:
    +
      +
    • depth (int) – Index of the depth to display in the flatmap volume (the last dimension).

    • +
    • volume ({'image', 'annotation', 'boundary', 'value'}) –

        +
      • ‘image’ - Allen image volume.

      • +
      • ’annotation’ - Allen annotation volume.

      • +
      • ’boundary’ - outline of boundaries between all regions.

      • +
      • +
        ’volume’ - custom volume, must pass in volume of shape BrainAtlas.image.shape as

        regions_value argument.

        +
        +
        +
      • +
      +

    • +
    • mapping (str, default='Allen') – The brain region mapping to use.

    • +
    • region_values (numpy.array) – An array the shape of the brain atlas image containing custom region values. Used when +volume value is ‘volume’.

    • +
    • ax (matplotlib.pyplot.Axes, optional) – A set of axes to plot to.

    • +
    • **kwargs – See matplotlib.pyplot.imshow.

    • +
    +
    +
    Returns:
    +

    The plotted image axes.

    +
    +
    Return type:
    +

    matplotlib.pyplot.Axes

    +
    +
    +
    + +
    +
    +extent_flmap()[source]
    +

    Returns the boundary coordinates of the flat map.

    +
    +
    Returns:
    +

    The bounding coordinates of the flat map image, specified as (left, right, bottom, top).

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    +
    + +
    + +
    +
    +circles(N=5, atlas=None, display='flat')[source]
    +
    +
    Parameters:
    +
      +
    • N – number of circles

    • +
    • atlas – brain atlas at 25 m

    • +
    • display – “flat” or “pyramid”

    • +
    +
    +
    Returns:
    +

    2D map of indices, ap_coordinate, ml_coordinate

    +
    +
    +
    + +
    +
    +swanson(filename='swanson2allen.npz')[source]
    +
    +
    FIXME Document! Which publication to reference? Are these specifically for flat maps?

    Shouldn’t this be made into an Atlas class with a mapping or scaling applied?

    +
    +
    +
    +
    Parameters:
    +

    filename

    +
    +
    +
    + +
    +
    +swanson_json(filename='swansonpaths.json', remap=True)[source]
    +

    Vectorized version of the swanson bitmap file. The vectorized version was generated from swanson() using matlab +contour to find the paths for each region. The paths for each region were then simplified using the +Ramer Douglas Peucker algorithm https://rdp.readthedocs.io/en/latest/

    +
    +
    Parameters:
    +
      +
    • filename

    • +
    • remap

    • +
    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.genes.html b/_autosummary/iblatlas.genes.html new file mode 100644 index 00000000..e0d55f98 --- /dev/null +++ b/_autosummary/iblatlas.genes.html @@ -0,0 +1,196 @@ + + + + + + + iblatlas.genes — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.genes

    +

    Gene expression maps.

    +

    Functions

    + + + + + + +

    allen_gene_expression

    Reads in the Allen gene expression experiments binary data.

    +
    +
    +allen_gene_expression(filename='gene-expression.pqt', folder_cache=None)[source]
    +

    Reads in the Allen gene expression experiments binary data.

    +
    +
    Parameters:
    +
      +
    • filename

    • +
    • folder_cache

    • +
    +
    +
    Returns:
    +

    a dataframe of experiments, where each record corresponds to a single gene expression

    +
    +
    +

    and a memmap of all experiments volumes, size (4345, 58, 41, 67) corresponding to +(nexperiments, ml, dv, ap). The spacing between slices is 200 um

    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.html b/_autosummary/iblatlas.html new file mode 100644 index 00000000..0dc2dc1a --- /dev/null +++ b/_autosummary/iblatlas.html @@ -0,0 +1,411 @@ + + + + + + + iblatlas — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas

    +

    A package for working with brain atlases.

    +

    For examples and tutorials on using the IBL atlas package, see +https://docs.internationalbrainlab.org/atlas_examples.html

    +

    Much of this was adapted from the cortexlab allenCCF repository.

    +
    +

    Terminology

    +

    There are many terms used somewhat incoherently within this API and the community at large. Below +are some definitions of the most common terms.

    +
      +
    • Atlas - A set of serial sections along different anatomical planes of a brain where each relevant brain structure is +assigned a number of coordinates to define its outline or volume. An atlas essentially comprises a set of images, annotations, +and a coordinate system.

    • +
    • Annotation - A set of identifiers assigned to different atlas regions.

    • +
    • Mapping - A function that maps one ordered list of brain region IDs to another, allowing one to control annotation +granularity and brain region hierarchy, or to translate brain region names from one atlas to another. The default mapping is +identity.

    • +
    • Coordinate framework - The way in which an atlas translates image coordinates (e.g. Cartesian or sperical coordinates) to +real-world anatomical coordinates in (typically physical distance from a given landmark such as bregma, along three axes, +ML-AP-DV).

    • +
    • Reference space - The coordinate system and annotations used by a given atlas. It is sometimes useful to compare anatomy +between atlases, which requires expressing one atlas in another’s reference space.

    • +
    • Structure tree - The hirarchy of brain regions, handled by the BrainRegions class.

    • +
    • Scaling - Atlases typically comprise images averaged over a number of brains. Scaling allows one to account for any +consistent and measurable imgaging or tissue distortion, or to better align to an individual brain of a specific size. The +default scaling is identity.

    • +
    • Flat map - An annotated projection of the 3D brain to 2D.

    • +
    • Slice - A 2D section of a brain atlas volume. Typically these are coronal (cut along the medio-lateral axis), sagittal +(along the dorso-ventral axis) or transverse a.k.a. axial, horizontal (along the rostro-caudal a.k.a. anterio-posterior axis).

    • +
    +
    +
    +

    Atlases

    +

    There are two principal mouse brain atlases in this module:

    +
      +
    1. The Allen Common Coordinate Framework (CCF) [1].

    2. +
    3. The Mouse Brain in Stereotaxic Coordinates (MBSC) 4th Edition, by Paxinos G, and Franklin KBJ [2], matched to +to the Allen Common Coordiante Framework by Chon et al. [3].

    4. +
    +

    The latter is referred to here as the ‘Franklin-Paxinos atlas’. These atlases comprise a 3D array of voxels and their associated +brain region identifiers (labels) at a given resolution. The Allen Atlas can be instantiated in 10um, 25um or 50um resolution. +The Franklin-Paxinos atlas has a resolution of 10um in the ML and DV axis, and 100um in the AP axis. TODO Mention flat maps.

    +
    +
    +

    Scalings

    +

    Additionally there are two further atlases that apply some form of scaling to the Allen CCF atlas +to account for distortion that occurs during the imaging and tissue fixation process:

    +
      +
    1. The Needles atlas - 40 C57BL/6J (p84) mice underwnt MRI imaging post-mortem while the brain was still in the skull, followed by +conventional Nissl histology [4]. These mouse brain atlas images combined with segmentation (known as DSURQE) were manually +transformed onto the Allen CCF atlas to determine the scaling.

    2. +
    3. The MRI Toronto - 12 p65 mice MRI images were taken in vivo then averaged and transformed on the Allen CCF atlas to determine +the scaling [5].

    4. +
    +

    All scaling is currently linear. Scaling of this kind can be applied arbitrarily to better represent a specific mouse age and +sex [5]. NB: In addition to distortions, the Allen CFF atlas is pitched down by about 5 degrees relative to a flat skull (where +bregma and lambda are at the same DV height) [6], however this is not currently accounted for.

    +
    +
    +

    Mappings

    +

    In addition to the atlases there are also multiple brain region mappings that serve one of two purposes: 1. control the +granularity particular brain regions; 2. support differing anatomical sub-devisions or nomenclature. The two Allen atlas mappings +below were created somewhat arbirarily by Nick Steinmetz to aid in analysis:

    +
      +
    1. Beryl - brain atlas annotations without layer sub-divisions or certain ganglial/nucleus sub-devisisions (e.g. the core/shell +sub-division of the lateral geniculate nucleus). Fibre tracts, pia, etc. are also absent. The choice of which areas to combine +was guided partially by the computed volume of each area. This mapping is used in the brainwide map and prior papers [7], [8] +.

    2. +
    3. Cosmos - coarse brain atlas annotations, dividing the atlas into 10 broad areas: isocortex, olfactory areas, cortical subplate, +cerebral nuclei, thalamus, hypothalamus, midbrain, hindbrain, cerebellum and hippocampal formation.

    4. +
    +

    The names of these two mappings appear to be without meaning.

    +

    Non-Allen mappings:

    +
      +
    1. Swanson - the brain atlas annotations from the Swansan rat brain flat map [9], mapped to the Allen atlas manually by Olivier +Winter. See Fixtures for details.

    2. +
    +

    Each mapping includes both a lateralized (suffix ‘-lr’) and non-laterized version. The lateralized mappings assign a different ID +to structures in the right side of the brain. The Allen atlas IDs are kept intact but lateralized as follows: labels are +duplicated and IDs multiplied by -1, with the understanding that left hemisphere regions have negative IDs. There is currently no +mapping between Franklin & Paxinos and the Allen atlases.

    +

    Notes

    +

    The Allen atlas and the CCF annotations have different release dates and versions [10]. The annotations used by IBL are the 2017 +version.

    +

    The IBL uses the following conventions:

    +
      +
    • All atlas images have dimensions (AP, ML, DV). With C-ordering this makes coronal slicing most efficient. The origin is the top +left corner of the image.

    • +
    • Coordinates are provided in the order (ML AP DV) and are in meters relative to bregma.

    • +
    • Left hemisphere ML coordinates are -ve; right, +ve.

    • +
    • AP coordinates anterior to bregma are +ve; posterior, -ve.

    • +
    • DV coordinates ventral to bregma are -ve; ventral +ve.

    • +
    • Bregma was determined by asking five experimentalists to pick the voxel containing bregma on the Allen atlas and taking the +average. NB: The midline appears slightly off-center in the Allen atlas image volume.

    • +
    • All left hemisphere regions have negative region IDs in all lateralized mappings.

    • +
    +

    Examples

    +

    Below are some breif API examples. For in depth tutorials on using the IBL atlas package, see +https://docs.internationalbrainlab.org/atlas_examples.html.

    +

    Find bregma position in indices * resolution in um

    +
    >>> ba = AllenAtlas()
    +>>> bregma_index = ALLEN_CCF_LANDMARKS_MLAPDV_UM['bregma'] / ba.res_um
    +
    +
    +

    Find bregma position in xyz in m (expect this to be 0 0 0)

    +
    >>> bregma_xyz = ba.bc.i2xyz(bregma_index)
    +
    +
    +
    +
    +

    Fixtures

    +
    +

    Local files

    +
      +
    • allen_structure_tree.csv - TODO Document. Where does this come from? Is it modified from either structure_tree_safe.csv or +structure_tree_safe_2017.csv?

    • +
    • franklin_paxinos_structure_tree.csv - Obtained from Supplementary Data 2 in reference [10].

    • +
    • beryl.npy - A 306 x 1 int32 array of Allen CCF brain region IDs generated in MATLAB [*]. See more information see +Mappings.

    • +
    • cosmos.npy - A 10 x 1 int32 array of Allen CCF brain region IDs generated in MATLAB []. See more information see +Mappings.

    • +
    • swanson_regions.npy - A 1D array of length 323 containing the Allen CCF brain region IDs

    • +
    • mappings.pqt - A table of mappings. Each column defines a mapping, with the ‘-lr’ suffix indicating a lateralized version. +The rows contain the correspondence of each mapping to the int64 index of the lateralized Allen structure tree. The table is +generated by iblatlas.regions.BrainRegions._compute_mappings.

    • +
    +
    +
    +

    Remote files

    +
      +
    • annotation_<res_um>.nrrd - A 3D volume containing indicies of the regions in the associated +structure tree. res_um indicates the isometric spacing in microns. These uint16 indicies are +known as the region ‘index’ in the structure tree, i.e. the position of the region in the +flattened tree.

    • +
    • average_template_<res_um>.nrrd - TODO Document

    • +
    • annotation_<res_um>_lut_<LUT_VERSION>.npz - TODO Document

    • +
    • FranklinPaxinons/annotation_<res_um>.npz - A 3D volume containing indices of the regions associated with the Franklin- +Paxinos structure tree.

    • +
    • FranklinPaxinons/average_template_<res_um>.npz - A 3D volume containing the Allen dwi image slices corresponding to +the slices in the annotation volume [*] .

    • +
    • swansonpaths.json - The paths of a vectorized Swanson flatmap image [*]. The vectorized version was generated +from the Swanson bitmap image using the matlab contour function to find the paths for each region. The paths for each +region were then simplified using the Ramer Douglas Peucker algorithm

    • +
    • swanson2allen.npz - TODO Document who made this, its contents, purpose and data type

    • +
    • <flatmap_name>_<res_um>.nrrd - TODO Document who made this, its contents, purpose and data type

    • +
    • gene-expression.pqt - TODO Document who made this, its contents, purpose and data type

    • +
    • gene-expression.bin - TODO Document who made this, its contents, purpose and data type.

    • +
    + +

    References

    + +
    +
    + + + + + + + + + + + + + + + + + + +

    iblatlas.atlas

    Classes for manipulating brain atlases, insertions, and coordinates.

    iblatlas.flatmaps

    Techniques to project the brain volume onto 2D images for visualisation purposes.

    iblatlas.genes

    Gene expression maps.

    iblatlas.plots

    Module that has convenience plotting functions for 2D atlas slices and flatmaps.

    iblatlas.regions

    Brain region mappings.

    +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.plots.html b/_autosummary/iblatlas.plots.html new file mode 100644 index 00000000..2aceec4e --- /dev/null +++ b/_autosummary/iblatlas.plots.html @@ -0,0 +1,635 @@ + + + + + + + iblatlas.plots — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.plots

    +

    Module that has convenience plotting functions for 2D atlas slices and flatmaps.

    +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    annotate_swanson

    Display annotations on a Swanson flatmap.

    compute_volume_from_points

    Creates a 3D volume with xyz points placed in corresponding voxel in volume.

    coords_for_poly_hole

    Function to convert

    get_bc_10

    Get BrainCoordinates object for 10um Allen Atlas

    load_slice_files

    Function to load in set of vectorised atlas slices for a given atlas axis and mapping.

    plot_points_on_slice

    Plot xyz points on slice.

    plot_polygon

    Function to plot matplotlib polygon on an axis

    plot_polygon_with_hole

    Function to plot matplotlib polygon that contains a hole on an axis

    plot_scalar_on_barplot

    Function to plot scalar value per allen region on a bar plot.

    plot_scalar_on_flatmap

    Function to plot scalar value per allen region on flatmap slice

    plot_scalar_on_slice

    Function to plot scalar value per region on histology slice.

    plot_swanson

    Displays the 2D image corresponding to the swanson flatmap.

    plot_swanson_vector

    Function to plot scalar value per allen region on the swanson projection.

    plot_volume_on_slice

    Plot slice through a volume

    prepare_lr_data

    Prepare data in format needed for plotting when providing different region values per hemisphere

    reorder_data

    Reorder list of acronyms and values to match the Allen ordering.

    +
    +
    +get_bc_10()[source]
    +

    Get BrainCoordinates object for 10um Allen Atlas

    +
    +
    Return type:
    +

    BrainCoordinates object

    +
    +
    +
    + +
    +
    +plot_polygon(ax, xy, color, reg_id, edgecolor='k', linewidth=0.3, alpha=1)[source]
    +

    Function to plot matplotlib polygon on an axis

    +
    +
    Parameters:
    +
      +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • xy (numpy.array) – 2D array of x and y coordinates of vertices of polygon

    • +
    • color (str, tuple of int) – The color to fill the polygon

    • +
    • reg_id (str, int) – An id to assign to the polygon

    • +
    • edgecolor (str, tuple of int) – The color of the edge of the polgon

    • +
    • linewidth (int) – The width of the edges of the polygon

    • +
    • alpha (float between 0 and 1) – The opacitiy of the polygon

    • +
    +
    +
    +
    + +
    +
    +plot_polygon_with_hole(ax, vertices, codes, color, reg_id, edgecolor='k', linewidth=0.3, alpha=1)[source]
    +

    Function to plot matplotlib polygon that contains a hole on an axis

    +
    +
    Parameters:
    +
      +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • vertices (numpy.array) – 2D array of x and y coordinates of vertices of polygon

    • +
    • codes (numpy.array) – 1D array of path codes used to link the vertices +(https://matplotlib.org/stable/tutorials/advanced/path_tutorial.html)

    • +
    • color (str, tuple of int) – The color to fill the polygon

    • +
    • reg_id (str, int) – An id to assign to the polygon

    • +
    • edgecolor (str, tuple of int) – The color of the edge of the polgon

    • +
    • linewidth (int) – The width of the edges of the polygon

    • +
    • alpha (float between 0 and 1) – The opacitiy of the polygon

    • +
    +
    +
    +
    + +
    +
    +coords_for_poly_hole(coords)[source]
    +

    Function to convert

    +
    +
    Parameters:
    +

    coords (dict) – Dictionary containing keys x, y and invert. x and y contain numpy.array of x coordinates, y coordinates +for the vertices of the polgyon. The invert key is either 1 or -1 and deterimine how to assign the paths. +The value for invert for each polygon was assigned manually after looking at the result

    +
    +
    Returns:
    +

    +

    +
    +
    +
    + +
    +
    +prepare_lr_data(acronyms_lh, values_lh, acronyms_rh, values_rh)[source]
    +

    Prepare data in format needed for plotting when providing different region values per hemisphere

    +
    +
    Parameters:
    +
      +
    • acronyms_lh – array of acronyms on left hemisphere

    • +
    • values_lh – values for each acronym on left hemisphere

    • +
    • acronyms_rh – array of acronyms on right hemisphere

    • +
    • values_rh – values for each acronym on left hemisphere

    • +
    +
    +
    Returns:
    +

    combined acronyms and two column array of values

    +
    +
    +
    + +
    +
    +reorder_data(acronyms, values, brain_regions=None)[source]
    +

    Reorder list of acronyms and values to match the Allen ordering.

    +

    TODO Document more

    +
    +
    Parameters:
    +
      +
    • acronyms (array_like of str) – The acronyms to match the Allen ordering, whatever that means.

    • +
    • values (array_like) – An array of some sort of values I guess…

    • +
    • brain_regions (iblatlas.regions.BrainRegions) – A brain regions object.

    • +
    +
    +
    Returns:
    +

      +
    • numpy.array of str – An ordered array of acronyms

    • +
    • numpy.array – An ordered array of values. I don’t know what those values are, not IDs, so maybe indices?

    • +
    +

    +
    +
    +
    + +
    +
    +load_slice_files(slice, mapping)[source]
    +

    Function to load in set of vectorised atlas slices for a given atlas axis and mapping.

    +

    If the data does not exist locally, it will download the files automatically stored in a AWS S3 +bucket.

    +
    +
    Parameters:
    +
      +
    • slice ({'coronal', 'sagittal', 'horizontal', 'top'}) – The axis of the atlas to load.

    • +
    • mapping ({'Allen', 'Beryl', 'Cosmos'}) – The mapping to load.

    • +
    +
    +
    Returns:
    +

    slice_data – A json containing the vertices to draw each region for each slice in the Allen annotation volume.

    +
    +
    Return type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +plot_scalar_on_slice(regions, values, coord=-1000, slice='coronal', mapping=None, hemisphere='left', background='image', cmap='viridis', clevels=None, show_cbar=False, empty_color='silver', brain_atlas=None, ax=None, vector=False, slice_files=None, **kwargs)[source]
    +

    Function to plot scalar value per region on histology slice.

    +
    +
    Parameters:
    +
      +
    • regions (array_like) – An array of brain region acronyms.

    • +
    • values (numpy.array) – An array of scalar value per acronym. If hemisphere is ‘both’ and different values want to +be shown on each hemisphere, values should contain 2 columns, 1st column for LH values, 2nd +column for RH values.

    • +
    • coord (float) – Coordinate of slice in um (not needed when slice=’top’).

    • +
    • slice ({'coronal', 'sagittal', 'horizontal', 'top'}, default='coronal') – Orientation of slice.

    • +
    • mapping (str, optional) – Atlas mapping to use, options are depend on atlas used (see iblatlas.regions.BrainRegions). +If None, the atlas default mapping is used.

    • +
    • hemisphere ({'left', 'right', 'both'}, default='left') – The hemisphere to display.

    • +
    • background ({image', 'boundary'}, default='image') – Background slice to overlay onto, options are ‘image’ or ‘boundary’. If vector is false, +this argument is ignored.

    • +
    • cmap (str, default='viridis') – Colormap to use.

    • +
    • clevels (array_like) – The min and max color levels to use.

    • +
    • show_cbar (bool, default=False) – Whether to display a colorbar.

    • +
    • empty_color (str, default='silver') – Color to use for regions without any values (only used when vector is true).

    • +
    • brain_atlas (iblatlas.atlas.AllenAtlas) – A brain atlas object.

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • vector (bool, default=False) – Whether to show as bitmap or vector graphic.

    • +
    • slice_files (numpy.array) – The set of vectorised slices for this slice, obtained using load_slice_files(slice, mapping).

    • +
    • **kwargs – Set of kwargs passed into matplotlib.patches.Polygon, e.g. linewidth=2, edgecolor=’None’ +(only used when vector = True).

    • +
    +
    +
    Returns:
    +

      +
    • fig (matplotlib.figure.Figure) – The plotted figure.

    • +
    • ax (matplotlib.pyplot.Axes) – The plotted axes.

    • +
    • cbar (matplotlib.pyplot.colorbar, optional) – matplotlib colorbar object, only returned if show_cbar=True.

    • +
    +

    +
    +
    +
    + +
    +
    +plot_scalar_on_flatmap(regions, values, depth=0, flatmap='dorsal_cortex', mapping='Allen', hemisphere='left', background='boundary', cmap='viridis', clevels=None, show_cbar=False, flmap_atlas=None, ax=None)[source]
    +

    Function to plot scalar value per allen region on flatmap slice

    +
    +
    Parameters:
    +
      +
    • regions – array of acronyms of Allen regions

    • +
    • values – array of scalar value per acronym. If hemisphere is ‘both’ and different values want to be shown on each

    • +
    +
    +
    +

    hemispheres, values should contain 2 columns, 1st column for LH values, 2nd column for RH values +:param depth: depth in flatmap in um +:param flatmap: name of flatmap (currently only option is ‘dorsal_cortex’) +:param mapping: atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’ +:param hemisphere: hemisphere to display, options are ‘left’, ‘right’, ‘both’ +:param background: background slice to overlay onto, options are ‘image’ or ‘boundary’ +:param cmap: colormap to use +:param clevels: min max color levels [cmin, cmax] +:param show_cbar: whether to add colorbar to axis +:param flmap_atlas: FlatMap object +:param ax: optional axis object to plot on +:return:

    +
    + +
    +
    +plot_volume_on_slice(volume, coord=-1000, slice='coronal', mapping='Allen', background='boundary', cmap='Reds', clevels=None, show_cbar=False, brain_atlas=None, ax=None)[source]
    +

    Plot slice through a volume

    +
    +
    Parameters:
    +
      +
    • volume – 3D array of volume (must be same shape as brain_atlas object)

    • +
    • coord – coordinate of slice in um

    • +
    • slice – orientation of slice, options are ‘coronal’, ‘sagittal’, ‘horizontal’

    • +
    • mapping – atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’

    • +
    • background – background slice to overlay onto, options are ‘image’ or ‘boundary’

    • +
    • cmap – colormap to use

    • +
    • clevels – min max color levels [cmin, cmax]

    • +
    • show_cbar – whether to add colorbar to axis

    • +
    • brain_atlas – AllenAtlas object

    • +
    • ax – optional axis object to plot on

    • +
    +
    +
    Returns:
    +

    +
    +
    +
    + +
    +
    +plot_points_on_slice(xyz, values=None, coord=-1000, slice='coronal', mapping='Allen', background='boundary', cmap='Reds', clevels=None, show_cbar=False, aggr='mean', fwhm=100, brain_atlas=None, ax=None)[source]
    +

    Plot xyz points on slice. Points that lie in the same voxel within slice are aggregated according to method specified. +A 3D Gaussian smoothing kernel with distance specified by fwhm is applied to images.

    +
    +
    Parameters:
    +
      +
    • xyz – 3 column array of xyz coordinates of points in metres

    • +
    • values – array of values per xyz coordinates, if no values are given the sum of xyz points in each voxel is

    • +
    +
    +
    +

    returned +:param coord: coordinate of slice in um (not needed when slice=’top’) +:param slice: orientation of slice, options are ‘coronal’, ‘sagittal’, ‘horizontal’, ‘top’ (top view of brain) +:param mapping: atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’ +:param background: background slice to overlay onto, options are ‘image’ or ‘boundary’ +:param cmap: colormap to use +:param clevels: min max color levels [cmin, cmax] +:param show_cbar: whether to add colorbar to axis +:param aggr: aggregation method. Options are sum, count, mean, std, median, min and max. +Can also give in custom function (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic.html) +:param fwhm: fwhm distance of gaussian kernel in um +:param brain_atlas: AllenAtlas object +:param ax: optional axis object to plot on

    +
    +
    Returns:
    +

    +
    +
    +
    + +
    +
    +compute_volume_from_points(xyz, values=None, aggr='sum', fwhm=100, ba=None)[source]
    +

    Creates a 3D volume with xyz points placed in corresponding voxel in volume. Points that fall into the same voxel within the +volume are aggregated according to the method specified in aggr. Gaussian smoothing with a 3D kernel with distance specified +by fwhm (full width half max) argument is applied. If fwhm = 0, no gaussian smoothing is applied.

    +
    +
    Parameters:
    +
      +
    • xyz – 3 column array of xyz coordinates of points in metres

    • +
    • values – 1 column array of values per xyz coordinates, if no values are given the sum of xyz points in each voxel is

    • +
    +
    +
    +

    returned +:param aggr: aggregation method. Options are sum, count, mean, std, median, min and max. Can also give in custom function +(https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic.html) +:param fwhm: full width at half maximum of gaussian kernel in um +:param ba: AllenAtlas object +:return:

    +
    + +
    +
    +plot_scalar_on_barplot(acronyms, values, errors=None, order=True, ax=None, brain_regions=None)[source]
    +

    Function to plot scalar value per allen region on a bar plot. If order=True, the acronyms and values are reordered +according to the order defined in the Allen structure tree

    +
    +
    Parameters:
    +
      +
    • acronyms (numpy.array) – A 1D array of acronyms

    • +
    • values (numpy.array) – A 1D array of values corresponding to each acronym in the acronyms array

    • +
    • errors (numpy.array) – A 1D array of error values corresponding to each acronym in the acronyms array

    • +
    • order (bool, default=True) – Whether to order the acronyms according to the order defined by the Allen structure tree

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • brain_regions (iblatlas.regions.BrainRegions) – A brain regions object

    • +
    +
    +
    Returns:
    +

      +
    • fig (matplotlib.figure.Figure) – The plotted figure

    • +
    • ax (matplotlib.pyplot.Axes) – The plotted axes.

    • +
    +

    +
    +
    +
    + +
    +
    +plot_swanson_vector(acronyms=None, values=None, ax=None, hemisphere=None, br=None, orientation='landscape', empty_color='silver', vmin=None, vmax=None, cmap='viridis', annotate=False, annotate_n=10, annotate_order='top', annotate_list=None, mask=None, mask_color='w', fontsize=10, **kwargs)[source]
    +

    Function to plot scalar value per allen region on the swanson projection. Plots on a vecortised version of the +swanson projection

    +
    +
    Parameters:
    +
      +
    • acronyms (numpy.array) – A 1D array of acronyms or atlas ids

    • +
    • values (numpy.array) – A 1D array of values corresponding to each acronym in the acronyms array

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • hemisphere ({'left', 'right', 'both', 'mirror'}) – The hemisphere to display.

    • +
    • br (iblatlas.regions.BrainRegions) – A brain regions object.

    • +
    • orientation ({landscape', 'portrait'}, default='landscape') – The plot orientation.

    • +
    • empty_color (str, tuple of int, default='silver') – The greyscale matplotlib color code or an RGBA int8 tuple defining the filling of brain +regions not provided.

    • +
    • vmin (float) – Minimum value to restrict the colormap

    • +
    • vmax (float) – Maximum value to restrict the colormap

    • +
    • cmap (string) – matplotlib named colormap to use

    • +
    • annotate (bool, default=False) – If true, labels the regions with acronyms.

    • +
    • annotate_n (int) – The number of regions to annotate

    • +
    • annotate_order ({'top', 'bottom'}) – If annotate_n is specified, whether to annotate the n regions with the highest (top) or lowest (bottom) values

    • +
    • annotate_list (numpy.array of list) – List of regions to annotate, if this is provided, if overwrites annotate_n and annotate_order

    • +
    • mask (numpy.array or list) – List of regions to apply a mask to (fill them with a specific color)

    • +
    • mask_color (string, tuple or list) – Color for the mask

    • +
    • fontsize (int) – The annotation font size in points.

    • +
    • **kwargs – See plot_polygon and plot_polygon_with_hole.

    • +
    +
    +
    Returns:
    +

    The plotted axes.

    +
    +
    Return type:
    +

    matplotlib.pyplot.Axes

    +
    +
    +
    + +
    +
    +plot_swanson(acronyms=None, values=None, ax=None, hemisphere=None, br=None, orientation='landscape', annotate=False, empty_color='silver', **kwargs)[source]
    +

    Displays the 2D image corresponding to the swanson flatmap.

    +

    This case is different from the others in the sense that only a region maps to another regions, +there is no correspondence to the spatial 3D coordinates.

    +
    +
    Parameters:
    +
      +
    • acronyms (numpy.array) – A 1D array of acronyms or atlas ids

    • +
    • values (numpy.array) – A 1D array of values corresponding to each acronym in the acronyms array

    • +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • hemisphere ({'left', 'right', 'both', 'mirror'}) – The hemisphere to display.

    • +
    • br (iblatlas.regions.BrainRegions) – A brain regions object.

    • +
    • orientation ({landscape', 'portrait'}, default='landscape') – The plot orientation.

    • +
    • empty_color (str, tuple of int, default='silver') – The greyscale matplotlib color code or an RGBA int8 tuple defining the filling of brain +regions not provided.

    • +
    • vmin (float) – Minimum value to restrict the colormap

    • +
    • vmax (float) – Maximum value to restrict the colormap

    • +
    • cmap (string) – matplotlib named colormap to use

    • +
    • annotate (bool, default=False) – If true, labels the regions with acronyms.

    • +
    • **kwargs – See matplotlib.pyplot.imshow.

    • +
    +
    +
    Returns:
    +

    The plotted axes.

    +
    +
    Return type:
    +

    matplotlib.pyplot.Axes

    +
    +
    +
    + +
    +
    +annotate_swanson(ax, acronyms=None, orientation='landscape', br=None, thres=20000, **kwargs)[source]
    +

    Display annotations on a Swanson flatmap.

    +
    +
    Parameters:
    +
      +
    • ax (matplotlib.pyplot.Axes) – An axis object to plot onto.

    • +
    • acronyms (array_like) – A list or numpy array of acronyms or Allen region IDs. If None plot all acronyms.

    • +
    • orientation ({landscape', 'portrait'}, default='landscape') – The plot orientation.

    • +
    • br (iblatlas.regions.BrainRegions) – A brain regions object.

    • +
    • thres (int, default=20000) – The number of pixels above which a region is labelled.

    • +
    • **kwargs – See matplotlib.pyplot.Axes.annotate.

    • +
    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/iblatlas.regions.html b/_autosummary/iblatlas.regions.html new file mode 100644 index 00000000..7cf1a8b5 --- /dev/null +++ b/_autosummary/iblatlas.regions.html @@ -0,0 +1,443 @@ + + + + + + + iblatlas.regions — IBL Library documentation + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    iblatlas.regions

    +

    Brain region mappings.

    +

    Four mappings are currently available within the IBL, these are:

    +
      +
    • Allen Atlas - total of 1328 annotation regions provided by Allen Atlas.

    • +
    • Beryl Atlas - total of 308 annotation regions determined by Nick Steinmetz for the brain wide map, mainly at the level of +major cortical areas, nuclei/ganglia. Thus annotations relating to layers and nuclear subregions are absent.

    • +
    • Cosmos Atlas - total of 10 annotation regions determined by Nick Steinmetz for coarse analysis. Annotations include the major +divisions of the brain only.

    • +
    • Swanson Atlas - total of 319 annotation regions provided by the Swanson atlas (FIXME which one?).

    • +
    +
    +

    Terminology

    +
      +
    • Name - The full anatomical name of a brain region.

    • +
    • Acronymn - A shortened version of a brain region name.

    • +
    • Index - The index of the of the brain region within the ordered list of brain regions.

    • +
    • ID - A unique numerical identifier of a brain region. These are typically integers that +therefore take up less space than storing the region names or acronyms.

    • +
    • Mapping - A function that maps one ordered list of brain region IDs to another, allowing one +to control annotation granularity and brain region hierarchy, or to translate brain region names +from one atlas to another. The default mapping is identity. See +[atlas package documentation](./ibllib.atlas.html#mappings) for other mappings.

    • +
    • Order - Each structure is assigned a consistent position within the flattened graph. This +value is known as the annotation index, i.e. the annotation volume contains the brain region +order at each point in the image.

    • +
    +

    FIXME Document the two structure trees. Which Website did they come from, and which publication/edition?

    +
    +

    Functions

    + + + + + + +

    regions_from_allen_csv

    (DEPRECATED) Reads csv file containing the ALlen Ontology and instantiates a BrainRegions object.

    +

    Classes

    + + + + + + + + + +

    BrainRegions

    A struct of Allen brain regions, their names, IDs, relationships and associated plot colours.

    FranklinPaxinosRegions

    Mouse Brain in Stereotaxic Coordinates (MBSC).

    +
    +
    +class FranklinPaxinosRegions[source]
    +

    Bases: _BrainRegions

    +

    Mouse Brain in Stereotaxic Coordinates (MBSC).

    +

    Paxinos G, and Franklin KBJ (2012). The Mouse Brain in Stereotaxic Coordinates, 4th edition (Elsevier Academic Press).

    +
    +
    +id: ndarray
    +

    A str array of verbose brain region names.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +name: object
    +

    A str array of brain region acronyms.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +acronym: object
    +

    A, (n, 3) uint8 array of brain region RGB colour values.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +rgb: uint8
    +

    An unsigned integer array indicating the number of degrees removed from root.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +level: ndarray
    +

    An integer array of parent brain region IDs.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +parent: ndarray
    +

    The position within the flattened graph.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +order: uint16
    +
    + +
    + +
    +
    +class BrainRegions[source]
    +

    Bases: _BrainRegions

    +

    A struct of Allen brain regions, their names, IDs, relationships and associated plot colours.

    +

    iblatlas.regions.BrainRegions(brainmap=’Allen’)

    +

    Notes

    +

    The Allen atlas IDs are kept intact but lateralized as follows: labels are duplicated +and IDs multiplied by -1, with the understanding that left hemisphere regions have negative +IDs.

    +
    +
    +id: ndarray
    +

    A str array of verbose brain region names.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +name: object
    +

    A str array of brain region acronyms.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +acronym: object
    +

    A, (n, 3) uint8 array of brain region RGB colour values.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +rgb: uint8
    +

    An unsigned integer array indicating the number of degrees removed from root.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +level: ndarray
    +

    An integer array of parent brain region IDs.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +parent: ndarray
    +

    The position within the flattened graph.

    +
    +
    Type:
    +

    numpy.array

    +
    +
    +
    + +
    +
    +order: uint16
    +
    + +
    +
    +compute_hierarchy()[source]
    +

    Creates a self.hierarchy attribute that is an n_levels by n_region array +of indices. This is useful to perform fast vectorized computations of +ancestors and descendants. +:return:

    +
    + +
    +
    +propagate_down(acronyms, values)[source]
    +

    This function remaps a set of user specified acronyms and values to the +swanson map, by filling down the child nodes when higher up values are +provided.

    +
    +
    Parameters:
    +
      +
    • acronyms – list or array of allen ids or acronyms

    • +
    • values – list or array of associated values

    • +
    +
    +
    Returns:
    +

    +
    +
    +

    # FIXME Why only the swanson map? Also, how is this actually related to the Swanson map?

    +
    + +
    +
    +remap(region_ids, source_map='Allen', target_map='Beryl')[source]
    +

    Remap atlas regions IDs from source map to target map.

    +

    Any NaNs in region_ids remain as NaN in the output array.

    +
    +
    Parameters:
    +
      +
    • region_ids (array_like of int) – The region IDs to remap.

    • +
    • source_map (str) – The source map name, in self.mappings.

    • +
    • target_map (str) – The target map name, in self.mappings.

    • +
    +
    +
    Returns:
    +

    The input IDs mapped to target_map.

    +
    +
    Return type:
    +

    numpy.array of int

    +
    +
    +
    + +
    + +
    +
    +regions_from_allen_csv()[source]
    +

    (DEPRECATED) Reads csv file containing the ALlen Ontology and instantiates a BrainRegions object.

    +

    NB: Instantiate BrainRegions directly instead.

    +
    +
    Returns:
    +

    BrainRegions object

    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/_autosummary/ibllib.atlas.atlas.html b/_autosummary/ibllib.atlas.atlas.html index 487418e6..e98da2ad 100644 --- a/_autosummary/ibllib.atlas.atlas.html +++ b/_autosummary/ibllib.atlas.atlas.html @@ -24,7 +24,7 @@ - + @@ -108,6 +108,7 @@
  • brainbox
  • +
  • iblatlas
  • Index
  • @@ -143,52 +144,35 @@

    ibllib.atlas.atlas

    Classes for manipulating brain atlases, insertions, and coordinates.

    -

    Module attributes

    +

    Functions

    - - + + - - + + - - + + + + + - -

    ALLEN_CCF_LANDMARKS_MLAPDV_UM

    The ML AP DV voxel coordinates of brain landmarks in the Allen atlas.

    AllenAtlas

    PAXINOS_CCF_LANDMARKS_MLAPDV_UM

    The ML AP DV voxel coordinates of brain landmarks in the Franklin & Paxinos atlas.

    BrainAtlas

    S3_BUCKET_IBL

    The name of the public IBL S3 bucket containing atlas data.

    BrainCoordinates

    FranklinPaxinosAtlas

    -

    Functions

    - - - + - + - - - - - + +

    MRITorontoAtlas

    The MRI Toronto brain atlas.

    NeedlesAtlas

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution using the IBL Bregma and coordinate system.

    cart2sph

    Converts cartesian to spherical coordinates.

    sph2cart

    Converts Spherical to Cartesian coordinates.

    deprecated_decorator

    Classes

    - - - - - - - - - - - - @@ -197,741 +181,25 @@

    AllenAtlas

    The Allan Common Coordinate Framework (CCF) brain atlas.

    BrainAtlas

    Objects that holds image, labels and coordinate transforms for a brain Atlas.

    BrainCoordinates

    Class for mapping and indexing a 3D array to real-world coordinates.

    FranklinPaxinosAtlas

    pathlib.PurePosixPath: The default relative path of the atlas file.

    Insertion

    Defines an ephys probe insertion in 3D coordinate.

    -
    -
    -ALLEN_CCF_LANDMARKS_MLAPDV_UM = {'bregma': array([5739, 5400,  332])}
    -

    The ML AP DV voxel coordinates of brain landmarks in the Allen atlas.

    -
    -
    Type:
    -

    dict

    -
    -
    -
    - -
    -
    -PAXINOS_CCF_LANDMARKS_MLAPDV_UM = {'bregma': array([5700, 4460,  330])}
    -

    The ML AP DV voxel coordinates of brain landmarks in the Franklin & Paxinos atlas.

    -
    -
    Type:
    -

    dict

    -
    -
    -
    - -
    -
    -S3_BUCKET_IBL = 'ibl-brain-wide-map-public'
    -

    The name of the public IBL S3 bucket containing atlas data.

    -
    -
    Type:
    -

    str

    -
    -
    -
    -
    -
    -cart2sph(x, y, z)[source]
    -

    Converts cartesian to spherical coordinates.

    -

    Returns spherical coordinates (r, theta, phi).

    -
    -
    Parameters:
    -
      -
    • x (numpy.array) – A 1D array of x-axis coordinates.

    • -
    • y (numpy.array) – A 1D array of y-axis coordinates.

    • -
    • z (numpy.array) – A 1D array of z-axis coordinates.

    • -
    -
    -
    Returns:
    -

      -
    • numpy.array – The radial distance of each point.

    • -
    • numpy.array – The polar angle.

    • -
    • numpy.array – The azimuthal angle.

    • -
    -

    -
    -
    -
    -

    See also

    -

    sph2cart

    -
    -
    +
    +deprecated_decorator(function)[source]
    +
    -
    -sph2cart(r, theta, phi)[source]
    -

    Converts Spherical to Cartesian coordinates.

    -

    Returns Cartesian coordinates (x, y, z).

    -
    -
    Parameters:
    -
      -
    • r (numpy.array) – A 1D array of radial distances.

    • -
    • theta (numpy.array) – A 1D array of polar angles.

    • -
    • phi (numpy.array) – A 1D array of azimuthal angles.

    • -
    -
    -
    Returns:
    -

      -
    • x (numpy.array) – A 1D array of x-axis coordinates.

    • -
    • y (numpy.array) – A 1D array of y-axis coordinates.

    • -
    • z (numpy.array) – A 1D array of z-axis coordinates.

    • -
    -

    -
    -
    -
    -

    See also

    -

    cart2sph

    -
    -
    - -
    -class BrainCoordinates(nxyz, xyz0=(0, 0, 0), dxyz=(1, 1, 1))[source]
    -

    Bases: object

    -

    Class for mapping and indexing a 3D array to real-world coordinates.

    -
      -
    • x = ml, right positive

    • -
    • y = ap, anterior positive

    • -
    • z = dv, dorsal positive

    • -
    -

    The layout of the Atlas dimension is done according to the most used sections so they lay -contiguous on disk assuming C-ordering: V[iap, iml, idv]

    -
    -
    Parameters:
    -
      -
    • nxyz (array_like) – Number of elements along each Cartesian axis (nx, ny, nz) = (nml, nap, ndv).

    • -
    • xyz0 (array_like) – Coordinates of the element volume[0, 0, 0] in the coordinate space.

    • -
    • dxyz (array_like, float) – Spatial interval of the volume along the 3 dimensions.

    • -
    -
    -
    -
    -
    -xyz0
    -

    The Cartesian coordinates of the element volume[0, 0, 0], i.e. the origin.

    -
    -
    Type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -x0
    -

    The x-axis origin coordinate of the element volume.

    -
    -
    Type:
    -

    int

    -
    -
    -
    - -
    -
    -y0
    -

    The y-axis origin coordinate of the element volume.

    -
    -
    Type:
    -

    int

    -
    -
    -
    - -
    -
    -z0
    -

    The z-axis origin coordinate of the element volume.

    -
    -
    Type:
    -

    int

    -
    -
    -
    - -
    -
    -property dxyz
    -

    Spatial interval of the volume along the 3 dimensions.

    -
    -
    Type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -property nxyz
    -

    Coordinates of the element volume[0, 0, 0] in the coordinate space.

    -
    -
    Type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -r2ix(r)[source]
    -
    - -
    -
    -r2iy(r)[source]
    -
    - -
    -
    -r2iz(r)[source]
    -
    - -
    -
    -x2i(x, round=True, mode='raise')[source]
    -

    Find the nearest volume image index to a given x-axis coordinate.

    -
    -
    Parameters:
    -
      -
    • x (float, numpy.array) – One or more x-axis coordinates, relative to the origin, x0.

    • -
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • -
    • mode ({'raise', 'clip', 'wrap'}, default='raise') – How to behave if the coordinate lies outside of the volume: raise (default) will raise -a ValueError; ‘clip’ will replace the index with the closest index inside the volume; -‘wrap’ will return the index as is.

    • -
    -
    -
    Returns:
    -

    The nearest indices of the image volume along the first dimension.

    -
    -
    Return type:
    -

    numpy.array

    -
    -
    Raises:
    -

    ValueError – At least one x value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to - keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    -
    -
    -
    - -
    -
    -y2i(y, round=True, mode='raise')[source]
    -

    Find the nearest volume image index to a given y-axis coordinate.

    -
    -
    Parameters:
    -
      -
    • y (float, numpy.array) – One or more y-axis coordinates, relative to the origin, y0.

    • -
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • -
    • mode ({'raise', 'clip', 'wrap'}) – How to behave if the coordinate lies outside of the volume: raise (default) will raise -a ValueError; ‘clip’ will replace the index with the closest index inside the volume; -‘wrap’ will return the index as is.

    • -
    -
    -
    Returns:
    -

    The nearest indices of the image volume along the second dimension.

    -
    -
    Return type:
    -

    numpy.array

    -
    -
    Raises:
    -

    ValueError – At least one y value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to - keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    -
    -
    -
    - -
    -
    -z2i(z, round=True, mode='raise')[source]
    -

    Find the nearest volume image index to a given z-axis coordinate.

    -
    -
    Parameters:
    -
      -
    • z (float, numpy.array) – One or more z-axis coordinates, relative to the origin, z0.

    • -
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • -
    • mode ({'raise', 'clip', 'wrap'}) – How to behave if the coordinate lies outside of the volume: raise (default) will raise -a ValueError; ‘clip’ will replace the index with the closest index inside the volume; -‘wrap’ will return the index as is.

    • -
    -
    -
    Returns:
    -

    The nearest indices of the image volume along the third dimension.

    -
    -
    Return type:
    -

    numpy.array

    -
    -
    Raises:
    -

    ValueError – At least one z value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to - keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    -
    -
    -
    - -
    -
    -xyz2i(xyz, round=True, mode='raise')[source]
    -

    Find the nearest volume image indices to the given Cartesian coordinates.

    -
    -
    Parameters:
    -
      -
    • xyz (array_like) – One or more Cartesian coordinates, relative to the origin, xyz0.

    • -
    • round (bool) – If true, round to the nearest index, replacing NaN values with 0.

    • -
    • mode ({'raise', 'clip', 'wrap'}) – How to behave if any coordinate lies outside of the volume: raise (default) will raise -a ValueError; ‘clip’ will replace the index with the closest index inside the volume; -‘wrap’ will return the index as is.

    • -
    -
    -
    Returns:
    -

    The nearest indices of the image volume.

    -
    -
    Return type:
    -

    numpy.array

    -
    -
    Raises:
    -

    ValueError – At least one coordinate lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ - to keep these values unchanged, or ‘clip’ to return the nearest valid indices.

    -
    -
    -
    - -
    -
    -i2x(ind)[source]
    -

    Return the x-axis coordinate of a given index.

    -
    -
    Parameters:
    -

    ind (int, numpy.array) – One or more indices along the first dimension of the image volume.

    -
    -
    Returns:
    -

    The corresponding x-axis coordinate(s), relative to the origin, x0.

    -
    -
    Return type:
    -

    float, numpy.array

    -
    -
    -
    - -
    -
    -i2y(ind)[source]
    -

    Return the y-axis coordinate of a given index.

    -
    -
    Parameters:
    -

    ind (int, numpy.array) – One or more indices along the second dimension of the image volume.

    -
    -
    Returns:
    -

    The corresponding y-axis coordinate(s), relative to the origin, y0.

    -
    -
    Return type:
    -

    float, numpy.array

    -
    -
    -
    - -
    -
    -i2z(ind)[source]
    -

    Return the z-axis coordinate of a given index.

    -
    -
    Parameters:
    -

    ind (int, numpy.array) – One or more indices along the third dimension of the image volume.

    -
    -
    Returns:
    -

    The corresponding z-axis coordinate(s), relative to the origin, z0.

    -
    -
    Return type:
    -

    float, numpy.array

    -
    -
    -
    - -
    -
    -i2xyz(iii)[source]
    -

    Return the Cartesian coordinates of a given index.

    -
    -
    Parameters:
    -

    iii (array_like) – One or more image volume indices.

    -
    -
    Returns:
    -

    The corresponding xyz coordinates, relative to the origin, xyz0.

    -
    -
    Return type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -property xlim
    +BrainCoordinates(*args, **kwargs)[source]
    -
    -
    -property ylim
    -
    - -
    -
    -property zlim
    -
    - -
    -
    -lim(axis)[source]
    -
    - -
    -
    -property xscale
    -
    - -
    -
    -property yscale
    -
    - -
    -
    -property zscale
    -
    - -
    -
    -property mgrid
    -
    - -
    - -
    +
    -class BrainAtlas(image, label, dxyz, regions, iorigin=[0, 0, 0], dims2xyz=[0, 1, 2], xyz2dims=[0, 1, 2])[source]
    -

    Bases: object

    -

    Objects that holds image, labels and coordinate transforms for a brain Atlas. -Currently this is designed for the AllenCCF at several resolutions, -yet this class can be used for other atlases arises.

    -
    -
    -image = None
    -

    An annotation label volume.

    -
    -
    Type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -label = None
    +BrainAtlas(*args, **kwargs)[source]
    -
    -
    -compute_surface()[source]
    -

    Get the volume top, bottom, left and right surfaces, and from these the outer surface of -the image volume. This is needed to compute probe insertions intersections.

    -

    NOTE: In places where the top or bottom surface touch the top or bottom of the atlas volume, the surface -will be set to np.nan. If you encounter issues working with these surfaces check if this might be the cause.

    -
    - -
    -
    -get_labels(xyz, mapping=None, radius_um=None, mode='raise')[source]
    -

    Performs a 3D lookup from real world coordinates to the volume labels -and return the regions ids according to the mapping

    -
    -
    Parameters:
    -
      -
    • xyz – [n, 3] array of coordinates

    • -
    • mapping – brain region mapping (defaults to original Allen mapping)

    • -
    • radius_um – if not null, returns a regions ids array and an array of proportion -of regions in a sphere of size radius around the coordinates.

    • -
    • mode – {‘raise’, ‘clip’} determines what to do when determined index lies outside the atlas volume

    • -
    -
    -
    -

    ‘raise’ will raise a ValueError (default) -‘clip’ will replace the index with the closest index inside the volume -:return: n array of region ids

    -
    - -
    -
    -tilted_slice(xyz, axis, volume='image')[source]
    -

    From line coordinates, extracts the tilted plane containing the line from the 3D volume

    -
    -
    Parameters:
    -

    xyz – np.array: points defining a probe trajectory in 3D space (xyz triplets)

    -
    -
    -

    if more than 2 points are provided will take the best fit -:param axis:

    -
    -

    0: along ml = sagittal-slice -1: along ap = coronal-slice -2: along dv = horizontal-slice

    -
    -
    -
    Parameters:
    -

    volume – ‘image’ or ‘annotation’

    -
    -
    Returns:
    -

    np.array, abscissa extent (width), ordinate extent (height),

    -
    -
    -

    squeezed axis extent (depth)

    -
    - -
    -
    -plot_tilted_slice(xyz, axis, volume='image', cmap=None, ax=None, return_sec=False, **kwargs)[source]
    -

    From line coordinates, extracts the tilted plane containing the line from the 3D volume

    -
    -
    Parameters:
    -

    xyz – np.array: points defining a probe trajectory in 3D space (xyz triplets)

    -
    -
    -

    if more than 2 points are provided will take the best fit -:param axis:

    -
    -

    0: along ml = sagittal-slice -1: along ap = coronal-slice -2: along dv = horizontal-slice

    -
    -
    -
    Parameters:
    -

    volume – ‘image’ or ‘annotation’

    -
    -
    Returns:
    -

    matplotlib axis

    -
    -
    -
    - -
    -
    -extent(axis)[source]
    -
    -
    Parameters:
    -

    axis – direction along which the volume is stacked: -(2 = z for horizontal slice) -(1 = y for coronal slice) -(0 = x for sagittal slice)

    -
    -
    Returns:
    -

    -
    -
    -
    - -
    -
    -slice(coordinate, axis, volume='image', mode='raise', region_values=None, mapping=None, bc=None)[source]
    -

    Get slice through atlas

    -
    -
    Parameters:
    -
      -
    • coordinate – coordinate to slice in metres, float

    • -
    • axis – xyz convention: 0 for ml, 1 for ap, 2 for dv -- 0: sagittal slice (along ml axis) -- 1: coronal slice (along ap axis) -- 2: horizontal slice (along dv axis)

    • -
    • volume

        -
      • ‘image’ - allen image volume

      • -
      • ’annotation’ - allen annotation volume

      • -
      • ’surface’ - outer surface of mesh

      • -
      • ’boundary’ - outline of boundaries between all regions

      • -
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • -
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • -
      -

    • -
    • mode – error mode for out of bounds coordinates -- ‘raise’ raise an error -- ‘clip’ gets the first or last index

    • -
    • region_values – custom values to plot -- if volume=’volume’, region_values must have shape ba.image.shape -- if volume=’value’, region_values must have shape ba.regions.id

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    -
    -
    Returns:
    -

    2d array or 3d RGB numpy int8 array

    -
    -
    -
    - -
    -
    -compute_boundaries(values)[source]
    -

    Compute the boundaries between regions on slice

    -
    -
    Parameters:
    -

    values

    -
    -
    Returns:
    -

    -
    -
    -
    - -
    -
    -plot_slices(xyz, *args, **kwargs)[source]
    -

    From a single coordinate, plots the 3 slices that intersect at this point in a single -matplotlib figure

    -
    -
    Parameters:
    -
      -
    • xyz – mlapdv coordinate in m

    • -
    • args – arguments to be forwarded to plot slices

    • -
    • kwargs – keyword arguments to be forwarded to plot slices

    • -
    -
    -
    Returns:
    -

    2 by 2 array of axes

    -
    -
    -
    - -
    -
    -plot_cslice(ap_coordinate, volume='image', mapping=None, region_values=None, **kwargs)[source]
    -

    Plot coronal slice through atlas at given ap_coordinate

    -
    -
    Param:
    -

    ap_coordinate (m)

    -
    -
    Parameters:
    -
      -
    • volume

        -
      • ‘image’ - allen image volume

      • -
      • ’annotation’ - allen annotation volume

      • -
      • ’surface’ - outer surface of mesh

      • -
      • ’boundary’ - outline of boundaries between all regions

      • -
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • -
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • -
      -

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • region_values – custom values to plot -- if volume=’volume’, region_values must have shape ba.image.shape -- if volume=’value’, region_values must have shape ba.regions.id

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • **kwargs

      matplotlib.pyplot.imshow kwarg arguments

      -

    • -
    -
    -
    Returns:
    -

    matplotlib ax object

    -
    -
    -
    - -
    -
    -plot_hslice(dv_coordinate, volume='image', mapping=None, region_values=None, **kwargs)[source]
    -

    Plot horizontal slice through atlas at given dv_coordinate

    -
    -
    Param:
    -

    dv_coordinate (m)

    -
    -
    Parameters:
    -
      -
    • volume

        -
      • ‘image’ - allen image volume

      • -
      • ’annotation’ - allen annotation volume

      • -
      • ’surface’ - outer surface of mesh

      • -
      • ’boundary’ - outline of boundaries between all regions

      • -
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • -
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • -
      -

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • region_values – custom values to plot -- if volume=’volume’, region_values must have shape ba.image.shape -- if volume=’value’, region_values must have shape ba.regions.id

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • **kwargs

      matplotlib.pyplot.imshow kwarg arguments

      -

    • -
    -
    -
    Returns:
    -

    matplotlib ax object

    -
    -
    -
    - -
    -
    -plot_sslice(ml_coordinate, volume='image', mapping=None, region_values=None, **kwargs)[source]
    -

    Plot sagittal slice through atlas at given ml_coordinate

    -
    -
    Param:
    -

    ml_coordinate (m)

    -
    -
    Parameters:
    -
      -
    • volume

        -
      • ‘image’ - allen image volume

      • -
      • ’annotation’ - allen annotation volume

      • -
      • ’surface’ - outer surface of mesh

      • -
      • ’boundary’ - outline of boundaries between all regions

      • -
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • -
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • -
      -

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • region_values – custom values to plot -- if volume=’volume’, region_values must have shape ba.image.shape -- if volume=’value’, region_values must have shape ba.regions.id

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • **kwargs

      matplotlib.pyplot.imshow kwarg arguments

      -

    • -
    -
    -
    Returns:
    -

    matplotlib ax object

    -
    -
    -
    - -
    -
    -plot_top(volume='annotation', mapping=None, region_values=None, ax=None, **kwargs)[source]
    -

    Plot top view of atlas

    -
    -
    Parameters:
    -
      -
    • volume

        -
      • ‘image’ - allen image volume

      • -
      • ’annotation’ - allen annotation volume

      • -
      • ’boundary’ - outline of boundaries between all regions

      • -
      • ’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument

      • -
      • ’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument

      • -
      -

    • -
    • mapping – mapping to use. Options can be found using ba.regions.mappings.keys()

    • -
    • region_values

    • -
    • ax

    • -
    • kwargs

    • -
    -
    -
    Returns:
    -

    -
    -
    -
    - -
    -
    class Trajectory(vector: ndarray, point: ndarray)[source]
    -

    Bases: object

    +

    Bases: Trajectory

    3D Trajectory (usually for a linear probe), minimally defined by a vector and a point.

    Examples

    Instantiate from a best fit from an n by 3 array containing xyz coordinates:

    @@ -948,119 +216,12 @@ point: ndarray
    -
    -
    -static fit(xyz)[source]
    -

    Fits a line to a 3D cloud of points.

    -
    -
    Parameters:
    -

    xyz (numpy.array) – An n by 3 array containing a cloud of points to fit a line to.

    -
    -
    Returns:
    -

    A new trajectory object.

    -
    -
    Return type:
    -

    Trajectory

    -
    -
    -
    - -
    -
    -eval_x(x)[source]
    -

    given an array of x coordinates, returns the xyz array of coordinates along the insertion

    -
    -
    Parameters:
    -

    x – n by 1 or numpy array containing x-coordinates

    -
    -
    Returns:
    -

    n by 3 numpy array containing xyz-coordinates

    -
    -
    -
    - -
    -
    -eval_y(y)[source]
    -

    given an array of y coordinates, returns the xyz array of coordinates along the insertion

    -
    -
    Parameters:
    -

    y – n by 1 or numpy array containing y-coordinates

    -
    -
    Returns:
    -

    n by 3 numpy array containing xyz-coordinates

    -
    -
    -
    - -
    -
    -eval_z(z)[source]
    -

    given an array of z coordinates, returns the xyz array of coordinates along the insertion

    -
    -
    Parameters:
    -

    z – n by 1 or numpy array containing z-coordinates

    -
    -
    Returns:
    -

    n by 3 numpy array containing xyz-coordinates

    -
    -
    -
    - -
    -
    -project(point)[source]
    -

    projects a point onto the trajectory line

    -
    -
    Parameters:
    -

    point – np.array(x, y, z) coordinates

    -
    -
    Returns:
    -

    -
    -
    -
    - -
    -
    -mindist(xyz, bounds=None)[source]
    -

    Computes the minimum distance to the trajectory line for one or a set of points. -If bounds are provided, computes the minimum distance to the segment instead of an -infinite line.

    -
    -
    Parameters:
    -
      -
    • xyz – […, 3]

    • -
    • bounds – defaults to None. np.array [2, 3]: segment boundaries, inf line if None

    • -
    -
    -
    Returns:
    -

    minimum distance […]

    -
    -
    -
    - -
    -
    -exit_points(bc)[source]
    -

    Given a Trajectory and a BrainCoordinates object, computes the intersection of the -trajectory with the brain coordinates bounding box

    -
    -
    Parameters:
    -

    bc – BrainCoordinate objects

    -
    -
    Returns:
    -

    np.ndarray 2 y 3 corresponding to exit points xyz coordinates

    -
    -
    -
    -
    class Insertion(x: float, y: float, z: float, phi: float, theta: float, depth: float, label: str = '', beta: float = 0)[source]
    -

    Bases: object

    +

    Bases: Insertion

    Defines an ephys probe insertion in 3D coordinate. IBL conventions.

    To instantiate, use the static methods: Insertion.from_track and Insertion.from_dict.

    @@ -1093,299 +254,28 @@ depth: float
    -
    -
    -label: str = ''
    -
    - -
    -
    -beta: float = 0
    -
    - -
    -
    -static from_track(xyzs, brain_atlas=None)[source]
    -

    Define an insersion from one or more trajectory.

    -
    -
    Parameters:
    -
      -
    • xyzs (numpy.array) – An n by 3 array xyz coordinates representing an insertion trajectory.

    • -
    • brain_atlas (BrainAtlas) – A brain atlas instance, used to attain the point of entry.

    • -
    -
    -
    Return type:
    -

    Insertion

    -
    -
    -
    - -
    -
    -static from_dict(d, brain_atlas=None)[source]
    -

    Constructs an Insertion object from the json information stored in probes.description file.

    -
    -
    Parameters:
    -
      -
    • d (dict) – A dictionary containing at least the following keys {‘x’, ‘y’, ‘z’, ‘phi’, ‘theta’, -‘depth’}. The depth and xyz coordinates must be in um.

    • -
    • brain_atlas (BrainAtlas, default=None) – If provided, disregards the z coordinate and locks the insertion point to the z of the -brain surface.

    • -
    -
    -
    Return type:
    -

    Insertion

    -
    -
    -

    Examples

    -
    >>> tri = {'x': 544.0, 'y': 1285.0, 'z': 0.0, 'phi': 0.0, 'theta': 5.0, 'depth': 4501.0}
    ->>> ins = Insertion.from_dict(tri)
    -
    -
    -
    - -
    -
    -property trajectory
    -

    Gets the trajectory object matching insertion coordinates -:return: atlas.Trajectory

    -
    -
    -property xyz
    -
    - -
    -
    -property entry
    -
    - -
    -
    -property tip
    -
    - -
    -
    -static get_brain_exit(traj, brain_atlas)[source]
    -

    Given a Trajectory and a BrainAtlas object, computes the brain exit coordinate as the -intersection of the trajectory and the brain surface (brain_atlas.surface)

    -
    -
    Parameters:
    -

    brain_atlas

    -
    -
    Returns:
    -

    3 element array x,y,z

    -
    -
    -
    - -
    -
    -static get_brain_entry(traj, brain_atlas)[source]
    -

    Given a Trajectory and a BrainAtlas object, computes the brain entry coordinate as the -intersection of the trajectory and the brain surface (brain_atlas.surface)

    -
    -
    Parameters:
    -

    brain_atlas

    -
    -
    Returns:
    -

    3 element array x,y,z

    -
    -
    -
    - -
    - -
    +
    -class AllenAtlas(res_um=25, scaling=(1, 1, 1), mock=False, hist_path=None)[source]
    -

    Bases: BrainAtlas

    -

    The Allan Common Coordinate Framework (CCF) brain atlas.

    -

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution -using the IBL Bregma and coordinate system.

    -
    -
    -atlas_rel_path = PurePosixPath('histology/ATLAS/Needles/Allen')
    -

    A diffusion weighted imaging (DWI) image volume.

    -

    The Allen atlas DWI average template volume has with the shape (ap, ml, dv) and contains uint16 -values. FIXME What do the values represent?

    -
    -
    Type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -image = None
    -

    An annotation label volume.

    -

    The Allen atlas label volume has with the shape (ap, ml, dv) and contains uint16 indices -of the Allen CCF brain regions to which each voxel belongs.

    -
    -
    Type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -label = None
    +AllenAtlas(*args, **kwargs)[source]
    -
    -
    -xyz2ccf(xyz, ccf_order='mlapdv', mode='raise')[source]
    -

    Converts anatomical coordinates to CCF coordinates.

    -

    Anatomical coordinates are in meters, relative to bregma, which CFF coordinates are -assumed to be the volume indices multiplied by the spacing in micormeters.

    -
    -
    Parameters:
    -
      -
    • xyz (numpy.array) – An N by 3 array of anatomical coordinates in meters, relative to bregma.

    • -
    • ccf_order ({'mlapdv', 'apdvml'}, default='mlapdv') – The order of the CCF coordinates returned. For IBL (the default) this is (ML, AP, DV), -for Allen MCC vertices, this is (AP, DV, ML).

    • -
    • mode ({'raise', 'clip', 'wrap'}, default='raise') – How to behave if the coordinate lies outside of the volume: raise (default) will raise -a ValueError; ‘clip’ will replace the index with the closest index inside the volume; -‘wrap’ will return the index as is.

    • -
    -
    -
    Returns:
    -

      -
    • numpy.array – Coordinates in CCF space (um, origin is the front left top corner of the data

    • -
    • volume, order determined by ccf_order

    • -
    -

    -
    -
    -
    - -
    -
    -ccf2xyz(ccf, ccf_order='mlapdv')[source]
    -

    Convert anatomical coordinates from CCF coordinates.

    -

    Anatomical coordinates are in meters, relative to bregma, which CFF coordinates are -assumed to be the volume indices multiplied by the spacing in micormeters.

    -
    -
    Parameters:
    -
      -
    • ccf (numpy.array) – An N by 3 array of coordinates in CCF space (atlas volume indices * um resolution). The -origin is the front left top corner of the data volume.

    • -
    • ccf_order ({'mlapdv', 'apdvml'}, default='mlapdv') – The order of the CCF coordinates given. For IBL (the default) this is (ML, AP, DV), -for Allen MCC vertices, this is (AP, DV, ML).

    • -
    -
    -
    Returns:
    -

    The MLAPDV coordinates in meters, relative to bregma.

    -
    -
    Return type:
    -

    numpy.array

    -
    -
    -
    - -
    -
    -compute_regions_volume(cumsum=False)[source]
    -

    Sums the number of voxels in the labels volume for each region. -Then compute volumes for all of the levels of hierarchy in cubic mm.

    -
    -
    Param:
    -

    cumsum: computes the cumulative sum of the volume as per the hierarchy (defaults to False)

    -
    -
    Returns:
    -

    -
    -
    -
    - -
    -
    NeedlesAtlas(*args, **kwargs)[source]
    -

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution -using the IBL Bregma and coordinate system. The Needles atlas defines a stretch along AP -axis and a squeeze along the DV axis.

    -
    -
    Parameters:
    -
      -
    • res_um ({10, 25, 50} int) – The Atlas resolution in micrometres; one of 10, 25 or 50um.

    • -
    • **kwargs – See AllenAtlas.

    • -
    -
    -
    Returns:
    -

    An Allen atlas object with MRI atlas scaling applied.

    -
    -
    Return type:
    -

    AllenAtlas

    -
    -
    -

    Notes

    -

    The scaling was determined by manually transforming the DSURQE atlas [1]_ onto the Allen CCF. -The DSURQE atlas is an MRI atlas acquired from 40 C57BL/6J mice post-mortem, with 40um -isometric resolution. The alignment was performed by Mayo Faulkner. -The atlas data can be found here. -More information on the dataset and segmentation can be found -here.

    -

    References

    - -
    +
    MRITorontoAtlas(*args, **kwargs)[source]
    -

    The MRI Toronto brain atlas.

    -

    Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution -using the IBL Bregma and coordinate system. The MRI Toronto atlas defines a stretch along AP -a squeeze along DV and a squeeze along ML. These are based on 12 p65 mice MRIs averaged [1]_.

    -
    -
    Parameters:
    -
      -
    • res_um ({10, 25, 50} int) – The Atlas resolution in micrometres; one of 10, 25 or 50um.

    • -
    • **kwargs – See AllenAtlas.

    • -
    -
    -
    Returns:
    -

    An Allen atlas object with MRI atlas scaling applied.

    -
    -
    Return type:
    -

    AllenAtlas

    -
    -
    -

    References

    - -
    +
    -
    +
    -class FranklinPaxinosAtlas(res_um=(10, 100, 10), scaling=(1, 1, 1), mock=False, hist_path=None)[source]
    -

    Bases: BrainAtlas

    -

    pathlib.PurePosixPath: The default relative path of the atlas file.

    -
    -
    -atlas_rel_path = PurePosixPath('histology/ATLAS/Needles/FranklinPaxinos')
    +FranklinPaxinosAtlas(*args, **kwargs)[source]
    -
    -
    @@ -1393,7 +283,7 @@