Skip to content

Commit

Permalink
ruff happiness
Browse files Browse the repository at this point in the history
  • Loading branch information
grg2rsr committed Jan 8, 2025
1 parent d7a5ec0 commit 631dec9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def convert(eid: str, one: ONE, data_interfaces: list, revision: str):
# Run conversion
session_converter = BrainwideMapConverter(one=one, session=eid, data_interfaces=data_interfaces, verbose=True)
metadata = session_converter.get_metadata()
metadata["NWBFile"]["session_id"] = f'{eid}:{revision}' # FIXME this hack has to go
metadata["NWBFile"]["session_id"] = f"{eid}:{revision}" # FIXME this hack has to go
subject_id = metadata["Subject"]["subject_id"]

subject_folder_path = output_folder / f"sub-{subject_id}"
Expand Down
2 changes: 1 addition & 1 deletion src/ibl_to_nwb/_scripts/_convert_brainwide_map_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def convert(eid: str, one: ONE, data_interfaces: list, raw: bool, revision: str)
# Run conversion
session_converter = BrainwideMapConverter(one=one, session=eid, data_interfaces=data_interfaces, verbose=True)
metadata = session_converter.get_metadata()
metadata["NWBFile"]["session_id"] = f'{eid}:{revision}' # FIXME this hack has to go
metadata["NWBFile"]["session_id"] = f"{eid}:{revision}" # FIXME this hack has to go
subject_id = metadata["Subject"]["subject_id"]

subject_folder_path = output_folder / f"sub-{subject_id}"
Expand Down
4 changes: 3 additions & 1 deletion src/ibl_to_nwb/_scripts/post_conversion_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path

from one.api import ONE

from ibl_to_nwb.testing._consistency_checks import check_nwbfile_for_consistency
from pathlib import Path

nwbfile_path = ""

Expand Down
6 changes: 4 additions & 2 deletions src/ibl_to_nwb/_scripts/post_conversion_check_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from ibl_to_nwb.testing._consistency_checks import check_nwbfile_for_consistency

# path setup
nwbfile_path = Path("/home/georg/ibl_scratch/nwbfiles/sub-NR_0031/sub-NR_0031_ses-caa5dddc-9290-4e27-9f5e-575ba3598614_desc-processed-debug.nwb")
nwbfile_path = Path(
"/home/georg/ibl_scratch/nwbfiles/sub-NR_0031/sub-NR_0031_ses-caa5dddc-9290-4e27-9f5e-575ba3598614_desc-processed-debug.nwb"
)
nwbfile = NWBHDF5IO.read_nwb(nwbfile_path)

eid, revision = nwbfile.session_id.split(':') # this is the hack that has to be removed eventually
eid, revision = nwbfile.session_id.split(":") # this is the hack that has to be removed eventually

# path setup
base_path = Path.home() / "ibl_scratch"
Expand Down
2 changes: 1 addition & 1 deletion src/ibl_to_nwb/datainterfaces/_brainwide_map_trials.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pathlib import Path
from typing import Optional

from brainbox.io.one import SessionLoader
from hdmf.common import VectorData
from neuroconv.basedatainterface import BaseDataInterface
from neuroconv.utils import load_dict_from_file
from one.api import ONE
from pynwb import NWBFile
from pynwb.epoch import TimeIntervals
from brainbox.io.one import SessionLoader


class BrainwideMapTrialsInterface(BaseDataInterface):
Expand Down
45 changes: 22 additions & 23 deletions src/ibl_to_nwb/testing/_consistency_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def check_nwbfile_for_consistency(*, one: ONE, nwbfile_path: Path):
def check_raw_nwbfile_for_consistency(*, one: ONE, nwbfile_path: Path):
with NWBHDF5IO(path=nwbfile_path, mode="r") as io:
nwbfile = io.read()
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")

# run checks for raw files
_check_raw_ephys_data(eid=eid, one=one, nwbfile=nwbfile)
_check_raw_video_data(eid=eid, one=one, nwbfile=nwbfile, nwbfile_path=nwbfile_path)


def _check_wheel_data(*, one: ONE, nwbfile: NWBFile):
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")
processing_module = nwbfile.processing["wheel"]
wheel_position_series = processing_module.data_interfaces["CompassDirection"].spatial_series["WheelPositionSeries"]
wheel_movement_table = processing_module.data_interfaces["WheelMovementIntervals"][:]
Expand All @@ -60,8 +60,8 @@ def _check_wheel_data(*, one: ONE, nwbfile: NWBFile):


def _check_lick_data(*, one: ONE, nwbfile: NWBFile):
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")

processing_module = nwbfile.processing["camera"]
lick_times_table = processing_module.data_interfaces["LickTimes"][:]

Expand All @@ -72,8 +72,7 @@ def _check_lick_data(*, one: ONE, nwbfile: NWBFile):

def _check_roi_motion_energy_data(*, one: ONE, nwbfile: NWBFile):
processing_module = nwbfile.processing["camera"]
eid, revision = nwbfile.session_id.split(':')

eid, revision = nwbfile.session_id.split(":")

camera_views = ["body", "left", "right"]
for view in camera_views:
Expand All @@ -92,8 +91,7 @@ def _check_roi_motion_energy_data(*, one: ONE, nwbfile: NWBFile):

def _check_pose_estimation_data(*, one: ONE, nwbfile: NWBFile):
processing_module = nwbfile.processing["camera"]
eid, revision = nwbfile.session_id.split(':')

eid, revision = nwbfile.session_id.split(":")

camera_views = ["body", "left", "right"]
for view in camera_views:
Expand Down Expand Up @@ -129,8 +127,7 @@ def _check_pose_estimation_data(*, one: ONE, nwbfile: NWBFile):


def _check_trials_data(*, one: ONE, nwbfile: NWBFile):
eid, revision = nwbfile.session_id.split(':')

eid, revision = nwbfile.session_id.split(":")

data_from_NWB = nwbfile.trials[:].reset_index(drop=True)
session_loader = SessionLoader(one=one, eid=eid, revision=revision)
Expand Down Expand Up @@ -166,8 +163,8 @@ def _check_trials_data(*, one: ONE, nwbfile: NWBFile):


def _check_pupil_tracking_data(*, one: ONE, nwbfile: NWBFile):
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")

processing_module = nwbfile.processing["camera"]

camera_views = ["left", "right"]
Expand All @@ -191,9 +188,9 @@ def _check_pupil_tracking_data(*, one: ONE, nwbfile: NWBFile):


def _check_spike_sorting_data(*, one: ONE, nwbfile: NWBFile):
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")

pids, probe_names = one.eid2pid(eid)
pids, probe_names = one.eid2pid(eid)
pids = dict(zip(probe_names, pids))

units_table = nwbfile.units[:]
Expand All @@ -219,18 +216,20 @@ def get_spikes_for_cluster(spike_clusters, spike_times, cluster):
clusters[probe_name] = clusters_

# pre-sort for fast access
sort_ix = np.argsort(spikes[probe_name]['clusters'])
spikes[probe_name]['times'] = spikes[probe_name]['times'][sort_ix]
spikes[probe_name]['clusters'] = spikes[probe_name]['clusters'][sort_ix]
sort_ix = np.argsort(spikes[probe_name]["clusters"])
spikes[probe_name]["times"] = spikes[probe_name]["times"][sort_ix]
spikes[probe_name]["clusters"] = spikes[probe_name]["clusters"][sort_ix]

for ix in units_table.index:
probe_name, uuid = units_table.loc[ix, ["probe_name", "cluster_uuid"]]
assert uuid in clusters[probe_name]['uuids'].values
assert uuid in clusters[probe_name]["uuids"].values
spike_times_from_NWB = units_table.loc[ix, "spike_times"]

cluster_id = np.where(clusters[probe_name]['uuids'] == uuid)[0][0]
spikes[probe_name]['clusters']
spike_times_from_ONE = get_spikes_for_cluster(spikes[probe_name]['clusters'], spikes[probe_name]['times'], cluster_id)
cluster_id = np.where(clusters[probe_name]["uuids"] == uuid)[0][0]
spikes[probe_name]["clusters"]
spike_times_from_ONE = get_spikes_for_cluster(
spikes[probe_name]["clusters"], spikes[probe_name]["times"], cluster_id
)

# more verbose but slower for more than ~20 checks
# spike_times_from_ONE = spike_times[probe_name][spike_clusters[probe_name] == cluster_id]
Expand All @@ -240,7 +239,7 @@ def get_spikes_for_cluster(spike_clusters, spike_times, cluster):


def _check_raw_ephys_data(*, one: ONE, nwbfile: NWBFile, pname: str = None, band: str = "ap"):
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")

# data_one
pids, pnames_one = one.eid2pid(eid)
Expand Down Expand Up @@ -293,7 +292,7 @@ def _check_raw_ephys_data(*, one: ONE, nwbfile: NWBFile, pname: str = None, band


def _check_raw_video_data(*, one: ONE, nwbfile: NWBFile, nwbfile_path: str):
eid, revision = nwbfile.session_id.split(':')
eid, revision = nwbfile.session_id.split(":")

# timestamps
datasets = one.list_datasets(eid, "*Camera.times*", collection="alf")
Expand Down

0 comments on commit 631dec9

Please sign in to comment.