Skip to content

Commit f981db5

Browse files
authored
Drop missing values in HARP csv (#37)
1 parent cd7681d commit f981db5

4 files changed

Lines changed: 45 additions & 34 deletions

File tree

src/aind_ephys_transformation/ephys_job.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def _get_read_blocks(self) -> Iterator[dict]: # noqa: C901
377377
timestamps = []
378378
for amplifier_dataset in amplifier_datasets_to_compress:
379379
recording = si.read_binary(amplifier_dataset, **binary_info)
380-
380+
recording_samples = recording.get_num_samples()
381381
# unsigned to signed
382382
recording = spre.unsigned_to_signed(
383383
recording, bit_depth=adc_depth
@@ -391,8 +391,6 @@ def _get_read_blocks(self) -> Iterator[dict]: # noqa: C901
391391
# update cumulative start frame
392392
cumulative_start_frame += recording.get_num_frames()
393393

394-
recording_list.append(recording)
395-
396394
# align timestamps based on harp sync data
397395
clock_dataset_name = amplifier_dataset.name.replace(
398396
"AmplifierData", "Clock"
@@ -414,11 +412,24 @@ def _get_read_blocks(self) -> Iterator[dict]: # noqa: C901
414412
clock_data = np.memmap(
415413
clock_dataset, dtype="uint64", mode="r"
416414
)
417-
harp_data = pd.read_csv(harp_sync_dataset)
415+
harp_data = pd.read_csv(harp_sync_dataset, index_col=False)
416+
# Drop rows with missing values (NaNs/zeros)
417+
harp_data = harp_data[harp_data != 0].dropna()
418418
timestamps_chunk = self._sync_chronic_timestamps(
419419
clock_data, harp_data, fs=recording.sampling_frequency
420420
)
421+
timestamps_samples = len(timestamps_chunk)
422+
if timestamps_samples != recording_samples:
423+
logging.warning( # pragma: no cover
424+
f"Number of timestamps ({timestamps_samples}) "
425+
f"does not match recording samples "
426+
f"({recording_samples}). "
427+
f"Skipping chunk {amplifier_dataset.name}!"
428+
)
429+
continue # pragma: no cover
430+
421431
timestamps.append(timestamps_chunk)
432+
recording_list.append(recording)
422433

423434
# concatenate recordings
424435
recording_concatenated = si.concatenate_recordings(recording_list)
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
,Seconds,Value.Clock
2-
0,10.0,10
3-
1,11.0,20
4-
2,12.0,30
5-
3,13.0,40
6-
4,14.0,50
7-
5,15.0,60
8-
6,16.0,70
9-
7,17.0,80
10-
8,18.0,90
1+
Seconds,Value.Clock
2+
10.0,10
3+
11.0,20
4+
12.0,30
5+
13.0,40
6+
14.0,50
7+
15.0,60
8+
16.0,70
9+
17.0,80
10+
18.0,90
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
,Seconds,Value.Clock
2-
0,20.0,110
3-
1,21.0,120
4-
2,22.0,130
5-
3,23.0,140
6-
4,24.0,150
7-
5,25.0,160
8-
6,26.0,170
9-
7,27.0,180
10-
8,28.0,190
1+
Seconds,Value.Clock
2+
20.0,110
3+
21.0,120
4+
22.0,130
5+
23.0,140
6+
24.0,150
7+
25.0,160
8+
26.0,170
9+
27.0,180
10+
28.0,190
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
,Seconds,Value.Clock
2-
0,30.0,210
3-
1,31.0,220
4-
2,32.0,230
5-
3,33.0,240
6-
4,34.0,250
7-
5,35.0,260
8-
6,36.0,270
9-
7,37.0,280
10-
8,38.0,290
1+
Seconds,Value.Clock
2+
30.0,210
3+
31.0,220
4+
32.0,230
5+
33.0,240
6+
34.0,250
7+
35.0,260
8+
36.0,270
9+
37.0,280
10+
38.0,290

0 commit comments

Comments
 (0)