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

Add symlink to Processing for ZDriftMetrics #5

Merged
merged 27 commits into from
Oct 6, 2023

Conversation

kushalbakshi
Copy link

This implementation is one suggestion but it might make more sense to create a table downstream from ZDriftMetrics called DropFrames with a foreign key reference to ZDriftMetrics. DropFrames would also have an additional boolean attribute indicating whether it was necessary to drop frames or not based on the drift values generated for each frame in ZDriftMetrics. If False, the Processing table will look for the raw data in the inbox, if True the Processing table will look for a symlink in the outbox.

@@ -353,6 +351,7 @@ class ZDriftMetrics(dj.Computed):
-> scan.Scan
-> ZDriftParamSet
---
exceeds_threshold: boolean # `True` if any value in z_drift > threshold from drift_params.

Choose a reason for hiding this comment

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

Instead of a boolean like this, why not directly store a longblob of the frame indices of the frames exceeding the threshold (call it bad_frames)?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's a good idea. It can be fetched directly in the make() function. Does the symlink part look correct? I was following the example of the ephys implementation of it.

@kushalbakshi kushalbakshi changed the title WIP: Add symlink to ZDriftMetrics Add symlink to Processing for ZDriftMetrics Oct 4, 2023
@kushalbakshi
Copy link
Author

@ttngu207, this is ready for review. This version of element-calcium-imaging generates the following line in the suite2p output:

bad frames file path: /home/anaconda/efs/outbox/20230627_Image_eCBsensor_activity/Behavior_20230627/C57-C11-3_Rm_CNO_30min/scan_0/suite2p_17/bad_frames.npy

This indicates suite2p successfully excludes these frames from registration.

@@ -522,16 +524,33 @@ def make(self, key):
else:
raise NotImplementedError("Unknown method: {}".format(method))
elif task_mode == "trigger":
drop_frames = (ZDriftMetrics & key).fetch1("bad_frames")
Copy link

Choose a reason for hiding this comment

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

Because there may be multiple entries in ZDriftMetrics for one particular scan (corresponding to different zdrift_paramset), there is a risk with fetch1() here.
There is no guarantee that there is only one. If there are multiple ZDriftMetrics for this scan, which zdrift_param are we going with? Can we make the assumption to go with the first one?

Copy link
Author

Choose a reason for hiding this comment

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

That is a good point. We can probably assume the first one for now, unless we want to refactor the module to allow zdrift_paramset_idx as an additional primary key for all downstream tables from ZDriftMetrics

Copy link
Author

Choose a reason for hiding this comment

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

Since this is a fork separate from the main element, I'm open to either approach. Let me know which one you prefer

Copy link

Choose a reason for hiding this comment

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

@kushalbakshi , let's go with the assumption that there is only one ZDriftMetrics for the particular scan, raise an error with a meaningful message if there are more than one.

Comment on lines 527 to 528
drop_frames = (ZDriftMetrics & key).fetch("bad_frames")
if len(drop_frames) > 1:
Copy link

Choose a reason for hiding this comment

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

You can simplify by doing try-catch around the fetch1() here

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@kushalbakshi kushalbakshi requested a review from ttngu207 October 5, 2023 22:07
@ttngu207 ttngu207 merged commit b51c500 into dj-sciops:main Oct 6, 2023
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