Skip to content
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

Tested DLC multicam pipeline #841

Merged
merged 21 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion environment_dlc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies:
- libgcc # dlc-only
- matplotlib
- non_local_detector
- numpy<1.24
- pip>=20.2.*
- position_tools
- pybind11 # req by mountainsort4 -> isosplit5
Expand All @@ -47,4 +46,5 @@ dependencies:
- pynwb>=2.2.0,<3
- sortingview>=0.11
- spikeinterface>=0.98.2,<0.99
- tensorflow<=2.12 # dlc-only
- .[dlc]
3 changes: 2 additions & 1 deletion src/spyglass/position/v1/dlc_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def pkl(self):
def yml(self):
if self._yml is None:
with open(self.yml_path, "rb") as f:
self._yml = yaml.safe_load(f)
safe_yaml = yaml.YAML(typ="safe", pure=True)
self._yml = safe_yaml.load(f)
return self._yml

@property
Expand Down
35 changes: 22 additions & 13 deletions src/spyglass/position/v1/dlc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pathlib
import pwd
import subprocess
import sys
from collections import abc
from contextlib import redirect_stdout
from itertools import groupby
Expand Down Expand Up @@ -419,8 +420,10 @@ def get_video_path(key):
"""
import pynwb

vf_key = {"nwb_file_name": key["nwb_file_name"], "epoch": key["epoch"]}
VideoFile()._no_transaction_make(vf_key, verbose=False)
valid_fields = VideoFile.fetch().dtype.fields.keys()
vf_key = {k: val for k, val in key.items() if k in valid_fields}
if not VideoFile & vf_key:
VideoFile()._no_transaction_make(vf_key, verbose=False)
video_query = VideoFile & vf_key

if len(video_query) != 1:
Expand Down Expand Up @@ -537,17 +540,23 @@ def _convert_mp4(
"copy",
f"{dest_path.as_posix()}",
]
try:
convert_process = subprocess.Popen(
convert_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as err:
raise RuntimeError(
f"command {err.cmd} return with error (code {err.returncode}): {err.output}"
) from err
out, _ = convert_process.communicate()
print(out.decode("utf-8"))
print(f"finished converting {filename}")
if dest_path.exists():
print(f"{dest_path} already exists, skipping conversion")
else:
try:
sys.stdout.flush()
convert_process = subprocess.Popen(
convert_command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
except subprocess.CalledProcessError as err:
raise RuntimeError(
f"command {err.cmd} return with error (code {err.returncode}): {err.output}"
) from err
out, _ = convert_process.communicate()
print(out.decode("utf-8"))
print(f"finished converting {filename}")
print(
f"Checking that number of packets match between {orig_filename} and {dest_filename}"
)
Expand Down
3 changes: 2 additions & 1 deletion src/spyglass/position/v1/position_dlc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def make(self, key):
raise OSError(f"config_path {config_path} does not exist.")
if config_path.suffix in (".yml", ".yaml"):
with open(config_path, "rb") as f:
dlc_config = yaml.safe_load(f)
safe_yaml = yaml.YAML(typ="safe", pure=True)
dlc_config = safe_yaml.load(f)
if isinstance(params["params"], dict):
dlc_config.update(params["params"])
del params["params"]
Expand Down
Loading