rtcog.utils package
Submodules
rtcog.utils.core module
- show-inheritance:
Bases:
objectMinimal clock for tracking elapsed time across processes.
This clock is initialized at instantiation and provides a method for retrieving the current time relative to that start point.
The absolute time (in seconds) when the clock was created, based on time.perf_counter().
- Type:
float
Get the current time relative to the clock’s start time.
- Returns:
Elapsed time in seconds since the clock was initialized.
- Return type:
float
rtcog.utils.exceptions module
rtcog.utils.fMRI module
- rtcog.utils.fMRI.load_fMRI_file(path, verbose=False)[source]
Load fMRI Dataset
Parameters:
- path: str
full path to the dataset of interest
Returns:
- img: nib.Nifti2Image
Image structure with data, affine, etc.
- rtcog.utils.fMRI.mask_fMRI_img(data_img, mask_img, verbose=False)[source]
Converts NiftiImage into vectorized numpy array [Nv,Nt] It is an equivalent to nilearn mask_img, but I needed to implement this becuase of the issues with ordering going from 3D/4D to vector. This way is consistent throughout the code.
Parameters:
- data_img: Nifti2Image
Nifti Image with the 3D or 4D to be vectorized
- mask_img: Nifti2Image
Nifti Image with the 3D mask
Returns:
data_v: np.array [Nacquisitions, Nvoxels in mask]
- rtcog.utils.fMRI.unmask_fMRI_img(data, mask_img, out_path=None)[source]
Convert Nv,Nt array of fMRI data into an actual Nifti Image, and possibly write to disk
Parameters:
- datanp.array [Nv,Nt]
data to be reshaped into an image
- mask_img: Nifti2Image
mask used to obtain the affine, and where to put the data in space
- out_path: str
path to write nifti file. None means do not write file
Returns:
out: Nifti2Image
rtcog.utils.log module
rtcog.utils.options module
- class rtcog.utils.options.Options(config)[source]
Bases:
objectConfiguration object for the real-time fMRI pipeline.
Loads configuration from a YAML file and/or command-line arguments, and exposes them as attributes for easy access throughout the experiment code.
- (Dynamically assigned)
All configuration keys are stored as object attributes.
- classmethod from_cli(argv=None)[source]
Create an Options object from CLI arguments (with YAML config as base).
- Parameters:
argv (list or None) – Command-line arguments.
- Returns:
An instance with merged YAML and CLI arguments.
- Return type:
- classmethod from_yaml(path)[source]
Create an Options object from a YAML file.
Useful for testing purposes.
- Parameters:
path (str) – Path to the YAML configuration file.
- Returns:
An instance populated with the file contents.
- Return type:
- static load_yaml(path)[source]
Load configuration from a YAML file.
- Parameters:
path (str) – Path to the YAML configuration file.
- Returns:
Parsed YAML content as a dictionary.
- Return type:
dict
- classmethod parse_cli_args(argv=None)[source]
Parse command-line arguments to load and optionally override config options.
- Parameters:
argv (list or None) – Command-line arguments.
- Returns:
Merged configuration from YAML and CLI overrides.
- Return type:
dict
- Raises:
FileNotFoundError – If the specified YAML config file cannot be found.
SystemExit – If required arguments are missing.
rtcog.utils.recorder module
recorder.py Provides WAV recording functionality via two approaches: Blocking mode (record for a set duration): >>> rec = Recorder(channels=2) >>> with rec.open(‘blocking.wav’, ‘wb’) as recfile: … recfile.record(duration=5.0) Non-blocking mode (start and stop recording): >>> rec = Recorder(channels=2) >>> with rec.open(‘nonblocking.wav’, ‘wb’) as recfile2: … recfile2.start_recording() … time.sleep(5.0) … recfile2.stop_recording() Original Code from: https://gist.github.com/sloria/5693955
rtcog.utils.sync module
- class rtcog.utils.sync.ActionState(action_onsets: List[int], action_offsets: List[int], in_action: bool, in_cooldown: bool, cooldown_end: int | None, hit: bool)[source]
Bases:
objectRepresents the current state of an action block during the experiment.
- action_offsets: List[int]
TR indices at which action blocks end.
- action_onsets: List[int]
TR indices at which action blocks start.
- cooldown_end: int | None
TR index at which the cooldown period ends, or
Noneif no cooldown has occurred.
- hit: bool
Whether a hit occurred.
- in_action: bool
Whether the experiment is currently within an action block.
- in_cooldown: bool
Whether the experiment is currently within a cooldown period.
- class rtcog.utils.sync.SyncEvents(hit: Event, action_end: Event, end: Event, new_tr: Event, shm_ready: Event, server_ready: Event, tr_index: Synchronized)[source]
Bases:
objectContainer for multiprocessing synchronization primitives used in experiment.
- action_end: Event
Set when the current action block ends.
- end: Event
Set when the entire experiment should terminate.
- hit: Event
Set when a hit event occurs.
- new_tr: Event
Set when a new TR is received.
- server_ready: Event
Set when the server process is ready.
- shm_ready: Event
Set when shared memory is ready for access.
- tr_index: Synchronized
Shared integer tracking the current TR index.