Skip to content
Snippets Groups Projects
Commit f8bb3c9e authored by Carlos de Lannoy's avatar Carlos de Lannoy
Browse files

Merge branch 'coa_analysis' of git.wur.nl:lanno001/baseless into coa_analysis

 Conflicts:
	coa_detection/AbfData.py
parents b29decf4 2bf73b7d
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,7 @@ class AbfData:
:param lowpass_freq: Frequency to use for low pass filter in KHz
:type lowpass_freq: float
"""
def __init__(self, abf_fn, normalization, lowpass_freq,
def __init__(self, abf_fn, normalization=False, lowpass_freq=80,
baseline_threshold=0.65):
self.abf_fn = abf_fn
self.normalization = normalization
......@@ -33,6 +32,7 @@ class AbfData:
@raw.setter
def raw(self, _):
abf = pyabf.ABF(self.abf_fn)
self.unfiltered_raw = abf.sweepY[~np.isnan(abf.sweepY)]
pyabf.filter.gaussian(abf, self.smoothing_sigma)
abf.setSweep(0)
# Drop NaNs because they show up at the edges due to smoothing
......@@ -61,7 +61,7 @@ class AbfData:
plt.hist(event_lengths, bins=100)
plt.show()
def get_pos(self, width):
def get_pos(self, width, unfiltered=False):
pos_list = []
for event in self.pos_events:
start_idx = event[0]
......@@ -73,16 +73,22 @@ class AbfData:
start_idx -= random_offset
end_idx += room_left - random_offset
assert (end_idx - start_idx) == width
pos_list.append(self.raw[start_idx: end_idx])
if unfiltered:
pos_list.append(self.unfiltered_raw[start_idx: end_idx])
else:
pos_list.append(self.raw[start_idx: end_idx])
return pos_list
def get_neg(self, width, nb_neg):
def get_neg(self, width, nb_neg, unfiltered=False):
neg_list = []
for i in range(nb_neg * 100): # take 100 attempts for each neg
random_idx = random.randint(0, len(self.raw)-width)
candidate_indices = np.arange(random_idx, random_idx+width)
if not np.any(np.isin(candidate_indices, self.flat_pos_indices)):
neg_list.append(self.raw[candidate_indices])
if unfiltered:
neg_list.append(self.unfiltered_raw[candidate_indices])
else:
neg_list.append(self.raw[candidate_indices])
if len(neg_list) >= nb_neg:
return neg_list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment