Skip to content

Commit 9f93859

Browse files
authored
Merge pull request #2 from OpenSMFS/gauss_psf
Implement GaussianPSF
2 parents 0491c46 + 10c602c commit 9f93859

8 files changed

Lines changed: 690 additions & 94 deletions

notebooks/PyBroMo - 1. Simulate 3D trajectories - single core.ipynb

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"\n",
102102
"# PSF definition\n",
103103
"psf = pbm.NumericPSF()\n",
104+
"#psf = pbm.GaussianPSF(sx=0.2e-6, sy=0.2e-6, sz=0.8e-6)\n",
104105
"\n",
105106
"# Particle simulation definition\n",
106107
"S = pbm.ParticlesSimulation(t_step=t_step, t_max=t_max, \n",
@@ -143,6 +144,24 @@
143144
"S.compact_name()"
144145
]
145146
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"metadata": {},
151+
"outputs": [],
152+
"source": [
153+
"S.psf.hash()"
154+
]
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": null,
159+
"metadata": {},
160+
"outputs": [],
161+
"source": [
162+
"S.psf"
163+
]
164+
},
146165
{
147166
"cell_type": "code",
148167
"execution_count": null,
@@ -234,6 +253,15 @@
234253
"print('Simulation file size: %d MB' % (S.store.h5file.get_filesize()/1024./1024.))"
235254
]
236255
},
256+
{
257+
"cell_type": "code",
258+
"execution_count": null,
259+
"metadata": {},
260+
"outputs": [],
261+
"source": [
262+
"S.compact_name()"
263+
]
264+
},
237265
{
238266
"cell_type": "code",
239267
"execution_count": null,
@@ -256,7 +284,7 @@
256284
"metadata": {},
257285
"outputs": [],
258286
"source": [
259-
"S.hash()"
287+
"S.compact_name()"
260288
]
261289
},
262290
{
@@ -268,6 +296,15 @@
268296
"S = pbm.ParticlesSimulation.from_datafile(S.hash()[:4]) # Read-only by default"
269297
]
270298
},
299+
{
300+
"cell_type": "code",
301+
"execution_count": null,
302+
"metadata": {},
303+
"outputs": [],
304+
"source": [
305+
"S.psf_pytables.attrs"
306+
]
307+
},
271308
{
272309
"cell_type": "code",
273310
"execution_count": null,
@@ -277,6 +314,22 @@
277314
"S"
278315
]
279316
},
317+
{
318+
"cell_type": "code",
319+
"execution_count": null,
320+
"metadata": {},
321+
"outputs": [],
322+
"source": [
323+
"S.compact_name()"
324+
]
325+
},
326+
{
327+
"cell_type": "markdown",
328+
"metadata": {},
329+
"source": [
330+
"> **BUG**: hash changed with GaussianPSF!"
331+
]
332+
},
280333
{
281334
"cell_type": "markdown",
282335
"metadata": {},
@@ -336,6 +389,50 @@
336389
"plot_emission(S, slice_=(0, 2e6, 10), em_th=0.05)"
337390
]
338391
},
392+
{
393+
"cell_type": "code",
394+
"execution_count": null,
395+
"metadata": {},
396+
"outputs": [],
397+
"source": [
398+
"def plot_tracks_r(S, slice_=None, particles=None):\n",
399+
" if slice_ is None:\n",
400+
" slice_ = (0, 100e3, 100)\n",
401+
" duration = (slice_[1] - slice_[0])*S.t_step\n",
402+
" slice_ = slice(*slice_)\n",
403+
" em = S.emission[:, slice_]\n",
404+
" t = np.arange(em.shape[1])*(S.t_step*1e3)\n",
405+
" \n",
406+
" if particles is None:\n",
407+
" particles = range(S.num_particles)\n",
408+
" \n",
409+
" fig, ax = plt.subplots(1, 1, figsize=(11, 5), sharey=True)\n",
410+
" plt.subplots_adjust(left=0.05, right=0.93, top=0.95, bottom=0.09,\n",
411+
" wspace=0.05)\n",
412+
" plt.suptitle(\"Total: %.1f s, Visualized: %.2f ms\" % (\n",
413+
" S.t_step*S.n_samples, duration*1e3))\n",
414+
"\n",
415+
" for ip in particles:\n",
416+
" x, y, z = S.position[ip, :, slice_]\n",
417+
" r = np.sqrt(x**2 + y**2 + z**2) * 1e6\n",
418+
" plot_kwargs = dict(ls='', marker='o', mew=0, ms=4, alpha=0.8, \n",
419+
" label='P%d' % ip)\n",
420+
" ax.plot(t, r, **plot_kwargs)\n",
421+
"\n",
422+
" ax.set_ylabel(\"r (um)\")\n",
423+
" ax.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.)\n",
424+
" ax.set_ylim(0)"
425+
]
426+
},
427+
{
428+
"cell_type": "code",
429+
"execution_count": null,
430+
"metadata": {},
431+
"outputs": [],
432+
"source": [
433+
"plot_tracks_r(S, slice_=(0, 2e6, 1000))"
434+
]
435+
},
339436
{
340437
"cell_type": "code",
341438
"execution_count": null,
@@ -395,6 +492,15 @@
395492
"plot_tracks(S) #particles=[2, 5, 7, 22, 30])"
396493
]
397494
},
495+
{
496+
"cell_type": "code",
497+
"execution_count": null,
498+
"metadata": {},
499+
"outputs": [],
500+
"source": [
501+
"#plot_tracks(S, slice_=(1.9e6, 2e6, 100), particles=[1])"
502+
]
503+
},
398504
{
399505
"cell_type": "code",
400506
"execution_count": null,
@@ -404,6 +510,16 @@
404510
"S.store.close()"
405511
]
406512
},
513+
{
514+
"cell_type": "code",
515+
"execution_count": null,
516+
"metadata": {},
517+
"outputs": [],
518+
"source": [
519+
"if hasattr(S, 'ts_store'):\n",
520+
" S.ts_store.close() # needed if timestamp file is already present"
521+
]
522+
},
407523
{
408524
"cell_type": "markdown",
409525
"metadata": {},
@@ -415,6 +531,15 @@
415531
"- [PyBroMo - 2. Generate smFRET data, including mixtures](PyBroMo - 2. Generate smFRET data, including mixtures.ipynb)"
416532
]
417533
},
534+
{
535+
"cell_type": "code",
536+
"execution_count": null,
537+
"metadata": {},
538+
"outputs": [],
539+
"source": [
540+
"S.compact_name()"
541+
]
542+
},
418543
{
419544
"cell_type": "code",
420545
"execution_count": null,
@@ -581,6 +706,16 @@
581706
"pos, ts"
582707
]
583708
},
709+
{
710+
"cell_type": "code",
711+
"execution_count": null,
712+
"metadata": {},
713+
"outputs": [],
714+
"source": [
715+
"S.store.close()\n",
716+
"S.ts_store.close()"
717+
]
718+
},
584719
{
585720
"cell_type": "code",
586721
"execution_count": null,
@@ -592,9 +727,9 @@
592727
"metadata": {
593728
"anaconda-cloud": {},
594729
"kernelspec": {
595-
"display_name": "Python 3.6 (py36)",
730+
"display_name": "py37-sm",
596731
"language": "python",
597-
"name": "py36"
732+
"name": "py37-sm"
598733
},
599734
"language_info": {
600735
"codemirror_mode": {
@@ -606,13 +741,16 @@
606741
"name": "python",
607742
"nbconvert_exporter": "python",
608743
"pygments_lexer": "ipython3",
609-
"version": "3.6.7"
744+
"version": "3.7.2"
610745
},
611746
"toc": {
747+
"base_numbering": 1,
612748
"nav_menu": {},
613749
"number_sections": true,
614750
"sideBar": true,
615751
"skip_h1_title": false,
752+
"title_cell": "Table of Contents",
753+
"title_sidebar": "Contents",
616754
"toc_cell": false,
617755
"toc_position": {
618756
"height": "591.867px",

notebooks/PyBroMo - 2. Generate smFRET data, including mixtures.ipynb

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
"metadata": {},
8282
"outputs": [],
8383
"source": [
84-
"code = 'e30f'\n",
84+
"code = 'e30f' # 1s simulation, NumericPSF\n",
85+
"#code = '10a1' # 1s simulation, GaussianPSF\n",
8586
"S = pbm.ParticlesSimulation.from_datafile(code, mode='w')"
8687
]
8788
},
@@ -694,9 +695,24 @@
694695
"metadata": {},
695696
"outputs": [],
696697
"source": [
697-
"PSF = pbm.NumericPSF()\n",
698-
"psf = PSF.hdata\n",
699-
"z_peak = PSF.zi[PSF.zm] # z position of PSF peak in μm\n",
698+
"S.psf"
699+
]
700+
},
701+
{
702+
"cell_type": "code",
703+
"execution_count": null,
704+
"metadata": {},
705+
"outputs": [],
706+
"source": [
707+
"if S.psf.kind == 'numeric':\n",
708+
" PSF = pbm.NumericPSF()\n",
709+
" psf = PSF.hdata\n",
710+
" z_peak = PSF.zi[PSF.zm] # z position of PSF peak in μm\n",
711+
"else:\n",
712+
" x = np.arange(0, 4, 0.01) * 1e-6\n",
713+
" z = np.arange(-6, 6, 0.01) * 1e-6\n",
714+
" X, Z = np.meshgrid(x, z)\n",
715+
" psf = S.psf.eval_xz(X, Z)\n",
700716
"cmap = plt.cm.YlGnBu\n",
701717
"cmap.set_under(alpha=0)\n",
702718
"kwargs = dict(interpolation='bicubic', origin='lower', cmap=cmap, vmin=1e-1, zorder=1)\n",
@@ -705,7 +721,7 @@
705721
"ax.imshow(psf.T, extent=(-6, 6, 0, 4), **kwargs)\n",
706722
"ax.plot(burstph.z_um, burstph.r_um, '.', ms=5, color='C1', alpha=0.3)\n",
707723
"ax.set(ylabel='R (μm)', xlabel='Z (μm)', ylim=(0, 1), xlim=(-2, 2),\n",
708-
" title='Position of photon emission');"
724+
" title=f'Position of photon emission (PSF {S.psf.kind})');"
709725
]
710726
},
711727
{
@@ -724,6 +740,16 @@
724740
" title='Position of photon emission by burst');"
725741
]
726742
},
743+
{
744+
"cell_type": "code",
745+
"execution_count": null,
746+
"metadata": {},
747+
"outputs": [],
748+
"source": [
749+
"S.store.close()\n",
750+
"S.ts_store.close()"
751+
]
752+
},
727753
{
728754
"cell_type": "code",
729755
"execution_count": null,

0 commit comments

Comments
 (0)