Skip to content

Commit

Permalink
minor hv changes
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed Aug 5, 2019
1 parent 87a1855 commit a9bfad9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 77 deletions.
7 changes: 4 additions & 3 deletions caiman/source_extraction/cnmf/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ def __init__(self, fnames=None, dims=None, dxy=(1, 1),
'normalize_yyt_one': True,
'nrgthr': 0.9999, # Energy threshold
'num_blocks_per_run_spat': num_blocks_per_run_spat, # number of process to parallelize residual computation ** DECREASE IF MEMORY ISSUES
'se': None, # Morphological closing structuring element
'ss': None, # Binary element for determining connectivity
'se': np.ones((3, 3), dtype='uint8'), # Morphological closing structuring element
'ss': np.ones((3, 3), dtype='uint8'), # Binary element for determining connectivity
'thr_method': 'nrg', # Method of thresholding ('max' or 'nrg')
# whether to update the background components in the spatial phase
'update_background_components': update_background_components,
Expand Down Expand Up @@ -805,7 +805,8 @@ def __init__(self, fnames=None, dims=None, dxy=(1, 1),
if self.init['gSig'] is None:
self.init['gSig'] = [-1, -1]
if self.init['gSiz'] is None:
self.init['gSiz'] = [2*gs + 1 for gs in self.init['gSig']]
self.init['gSiz'] = [2*gs + 3 for gs in self.init['gSig']]
self.init['gSiz'] = [gz if gz % 2 else gz + 1 for gz in self.init['gSiz']]

if gnb <= 0:
logging.warning("gnb={0}, hence setting keys nb_patch and low_rank_background ".format(gnb) +
Expand Down
10 changes: 5 additions & 5 deletions caiman/utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,19 @@ def norm(a, rg=(0, 1)):

def plot_unit(uid, scl):
trace = (
hv.Curve(Y_r[uid, :], kdims='time').opts(framewise=True)
* (hv.Curve(C[uid, :], kdims='time')
hv.Curve(Y_r[uid, :], kdims='frame #').opts(framewise=True)
* (hv.Curve(C[uid, :], kdims='frame #')
.opts(color=denoised_color, framewise=True))
).opts(aspect=2, frame_height=200)
).opts(aspect=3, frame_height=200)
A_scl = norm(Ad[:, :, uid], (scl, 1))
im_hsv_scl = im_hsv.copy()
im_hsv_scl[:, :, 2] = im_hsv[:, :, 2] * A_scl
im_u = (hv.HSV(im_hsv_scl, kdims=['height', 'width'])
.opts(aspect='equal', frame_height=200))
return im_u + trace
return hv.Layout([im_u] + [trace]).cols(1) #im_u + trace

return (hv.DynamicMap(plot_unit, kdims=['unit_id', 'scale'])
.redim.range(unit_id=(0, nr), scale=(0.0, 1.0)))
.redim.range(unit_id=(0, nr-1), scale=(0.0, 1.0)))


def get_contours(A, dims, thr=0.9, thr_method='nrg', swap_dim=False):
Expand Down
24 changes: 12 additions & 12 deletions demos/notebooks/demo_dendritic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"metadata": {},
"outputs": [],
"source": [
"import bokeh.plotting as bpl\n",
"import cv2\n",
"import glob\n",
"import logging\n",
Expand All @@ -41,7 +40,10 @@
"from caiman.utils.utils import download_demo\n",
"from caiman.utils.visualization import nb_view_patches\n",
"from skimage.util import montage\n",
"bpl.output_notebook()"
"import bokeh.plotting as bpl\n",
"import holoviews as hv\n",
"bpl.output_notebook()\n",
"hv.notebook_extension('bokeh')"
]
},
{
Expand Down Expand Up @@ -301,12 +303,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
"scrolled": false
},
"outputs": [],
"source": [
"# our plotting function is not optimized for dendritic components (yet)\n",
"cnm.estimates.nb_view_components(img=CI)"
"cnm.estimates.hv_view_components(img=CI)"
]
},
{
Expand All @@ -315,8 +316,7 @@
"source": [
"## Plot a montage array of all the components\n",
"\n",
"The visualization method above is more appropriate for cell bodies. For dendritic components we can plot\n",
"a montage of all the identified spatial footprints."
"We can also plot a montage of all the identified spatial footprints."
]
},
{
Expand Down Expand Up @@ -364,7 +364,7 @@
"metadata": {},
"outputs": [],
"source": [
"cnm2.estimates.nb_view_components(img=CI)"
"cnm2.estimates.hv_view_components(img=CI)"
]
},
{
Expand Down Expand Up @@ -488,7 +488,7 @@
"metadata": {},
"outputs": [],
"source": [
"cnm_patches.estimates.nb_view_components(img=CI)"
"cnm_patches.estimates.hv_view_components(img=CI)"
]
},
{
Expand Down Expand Up @@ -610,9 +610,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [conda env:caiman-nwb] *",
"language": "python",
"name": "python3"
"name": "conda-env-caiman-nwb-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -624,7 +624,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down
86 changes: 29 additions & 57 deletions demos/notebooks/demo_pipeline_cnmfE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/env python\n",
Expand Down Expand Up @@ -70,9 +68,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"fnames = ['data_endoscope.tif'] # filename to be processed\n",
Expand All @@ -90,9 +86,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"#%% start a cluster for parallel processing (if a cluster already exists it will be closed and a new session will be opened)\n",
Expand All @@ -114,7 +108,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
Expand Down Expand Up @@ -165,9 +158,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"if motion_correct:\n",
Expand Down Expand Up @@ -204,9 +195,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# load memory mappable file\n",
Expand All @@ -226,9 +215,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# parameters for source extraction and deconvolution\n",
Expand Down Expand Up @@ -300,9 +287,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# compute some summary images (correlation and peak to noise)\n",
Expand All @@ -311,12 +296,17 @@
"nb_inspect_correlation_pnr(cn_filter, pnr)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can inspect the correlation and PNR images to select the threshold values for `min_corr` and `min_pnr`. The algorithm will look for components only in places where these value are above the specified thresholds. You can adjust the dynamic range in the plots shown above by choosing the selection tool (third button from the left) and selecting the desired region in the histogram plots on the right of each panel."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# print parameters set above, modify them if necessary based on summary images\n",
Expand All @@ -334,9 +324,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"cnm = cnmf.CNMF(n_processes=n_processes, dview=dview, Ain=Ain, params=opts)\n",
Expand All @@ -354,9 +342,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# cnm1 = cnmf.CNMF(n_processes, params=opts, dview=dview)\n",
Expand All @@ -382,9 +368,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"#%% COMPONENT EVALUATION\n",
Expand Down Expand Up @@ -417,12 +401,12 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"scrolled": false
},
"outputs": [],
"source": [
"#%% plot contour plots of accepted and rejected components\n",
"cnm.estimates.plot_contours(img=cn_filter, idx=cnm.estimates.idx_components)"
"cnm.estimates.plot_contours_nb(img=cn_filter, idx=cnm.estimates.idx_components, c)"
]
},
{
Expand All @@ -436,9 +420,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# accepted components\n",
Expand All @@ -449,9 +431,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# rejected components\n",
Expand All @@ -469,9 +449,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"cm.stop_server(dview=dview)"
Expand All @@ -488,9 +466,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# with background \n",
Expand All @@ -501,9 +477,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# without background\n",
Expand All @@ -514,19 +488,17 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python [conda env:caiman-nwb] *",
"language": "python",
"name": "python3"
"name": "conda-env-caiman-nwb-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -538,7 +510,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down

0 comments on commit a9bfad9

Please sign in to comment.