Preprocessing API
Core API
preprocess_cmd(**kwargs)
This command will preprocess a single session dual-channel mixed recording to extract a deltaF signal corrected for the haemodynamic response.
Source code in src/mesoscopy/preprocess/__init__.py
run_preprocessing(path, out_dir, chunks=100, crop=0, bins=2, channel_means_only=False, use_means=False, flip_channels=False, interim_dir='interim/', skip_start=None, skip_end=None, no_qa=False)
Preprocessing to extract deltaF from a single session dual-channel mixed recording.
Preprocessing separates the two channels, applies the haemodynamic correction, and extracts the delta F signal.
Parameters:
-
path(str) –Path to the raw recording HDF5 or NWB file.
-
out_dir(str) –Path to the output directory.
-
chunks(int, default:100) –Number of chunks to load in memory. Defaults to 100.
-
crop(int, default:0) –Number of pixels to crop from the edges of the recording. Defaults to 0.
-
bins(int, default:2) –Recording pixel binning factor. Defaults to 2.
-
channel_means_only(bool, default:False) –Extract the channel means and exit without extracting a delta F series. Defaults to False.
-
use_means(bool, default:False) –Use means histogram instead of standard deviation to separate channels. Defaults to False.
-
flip_channels(bool, default:False) –Flip extracted channel order. Defaults to False.
-
interim_dir(str, default:'interim/') –Path to the interim directory. Defaults to "interim/".
-
skip_start(int, default:None) –Number of frames to skip at the start of the recording. Defaults to None.
-
skip_end(int, default:None) –Number of frames to skip at the end of the recording. Defaults to None.
-
no_qa(bool, default:False) –Skip automatic quality control checks. Defaults to False.
Source code in src/mesoscopy/preprocess/__init__.py
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 | |
load_raw(raw_path, nwb=False)
Load raw imaging data from an HDF5 or NWB file.
Parameters:
-
raw_path(str) –Path to the raw recording HDF5 or NWB file.
-
nwb(bool, default:False) –Whether the file is an NWB file. Defaults to False.
Returns:
-
tuple[str, Array | ndarray, Array | ndarray]–tuple[str, da.Array | np.ndarray, da.Array | np.ndarray]: Session ID, imaging data, and timestamps.
Source code in src/mesoscopy/preprocess/__init__.py
update_nwb(nwb_path, h5_path)
Update an NWB file with a delta F imaging series stored in an HDF5 file.
Creates a link between the NWB file and the HDF5 file. See https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/linking_data.html.
Parameters:
-
nwb_path(str) –Path to NWB file.
-
h5_path(str) –Path to HDF5 file containing the delta F imaging series.
Source code in src/mesoscopy/preprocess/__init__.py
Calculations API
bin_array(array, bins, interim_dir='.', session_id='null')
Bin a 3D image array across its x and y axes.
The function bins the width and height of a 3D image array by a factor of bins. It does not bin the z-axis (time).
Parameters:
-
array(Dask or NumPy Array) –Array to be binned.
-
bins(int) –Number of bins in x and y directions (i.e. width and height).
-
interim_dir(str or PathLike object, default:'.') –Directory to store interim binned array data. Defaults to current working directory (".").
-
session_id(str, default:'null') –Session identifier for interim path. Defaults to "null".
Returns:
-
Array–zarr.core.Array: Binned array as a persistent Zarr array object.
Source code in src/mesoscopy/preprocess/compute.py
frame_statistics(array)
Calculate mean and standard deviation for each frame in a 3D image array.
Parameters:
-
array(Dask or NumPy Array) –Imaging array to calculate statistics for.
Returns:
-
tuple[NDArray, NDArray]–tuple[npt.NDArray, npt.NDArray]: Tuple containing two NumPy arrays: means and standard deviations for each frame.
Source code in src/mesoscopy/preprocess/compute.py
channel_separation_filters(frame_means, frame_stds, use_means=False, flip_channels=False)
Generate filters for separating channels based on frame means and standard deviations.
Parameters:
-
frame_means(NDArray) –Array of mean values for each frame.
-
frame_stds(NDArray) –Array of standard deviation values for each frame.
-
use_means(bool, default:False) –Use means instead of standard deviations for filtering. Defaults to False.
-
flip_channels(bool, default:False) –Flip the channels. Defaults to False.
Returns:
-
tuple[list, list]–tuple[list, list]: Tuple of two lists, containing the frame indices for each channel.
Source code in src/mesoscopy/preprocess/compute.py
rolling_dff(array, window_width=750, channel_name='null', interim_dir='.', session_id='null')
Calculate dF/F using a rolling window.
Parameters:
-
array(Dask or NumPy Array) –Array to be separated. If array is a multi-channel recording, it needs to be filtered before it's passed to this function.
-
window_width(int, default:750) –Window width for dF/F calculation. Defaults to 750.
-
channel_name(str, default:'null') –Channel name for interim path. Defaults to "null".
-
interim_dir(str, default:'.') –Directory to store interim dF/F data. Defaults to current working directory (".").
-
session_id(str, default:'null') –Session identifier for interim path. Defaults to "null".
Returns:
-
Array–zarr.core.Array: dF/F array as a persistent Zarr array object.
Raises:
-
ValueError–If the window width is greater than the number of frames in the array.
Source code in src/mesoscopy/preprocess/compute.py
projections(array)
Calculate mean, standard deviation and maximum intensity projection frames.
Parameters:
-
array(NDArray) –Frame array to calculate projections for.
Returns:
-
dict[str, NDArray]–dict[str, npt.NDArray]: Dictionary containing mean, standard deviation and maximum intensity projection frames.