nirspipe.pipeline.hyper.roi#

Grouping per-channel coherence into regions.

roi_mean_of_channels The band means, averaged per region pair. roi_mean_of_homologous The same, restricted to a region against itself in the partner. roi_maps_from_channels The maps grouped the same way, so a figure matches the table.

ROI coherence is always computed per channel pair and then averaged.

Module Contents#

Functions#

roi_maps_from_channels

Average the channel-pair WTC maps cell by cell into one map per ROI pair.

roi_mean_of_channels

Average channel-level band means within each ROI.

roi_mean_of_homologous

Average an ROI’s homologous channel pairs: one value per ROI, however the run was made.

Data#

API#

nirspipe.pipeline.hyper.roi.logger = 'get_logger(...)'#
nirspipe.pipeline.hyper.roi.roi_maps_from_channels(result: nirspipe.pipeline.hyper.wtc.WTCResult, roi_map: dict[str, list[str]], min_channels: int = ROI_MIN_CHANNELS, levels: dict | None = None) → nirspipe.pipeline.hyper.wtc.WTCResult#

Average the channel-pair WTC maps cell by cell into one map per ROI pair.

The ROI number is a mean over channel-pair coherences, so the figure beside it is the mean over those channels’ maps. Averaging the maps first and the band second gives the same number as averaging the band first and the channels second, so the picture and the table agree.

{"S1_D1": map, "S1_D2": map}  + {"lPFC": ["S1_D1", "S1_D2"]}  ->  {"lPFC": mean map}

The COI depends only on record length and sampling rate, so every member shares one and it is carried through unchanged. sig is dropped: a Monte Carlo level belongs to the pair it was computed for and does not average. levels, {pairing: {roi key: ndarray}}, puts back the ROI maps’ own phase-scrambled level, matched on the exact key.

Phase averages as a direction, not as a number: the arithmetic mean of 179 degrees and -179 degrees is 0, the one direction neither member points in. The members are summed as unit vectors and the angle read off the sum, so a set of members that disagree gives a short resultant and, drawn as an arrow, a direction no more confident than they were.

min_channels leaves out a cell where either member contributes fewer channels, the rule roi_mean_of_channels() blanks the same cell by, so no map stands for a region the table leaves empty.

nirspipe.pipeline.hyper.roi.roi_mean_of_channels(band_df: pandas.DataFrame, roi_map: dict[str, list[str]], min_channels: int = ROI_MIN_CHANNELS) → pandas.DataFrame#

Average channel-level band means within each ROI.

band_df is what wtc_band_mean() returns for a channel-level result; a crossed one carries label2 and is grouped on both sides into the ROI-by-ROI matrix. n_ch counts the channel pairs behind each mean, so an ROI thinned by rejection is visible. Channels no ROI lists are dropped.

min_channels blanks a cell where either member contributes fewer than that many channels with a value; at one, only a member with no channel left blanks it. On a crossed frame each side is counted on its own: two channels against one is two pairings but one channel of the second member, and is blanked. A blanked cell keeps its row and its n_ch, with NaN in every measured column, as a channel with no map does in wtc_band_mean().

coherence_z is recomputed from the averaged coherence rather than averaged itself, so it stays the Fisher z of the number in the same row.

phase_angle is averaged circularly, an arithmetic mean of angles being wrong at the wrap. Its ``phase_sd`` changes meaning here: at channel level it is the spread of the cells behind one pairing, and here it is the spread of the pairings behind one ROI, so a tight channel angle that disagrees with its neighbours’ gives a small one there and a large one here. phase_n stays a cell count and is summed. The columns are absent when the frame has none, so a caller that built one by hand is unaffected.

nirspipe.pipeline.hyper.roi.roi_mean_of_homologous(band_df: pandas.DataFrame, roi_map: dict[str, list[str]], min_channels: int = ROI_MIN_CHANNELS) → pandas.DataFrame#

Average an ROI’s homologous channel pairs: one value per ROI, however the run was made.

right_pfc holds S1_D1, S1_D2, S2_D1, S2_D2
-> the mean of the four (S1_D1, S1_D1), (S1_D2, S1_D2), ... coherences

roi_mean_of_channels() groups whatever it is handed, so on a crossed frame its (roi, roi) diagonal is the mean of every pairing inside the ROI, sixteen of them here, of which four are homologous. That is a different quantity from the one an uncrossed run produces. This function is the homologous mean, identical whether or not the run crossed.

It is also the only ROI value the homologous phase-scrambled null can rank, since the null draws exactly these pairings.