-
Notifications
You must be signed in to change notification settings - Fork 260
Probe refactoring with wiring #4548
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
Open
h-mayorquin
wants to merge
33
commits into
SpikeInterface:main
Choose a base branch
from
h-mayorquin:probe_refactoring_with_wiring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f88dc2d
First draft
h-mayorquin cd52ef3
second iteration
h-mayorquin f52c39c
using cache and consistent use of set_probe_groups
h-mayorquin 594122c
using cache and consistent use of set_probe_groups
h-mayorquin 8bdcdc9
recover cophy semantics
h-mayorquin d499bc0
add docstring
h-mayorquin f15e5c6
just copies
h-mayorquin e1b7103
remove comments
h-mayorquin 5d1f57d
rename
h-mayorquin c02e760
more backwards compatability
h-mayorquin 591be63
testing
h-mayorquin ed22a73
beahvior for 0 channel recording
h-mayorquin 565d775
more fixes
h-mayorquin 5ef0221
second fix
h-mayorquin 07f4e9e
remove non-overallaping redundant check
h-mayorquin e6129bc
another fallack
h-mayorquin b3ab028
Merge branch 'main' into probe_refactoring
h-mayorquin 6eb09a6
propgate to children
h-mayorquin 1f4afee
fix tests
h-mayorquin eb07eea
fixes
h-mayorquin cc9e9b0
another numpy fix
h-mayorquin a7db1e3
remove cache
h-mayorquin 4f96a31
Merge branch 'main' into probe_refactoring
h-mayorquin 20b535f
Refactor with wiring
h-mayorquin b1de969
go furhter
h-mayorquin 56761c8
drop deep cpy
h-mayorquin 999a5c4
fix
h-mayorquin 5119d53
refactor
h-mayorquin bdf9d24
serialization fix
h-mayorquin 8b642d9
more fixes
h-mayorquin e801124
add to main properties
h-mayorquin ffee07c
cleanup
h-mayorquin f48b88d
fix doccstring
h-mayorquin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -574,6 +574,9 @@ def to_dict( | |
| folder_metadata = Path(folder_metadata).resolve().absolute().relative_to(relative_to) | ||
| dump_dict["folder_metadata"] = str(folder_metadata) | ||
|
|
||
| if getattr(self, "_probegroup", None) is not None: | ||
| dump_dict["probegroup"] = self._probegroup.to_dict(array_as_list=True) | ||
|
|
||
| return dump_dict | ||
|
|
||
| @staticmethod | ||
|
|
@@ -607,12 +610,11 @@ def from_dict(dictionary: dict, base_folder: Path | str | None = None) -> "BaseE | |
| return extractor | ||
|
|
||
| def load_metadata_from_folder(self, folder_metadata): | ||
| # hack to load probe for recording | ||
| folder_metadata = Path(folder_metadata) | ||
|
|
||
| self._extra_metadata_from_folder(folder_metadata) | ||
|
|
||
| # load properties | ||
| # load properties first so that `_extra_metadata_from_folder` can see | ||
| # restored state like the `wiring` property and skip re-running | ||
| # `set_probegroup` when the mapping is already in place. | ||
| prop_folder = folder_metadata / "properties" | ||
| if prop_folder.is_dir(): | ||
| for prop_file in prop_folder.iterdir(): | ||
|
|
@@ -621,6 +623,8 @@ def load_metadata_from_folder(self, folder_metadata): | |
| key = prop_file.stem | ||
| self.set_property(key, values) | ||
|
|
||
| self._extra_metadata_from_folder(folder_metadata) | ||
|
|
||
| def save_metadata_to_folder(self, folder_metadata): | ||
| self._extra_metadata_to_folder(folder_metadata) | ||
|
|
||
|
|
@@ -1155,9 +1159,53 @@ def _load_extractor_from_dict(dic) -> "BaseExtractor": | |
| for k, v in dic["properties"].items(): | ||
| extractor.set_property(k, v) | ||
|
|
||
| if "probegroup" in dic: | ||
| from probeinterface import ProbeGroup | ||
|
|
||
| probegroup = ProbeGroup.from_dict(dic["probegroup"]) | ||
| # The `wiring` per-channel property was restored above by the standard | ||
| # property-load loop; we just attach the probegroup object. | ||
| extractor._probegroup = probegroup | ||
| elif "contact_vector" in dic.get("properties", {}): | ||
| _restore_probegroup_from_legacy_contact_vector(extractor) | ||
|
|
||
| return extractor | ||
|
|
||
|
|
||
| def _restore_probegroup_from_legacy_contact_vector(extractor) -> None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| """ | ||
| Reconstruct a `ProbeGroup` from the legacy `contact_vector` property. | ||
|
|
||
| Recordings saved before the probegroup refactor stored the probe as a structured numpy | ||
| array under the `contact_vector` property, with probe-level annotations under a separate | ||
| `probes_info` annotation and per-probe planar contours under `probe_{i}_planar_contour` | ||
| annotations. This function reconstructs a `ProbeGroup` from those legacy fields, attaches | ||
| it via the canonical `set_probegroup` path, and removes the legacy property so the new | ||
| and old representations do not coexist on the loaded extractor. | ||
| """ | ||
| from probeinterface import ProbeGroup | ||
|
|
||
| contact_vector_array = extractor.get_property("contact_vector") | ||
| probegroup = ProbeGroup.from_numpy(contact_vector_array) | ||
|
|
||
| if "probes_info" in extractor.get_annotation_keys(): | ||
| probes_info = extractor.get_annotation("probes_info") | ||
| for probe, probe_info in zip(probegroup.probes, probes_info): | ||
| probe.annotations = probe_info | ||
|
|
||
| for probe_index, probe in enumerate(probegroup.probes): | ||
| contour = extractor._annotations.get(f"probe_{probe_index}_planar_contour") | ||
| if contour is not None: | ||
| probe.set_planar_contour(contour) | ||
|
|
||
| if hasattr(extractor, "set_probegroup"): | ||
| extractor.set_probegroup(probegroup, in_place=True) | ||
| else: | ||
| extractor._probegroup = probegroup | ||
|
|
||
| extractor._properties.pop("contact_vector", None) | ||
|
|
||
|
|
||
| def _get_class_from_string(class_string): | ||
| class_name = class_string.split(".")[-1] | ||
| module = ".".join(class_string.split(".")[:-1]) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should not be in base, since it's specific to the
BaseRecordingSnippets