Skip to content

Commit 3a74ae4

Browse files
alejoe91mahlzahn
authored andcommitted
Replace true_zeroes/use_synthetic_noise with fill_gaps_strategy
1 parent f38bb7b commit 3a74ae4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

neo/rawio/biocamrawio.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class BiocamRawIO(BaseRawIO):
3333
----------
3434
filename: str, default: ''
3535
The *.h5 file to be read
36+
fill_gaps_strategy: "zeros" | "synthetic_noise", default: "zeros"
37+
The strategy to fill the gaps in the data when using event-based
38+
compression. If "zeros", the gaps are filled with 0s. If "synthetic_noise",
39+
the gaps are filled with synthetic noise. This is only relevant for
40+
event-based compression.
3641
3742
Examples
3843
--------
@@ -53,15 +58,19 @@ class BiocamRawIO(BaseRawIO):
5358
extensions = ["h5", "brw"]
5459
rawmode = "one-file"
5560

56-
def __init__(self, filename="", true_zeroes=False, use_synthetic_noise=False):
61+
def __init__(self, filename="", fill_gaps_strategy="zeros"):
5762
BaseRawIO.__init__(self)
5863
self.filename = filename
59-
self.true_zeroes = true_zeroes
60-
self.use_synthetic_noise = use_synthetic_noise
6164

62-
if self.use_synthetic_noise:
65+
if fill_gaps_strategy == "synthetic_noise":
6366
warnings.warn("Event-based compression : gaps will be filled with synthetic noise."
6467
" Set use_synthetic_noise to False for raw traces.")
68+
self.use_synthetic_noise = True
69+
elif fill_gaps_strategy == "zeros":
70+
warnings.warn("Event-based compression : gaps will be filled with 0s.")
71+
self.use_synthetic_noise = False
72+
else:
73+
raise ValueError("sparse_missing_data_strategy must be 'zeros' or 'synthetic_noise'")
6574

6675
def _source_name(self):
6776
return self.filename
@@ -142,7 +151,7 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
142151
# read functions are different based on the version of biocam
143152
if self._read_function is readHDF5t_brw4_sparse:
144153
data = self._read_function(self._filehandle, i_start, i_stop, self._num_channels,
145-
self.true_zeroes, self.use_synthetic_noise)
154+
use_synthetic_noise=self.use_synthetic_noise)
146155
else:
147156
data = self._read_function(self._filehandle, i_start, i_stop, self._num_channels)
148157

@@ -329,7 +338,7 @@ def readHDF5t_brw4(rf, t0, t1, nch):
329338
return rf[key]["Raw"][nch * t0 : nch * t1]
330339

331340

332-
def readHDF5t_brw4_sparse(rf, t0, t1, nch, true_zeroes=False, use_synthetic_noise=False):
341+
def readHDF5t_brw4_sparse(rf, t0, t1, nch, use_synthetic_noise=False):
333342

334343
# noise_std = None
335344
start_frame = t0
@@ -339,11 +348,11 @@ def readHDF5t_brw4_sparse(rf, t0, t1, nch, true_zeroes=False, use_synthetic_nois
339348
break
340349
# initialize an empty (fill with zeros) data collection
341350
data = np.zeros((nch, num_frames), dtype=np.int16)
342-
if not true_zeroes:
351+
if not use_synthetic_noise:
343352
# Will read as 0s after 12 bits signed conversion
344353
data.fill(2048)
345354
# fill the data collection with Gaussian noise if requested
346-
if use_synthetic_noise:
355+
else:
347356
data = generate_synthetic_noise(rf, data, well_ID, start_frame, num_frames) #, std=noise_std)
348357
# fill the data collection with the decoded event based sparse raw data
349358
data = decode_event_based_raw_data(rf, data, well_ID, start_frame, num_frames)

0 commit comments

Comments
 (0)