|
270 | 270 | "cell_type": "markdown",
|
271 | 271 | "metadata": {},
|
272 | 272 | "source": [
|
273 |
| - "### Parameters for the Movie and Name of the Movie " |
| 273 | + "### Parameters for the Movie" |
274 | 274 | ]
|
275 | 275 | },
|
276 | 276 | {
|
|
292 | 292 | "cell_type": "markdown",
|
293 | 293 | "metadata": {},
|
294 | 294 | "source": [
|
295 |
| - "## Analysis " |
| 295 | + "## Run Analysis" |
296 | 296 | ]
|
297 | 297 | },
|
298 | 298 | {
|
|
308 | 308 | "d1, d2 = dims\n",
|
309 | 309 | "images = np.reshape(Yr.T, [T] + list(dims), order='F')\n",
|
310 | 310 | "Y = np.reshape(Yr, dims + (T,), order='F')\n",
|
311 |
| - "m_images = cm.movie(images)\n", |
312 |
| - "\n", |
313 |
| - "# correlation image\n", |
| 311 | + "m_images = cm.movie(images)" |
| 312 | + ] |
| 313 | + }, |
| 314 | + { |
| 315 | + "cell_type": "markdown", |
| 316 | + "metadata": {}, |
| 317 | + "source": [ |
| 318 | + "### Correlation Image" |
| 319 | + ] |
| 320 | + }, |
| 321 | + { |
| 322 | + "cell_type": "code", |
| 323 | + "execution_count": null, |
| 324 | + "metadata": {}, |
| 325 | + "outputs": [], |
| 326 | + "source": [ |
314 | 327 | "if m_images.shape[0] < 10000:\n",
|
315 | 328 | " Cn = m_images.local_correlations(\n",
|
316 | 329 | " swap_dim=params_movie['swap_dim'], frames_per_chunk=1500)\n",
|
317 | 330 | " Cn[np.isnan(Cn)] = 0\n",
|
318 | 331 | "else:\n",
|
| 332 | + " #Saved as a tif file\n", |
319 | 333 | " Cn = np.array(cm.load(('/'.join(params_movie['gtname'][0].split('/')[:-2] + [\n",
|
320 |
| - " 'projections', 'correlation_image_better.tif'])))).squeeze()\n", |
| 334 | + " 'projections', 'correlation_image_better.tif'])))).squeeze() \n", |
321 | 335 | "\n",
|
322 | 336 | "plt.imshow(Cn, cmap='gray', vmax=.95)"
|
323 | 337 | ]
|
|
338 | 352 | "\n",
|
339 | 353 | "print(radius)\n",
|
340 | 354 | "print(roi_cons.shape)\n",
|
341 |
| - "pl.imshow(roi_cons.sum(0))\n", |
342 |
| - "\n", |
| 355 | + "plt.imshow(roi_cons.sum(0))" |
| 356 | + ] |
| 357 | + }, |
| 358 | + { |
| 359 | + "cell_type": "code", |
| 360 | + "execution_count": null, |
| 361 | + "metadata": {}, |
| 362 | + "outputs": [], |
| 363 | + "source": [ |
343 | 364 | "if params_movie['kernel'] is not None: # kernel usually two\n",
|
344 | 365 | " kernel = np.ones(\n",
|
345 | 366 | " (radius // params_movie['kernel'], radius // params_movie['kernel']), np.uint8)\n",
|
|
349 | 370 | "\n",
|
350 | 371 | "A_in = np.reshape(roi_cons.transpose(\n",
|
351 | 372 | " [2, 1, 0]), (-1, roi_cons.shape[0]), order='C')\n",
|
352 |
| - "pl.figure()\n", |
| 373 | + "plt.figure()\n", |
353 | 374 | "crd = plot_contours(A_in, Cn, thr=.99999)"
|
354 | 375 | ]
|
355 | 376 | },
|
| 377 | + { |
| 378 | + "cell_type": "markdown", |
| 379 | + "metadata": {}, |
| 380 | + "source": [ |
| 381 | + "### Parameter Setting" |
| 382 | + ] |
| 383 | + }, |
356 | 384 | {
|
357 | 385 | "cell_type": "code",
|
358 | 386 | "execution_count": null,
|
359 | 387 | "metadata": {},
|
360 | 388 | "outputs": [],
|
361 | 389 | "source": [
|
362 |
| - "# %% some parameter settings\n", |
363 | 390 | "# order of the autoregressive fit to calcium imaging in general one (slow gcamps) or two (fast gcamps fast scanning)\n",
|
364 | 391 | "p = params_movie['p']\n",
|
365 | 392 | "# merging threshold, max correlation allowed\n",
|
366 |
| - "merge_thresh = params_movie['merge_thresh']\n", |
367 |
| - "\n", |
368 |
| - "# %% Extract spatial and temporal components on patches\n", |
369 |
| - "# TODO: todocument\n", |
| 393 | + "merge_thresh = params_movie['merge_thresh']" |
| 394 | + ] |
| 395 | + }, |
| 396 | + { |
| 397 | + "cell_type": "markdown", |
| 398 | + "metadata": {}, |
| 399 | + "source": [ |
| 400 | + "### Extract spatial and temporal components on patches" |
| 401 | + ] |
| 402 | + }, |
| 403 | + { |
| 404 | + "cell_type": "code", |
| 405 | + "execution_count": null, |
| 406 | + "metadata": {}, |
| 407 | + "outputs": [], |
| 408 | + "source": [ |
370 | 409 | "if images.shape[0] > 10000:\n",
|
371 | 410 | " check_nan = False\n",
|
372 | 411 | "else:\n",
|
|
383 | 422 | "f = cnm.f\n",
|
384 | 423 | "snt = cnm.sn\n",
|
385 | 424 | "print(('Number of components:' + str(A.shape[-1])))\n",
|
386 |
| - "# %%\n", |
387 |
| - "pl.figure()\n", |
388 |
| - "# TODO: show screenshot 12`\n", |
389 |
| - "# TODO : change the way it is used\n", |
| 425 | + "plt.figure()\n", |
390 | 426 | "crd = plot_contours(A, Cn, thr=params_display['thr_plot'])"
|
391 | 427 | ]
|
392 | 428 | },
|
| 429 | + { |
| 430 | + "cell_type": "markdown", |
| 431 | + "metadata": {}, |
| 432 | + "source": [ |
| 433 | + "Threshold Components " |
| 434 | + ] |
| 435 | + }, |
393 | 436 | {
|
394 | 437 | "cell_type": "code",
|
395 | 438 | "execution_count": null,
|
|
400 | 443 | "view_patches_bar(Yr, scipy.sparse.coo_matrix(A.tocsc()[:, :]), C[:, :], b, f, dims[0], dims[1],\n",
|
401 | 444 | " YrA=YrA[:, :], img=Cn)\n",
|
402 | 445 | "\n",
|
403 |
| - "#%%\n", |
404 | 446 | "c, dview, n_processes = cm.cluster.setup_cluster(\n",
|
405 | 447 | " backend='local', n_processes=None, single_thread=False)\n",
|
406 |
| - "#%% thredshold components\n", |
| 448 | + "\n", |
407 | 449 | "min_size_neuro = 3 * 2 * np.pi\n",
|
408 | 450 | "max_size_neuro = (2 * radius)**2 * np.pi\n",
|
409 | 451 | "A_thr = cm.source_extraction.cnmf.spatial.threshold_components(A.tocsc()[:, :].toarray(), dims, medw=None, thr_method='max', maxthr=0.2, nrgthr=0.99, extract_cc=True,\n",
|
|
415 | 457 | " & (size_neurons < max_size_neuro))[0]\n",
|
416 | 458 | "A_thr = A_thr[:, idx_size_neuro]\n",
|
417 | 459 | "print(A_thr.shape)\n",
|
418 |
| - "#%%\n", |
| 460 | + "\n", |
419 | 461 | "crd = plot_contours(scipy.sparse.coo_matrix(\n",
|
420 | 462 | " A_thr * 1.), Cn, thr=.99, vmax=0.35)\n",
|
421 |
| - "#%%\n", |
| 463 | + "\n", |
422 | 464 | "roi_cons = np.load(params_movie['gtname'][0])\n",
|
423 | 465 | "print(roi_cons.shape)\n",
|
424 |
| - "pl.imshow(roi_cons.sum(0))\n", |
425 |
| - "#%% compare CNMF sedded with ground truth\n", |
426 |
| - "pl.figure(figsize=(30, 20))\n", |
| 466 | + "plt.imshow(roi_cons.sum(0))" |
| 467 | + ] |
| 468 | + }, |
| 469 | + { |
| 470 | + "cell_type": "markdown", |
| 471 | + "metadata": {}, |
| 472 | + "source": [ |
| 473 | + "### Compare CNMF Seeded with ground truth" |
| 474 | + ] |
| 475 | + }, |
| 476 | + { |
| 477 | + "cell_type": "code", |
| 478 | + "execution_count": null, |
| 479 | + "metadata": {}, |
| 480 | + "outputs": [], |
| 481 | + "source": [ |
| 482 | + "plt.figure(figsize=(30, 20))\n", |
427 | 483 | "tp_gt, tp_comp, fn_gt, fp_comp, performance_cons_off = cm.base.rois.nf_match_neurons_in_binary_masks(roi_cons, A_thr[:, :].reshape([dims[0], dims[1], -1], order='F').transpose([2, 0, 1]) * 1., thresh_cost=.7, min_dist=10,\n",
|
428 | 484 | " print_assignment=False, plot_results=False, Cn=Cn, labels=['GT', 'Offline'])\n",
|
429 |
| - "pl.rcParams['pdf.fonttype'] = 42\n", |
| 485 | + "plt.rcParams['pdf.fonttype'] = 42\n", |
430 | 486 | "font = {'family': 'Myriad Pro',\n",
|
431 | 487 | " 'weight': 'regular',\n",
|
432 | 488 | " 'size': 20}\n",
|
433 |
| - "pl.rc('font', **font)\n", |
434 |
| - "\n", |
435 |
| - "#%%\n", |
436 |
| - "np.savez(os.path.join(os.path.split(fname_new)[0], os.path.split(fname_new)[1][:-4] + 'match_masks.npz'), Cn=Cn,\n", |
437 |
| - " tp_gt=tp_gt, tp_comp=tp_comp, fn_gt=fn_gt, fp_comp=fp_comp, performance_cons_off=performance_cons_off, idx_size_neuro_gt=idx_size_neuro, A_thr=A_thr,\n", |
438 |
| - " A_gt=A, C_gt=C, b_gt=b, f_gt=f, YrA_gt=YrA, d1=d1, d2=d2, idx_components_gt=idx_size_neuro[\n", |
439 |
| - " tp_comp],\n", |
440 |
| - " idx_components_bad_gt=idx_size_neuro[fp_comp], fname_new=fname_new)\n" |
| 489 | + "plt.rc('font', **font)" |
| 490 | + ] |
| 491 | + }, |
| 492 | + { |
| 493 | + "cell_type": "markdown", |
| 494 | + "metadata": {}, |
| 495 | + "source": [ |
| 496 | + "### Generating match_masks.npz" |
441 | 497 | ]
|
442 | 498 | },
|
443 | 499 | {
|
444 | 500 | "cell_type": "code",
|
445 | 501 | "execution_count": null,
|
446 | 502 | "metadata": {},
|
447 | 503 | "outputs": [],
|
448 |
| - "source": [] |
| 504 | + "source": [ |
| 505 | + "np.savez(os.path.join(os.path.split(fname_new)[0], os.path.split(fname_new)[1][:-4] + 'match_masks.npz'), Cn=Cn,\n", |
| 506 | + " tp_gt=tp_gt, tp_comp=tp_comp, fn_gt=fn_gt, fp_comp=fp_comp, performance_cons_off=performance_cons_off, idx_size_neuro_gt=idx_size_neuro, A_thr=A_thr,\n", |
| 507 | + " A_gt=A, C_gt=C, b_gt=b, f_gt=f, YrA_gt=YrA, d1=d1, d2=d2, idx_components_gt=idx_size_neuro[\n", |
| 508 | + " tp_comp],\n", |
| 509 | + " idx_components_bad_gt=idx_size_neuro[fp_comp], fname_new=fname_new)" |
| 510 | + ] |
449 | 511 | }
|
450 | 512 | ],
|
451 | 513 | "metadata": {
|
|
0 commit comments