Skip to content

Commit

Permalink
Ensure request will pass. Fix association during compatibility request
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Jun 4, 2024
1 parent daf95a3 commit 15a6d19
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +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);

Expand All @@ -288,12 +290,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
65 changes: 46 additions & 19 deletions src/pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,19 +751,62 @@ 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 +820,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 15a6d19

Please sign in to comment.