Skip to content

Commit

Permalink
added cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
keyaloding committed Aug 9, 2024
1 parent a2f96ab commit 30fbe6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies = [
"attrs",
"h5py>=3.8.0",
"pynwb",
"ndx-pose @ git+https://github.com/rly/ndx-pose@a847ad4be75e60ef9e413b8cbfc99c616fc9fd05",
"ndx-pose",
"pandas",
"simplejson",
"imageio",
Expand Down
4 changes: 2 additions & 2 deletions sleap_io/io/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def load_nwb(filename: str) -> Labels:
"""
with NWBHDF5IO(filename, "r", load_namespaces=True) as io:
nwb_processing = io.read().processing
if any('PoseTraining' in module for module in nwb_processing.values()):
if any("PoseTraining" in module for module in nwb_processing.values()):
return nwb.read_nwb_training(nwb_processing)
return nwb.read_nwb(filename)


def save_nwb(
labels: Labels,
filename: str,
as_training: bool = True,
as_training: bool = False,
append: bool = True,
frame_inds: Optional[list[int]] = None,
frame_path: Optional[str] = None,
Expand Down
17 changes: 16 additions & 1 deletion sleap_io/io/nwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def write_nwb(
nwbfile_path: str,
nwb_file_kwargs: Optional[dict] = None,
pose_estimation_metadata: Optional[dict] = None,
as_training: bool = True,
as_training: bool = False,
frame_inds: Optional[list[int]] = None,
frame_path: Optional[str] = None,
):
Expand Down Expand Up @@ -813,12 +813,27 @@ def build_pose_estimation_container_for_track(
track_data_df, timestamps
)

cameras = []
nwbfile = NWBFile(
session_description="Processed SLEAP pose data",
session_start_time=datetime.datetime.now(datetime.timezone.utc),
identifier=str(uuid.uuid1()),
)
for i, video in enumerate(labels.videos):
camera = nwbfile.create_device(
name=f"camera {i}",
description="Camera used to record video {i}",
manufacturer="No specified manufacturer",
)
cameras.append(camera)

# Arrange and mix metadata
pose_estimation_container_kwargs = dict(
name=f"track={track_name}",
description=f"Estimated positions of {skeleton.name} in video {video_path.name}",
pose_estimation_series=pose_estimation_series_list,
nodes=skeleton.node_names,
devices=cameras,
edges=np.array(skeleton.edge_inds).astype("uint64"),
source_software="SLEAP",
# dimensions=np.array([[video.backend.height, video.backend.width]]),
Expand Down

0 comments on commit 30fbe6f

Please sign in to comment.