cortexlab_fusi_utils.bids¶
bids ¶
BIDS conversion utilities for fUSI data.
Modules:
-
io–File finding and fUSI data loading utilities for BIDS conversion.
-
physio–Physiology data conversion utilities.
-
sidecar–BIDS sidecar JSON building utilities.
Classes:
-
DataPathResolver–Resolves data paths for a given animal.
-
SequenceMetadata–Metadata extracted from a
_fus.matfile plus computed values. -
SpatialInfo–Spatial information computed from AUTCMetadata.
-
VoxelDimensions–Voxel dimensions in millimeters.
Functions:
-
build_functional_sidecar–Build the complete BIDS sidecar JSON for a functional fUSI scan.
-
build_scans_tsv–Build a
*_scans.tsvDataFrame for a single subject. -
build_sequence_sidecar–Build the sequence-parameter portion of a BIDS fUSI sidecar JSON.
-
convert_physio_session–Convert physiology data for one recording session to BIDS physio files.
-
find_bids_paths–Return absolute BIDS paths for a subject, optionally filtered.
-
find_fus_mat–Return the path to the
_fus.matfile for a recording session. -
find_mot_svd_files–Return available Facemap motSVD NPZ files for a recording session.
-
find_rotary_encoder–Return the path to the rotary encoder file for a recording session.
-
find_timeline_mat–Return the path to the
Timeline.matfile for a recording session. -
get_data_path_resolver–Get the current data path resolver.
-
load_angio_as_nifti–Load the latest reference (angiography) scan and return as a NIfTI image.
-
load_fusi_as_nifti–Load a preprocessed fUSI file and return a NIfTI image.
-
load_sequence_metadata–Load sequence acquisition metadata from the
_fus.matHDF5 file. -
save_physio_bids–Save physiological data to BIDS format (TSV.gz + JSON sidecar).
-
set_data_path_resolver–Set the global data path resolver.
DataPathResolver ¶
Resolves data paths for a given animal.
Parameters:
-
(animal_data_path_func¶callable) –Function that takes an animal ID and returns its data root path.
-
(iq_blocks_per_doppler_frame¶int) –Number of IQ blocks per Doppler frame (from preprocessing).
-
(doppler_frames_per_clutter_window¶int) –Number of Doppler frames per clutter filter window.
-
(camera_names¶tuple[str, ...], default:("eyeCamRight", "eyeCamLeft", "frontCam", "bellyCam")) –Ordered camera names used to search for motion SVD files.
-
(fusi_filename_pattern¶str, default:'fUSi_preprocessed_{date}_{session}_50.npz') –Format string for fUSI NPZ filenames. Variables: {date}, {session}, {animal}.
-
(fus_filename_pattern¶str, default:'{date}_{session}_{animal}_fus.mat') –Format string for _fus.mat filenames. Variables: {date}, {session}, {animal}.
-
(timeline_filename_pattern¶str, default:'{date}_{session}_{animal}_Timeline.mat') –Format string for Timeline.mat filenames. Variables: {date}, {session}, {animal}.
Methods:
-
animal_root–Return the root data directory for an animal.
-
available_mot_svds–Return available motion-SVD files for one session.
-
fus_mat–Return the expected path to the raw
_fus.matfile. -
fusi_npz–Return the expected path to the preprocessed fUSI archive.
-
mot_svd_for_camera–Return the expected motion-SVD NPZ path for one camera and session.
-
reference_scan–Return the latest angiography reference scan for an animal.
-
rotary_encoder–Return the expected path to the rotary encoder recording.
-
timeline_mat–Return the expected path to the raw
Timeline.matfile.
Attributes:
-
camera_names(tuple[str, ...]) –Return camera names searched for motion SVD files.
camera_names
property
¶
animal_root ¶
available_mot_svds ¶
available_mot_svds(
animal: str,
date: str,
session: int,
camera_names: tuple[str, ...] | None = None,
) -> dict[str, Path]
Return available motion-SVD files for one session.
Parameters:
-
(animal¶str) –Animal identifier.
-
(date¶str) –Recording date in
YYYY-MM-DDformat. -
(session¶int) –Session number.
-
(camera_names¶tuple[str, ...], default:None) –Camera names to search, in priority order. If None, uses
self.camera_names.
Returns:
fus_mat ¶
fusi_npz ¶
mot_svd_for_camera ¶
Return the expected motion-SVD NPZ path for one camera and session.
Parameters:
-
(animal¶str) –Animal identifier.
-
(date¶str) –Recording date in
YYYY-MM-DDformat. -
(session¶int) –Session number.
-
(camera_name¶str) –Camera name used in the motSVD filename.
Returns:
-
Path–Expected motSVD archive path for the session.
reference_scan ¶
rotary_encoder ¶
timeline_mat ¶
SequenceMetadata ¶
Metadata extracted from a _fus.mat file plus computed values.
Parameters:
-
(autc_meta¶AUTCMetadata) –Raw metadata from load_autc_metadata.
-
(spatial¶SpatialInfo) –Computed spatial information, including voxel dimensions.
-
(tr¶float) –Repetition time in seconds.
-
(probe_voltage¶float) –Probe HV voltage in volts.
-
(n_iq_frames_per_hardware_block¶int) –Number of IQ frames per hardware block.
-
(svd_hp_threshold¶float) –SVD high-pass filter threshold.
-
(low_rank_kernel¶float) –Low-rank kernel filter parameter.
-
(iq_blocks_per_doppler_frame¶int) –Number of IQ blocks integrated into one Doppler frame.
-
(doppler_frames_per_clutter_window¶int) –Number of Doppler frames used by the clutter filter.
Attributes:
-
autc_meta(AUTCMetadata) –Raw metadata from load_autc_metadata.
-
spatial(SpatialInfo) –Computed spatial information (voxel dimensions).
-
probe_voltage(float) –Probe HV voltage in volts.
-
n_iq_frames_per_hardware_block(int) –Number of IQ frames per hardware block.
-
svd_hp_threshold(float) –SVD high-pass filter threshold.
-
low_rank_kernel(float) –Low-rank kernel filter parameter.
-
tr(float) –Repetition time in seconds (median inter-block interval).
-
power_doppler_integration_duration(float) –Duration of one power Doppler frame.
-
clutter_filter_window_duration(float) –Duration of the SVD clutter filter window.
SpatialInfo
dataclass
¶
Spatial information computed from AUTCMetadata.
VoxelDimensions
dataclass
¶
Voxel dimensions in millimeters.
build_functional_sidecar ¶
build_functional_sidecar(
meta: SequenceMetadata,
animal: str,
date: str,
session: int,
task: Optional[TaskConfig] = None,
hardware: Optional[HardwareConfig] = None,
) -> dict[str, Any]
Build the complete BIDS sidecar JSON for a functional fUSI scan.
Parameters:
-
(meta¶SequenceMetadata) –Sequence metadata loaded from the
_fus.matfile. -
(animal¶str) –Animal identifier.
-
(date¶str) –Recording date in
YYYY-MM-DDformat. -
(session¶int) –Session number.
-
(task¶TaskConfig, default:None) –Task configuration. Uses defaults if not provided.
-
(hardware¶HardwareConfig, default:None) –Hardware configuration. Uses defaults if not provided.
Returns:
-
dict–Complete sidecar JSON content for the functional scan.
build_scans_tsv ¶
build_scans_tsv(
functional_df: DataFrame,
angio_df: DataFrame,
animal: str,
) -> DataFrame
Build a *_scans.tsv DataFrame for a single subject.
Parameters:
-
(functional_df¶DataFrame) –Table describing functional BIDS outputs.
-
(angio_df¶DataFrame) –Table describing angiography BIDS outputs.
-
(animal¶str) –Animal identifier used to filter both tables.
Returns:
-
DataFrame–Rows for the subject's
*_scans.tsvfile.
build_sequence_sidecar ¶
build_sequence_sidecar(
meta: SequenceMetadata,
hardware: Optional[HardwareConfig] = None,
) -> dict[str, Any]
Build the sequence-parameter portion of a BIDS fUSI sidecar JSON.
Parameters:
-
(meta¶SequenceMetadata) –Sequence metadata loaded from the
_fus.matfile. -
(hardware¶HardwareConfig, default:None) –Hardware configuration. Uses defaults if not provided.
Returns:
-
dict–Sidecar fields describing the acquisition hardware and sequence.
convert_physio_session ¶
convert_physio_session(
animal: str,
date: str,
session: int,
bids_stem: str,
bids_root: Path,
console: Optional[Any] = None,
) -> None
Convert physiology data for one recording session to BIDS physio files.
Parameters:
-
(animal¶str) –Animal identifier.
-
(date¶str) –Recording date in
YYYY-MM-DDformat. -
(session¶int) –Session number.
-
(bids_stem¶str) –BIDS filename stem shared with the functional scan.
-
(bids_root¶Path) –Root of the output BIDS dataset.
-
(console¶Any, default:None) –Rich console for logging. If None, logging is disabled.
find_bids_paths ¶
find_bids_paths(
animal: str,
bids_root: Path,
date: Optional[str] = None,
experiment_id: Optional[int] = None,
) -> list[Path]
Return absolute BIDS paths for a subject, optionally filtered.
Parameters:
-
(animal¶str) –Animal identifier.
-
(bids_root¶Path) –Root of the BIDS dataset.
-
(date¶str, default:None) –Restrict matches to acquisitions whose
acq_timestarts with this date. -
(experiment_id¶int, default:None) –Restrict matches to a single experiment identifier.
Returns:
find_fus_mat ¶
find_mot_svd_files ¶
find_mot_svd_files(
animal: str,
date: str,
session: int,
camera_names: tuple[str, ...] | None = None,
) -> dict[str, Path]
Return available Facemap motSVD NPZ files for a recording session.
Parameters:
-
(animal¶str) –Animal identifier.
-
(date¶str) –Recording date in
YYYY-MM-DDformat. -
(session¶int) –Session number.
-
(camera_names¶tuple[str, ...], default:None) –Camera names to search, in priority order. If None, uses resolver defaults.
Returns:
Raises:
-
FileNotFoundError–If no motSVD files are found for the requested session.
find_rotary_encoder ¶
find_timeline_mat ¶
get_data_path_resolver ¶
get_data_path_resolver() -> DataPathResolver
Get the current data path resolver.
Returns:
-
DataPathResolver–The configured global data path resolver.
load_angio_as_nifti ¶
load_fusi_as_nifti ¶
load_sequence_metadata ¶
Load sequence acquisition metadata from the _fus.mat HDF5 file.
Computes TR from block times and voxel dimensions from AUTCMetadata.
Parameters:
-
(animal¶str) –Animal identifier.
-
(date¶str) –Recording date in
YYYY-MM-DDformat. -
(session¶int) –Session number.
Returns:
-
SequenceMetadata–Metadata extracted from the raw sequence file and derived timing values.
save_physio_bids ¶
save_physio_bids(
data: ndarray,
timestamps: ndarray,
columns: list[str],
output_path: Path,
column_metadata: Optional[dict[str, dict]] = None,
) -> None
Save physiological data to BIDS format (TSV.gz + JSON sidecar).
Parameters:
-
(data¶ndarray) –One- or two-dimensional array containing the physiological signals.
-
(timestamps¶ndarray) –Sample timestamps in seconds.
-
(columns¶list of str) –Column names for the physiological signals stored in
data. -
(output_path¶Path) –Output stem used to derive the
.tsv.gzand.jsonfiles. -
(column_metadata¶dict of str to dict, default:None) –Per-column metadata to merge into the JSON sidecar.
set_data_path_resolver ¶
set_data_path_resolver(resolver: DataPathResolver) -> None
Set the global data path resolver.
Parameters:
-
(resolver¶DataPathResolver) –Resolver used by BIDS helpers to locate source data files.