Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the pyphotometry preprocessing steps. There is a function calle… #21

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

j2figuer
Copy link
Collaborator

…d 'import_ppd' that is needed to import .ppd data. I included it in the description of the processppdphotometry function. Is this correct?

requires the import_ppd function from the data_import.py script
The code needed is below.

def import_ppd(file_path, low_pass=20, high_pass=15.9):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the import_ppd function needs to be on its own instead of in a comment - otherwise the processppdphotometry function won't know what import_ppd means and this will break when you run it

sampling_rate = ppd_data['sampling_rate']

b,a = butter(2, 10, btype='low', fs=sampling_rate)
GACh_denoised = filtfilt(b,a, raw_green)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name these green_denoised and red_denoised instead of ACh and DA specific because this pipeline should work regardless of the identity of the red/green signals

ratio_zscored = np.divide(np.subtract(ratio_highpass,ratio_highpass.mean()),ratio_highpass.std())

return {"green_zscored": green_zscored, "red_zscored": red_zscored, "ratio_zscored": ratio_zscored, "zscored_405": zscored_405}
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete pass - doesn't do anything bc you have already returned a dict

@@ -336,6 +336,141 @@ def airPLS(data, lambda_=1e8, max_iterations=50):
weights[-1] = weights[0]
return baseline

def processppdphotometry(ppd_file_path):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick but I would rename this process_ppd_photometry for readability and to match style with the other function names


ratio_zscored = np.divide(np.subtract(ratio_highpass,ratio_highpass.mean()),ratio_highpass.std())

return {"green_zscored": green_zscored, "red_zscored": red_zscored, "ratio_zscored": ratio_zscored, "zscored_405": zscored_405}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also return port visit times for alignment

Copy link
Owner

@calderast calderast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Added some minor comments

@@ -395,9 +601,11 @@ def add_photometry(nwbfile: NWBFile, metadata: dict):
elif "ppd_file_path" in metadata["photometry"]:
# Process ppd file from pyPhotometry
print("Processing ppd file from pyPhotometry...")

ppd_file_path = metadata["photometry"]["ppd_file_path"]
signals = process_ppd_photometry(ppd_file_path)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change returned values and arguments to match the function definition

Suggested change
signals = process_ppd_photometry(ppd_file_path)
sampling_rate, visits = process_ppd_photometry(nwbfile, ppd_file_path)

Comment on lines 606 to 609
# TODO for Jose - add pyPhotometry processing here!!
# Probably add the processing functions above and just call them here

raise NotImplementedError("pyPhotometry processing is not yet implemented.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO and NotImplementedError because it is now implemented

Suggested change
# TODO for Jose - add pyPhotometry processing here!!
# Probably add the processing functions above and just call them here
raise NotImplementedError("pyPhotometry processing is not yet implemented.")

Comment on lines +541 to +542
# Return port visits in downsampled photometry time (250 Hz) to use for alignment

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe pyPhotometry is 86(?) Hz instead of 250

Suggested change
# Return port visits in downsampled photometry time (250 Hz) to use for alignment
# Return port visits in downsampled photometry time (86 Hz) to use for alignment

data_dict.update(header_dict)
return data_dict

def process_ppd_photometry(ppd_file_path, nwbfile: NWBFile, metadata: dict):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove metadata here bc we don't use it. Also put nwbfile as the first argument for consistency

Suggested change
def process_ppd_photometry(ppd_file_path, nwbfile: NWBFile, metadata: dict):
def process_ppd_photometry(nwbfile: NWBFile, ppd_file_path):

Comment on lines +460 to +463
# Add photometry metadata to the NWB
print("Adding photometry metadata to NWB ...")
add_photometry_metadata(NWBFile, metadata)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this because I will reorganize in the next PR to add it separately (outside of either the LabVIEW or pyPhotometry specific processing)

Suggested change
# Add photometry metadata to the NWB
print("Adding photometry metadata to NWB ...")
add_photometry_metadata(NWBFile, metadata)

zscored_405 = np.divide(np.subtract(highpass_405,highpass_405.mean()),highpass_405.std())

ratio_zscored = np.divide(np.subtract(ratio_highpass,ratio_highpass.mean()),ratio_highpass.std())
print('Done processing photometry data! Returning z-scored signals...')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but changing this bc we don't actually return them and the next comment is "adding to NWB" which is what we actually do next

Suggested change
print('Done processing photometry data! Returning z-scored signals...')
print('Done processing photometry data!')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants