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

Change add_imaging_plane to add imaging plane by name instead of index #594

Merged
merged 15 commits into from
Oct 18, 2023

Conversation

weiglszonja
Copy link
Contributor

  • add imaging_plane_name keyword argument to add_imaging_plane function
  • find which imaging plane to add from the metadata by name instead of index
  • in add_photon_series and add_plane_segmentation the name of the imaging plane is identified from the metadata of photon series or plane segmentation
  • add imaging_plane to default plane segmentation metadata
    resolve [Question]: Assigning two PhotonSeries to the same ImagingPlane  #575

@weiglszonja weiglszonja marked this pull request as draft October 13, 2023 15:19
@weiglszonja weiglszonja self-assigned this Oct 13, 2023
@weiglszonja weiglszonja marked this pull request as ready for review October 16, 2023 09:48
Copy link
Collaborator

@h-mayorquin h-mayorquin left a 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.

src/neuroconv/tools/roiextractors/roiextractors.py Outdated Show resolved Hide resolved
src/neuroconv/tools/roiextractors/roiextractors.py Outdated Show resolved Hide resolved
tests/test_ophys/test_tools_roiextractors.py Outdated Show resolved Hide resolved
tests/test_ophys/test_tools_roiextractors.py Outdated Show resolved Hide resolved
tests/test_ophys/test_tools_roiextractors.py Show resolved Hide resolved
Copy link
Collaborator

@h-mayorquin h-mayorquin left a 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)
Copy link
Collaborator

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?

Copy link
Member

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 😅

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

tests/test_ophys/test_tools_roiextractors.py Show resolved Hide resolved
@@ -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(
Copy link
Collaborator

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...

Copy link
Contributor Author

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:

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

Copy link
Collaborator

@h-mayorquin h-mayorquin Oct 17, 2023

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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)

Copy link
Collaborator

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.

Copy link
Contributor Author

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)
Copy link
Contributor Author

@weiglszonja weiglszonja Oct 17, 2023

Choose a reason for hiding this comment

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

@h-mayorquin

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.

Copy link
Collaborator

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.

@CodyCBakerPhD
Copy link
Member

First steps towards #269

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #594 (8aeeeb8) into main (32df08a) will increase coverage by 0.01%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
unittests 91.00% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/neuroconv/tools/roiextractors/roiextractors.py 89.14% <100.00%> (+0.29%) ⬆️

Copy link
Collaborator

@h-mayorquin h-mayorquin left a 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?

@weiglszonja
Copy link
Contributor Author

weiglszonja commented Oct 18, 2023

Yes, I think it's finished.
There is one failing CI test but I think it is not related to these changes.
Should I merge?

@h-mayorquin
Copy link
Collaborator

Yes, that's fine, I think the current one that is failing I fixed but another one seems to have appeared.

@h-mayorquin h-mayorquin merged commit ec748f1 into main Oct 18, 2023
33 of 34 checks passed
@h-mayorquin h-mayorquin deleted the change_imaging_plane_identifier_to_string branch October 18, 2023 12:26
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.

[Question]: Assigning two PhotonSeries to the same ImagingPlane
3 participants