group_statistics#

Create some statistics to test significant changes in voxelized and labeled data.

class LoadedPValueResults(gp1_avg: numpy.ndarray, gp1_sd: numpy.ndarray | None, gp2_avg: numpy.ndarray, gp2_sd: numpy.ndarray | None, p_vals: numpy.ndarray, effect_size: numpy.ndarray | None)[source]#

Bases: object

effect_size: ndarray | None#
gp1_avg: ndarray#
property gp1_imgs#
gp1_sd: ndarray | None#
gp2_avg: ndarray#
property gp2_imgs#
gp2_sd: ndarray | None#
property has_effect: bool#
property has_sd: bool#
p_vals: ndarray#
property stats_imgs#
color_p_values(p_vals, p_sign, positive_color=(1, 0), negative_color=(0, 1), p_cutoff=None, positive_trend=(0, 0, 1, 0), negative_trend=(0, 0, 0, 1), p_max=None)[source]#
Parameters:
  • p_vals (np.ndarray)

  • p_sign (np.ndarray)

  • positive_color (tuple)

  • negative_color (tuple)

  • p_cutoff (float, optional)

  • positive_trend (tuple)

  • negative_trend (tuple)

  • p_max (float, optional)

Returns

np.ndarray

generate_summary_table(cells_dfs, p_cutoff=None)[source]#
get_colored_p_vals(p_vals, t_vals, significance, color_names)[source]#
group_region_counts(annotator, region_ids, group_dfs, sample_ids, volume_map) DataFrame[source]#

Count entities (cells, tracts, …) per region per hemisphere for each sample in a group.

Note

Works for any labeled DataFrame that has an ‘id’ column. ‘hemisphere’ is optional — when absent all entities are treated as belonging to a single synthetic hemisphere (value 0).

Parameters:
  • annotator (Annotator) – Atlas annotator for structure name lookup.

  • region_ids (array-like) – Region IDs to count.

  • group_dfs (list[pd.DataFrame]) – One DataFrame per sample, with ‘id’ and (optional) ‘hemisphere’ columns.

  • sample_ids (list) – Sample identifiers (strings or ints).

  • volume_map (dict) – Maps (id, hemisphere) to structure volume in pixels.

Returns

pd.DataFrame

read_group(sources, combine=True, **args)[source]#

Turn a list of sources for data into a numpy stack.

Arguments

sourceslist of str or sources

The sources to combine.

combinebool

If true combine the sources to ndarray, otherwise return a list.

Returns

grouparray or list

The group data.

remove_p_val_nans(p_vals, t_vals)[source]#
sanitize_df(gp_names, grouped_counts, total_df)[source]#

Remove rows with all 0 or NaN in at least 1 group

stack_voxelizations(arrays: list[ndarray]) ndarray[source]#

Stack a list of 3-D voxelization arrays into a single (X, Y, Z, N) float32 array.

Parameters:

arrays (list of np.ndarray) – Per-sample voxelization volumes, each shaped (X, Y, Z).

Returns

np.ndarray

Shape (X, Y, Z, N).

t_test_region_counts(counts1, counts2, *, signed=False, remove_nan=True, p_cutoff=None, equal_var=False)[source]#

t-Test on differences in counts of points in labeled regions

t_test_voxelization(group1, group2, *, signed=False, remove_nan=True, p_cutoff=None)[source]#

t-Test on differences between the individual voxels in group1 and group2

Arguments

group1, group2array of arrays

The group of voxelizations to compare.

signedbool

If True, return also the direction of the changes as +1 or -1.

remove_nanbool

Remove Nan values from the data.

p_cutoffNone or float

Optional cutoff for the p-values.

Returns

p_valuesarray

The p values for the group wise comparison.