Miniscope Modules API
This section details the pipeline for processing calcium imaging data.
Miniscope Data Manager
ace_neuro.miniscope.miniscope_data_manager.MiniscopeDataManager
Bases: ExperimentDataManager, ABC
Manages raw Miniscope data import and storage.
Abstract Base Class for Miniscope data managers.
Attributes:
| Name | Type | Description |
|---|---|---|
line_num |
int
|
Experiment line number in experiments.csv. |
time_stamps |
Optional[ndarray]
|
Array of frame timestamps in seconds. |
frame_numbers |
Optional[ndarray]
|
List of frame indices. |
all_movie_filepaths |
List[Union[Path, str]]
|
All discovered .avi movie files. |
chosen_movie_filepaths |
Optional[List[Union[str, Path]]]
|
Subset selected by filenames parameter. |
movie |
movie
|
Loaded CaImAn movie object. |
fr |
float
|
Frame rate from metadata. |
Source code in src/ace_neuro/miniscope/miniscope_data_manager.py
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
__init__(line_num, project_path=None, data_path=None, filenames=[], auto_import_data=True)
Initialize data manager and optionally load movie data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_num
|
int
|
Row number in experiments.csv to load. |
required |
project_path
|
Optional[Union[str, Path]]
|
Optional explicit project repository path. |
None
|
data_path
|
Optional[Union[str, Path]]
|
Optional explicit data storage path. |
None
|
filenames
|
List[str]
|
Optional list of specific movie filenames to load. |
[]
|
auto_import_data
|
bool
|
If True, automatically load movie and metadata. |
True
|
Source code in src/ace_neuro/miniscope/miniscope_data_manager.py
can_handle(directory)
abstractmethod
classmethod
Return True if this class can handle the format in the given directory.
convert_ca_movies(filenames=None, new_file_type='.tif', join_movies=False, metadata_convert=True)
Convert calcium movies from one type to another. File types must be supported by CaImAn.
The new filename(s) is based on the first filename in 'filenames', with new_file_type appended. 'join_movies' determines whether all movie files in 'filenames' are combined into a single movie, or whether each file is converted separately.
If 'filenames' is None, the method will attempt to load filenames from self.movieFilePaths.
Source code in src/ace_neuro/miniscope/miniscope_data_manager.py
create(line_num, project_path=None, data_path=None, **kwargs)
classmethod
Factory method to select the correct subclass for the directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_num
|
int
|
Experiment line number. |
required |
project_path
|
Optional[Union[str, Path]]
|
Optional explicit project repository path. |
None
|
data_path
|
Optional[Union[str, Path]]
|
Optional explicit data storage path. |
None
|
**kwargs
|
Any
|
Additional arguments for subclass initialization. |
{}
|
Source code in src/ace_neuro/miniscope/miniscope_data_manager.py
load_attributes(filepaths)
Load movie data and metadata from disk.
Populates metadata, timestamps, movie array, events, and frame rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepaths
|
List[Union[str, Path]]
|
List of movie file paths to load. |
required |
Source code in src/ace_neuro/miniscope/miniscope_data_manager.py
sync_timestamps(ephys_dm=None, channel_name=None, **kwargs)
abstractmethod
Synchronize miniscope frame timestamps to ephys time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ephys_dm
|
Optional[Any]
|
Optional EphysDataManager to sync against. |
None
|
channel_name
|
Optional[str]
|
Optional channel name for the ephys_dm. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple containing: |
ndarray
|
|
Tuple[ndarray, ndarray]
|
|
Source code in src/ace_neuro/miniscope/miniscope_data_manager.py
Preprocessor
ace_neuro.miniscope.miniscope_preprocessor.MiniscopePreprocessor
Preprocessor for calcium imaging movies before CNMF-E analysis.
Handles cropping, detrending, and DF/F computation to prepare raw miniscope recordings for source extraction.
Attributes:
| Name | Type | Description |
|---|---|---|
data_manager |
MiniscopeDataManager
|
MiniscopeDataManager with loaded movie. |
frame_rate |
float
|
Movie frame rate in Hz. |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
__init__(data_manager)
Initialize preprocessor with data manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_manager
|
MiniscopeDataManager
|
MiniscopeDataManager with movie attribute. |
required |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
compute_df_over_f(movie, secs_window=5, quantile_min=8, method='delta_f_over_sqrt_f')
Compute DF/F or DF/sqrt(F) normalization of the movie.
Normalizes fluorescence to percentage changes relative to baseline, which is estimated using a sliding window and quantile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movie
|
Union[movie, ndarray]
|
CaImAn movie to normalize. |
required |
secs_window
|
float
|
Window size in seconds for baseline estimation. |
5
|
quantile_min
|
float
|
Percentile for baseline (0-100). |
8
|
method
|
str
|
'delta_f_over_sqrt_f' or 'delta_f_over_f'. |
'delta_f_over_sqrt_f'
|
Returns:
| Type | Description |
|---|---|
movie
|
Normalized CaImAn movie. |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
compute_projections(movie=None)
Compute spatial and temporal projections of the movie.
Calculates max, min, mean, median, std, range projections and mean fluorescence time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movie
|
Optional[movie]
|
CaImAn movie object to compute projections from. |
None
|
Returns:
| Type | Description |
|---|---|
Projections
|
Projections object containing all computed projections. |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
crop_movie(movie, coords_dict)
Crop a movie using the given coordinates.
Performs y-coordinate flipping (GUI origin is bottom-left, numpy origin is top-left), sorts coordinates, and slices the movie array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movie
|
movie
|
CaImAn movie to crop. |
required |
coords_dict
|
Dict[str, int]
|
Dict with x0, y0, x1, y1 keys (in GUI coordinate space). |
required |
Returns:
| Type | Description |
|---|---|
Tuple[movie, str]
|
Tuple of (cropped_movie, coords_string). |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
detrend_movie(movie, method='median', plot_trend=True)
Remove slow temporal trends from the movie.
Supports linear detrending or median-based debleaching to correct for photobleaching and other drift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movie
|
movie
|
CaImAn movie to detrend. |
required |
method
|
str
|
'linear' for scipy detrend, 'median' for CaImAn debleach. |
'median'
|
plot_trend
|
bool
|
If True, display before/after comparison plot. |
True
|
Returns:
| Type | Description |
|---|---|
movie
|
Detrended CaImAn movie. |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
get_crop_coordinates(coords_dict, projections, movie_height, movie_width, headless=False)
Get crop coordinates from GUI or provided coordinates.
In headless mode, returns the provided coordinates directly without opening a GUI. If no coordinates are available in headless mode, returns None with a warning.
In interactive mode, opens crop GUI (pre-populated with coords_dict if available) for visual adjustment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords_dict
|
Optional[Dict[str, int]]
|
Dict with x0, y0, x1, y1 keys, or None for GUI. |
required |
projections
|
Projections
|
Projections object for GUI visualization. |
required |
movie_height
|
int
|
Height of the movie in pixels. |
required |
movie_width
|
int
|
Width of the movie in pixels. |
required |
headless
|
bool
|
If True, bypass GUI and use coords_dict directly. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, int]]
|
Dict with x0, y0, x1, y1 keys, or None if no coordinates available. |
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
preprocess_calcium_movie(coords_dict=None, crop=False, detrend_method=None, df_over_f=False, crop_job_name_for_file='_cropped', secs_window=5, quantile_min=8, df_over_f_method='delta_f_over_sqrt_f', headless=False)
Run preprocessing steps based on provided flags. coords_dict: is passed in and represents what you want the final coordinates for the movie to be in the form {'x0': A, 'y0': B, 'x1': C, 'y1': D}
Source code in src/ace_neuro/miniscope/miniscope_preprocessor.py
Processor (CNMF-E)
ace_neuro.miniscope.miniscope_processor.MiniscopeProcessor
Main processor for calcium imaging movie analysis using CaImAn.
Orchestrates the complete analysis pipeline including motion correction, CNMF-E source extraction, and result saving. Works with MiniscopeDataManager to track all processing state and outputs.
Attributes:
| Name | Type | Description |
|---|---|---|
data_manager |
MiniscopeDataManager
|
MiniscopeDataManager containing movie and parameters. |
preprocessed_movie |
movie
|
Copy of original movie before processing. |
Source code in src/ace_neuro/miniscope/miniscope_processor.py
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
__init__(data_manager)
Ensure that data_manager.movie contains the proper movie that you want to process before intializing this class
This class has five main steps
- Set up what processing type you would like to do the next steps with (parellel, how many cores, etc.)
- Motion correct (or don't) what is stored in data_manager.movie and save the result as a memory map
- Prepare/visualize different things to help you find optimal paramters for running CNMFE (an algorithm that decomposes a movie into multiple matrices)
- Run CNMFE using our memory map using the parameters stored in opts_caiman, which draws from analysis_parameters.csv
- Save any results
Source code in src/ace_neuro/miniscope/miniscope_processor.py
cleanup_tkinter()
Helper to cleanup tkinter root if it exists.
Source code in src/ace_neuro/miniscope/miniscope_processor.py
cnmfe_parameter_handler(dm, plot_params=False)
-This is an important step before CNMFE. It handles the most important CNMFE parameters.
-It uses the 'gsig_tmp' below to make the first plot. Adjust this value until the plot shown does not merge any neurons, then update 'gsig' in analysis_parameters.csv with the best 'gsig_tmp' value
-First, this function calculates correlation and peak to noise ratios and plots them. Use the sliders to adjust 'vmax' until neurons are most visible, then adjust 'min_corr' and 'min_pnr' in analysis_parameters.csv to values slightly below those vmax values Example: If neurons are most clear at vmax=0.9, set min_corr=0.8 or 0.85 (slightly below to capture most neurons)
-Second, it plots your 'rf' and 'stride' values which form patches around your movie. We want to select rf and stride parameters so that at least 3-4 neuron diameters can fit into each patch, and at least one neuron fits in the overlap region between patches. If patches and overlaps seem a bit large that is ok: our main concern is that they not be too small.
Source code in src/ace_neuro/miniscope/miniscope_processor.py
inspect_motion_correction(mc, opts_caiman, original_movie, frame_rate, plot_rigid_motion_correction=True, plot_shifts=True, play_concatenated_movies=True, down_sample_ratio=0.2, plot_correlation=True, plot_advanced_MC_inspection=True)
This function is a mess and needs a lot of work. It does not work well at all. mc: the motion correction object obtained from apply_motion_correction() opts_caiman: a caiman parameters object obtained from cm.CNMFParams() original_movie: your movie jsut before motion_correction plot_rigid_motion_correction: a boolean that determines whether rigid motion correction is plotted. play_concatenated_movies: a boolean that determines whether the original and motion-corrected movies are plotted side-by-side. down_sample_ratio: a float that determines the factor by which to shrink the duration of the playback (helpful for making the motion more obvious). plot_shifts: a boolean that determines whether to plot the x and y pixel shifts over time. plot_correlation: a boolean that determines whether to plot the correlation images for the original and motion-corrected movies side-by-side.
Source code in src/ace_neuro/miniscope/miniscope_processor.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
motion_correction_manager(data_manager, dview, apply_motion_correction, inspect_motion_correction)
Manage the motion correction workflow.
Applies motion correction if requested, creates memory-mapped files, and optionally displays diagnostic visualizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_manager
|
MiniscopeDataManager
|
MiniscopeDataManager with movie data. |
required |
dview
|
Any
|
CaImAn distributed view object for parallel processing. |
required |
apply_motion_correction
|
bool
|
If True, perform motion correction. |
required |
inspect_motion_correction
|
bool
|
If True, show before/after comparisons. |
required |
Returns:
| Type | Description |
|---|---|
MiniscopeDataManager
|
Updated data_manager with motion-corrected memory map. |
Source code in src/ace_neuro/miniscope/miniscope_processor.py
process_calcium_movie(parallel=True, n_processes=12, apply_motion_correction=True, inspect_motion_correction=False, plot_params=False, run_CNMFE=True, save_estimates=True, save_CNMFE_estimates_filename='estimates.hdf5', save_CNMFE_params=False)
Run the complete calcium movie processing pipeline.
Executes motion correction, CNMF-E source extraction, and saves results. This is the main entry point for processing miniscope recordings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel
|
bool
|
If True, use multiprocessing for CaImAn operations. |
True
|
n_processes
|
int
|
Number of parallel processes to use. |
12
|
apply_motion_correction
|
bool
|
If True, perform motion correction. |
True
|
inspect_motion_correction
|
bool
|
If True, show motion correction diagnostics. |
False
|
plot_params
|
bool
|
If True, display CNMF-E parameter tuning plots. |
False
|
run_CNMFE
|
bool
|
If True, run CNMF-E source extraction algorithm. |
True
|
save_estimates
|
bool
|
If True, save CNMF-E results to disk. |
True
|
save_CNMFE_estimates_filename
|
str
|
Filename for saved estimates. |
'estimates.hdf5'
|
save_CNMFE_params
|
bool
|
If True, save CaImAn parameters to JSON. |
False
|
Returns:
| Type | Description |
|---|---|
MiniscopeDataManager
|
Updated MiniscopeDataManager with processing results. |
Source code in src/ace_neuro/miniscope/miniscope_processor.py
Postprocessor
ace_neuro.miniscope.miniscope_postprocessor.MiniscopePostprocessor
Post-processor for CNMF-E extracted calcium imaging components.
Performs component refinement, calcium event detection, spectral analysis, and phase computation on processed miniscope data.
Attributes:
| Name | Type | Description |
|---|---|---|
data_manager |
MiniscopeDataManager
|
MiniscopeDataManager with CNMFE results. |
frame_rate |
float
|
Recording frame rate from data_manager. |
dview |
Any
|
CaImAn distributed view for parallel processing. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
__init__(data_manager)
Initialize post-processor with data manager.
Automatically computes movie projections on initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_manager
|
MiniscopeDataManager
|
MiniscopeDataManager with movie and CNMFE results. |
required |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
calculate_black_component_movie(dm)
Create a movie with detected neuron regions blacked out.
Useful for visualizing background activity without neural signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm
|
MiniscopeDataManager
|
MiniscopeDataManager with CNMFE estimates. |
required |
Returns:
| Type | Description |
|---|---|
movie
|
CaImAn movie with neuron ROI pixels set to zero. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
calculate_component_movie(dm)
Create movies showing neural activity and background separately.
Reconstructs the movie as A*C (neural) plus background model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm
|
MiniscopeDataManager
|
MiniscopeDataManager with CNMFE results. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[movie, movie]
|
Tuple of (neural_movie, background_movie) as CaImAn movies. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
compute_miniscope_phase(data)
Compute instantaneous phase of fluorescence using Hilbert transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
1D array of fluorescence signal. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of instantaneous phase in radians (-pi to pi). |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
compute_miniscope_spectrogram(data, frame_rate, window_length=30, window_step=3, freq_lims=[0, 15], time_bandwidth=2, plot_spectrogram=True)
staticmethod
Compute multitaper spectrogram of mean fluorescence signal.
Uses the multitaper method for robust spectral estimation with reduced variance compared to standard periodograms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
1D array of mean fluorescence over time. |
required |
frame_rate
|
float
|
Recording frame rate in Hz. |
required |
window_length
|
float
|
Window length in seconds. |
30
|
window_step
|
float
|
Step size between windows in seconds. |
3
|
freq_lims
|
List[float]
|
[low, high] frequency range to compute. |
[0, 15]
|
time_bandwidth
|
float
|
Time-bandwidth product (higher = smoother). |
2
|
plot_spectrogram
|
bool
|
If True, display the spectrogram plot. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray, ndarray, ndarray]
|
Tuple of (PSD matrix, time points, frequencies, PSD in dB). |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
compute_projections(movie=None)
Compute spatial and temporal projections of the movie.
Calculates max, min, mean, median, std, range projections and mean fluorescence time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movie
|
Optional[movie]
|
CaImAn movie object to compute projections from. |
None
|
Returns:
| Type | Description |
|---|---|
Projections
|
Projections object containing all computed projections. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
evaluate_components(estimates, opts_caiman, min_SNR=3, r_values_min=0.85)
Compute quality metrics for CNMF-E components.
Evaluates each component's SNR and spatial correlation, storing indices of components that pass the specified thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimates
|
Estimates
|
CNMF-E estimates object with extracted components. |
required |
opts_caiman
|
CNMFParams
|
CaImAn parameters object. |
required |
min_SNR
|
float
|
Minimum signal-to-noise ratio threshold. |
3
|
r_values_min
|
float
|
Minimum spatial correlation threshold. |
0.85
|
Returns:
| Type | Description |
|---|---|
Tuple[Estimates, CNMFParams]
|
Tuple of (estimates, opts_caiman) with quality metrics added. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
find_calcium_events_with_deconvolution(estimates, opts_caiman, dview, dff_flag=False)
Detect calcium events using deconvolution-based spike inference.
Uses CaImAn's deconvolution to extract spike trains from calcium traces and identifies event indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimates
|
Estimates
|
CNMF-E estimates with calcium traces. |
required |
opts_caiman
|
CNMFParams
|
CaImAn parameters for deconvolution. |
required |
dview
|
Any
|
Distributed view for parallel processing. |
required |
dff_flag
|
bool
|
If True, use DF/F traces. |
False
|
Returns:
| Type | Description |
|---|---|
Dict[int, ndarray]
|
Dict mapping neuron indices to arrays of event frame indices. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
find_calcium_events_with_derivatives(estimates, derivative='first', event_height=5)
Detect calcium events using derivative-based peak detection.
Computes the specified derivative of calcium traces and finds peaks above the threshold height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimates
|
Estimates
|
CNMF-E estimates with calcium traces (C matrix). |
required |
derivative
|
str
|
Order of derivative ('zeroth', 'first', 'second'). |
'first'
|
event_height
|
float
|
Minimum peak height threshold. |
5
|
Returns:
| Type | Description |
|---|---|
Dict[int, ndarray]
|
Dict mapping neuron indices to arrays of event frame indices. |
Source code in src/ace_neuro/miniscope/miniscope_postprocessor.py
postprocess_calcium_movie(remove_components_with_gui=True, find_calcium_events=True, derivative_for_estimates='first', event_height=5, compute_miniscope_phase=True, filter_miniscope_data=True, n=2, cut=[0.1, 1.5], ftype='butter', btype='bandpass', inline=False, compute_miniscope_spectrogram=True, window_length=30, window_step=3, freq_lims=[0, 15], time_bandwidth=2)
Run the complete post-processing pipeline on CNMF-E results.
Performs component curation via GUI, calcium event detection, phase computation, filtering, and spectral analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remove_components_with_gui
|
bool
|
If True, open interactive GUI for component selection. |
True
|
find_calcium_events
|
bool
|
If True, detect calcium transient events. |
True
|
derivative_for_estimates
|
str
|
Derivative order for event detection ('zeroth', 'first', 'second'). |
'first'
|
event_height
|
float
|
Threshold height for peak detection. |
5
|
compute_miniscope_phase
|
bool
|
If True, compute instantaneous phase via Hilbert. |
True
|
filter_miniscope_data
|
bool
|
If True, apply bandpass filter to projections. |
True
|
n
|
int
|
Filter order. |
2
|
cut
|
List[float]
|
[low, high] cutoff frequencies for bandpass. |
[0.1, 1.5]
|
ftype
|
str
|
Filter type ('butter', 'fir'). |
'butter'
|
btype
|
str
|
Band type for filter. |
'bandpass'
|
inline
|
bool
|
If True, replace original data with filtered. |
False
|
compute_miniscope_spectrogram
|
bool
|
If True, compute multitaper spectrogram. |
True
|
window_length
|
float
|
Spectrogram window length in seconds. |
30
|
window_step
|
float
|
Spectrogram step size in seconds. |
3
|
freq_lims
|
List[float]
|
[low, high] frequency limits for spectrogram. |
[0, 15]
|
time_bandwidth
|
float
|
Time-bandwidth product for multitaper. |
2
|
Returns:
| Type | Description |
|---|---|
MiniscopeDataManager
|
Updated MiniscopeDataManager with all post-processing results. |