Skip to content

Commit 1c9fe85

Browse files
committed
Fix errors in nb 2
1 parent 5b1efe0 commit 1c9fe85

3 files changed

Lines changed: 31 additions & 22 deletions

File tree

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"metadata": {},
8282
"outputs": [],
8383
"source": [
84-
"S = pbm.ParticlesSimulation.from_datafile('0168', mode='w')"
84+
"S = pbm.ParticlesSimulation.from_datafile('a715', mode='w')"
8585
]
8686
},
8787
{
@@ -116,15 +116,13 @@
116116
{
117117
"cell_type": "code",
118118
"execution_count": null,
119-
"metadata": {
120-
"collapsed": true
121-
},
119+
"metadata": {},
122120
"outputs": [],
123121
"source": [
124122
"params = dict(\n",
125-
" em_rates = (200e3,), # Peak emission rates (cps) for each population (D+A)\n",
126-
" E_values = (0.75,), # FRET efficiency for each population\n",
127-
" num_particles = (20,), # Number of particles in each population\n",
123+
" em_rates = (200e3, 300e3), # Peak emission rates (cps) for each population (D+A)\n",
124+
" E_values = (0.75, 0.25), # FRET efficiency for each population\n",
125+
" num_particles = (2, 3), # Number of particles in each population\n",
128126
" bg_rate_d = 1500, # Poisson background rate (cps) Donor channel\n",
129127
" bg_rate_a = 800, # Poisson background rate (cps) Acceptor channel\n",
130128
" )"
@@ -161,7 +159,7 @@
161159
"outputs": [],
162160
"source": [
163161
"rs = np.random.RandomState(1234)\n",
164-
"mix_sim.run(rs=rs, overwrite=False, skip_existing=True)"
162+
"mix_sim.run(rs=rs, overwrite=True, skip_existing=True, save_pos=True)"
165163
]
166164
},
167165
{
@@ -195,9 +193,7 @@
195193
{
196194
"cell_type": "code",
197195
"execution_count": null,
198-
"metadata": {
199-
"collapsed": true
200-
},
196+
"metadata": {},
201197
"outputs": [],
202198
"source": [
203199
"params = dict(\n",
@@ -396,9 +392,7 @@
396392
{
397393
"cell_type": "code",
398394
"execution_count": null,
399-
"metadata": {
400-
"collapsed": true
401-
},
395+
"metadata": {},
402396
"outputs": [],
403397
"source": []
404398
}

pybromo/storage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ def add_timestamps(self, name, clk_p, max_rates, bg_rate,
261261
if overwrite:
262262
self.h5file.remove_node('/timestamps', name=name)
263263
self.h5file.remove_node('/timestamps', name=name + '_par')
264-
self.h5file.remove_node('/timestamps', name=name + '_pos')
264+
try:
265+
self.h5file.remove_node('/timestamps', name=name + '_pos')
266+
except tables.NoSuchNodeError:
267+
pass
265268
else:
266269
msg = 'Timestamp array already exist (%s)' % name
267270
raise ExistingArrayError(msg)

pybromo/timestamps.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def merge_da_multi(*da_arrays):
4646
merged_arrays.append(np.concatenate((donor, acceptor)))
4747
a_ch = np.hstack([np.zeros(donors[0].shape[0], dtype=bool),
4848
np.ones(acceptors[1].shape[0], dtype=bool)])
49-
index_sort = merged_arrays.argsort()
49+
index_sort = merged_arrays[0].argsort()
5050
return [a[index_sort] for a in merged_arrays], a_ch[index_sort]
5151

5252

@@ -112,10 +112,12 @@ def populations_diff_coeff(particles, populations):
112112

113113
D_list = []
114114
D_pop_start = 0 # start index of diffusion-based populations
115+
msg = ('The populations you defined do not align with the '
116+
'populations in the trajectory file.')
115117
for pop, (D, counts) in zip(populations, D_counts):
116118
D_list.append(D)
117-
assert pop.start >= D_pop_start
118-
assert pop.stop <= D_pop_start + counts
119+
assert pop.start >= D_pop_start, msg
120+
assert pop.stop <= D_pop_start + counts, msg
119121
D_pop_start += counts
120122
return D_list
121123

@@ -163,7 +165,16 @@ class TimestampSimulation:
163165

164166
def __init__(self, S, em_rates, E_values, num_particles,
165167
bg_rate_d, bg_rate_a, timeslice=None):
166-
assert np.sum(num_particles) <= S.num_particles
168+
if np.sum(num_particles) > S.num_particles:
169+
msg = (f'Wrong number of particles. \n\nWith this trajectory '
170+
f'file you can specify up to {S.num_particles} particles, '
171+
f'but you requested {np.sum(num_particles)}.')
172+
raise ValueError(msg)
173+
if np.sum(num_particles) < S.num_particles:
174+
msg = (f'NOTE: You requested a timestamp simulation for only '
175+
f'{np.sum(num_particles)} out of the {S.num_particles} '
176+
f'available particles.')
177+
print(msg)
167178
if timeslice is None:
168179
timeslice = S.t_max
169180
assert timeslice <= S.t_max
@@ -340,9 +351,9 @@ def merge_da(self):
340351
"""Merge donor and acceptor timestamps, computes `ts`, `a_ch`, `part`.
341352
"""
342353
print(' - Merging D and A timestamps', flush=True)
343-
ts_d, ts_par_d, ts_pos_d = self.S.get_timestamps_data(
354+
ts_d, ts_par_d, ts_pos_d = self.S.get_timestamp_data(
344355
self.name_timestamps_d)
345-
ts_a, ts_par_a, ts_pos_a = self.S.get_timestamps_data(
356+
ts_a, ts_par_a, ts_pos_a = self.S.get_timestamp_data(
346357
self.name_timestamps_a)
347358
da_pairs = [ts_d, ts_a, ts_par_d, ts_par_a]
348359
self.pos = None
@@ -372,7 +383,8 @@ def _make_photon_hdf5(self, identity=None):
372383
detectors_specs = dict(spectral_ch1 = np.atleast_1d(0),
373384
spectral_ch2 = np.atleast_1d(1))))
374385
if self.pos is not None:
375-
photon_data['positions'] = self.pos
386+
print('positio')
387+
photon_data['user'] = dict(positions=self.pos)
376388

377389
setup = dict(
378390
num_pixels = 2,

0 commit comments

Comments
 (0)