-
Notifications
You must be signed in to change notification settings - Fork 23
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
Change add_imaging_plane
to add imaging plane by name instead of index
#594
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good to me and makes sense.
No major comments other than minor suggestions.
Co-authored-by: Heberto Mayorquin <[email protected]>
for more information, see https://pre-commit.ci
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. I am wondering if it would make sense to also get the photon_series properties by name instead of by index as well.
Just some final suggestions about the tests and a small question.
imaging_plane = nwbfile.get_imaging_plane(name=imaging_plane_name) | ||
photon_series_kwargs = deepcopy(photon_series_metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this needed?
My memory is that we needed to deepcopy the metadata so we don't modify the data that the user passes but the hpoton_series_metadata is already deepcopied so why copy it again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid mutating the other copy I assume 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, sorry I answered in a separate reply ..
You're right, the reason why I chose this is to avoid overwriting the "imaging_plane" in the metadata with the actual ImagingPlane object at this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and it would definitely make sense to eventually also use photon_series_name as identifier instead of index!
@@ -1427,6 +1469,25 @@ def test_add_one_photon_series_roundtrip(self): | |||
expected_one_photon_series_shape = (self.num_frames, self.num_columns, self.num_rows) | |||
assert one_photon_series.shape == expected_one_photon_series_shape | |||
|
|||
def test_add_multiple_one_photon_series_with_same_imaging_plane(self): | |||
"""Test adding two OnePhotonSeries that use the same ImagingPlane.""" | |||
add_photon_series( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of making this explicit by explictly setting the:
first_photon_series_metadata = deepcopy(self.one_photon_series_metadata)
second_photon_series_metadata = deepcopy(self.one_photon_series_metadata)
first_photon_series_metadata["Ophys"]["OnePhotonSeries"][0]["imaging_plane"] = "same_imaging_plane_for_two_series"
second_photon_series_metadata["Ophys"]["OnePhotonSeries"][0]["imaging_plane"] = "same_imaging_plane_for_two_series"
Or we could use a single metadata dictionary for the two of them as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit is always better, but I'm not sure how you imagine the single metadata dictionary, something like this:
neuroconv/tests/test_ophys/test_tools_roiextractors.py
Lines 1474 to 1480 in 3c17f24
shared_photon_series_metadata = deepcopy(self.one_photon_series_metadata) | |
shared_imaging_plane_name = "same_imaging_plane_for_two_series" | |
shared_photon_series_metadata["Ophys"]["ImagingPlane"][0]["name"] = shared_imaging_plane_name | |
shared_photon_series_metadata["Ophys"]["OnePhotonSeries"][0]["imaging_plane"] = shared_imaging_plane_name | |
add_photon_series( |
3c17f24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So,
metadata["Ophys"]["OnePhotonSeries"]
will be a list with two elements (one per plane). Then you will need to specificy the photon_series_index
for each call to add_photon_series
But if we are moving towards #269 then maybe is not worth to do it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h-mayorquin are you imagining for this PR to include the change in the metadata schema? If not, I think here is fine to assume the list structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not all, I am saying that if you don't want to have a single metadata dictionary that is totally fine. Because, when we eventually do #269 then we will need to change the list structure anyway.
So up to you.
) | ||
|
||
self.assertIn("second_photon_series", self.nwbfile.acquisition) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be a good idea to check that we only have one imaging plane here written?
Something like
assert len(self.nwbfile.imaging_planes) == 0
assert self.nwbfile.imaging_planes[0]["name"] == "the_default_name_or_the_name_we_chosen_in_this_test"
The second line is probably wrong but you get the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should add a check for that! Thanks
imaging_plane = nwbfile.get_imaging_plane(name=imaging_plane_name) | ||
photon_series_kwargs = deepcopy(photon_series_metadata) | ||
photon_series_kwargs.update(imaging_plane=imaging_plane) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My memory is that we needed to deepcopy the metadata so we don't modify the data that the user passes but the hpoton_series_metadata is already deepcopied so why copy it again?
You're right, the reason why I chose this is to avoid overwriting the "imaging_plane" in the metadata with the actual ImagingPlane object at this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK, probably not necessary anymore then.
First steps towards #269 |
Codecov Report
@@ Coverage Diff @@
## main #594 +/- ##
==========================================
+ Coverage 90.98% 91.00% +0.01%
==========================================
Files 103 103
Lines 5369 5378 +9
==========================================
+ Hits 4885 4894 +9
Misses 484 484
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is done right?
Yes, I think it's finished. |
Yes, that's fine, I think the current one that is failing I fixed but another one seems to have appeared. |
imaging_plane_name
keyword argument toadd_imaging_plane
functionadd_photon_series
andadd_plane_segmentation
the name of the imaging plane is identified from the metadata of photon series or plane segmentationimaging_plane
to default plane segmentation metadataresolve [Question]: Assigning two
PhotonSeries
to the sameImagingPlane
#575