Skip to content

Commit

Permalink
Merge pull request #827 from NeurodataWithoutBorders/fix-alignment
Browse files Browse the repository at this point in the history
Fix Alignment
  • Loading branch information
CodyCBakerPhD authored Jun 4, 2024
2 parents c796208 + b2862c6 commit 1057450
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/electron/frontend/core/components/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class Page extends LitElement {
...conversionOptions, // Any additional conversion options override the defaults

interfaces: globalState.interfaces,
alignment,
};

fileConfiguration.push(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ export class GuidedSourceDataPage extends ManagedPage {
if (alignment) {
globalState.project.alignment = alignment.results;
this.unsavedUpdates = "conversions";
await this.save();
}

await this.save();

const sourceCopy = structuredClone(globalState.results[subject][session].source_data);

const alignmentInfo =
Expand All @@ -288,12 +289,16 @@ export class GuidedSourceDataPage extends ManagedPage {
alignment: alignmentInfo,
};

console.warn("Sending", sessionInfo);

const data = await run("neuroconv/alignment", sessionInfo, {
title: "Checking Alignment",
message: "Please wait...",
});

const { metadata } = data;
console.warn("GOT", data);

if (Object.keys(metadata).length === 0) {
this.notify(
`<h4 style="margin: 0">Time Alignment Failed</h4><small>Please ensure that all source data is specified.</small>`,
Expand Down
62 changes: 43 additions & 19 deletions src/pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,19 +751,59 @@ def set_interface_alignment(converter: dict, alignment_info: dict) -> dict:
return errors


def get_interface_alignment(info: dict) -> dict:
def get_compatible_interfaces(info: dict) -> dict:

from neuroconv.basetemporalalignmentinterface import BaseTemporalAlignmentInterface
from neuroconv.datainterfaces.ecephys.baserecordingextractorinterface import (
BaseRecordingExtractorInterface,
)
from neuroconv.datainterfaces.ecephys.basesortingextractorinterface import (
BaseSortingExtractorInterface,
)

converter = instantiate_custom_converter(source_data=info["source_data"], interface_class_dict=info["interfaces"])

compatible = {}

for name, interface in converter.data_interface_objects.items():

is_sorting = isinstance(interface, BaseSortingExtractorInterface)

if is_sorting is True:
compatible[name] = []

# If at least one recording and sorting interface is selected on the formats page
# Then it is possible the two could be linked (the sorting was applied to the recording)
# But there are very strict conditions from SpikeInterface determining compatibility
# Those conditions are not easily exposed so we just 'try' to register them and skip on error
sibling_recording_interfaces = {
interface_key: interface
for interface_key, interface in converter.data_interface_objects.items()
if isinstance(interface, BaseRecordingExtractorInterface)
}

for recording_interface_key, recording_interface in sibling_recording_interfaces.items():
try:
interface.register_recording(recording_interface=recording_interface)
compatible[name].append(recording_interface_key)
except Exception:
pass

return compatible


def get_interface_alignment(info: dict) -> dict:

from neuroconv.basetemporalalignmentinterface import BaseTemporalAlignmentInterface
from neuroconv.datainterfaces.ecephys.basesortingextractorinterface import (
BaseSortingExtractorInterface,
)

alignment_info = info.get("alignment", dict())

converter = instantiate_custom_converter(source_data=info["source_data"], interface_class_dict=info["interfaces"])

compatibility = get_compatible_interfaces(info)

errors = set_interface_alignment(converter=converter, alignment_info=alignment_info)

metadata = dict()
Expand All @@ -777,23 +817,7 @@ def get_interface_alignment(info: dict) -> dict:
metadata[name]["sorting"] = is_sorting

if is_sorting is True:
metadata[name]["compatible"] = []

# If at least one recording and sorting interface is selected on the formats page
# Then it is possible the two could be linked (the sorting was applied to the recording)
# But there are very strict conditions from SpikeInterface determining compatibility
# Those conditions are not easily exposed so we just 'try' to register them and skip on error
sibling_recording_interfaces = {
interface_key: interface
for interface_key, interface in converter.data_interface_objects.items()
if isinstance(interface, BaseRecordingExtractorInterface)
}
for recording_interface_key, recording_interface in sibling_recording_interfaces.items():
try:
interface.register_recording(recording_interface=recording_interface)
metadata[name]["compatible"].append(recording_interface_key)
except Exception:
pass
metadata[name]["compatible"] = compatibility.get(name, None)

if not isinstance(interface, BaseTemporalAlignmentInterface):
timestamps[name] = []
Expand Down

0 comments on commit 1057450

Please sign in to comment.