Skip to content

Correct the pc_features axis order and indexing example - #1408

Merged
rossant merged 1 commit into
cortex-lab:masterfrom
adityasingh2400:docs/1364-pc-features
Aug 9, 2026
Merged

Correct the pc_features axis order and indexing example#1408
rossant merged 1 commit into
cortex-lab:masterfrom
adityasingh2400:docs/1364-pc-features

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

The pc_features.npy description is wrong in two different ways on two different pages, which is what prompted the question in the issue about whether pc_features[123, 1, 5] should be pc_features[123, 0, 5].

In docs/dataset.md, the file table lists the shape as (n_spikes_subset, n_channels_loc, n_pcs). That is the shape phy holds in memory, not the shape on disk. phylib.io.model.TemplateModel._load_features reads the array and then applies data.transpose((0, 2, 1)), so the file itself stores (n_spikes_subset, n_pcs, n_channels_loc). The neighboring rows of that same table do describe the on-disk layout, so the entry was inconsistent with its own table.

In docs/sorting_user_guide.md, the declared shape [nSpikes, nFeaturesPerChannel, nPCFeatures] is correct, but the worked example is not. It calls axis index 1 the first PC when array indices are zero-based, and it indexes pc_feature_ind as pc_feature_ind[5] when that array is two-dimensional, [nTemplates, nPCFeatures], and has to be indexed by the spike's own template first. The sentence also referred to a file named pc_features_ind.npy, which does not exist.

I verified the layout by driving phylib's loader directly with a synthetic on-disk array of shape (7, 3, 4). It comes back as (7, 4, 3), pc_feature_ind is asserted to be (n_templates, n_channels_loc), and disk[2, 1, 3] equals memory[2, 3, 1], confirming the transpose and confirming which axis the channel index belongs to. The change corrects the shape in the dataset reference, corrects the worked example and the filename in the user guide, and notes the transpose on both pages so readers moving between the file and model.get_features() are not caught out. make doc-check passes, including the strict mkdocs build.

Fixes #1364

The dataset reference gave the in-memory shape for the file on disk, and
the sorting user guide indexed pc_feature_ind as a one-dimensional array
and described a zero-based PC index as the first PC.

phylib reads pc_features.npy and transposes its last two axes, so the file
holds (n_spikes, n_pcs, n_channels_loc) and pc_feature_ind is indexed by
the spike's template. Correct both pages and note the transpose.

Fixes cortex-lab#1364
@rossant
rossant merged commit bcf01c1 into cortex-lab:master Aug 9, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarification on pc_features description in the documentation

2 participants