Skip to content

Commit 22c0fd8

Browse files
committed
added the import_ppd function with credit to Thomas Akam's Github
1 parent b9c58ce commit 22c0fd8

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

src/jdb_to_nwb/convert_photometry.py

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import struct
33
import pandas as pd
44
import numpy as np
5+
import os
6+
import json
57
import warnings
68
import scipy.io
79
from scipy.signal import butter, lfilter, hilbert, filtfilt
@@ -336,17 +338,13 @@ def airPLS(data, lambda_=1e8, max_iterations=50):
336338
weights[-1] = weights[0]
337339
return baseline
338340

339-
def processppdphotometry(ppd_file_path):
340-
"""
341-
Process ppd file from pyPhotometry into a dict
342-
requires the import_ppd function from the data_import.py script
343-
The code needed is below.
344-
345-
def import_ppd(file_path, low_pass=20, high_pass=15.9):
346-
Function to import pyPhotometry binary data files into Python. The high_pass
347-
and low_pass arguments determine the frequency in Hz of highpass and lowpass
348-
filtering applied to the filtered analog signals. To disable highpass or lowpass
349-
filtering set the respective argument to None. Returns a dictionary with the
341+
def import_ppd(ppd_file_path):
342+
'''
343+
Credit to the homie: https://github.com/ThomasAkam/photometry_preprocessing.git
344+
I eddited it so that his function only retuns the data dictionary without the filtered data.
345+
Raw data is filtered later/separately using the processppdphotometry function.
346+
347+
Function to import pyPhotometry binary data files into Python. Returns a dictionary with the
350348
following items:
351349
'filename' - Data filename
352350
'subject_ID' - Subject ID
@@ -359,18 +357,15 @@ def import_ppd(file_path, low_pass=20, high_pass=15.9):
359357
'analog_1' - Raw analog signal 1 (volts)
360358
'analog_2' - Raw analog signal 2 (volts)
361359
'analog_3' - Raw analog signal 3 (if present, volts)
362-
'analog_1_filt' - Filtered analog signal 1 (volts)
363-
'analog_2_filt' - Filtered analog signal 2 (volts)
364-
'analog_3_filt' - Filtered analog signal 2 (if present, volts)
365360
'digital_1' - Digital signal 1
366361
'digital_2' - Digital signal 2 (if present)
367362
'pulse_inds_1' - Locations of rising edges on digital input 1 (samples).
368363
'pulse_inds_2' - Locations of rising edges on digital input 2 (samples).
369364
'pulse_times_1' - Times of rising edges on digital input 1 (ms).
370365
'pulse_times_2' - Times of rising edges on digital input 2 (ms).
371366
'time' - Time of each sample relative to start of recording (ms)
372-
373-
with open(file_path, "rb") as f:
367+
'''
368+
with open(, "rb") as f:
374369
header_size = int.from_bytes(f.read(2), "little")
375370
data_header = f.read(header_size)
376371
data = np.frombuffer(f.read(), dtype=np.dtype("<u2"))
@@ -394,31 +389,17 @@ def import_ppd(file_path, low_pass=20, high_pass=15.9):
394389
digital_1 = digital[::n_analog_signals]
395390
digital_2 = digital[1::n_analog_signals] if n_digital_signals == 2 else None
396391
time = np.arange(analog_1.shape[0]) * 1000 / sampling_rate # Time relative to start of recording (ms).
397-
# Filter signals with specified high and low pass frequencies (Hz).
398-
if low_pass and high_pass:
399-
b, a = butter(2, np.array([high_pass, low_pass]) / (0.5 * sampling_rate), "bandpass")
400-
elif low_pass:
401-
b, a = butter(2, low_pass / (0.5 * sampling_rate), "low")
402-
elif high_pass:
403-
b, a = butter(2, high_pass / (0.5 * sampling_rate), "high")
404-
if low_pass or high_pass:
405-
analog_1_filt = filtfilt(b, a, analog_1)
406-
analog_2_filt = filtfilt(b, a, analog_2)
407-
analog_3_filt = filtfilt(b, a, analog_3) if n_analog_signals == 3 else None
408-
else:
409-
analog_1_filt = analog_2_filt = analog_3_filt = None
392+
410393
# Extract rising edges for digital inputs.
411394
pulse_inds_1 = 1 + np.where(np.diff(digital_1) == 1)[0]
412395
pulse_inds_2 = 1 + np.where(np.diff(digital_2) == 1)[0] if n_digital_signals == 2 else None
413396
pulse_times_1 = pulse_inds_1 * 1000 / sampling_rate
414397
pulse_times_2 = pulse_inds_2 * 1000 / sampling_rate if n_digital_signals == 2 else None
415398
# Return signals + header information as a dictionary.
416399
data_dict = {
417-
"filename": os.path.basename(file_path),
400+
"filename": os.path.basename(ppd_file_path),
418401
"analog_1": analog_1,
419402
"analog_2": analog_2,
420-
"analog_1_filt": analog_1_filt,
421-
"analog_2_filt": analog_2_filt,
422403
"digital_1": digital_1,
423404
"digital_2": digital_2,
424405
"pulse_inds_1": pulse_inds_1,
@@ -431,11 +412,14 @@ def import_ppd(file_path, low_pass=20, high_pass=15.9):
431412
data_dict.update(
432413
{
433414
"analog_3": analog_3,
434-
"analog_3_filt": analog_3_filt,
435415
}
436416
)
437417
data_dict.update(header_dict)
438418
return data_dict
419+
420+
def processppdphotometry(ppd_file_path):
421+
"""
422+
439423
"""
440424
ppd_data = import_ppd(ppd_file_path)
441425

0 commit comments

Comments
 (0)