Shared Modules API
This section details the shared data structures and configuration utilities of the pipeline.
Experiment Data Manager
ace_neuro.shared.experiment_data_manager.ExperimentDataManager
Manages experiment metadata and analysis parameters.
This class loads data from two CSV files in the project repository: - experiments.csv: Experiment metadata (subject, date, directories, etc.) - analysis_parameters.csv: Processing settings for each experiment
Both project_path and data_path must be supplied explicitly —
either directly or via CLI flags / notebook variables. There is no
automatic fallback to environment variables or .env files.
Attributes:
| Name | Type | Description |
|---|---|---|
line_num |
int
|
The experiment line number. |
metadata |
Optional[Dict[str, Any]]
|
Dict of experiment metadata from experiments.csv. |
analysis_params |
Optional[Dict[str, Any]]
|
Dict of analysis parameters from analysis_parameters.csv. |
Example
edm = ExperimentDataManager( ... 96, ... project_path="/home/user/projects/my_project", ... data_path="/data/raw" ... ) print(edm.metadata['id']) 'R230706B'
Source code in src/ace_neuro/shared/experiment_data_manager.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__init__(line_num, project_path=None, data_path=None, auto_import_metadata=True, auto_import_analysis_params=True, logging_level=logging.CRITICAL)
Initialize the data manager for a specific experiment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_num
|
int
|
Experiment line number (matches 'line number' column in CSVs). |
required |
project_path
|
Optional[Union[str, Path]]
|
Path to project directory containing metadata CSVs. Required for most workflows. Defaults to PROJECT_ROOT/data if not provided. |
None
|
data_path
|
Optional[Union[str, Path]]
|
Base path for raw experimental data. Defaults to PROJECT_ROOT/data/downloaded_data if not provided. |
None
|
auto_import_metadata
|
bool
|
If True, load metadata from experiments.csv on init. |
True
|
auto_import_analysis_params
|
bool
|
If True, load analysis params on init. |
True
|
logging_level
|
Union[str, int]
|
Logging verbosity ('DEBUG', 'INFO', 'WARNING', 'CRITICAL'). |
CRITICAL
|
Source code in src/ace_neuro/shared/experiment_data_manager.py
get_ephys_directory()
Return the ephys directory path from metadata.
get_miniscope_directory()
Return the miniscope/calcium imaging directory path from metadata.
Source code in src/ace_neuro/shared/experiment_data_manager.py
get_pipeline_params()
Return analysis parameters formatted for pipeline.run().
Converts the raw analysis_params dict to kwargs compatible with MiniscopePipeline.run() and EphysPipeline.run().
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict of kwargs to pass to pipeline.run() |
Source code in src/ace_neuro/shared/experiment_data_manager.py
import_analysis_parameters()
Load analysis parameters from project_path/analysis_parameters.csv.
Populates self.analysis_params. If the file doesn't exist or the line number isn't found, sets analysis_params to an empty dict (allowing pipeline defaults to be used).
Source code in src/ace_neuro/shared/experiment_data_manager.py
import_metadata()
Load experiment metadata from project_path/experiments.csv.
Populates self.metadata with converted data types. Directory paths are resolved relative to self.data_path.
Source code in src/ace_neuro/shared/experiment_data_manager.py
Configuration helpers (analysis_parameters.csv)
ace_neuro.shared.config_utils.load_analysis_params(line_num, project_path=None)
Load analysis parameters for an experiment from the project directory.
Reads from project_path/analysis_parameters.csv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_num
|
int
|
Experiment line number (matches 'line number' column in CSV) |
required |
project_path
|
Optional[Path]
|
Path to project directory containing analysis_parameters.csv. Required — raises ValueError if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict of parameters ready to pass to pipeline.run() |
Raises:
| Type | Description |
|---|---|
ValueError
|
If project_path is not provided |
FileNotFoundError
|
If analysis_parameters.csv doesn't exist |
ValueError
|
If line_num not found in CSV |
Example
params = load_analysis_params(96, project_path=Path("/path/to/project")) api = MiniscopePipeline() api.run(line_num=96, project_path="/path/to/project", **params)
Source code in src/ace_neuro/shared/config_utils.py
ace_neuro.shared.config_utils.parse_analysis_params(params)
Convert CSV column values to pipeline kwargs.
Maps column names from analysis_parameters.csv to the exact argument names expected by MiniscopePipeline.run() and EphysPipeline.run(). Empty/None values are skipped, allowing pipeline defaults to apply.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Dict[str, Any]
|
Dict from CSVWorker.csv_row_to_dict() |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with keys matching pipeline.run() arguments |
Source code in src/ace_neuro/shared/config_utils.py
Path Resolution
ace_neuro.shared.paths
Path configuration for the experiment_analysis package.
All data paths (project_path, data_path) must be provided explicitly by the user — either as arguments to Pipeline/DataManager constructors, or as CLI flags (--project-path, --data-path).
There is no hidden state: no .env files, no environment variable lookups.
Misc Functions
ace_neuro.shared.misc_functions
append_row_csv(data, filename)
Appends a new row to a CSV file. Args: data: Dictionary of data to be added to the csv file filename: Name of the CSV file to write to.
Source code in src/ace_neuro/shared/misc_functions.py
conv_quat_to_euler(line)
Convert a CSV line of quaternion data to Euler angles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
List[Any]
|
List of [time, qw, qx, qy, qz]. |
required |
Returns:
| Type | Description |
|---|---|
Optional[List[Any]]
|
List of [time, roll, pitch, yaw]. |
Source code in src/ace_neuro/shared/misc_functions.py
denoise_movie(dataDir, dataFilePrefix='', showVideo=False, startingFileNum=0, framesPerFile=1000, fs=30, frameStep=10, goodRadius=2000, notchHalfWidth=3, centerHalfHeightToLeave=90, cutoff=3.0, butterOrder=6, mode='display', compressionCodec='FFV1', jobID='')
Remove horizontal bands and slow flicker from miniscope movies.
Applies 2D FFT-based denoising to remove traveling horizontal bands and whole-image flicker artifacts. Based on Daniel Aharoni's denoising notebook: https://github.com/Aharoni-Lab/Miniscope-v4/tree/master/Miniscope-v4-Denoising-Notebook
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataDir
|
Union[str, List[str]]
|
Directory containing movie files to denoise. |
required |
dataFilePrefix
|
str
|
Prefix before file numbers (e.g., 'msCam' for 'msCam0.avi'). |
''
|
showVideo
|
bool
|
If True, display movie before analysis. |
False
|
startingFileNum
|
int
|
First file number to process; all subsequent files included. |
0
|
framesPerFile
|
int
|
Number of frames per file (set by Miniscope software). |
1000
|
fs
|
float
|
Frame acquisition rate in Hz. |
30
|
frameStep
|
int
|
Step size for 2D FFT generation (skip frames to speed up). |
10
|
goodRadius
|
int
|
Radius parameter for FFT filtering. |
2000
|
notchHalfWidth
|
int
|
Half-width of notch filter. |
3
|
centerHalfHeightToLeave
|
int
|
Half-height of pass frequencies in 2D FFT. |
90
|
cutoff
|
float
|
Cutoff frequency for filtering. |
3.0
|
butterOrder
|
int
|
Butterworth filter order (4-9 recommended to avoid artifacts). |
6
|
mode
|
str
|
'save' to write output or 'display' to show denoised movie. |
'display'
|
compressionCodec
|
str
|
Video codec for saving ('FFV1' or 'GREY'). |
'FFV1'
|
jobID
|
str
|
Optional job identifier string. |
''
|
Source code in src/ace_neuro/shared/misc_functions.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
filter_data(data, n, cut, ftype, btype, fs, bodePlot=False)
Use ftype to indicate FIR or Butterworth filter.
For the FIR filter indicate a LowPass, HighPass, or BandPass with btype = lowpass, highpass, or bandpass, respectively. n is the length of the filter (number of coefficients, i.e. the filter order + 1). numtaps must be odd if a passband includes the Nyquist frequency. A good value for n is 10000. Channel should be set to desired .ncs file
The Butterworth filters have a more linear phase response in the pass-band than other types and is able to provide better group delay performance, and also a lower level of overshoot. Indicate the filter type by setting btype = 'low', 'high', or 'band'. The default for n is n = 2 For a bandpass filter indicate the lowstop and the highstop by using an array. example: wn= ([10, 30])
Source code in src/ace_neuro/shared/misc_functions.py
get_coords_dict_from_analysis_params(miniscope_data_manager)
Extract crop coordinates from analysis parameters.
Reads the 'crop_coords' column from analysis_params and returns a dict with x0, y0, x1, y1 keys suitable for cropping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
miniscope_data_manager
|
Any
|
Data manager with analysis_params. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, int]]
|
Tuple of (coords_dict, crop_job_name). coords_dict is None |
str
|
if no crop coordinates are found. |
Source code in src/ace_neuro/shared/misc_functions.py
import_video_as_numpy_array(filename, frames='all', displayFrame=False, frameToDisplay=10)
Import a video file directly into a NumPy array.
This function leverages OpenCV to read video frames sequentially and load them
into a preallocated 4D NumPy array (frames, height, width, channels).
Credit: Adapted from https://stackoverflow.com/questions/42163058/how-to-turn-a-video-into-numpy-array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The absolute or relative path to the video file. |
required |
frames
|
int or all
|
Number of frames to read. Defaults to 'all'. |
'all'
|
displayFrame
|
bool
|
If True, displays a specific frame after loading. Defaults to False. |
False
|
frameToDisplay
|
int
|
The 1-indexed frame number to display if |
10
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A 4D uint8 array containing the video data |
Source code in src/ace_neuro/shared/misc_functions.py
load_obj(filename)
Load a pickled object from disk.
Useful for loading previously saved class instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Union[str, Path]
|
Path to the pickle file. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The unpickled Python object. |
Source code in src/ace_neuro/shared/misc_functions.py
mark_events(axisHandle, eventTimes)
Draw vertical event markers on a plot at specified times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axisHandle
|
Axes
|
Matplotlib axis to draw on. |
required |
eventTimes
|
Union[float, List[float], ndarray]
|
Single time or list of times to mark. |
required |
Source code in src/ace_neuro/shared/misc_functions.py
quat_to_euler(qw, qx, qy, qz, degrees=False)
Convert quaternion to Euler angles (roll, pitch, yaw).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qw
|
float
|
Quaternion w component. |
required |
qx
|
float
|
Quaternion x component. |
required |
qy
|
float
|
Quaternion y component. |
required |
qz
|
float
|
Quaternion z component. |
required |
degrees
|
bool
|
If True, return angles in degrees; otherwise radians. |
False
|
Returns:
| Type | Description |
|---|---|
List[float]
|
List of [roll, pitch, yaw] angles. |
Source code in src/ace_neuro/shared/misc_functions.py
spectrogram(tVec, freqVec, specData, cBarPercentLims=[5.0, 95.0], xLabel='Time (s)', yLabel='Frequency (Hz)', cLabel='Power (dB)')
Plots a spectrogram that has already been computed. TVEC is a vector of the x-axis time points or a time vector consisting of just [min, max]. FREQVEC is a vector of the y-axis frequency points, or a frequency vector consisting of just [min, max]. SPECDATA is the matrix of spectral power. CBARPERCENTLIMS sets the bounds on the color bar by finding the specified percentages of the power in specData.
Source code in src/ace_neuro/shared/misc_functions.py
spike_trig_avg(eventArray, dataArray, framesb, framesa)
Compute the average spike values starting 'framesb' before the event and ending 'framesa' after the event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eventArray
|
ndarray
|
A numpy array of when and/or where events occur. Can either be in the format of [[component, frame],...] or [[frame],...] |
required |
dataArray
|
ndarray
|
A numpy array of the signal values at each frame. |
required |
framesb
|
int
|
Number of frames before the event to include. |
required |
framesa
|
int
|
Number of frames after the event to include. |
required |
Returns: avgEventDict: a dictionary dictionary where the keys represent the component number from the dataArray and the value is a numpy array of the average values at each frame of the designated window around the event
Source code in src/ace_neuro/shared/misc_functions.py
thresh_func(dataArray, threshVal)
Find indices where data crosses above a threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataArray
|
ndarray
|
Input data array. |
required |
threshVal
|
float
|
Threshold value. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of indices where threshold crossings occur. |
Source code in src/ace_neuro/shared/misc_functions.py
update_csv_cell(data, columnTitle, lineNum, csvFile)
Update a single cell in a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
New value to write. |
required |
columnTitle
|
str
|
Column header name. |
required |
lineNum
|
int
|
Line number to update. |
required |
csvFile
|
Union[str, Path]
|
Path to CSV file. |
required |
Source code in src/ace_neuro/shared/misc_functions.py
z_score(dataArray, frameWindow=1000)
Compute the z-score of the data array values every designated frame window length based on the values within that frame window
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataArray
|
ndarray
|
A numpy array of values where the row represents the component and the column represents the frame number |
required |
frameWindow
|
int
|
An integer value that determines the length of the window which the function z-scores across. Defaults to 1000 frames |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
zScoreArray |
ndarray
|
A numpy array of the same shape as dataArray containing the z-score values of each frame |