API Reference¶
psychoanalyze
¶
Top-level package for psychoanalyze
.
Modules:
plot
: Global plot settings and generic plot utilities.sigmoids
: Implementations of psychometric sigmoid functions.
Subpackages:
data
: Submodules inpsychoanalyze.data
contain data manipulation and transformation functions that relate to a level in the data hierarchy.analysis
: Submodules inpsychoanalyze.analysis
contain data manipulation and transformation functions, often corresponding to a level in the data hierarchy.
main
¶
PsychoAnalyze command line interface.
params
¶
plot
¶
Global plot settings and generic plot utilities.
sigmoids
¶
data
¶
Data modules and general-purpose data transformation utilities.
Submodules:
psychoanalyze.data.blocks
psychoanalyze.data.points
psychoanalyze.data.trials
psychoanalyze.data.sessions
psychoanalyze.data.subjects
psychoanalyze.data.types
points
¶
Utilities for points-level data.
Points correspond to the aggregate measures of method-of-constant-stimuli experiments at each stimulus level measured. For example, a block that samples 8 stimulus intensity levels would have 8 corresponding points.
from_trials(trials)
¶
Aggregate point-level measures from trial data.
Source code in psychoanalyze/data/points.py
load(data_path)
¶
prep_fit(points, dimension='Amp1')
¶
Transform points data for numpy-related fitting procedures.
Source code in psychoanalyze/data/points.py
hits(n, params)
¶
Sample list of n hits from a list of intensity values.
Source code in psychoanalyze/data/points.py
generate(n_trials, options, params)
¶
Generate points-level data.
Source code in psychoanalyze/data/points.py
generate_point(n, p)
¶
datatable(data)
¶
Convert dataframe to Dash DataTable-friendly format.
Source code in psychoanalyze/data/points.py
from_store(store_data)
¶
combine_plots(fig1, fig2)
¶
n(trials)
¶
generate_n(n_trials, options)
¶
Simulate how many trials were performed per intensity level.
to_block(points)
¶
psi(x, params)
¶
Calculate psi for an array of intensity levels x.
Source code in psychoanalyze/data/points.py
plot(points, y)
¶
Plot the psychometric function.
hit_rate(df)
¶
transform(hit_rate, y)
¶
generate_index(n_levels, x_range)
¶
Generate evenly-spaced values along the modulated stimulus dimension.
Source code in psychoanalyze/data/points.py
logistic
¶
Utilities for working with logistic distributions.
to_intercept(location, scale)
¶
Calculate the intercept of a logistic distribution given location and scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
float
|
The location parameter of a logistic distribution. |
required |
scale |
float
|
The scale parameter of a logistic distribution. |
required |
Returns:
Type | Description |
---|---|
float
|
The intercept of the logistic distribution. |
Source code in psychoanalyze/data/logistic.py
to_slope(scale)
¶
Calculate the slope of a logistic distribution given scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale |
float
|
The scale parameter of a logistic distribution. |
required |
Returns:
Type | Description |
---|---|
float
|
The slope of the logistic distribution at the inflection point. |
Source code in psychoanalyze/data/logistic.py
min_x(intercept, slope)
¶
Calculate the minimum x value to be sampled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intercept |
float
|
The intercept of the logistic distribution. |
required |
slope |
float
|
The slope of the logistic distribution at the inflection point. |
required |
Returns:
Type | Description |
---|---|
float
|
The minimum x value of the logistic distribution. |
Source code in psychoanalyze/data/logistic.py
stimulus
¶
Constants for dimension labels.
subjects
¶
Data transformation functions for subject-level data.
load(data_path)
¶
generate_letter_names(n_subjects)
¶
generate_trials(n_trials, model_params, n_days, n_subjects)
¶
Generate trial-level data, including subject-level info.
Source code in psychoanalyze/data/subjects.py
blocks
¶
Block-level data utilities.
Blocks are the most analytically significant objects in the PsychoAnalyze data hierarchy. They represent a specific set of experimental conditions and generally correspond to a single fit of the psychometric function.
generate(n_trials_per_level, x_min, x_max, n_levels)
¶
Generate block-level data.
Source code in psychoanalyze/data/blocks.py
plot_fits(blocks)
¶
load(data_path)
¶
Load block data from csv.
Source code in psychoanalyze/data/blocks.py
days(blocks, intervention_dates)
¶
Calculate days for block-level data. Possible duplicate.
Source code in psychoanalyze/data/blocks.py
n_trials(trials)
¶
Calculate n trials for each block.
Source code in psychoanalyze/data/blocks.py
is_valid(block)
¶
subject_counts(data)
¶
Determine how many subjects are in the data.
Source code in psychoanalyze/data/blocks.py
fit(trials)
¶
Fit logistic regression to trial data.
Source code in psychoanalyze/data/blocks.py
generate_trials(n_trials, model_params)
¶
from_points(points)
¶
plot_thresholds(blocks)
¶
Plot longitudinal threshold data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blocks |
pd.DataFrame
|
Block-level DataFrame. |
required |
Returns:
Type | Description |
---|---|
go.Figure
|
A plotly Graph Object. |
Source code in psychoanalyze/data/blocks.py
transform_errors(fit)
¶
Transform errors from absolute to relative.
reshape_fit_results(fits, x, y)
¶
Reshape fit params for plotting.
Source code in psychoanalyze/data/blocks.py
standard_logistic()
¶
Generate points for a line trace of a standard logistic function.
logistic(location, scale)
¶
Generate points for a line trace of a logistic function.
Source code in psychoanalyze/data/blocks.py
plot_logistic(location, scale)
¶
Plot a logistic function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
float
|
x₀ in the location-scale parameterization, corresponds to threshold. |
required |
scale |
float
|
σ corresponds to the width of the curve (inverse of slope) |
required |
Returns:
Type | Description |
---|---|
go.Scatter
|
A Plotly figure of the psychometric function with a logistic link function. |
Source code in psychoanalyze/data/blocks.py
plot_standard_logistic()
¶
Plot a standard logistic function.
trials
¶
Functions for data manipulations at the trial level.
generate_trial_index(n_trials, options)
¶
sample_trials(trials_ix, params)
¶
Sample trials from a given index.
generate(n_trials, options, params, n_blocks)
¶
Generate n trials with outcomes.
Source code in psychoanalyze/data/trials.py
load(data_path)
¶
Load trials data from csv.
from_store(store_data)
¶
Convert JSON-formatted string to DataFrame.
Source code in psychoanalyze/data/trials.py
to_store(trials)
¶
Convert data to a JSON-formatted string for dcc.Store.
normalize(trials)
¶
Normalize denormalized trial data.
Source code in psychoanalyze/data/trials.py
result(p)
¶
results(n, p_x)
¶
Return a list of trial results in dict format.
Source code in psychoanalyze/data/trials.py
labels(results)
¶
psi(intensity, params)
¶
Calculate the value of the psychometric function for a given intensity.
Source code in psychoanalyze/data/trials.py
moc_sample(n_trials, model_params)
¶
Sample results from a method-of-constant-stimuli experiment.
Source code in psychoanalyze/data/trials.py
fit(trials)
¶
Fit trial data using logistic regression.
sessions
¶
Utilities for session-level data.
Sessions represent a single day of experiments performed by a subject. It may contain several blocks.
generate(n)
¶
cache_results(sessions)
¶
from_trials_csv(path)
¶
day_marks(subjects, sessions, monkey)
¶
Calculate days since surgery date for a given subject.
Source code in psychoanalyze/data/sessions.py
days(sessions, subjects)
¶
Calculate days since surgery date.
Source code in psychoanalyze/data/sessions.py
n_trials(trials)
¶
load(data_dir)
¶
generate_trials(n_trials, model_params, n_days)
¶
Generate trial-level data for session-level context.
Source code in psychoanalyze/data/sessions.py
types
¶
Pandera schemas for psychoanalyze dataframes.
Contains data table schemas of the hierarchical entities described above.
PsiAnimation
¶
Bases: DataFrameModel
Pandera type for psychometric function animation dataset.
Source code in psychoanalyze/data/types.py
PsiAnimationFrame
¶
Bases: DataFrameModel
Pandera type for a single psychometric function animation frame.
Source code in psychoanalyze/data/types.py
Blocks
¶
Points
¶
dashboard
¶
The PsychoAnalyze dashboard is powered by Plotly/Dash.
-
app.py
is the main file which contains the infrastructure for the Dash app. and callback functions in their entirety. -
layout.py
specifies the layout of the HTML and Dash components that comprise the app. -
components.py
contains more complex and/or reusable components used in the app.
app
¶
Main Dash app file.
Contains callbacks.
update_trials(contents, filename, n_param, param)
¶
Update points table.
Source code in psychoanalyze/dashboard/app.py
update_points_table(trials)
¶
Update points table.
Source code in psychoanalyze/dashboard/app.py
update_blocks_table(trials)
¶
Update blocks table.
Source code in psychoanalyze/dashboard/app.py
filter_points(selected_rows, points)
¶
Filter points table.
Source code in psychoanalyze/dashboard/app.py
update_fig(param, points, blocks, selected_rows, min_x, max_x)
¶
Update plot and tables based on data store and selected view.
Source code in psychoanalyze/dashboard/app.py
export_image(export_clicked, fig)
¶
Export image.
Source code in psychoanalyze/dashboard/app.py
export_data(export_clicked, points, blocks, trials)
¶
Export image.
Source code in psychoanalyze/dashboard/app.py
toggle_eqn(n_clicks)
¶
Toggle equation.
Source code in psychoanalyze/dashboard/app.py
toggle_param(free)
¶
Toggle parameter.
Source code in psychoanalyze/dashboard/app.py
set_params_to_preset(preset, param)
¶
Set parameters to preset values.
Source code in psychoanalyze/dashboard/app.py
set_fixed_params_to_preset(preset, param)
¶
Set parameters to preset values.
Source code in psychoanalyze/dashboard/app.py
update_page_size(n_levels)
¶
utils
¶
Helper functions for the dashboard.
process_upload(contents, filename)
¶
Process a file upload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
contents |
str
|
The contents of the uploaded file. |
required |
filename |
str
|
The name of the uploaded file. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
A dataframe of the uploaded file. |
Source code in psychoanalyze/dashboard/utils.py
components
¶
Components for Dash dashboard.
layout
¶
Layout for Dash dashboard.
analysis
¶
Data structures and manipulation methods.
strength_duration
¶
Strength-duration analysis.
Contains functions assessing the relationship between the amplitude and the time course of the stimulus.
from_blocks(blocks, dim)
¶
Calculate strength-duration measures from block data.
Source code in psychoanalyze/analysis/strength_duration.py
plot(blocks, dim, x_data, y_data)
¶
Plot strength-duration curve given detection data.
Source code in psychoanalyze/analysis/strength_duration.py
bayes
¶
Bayesian analysis of psychophysical data.
plot(simulated, estimated)
¶
Plot Psychometric curve to emphasize Bayesian posteriors.
Source code in psychoanalyze/analysis/bayes.py
ecdf
¶
Empirical Distribution Functions (eCDF).
plot(blocks, param)
¶
Plot empirical cumulative distrubtion function (eCDF) of fitted params.
Source code in psychoanalyze/analysis/ecdf.py
weber
¶
Test functions related to Weber's Law analysis.
Contains functions assessing how discriminability of two stimuli relates to the baseline intensities of the stimuli according to Weber's Law.
plot(data, trendline='ols', error_y=None)
¶
Plot data according to Weber's Law.
Source code in psychoanalyze/analysis/weber.py
aggregate(data)
¶
Calculate agg stats for Weber data.
Source code in psychoanalyze/analysis/weber.py
load(path)
¶
Load weber file from a csv.