Skip to content

Commit

Permalink
WIP: Tidy position 2
Browse files Browse the repository at this point in the history
  • Loading branch information
CBroz1 committed Mar 13, 2024
1 parent 01faadd commit 7f1b22a
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 724 deletions.
42 changes: 24 additions & 18 deletions src/spyglass/common/common_behav.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class VideoFile(SpyglassMixin, dj.Imported):
def make(self, key):
self._no_transaction_make(key)

def _no_transaction_make(self, key, verbose=True):
def _no_transaction_make(self, key, verbose=True, skip_duplicates=False):
if not self.connection.in_transaction:
self.populate(key)
return
Expand All @@ -394,6 +394,7 @@ def _no_transaction_make(self, key, verbose=True):
"interval_list_name": interval_list_name,
}
).fetch1("valid_times")

cam_device_str = r"camera_device (\d+)"
is_found = False
for ind, video in enumerate(videos.values()):
Expand All @@ -403,26 +404,31 @@ def _no_transaction_make(self, key, verbose=True):
# check to see if the times for this video_object are largely
# overlapping with the task epoch times

if len(
if not len(
interval_list_contains(valid_times, video_obj.timestamps)
> 0.9 * len(video_obj.timestamps)
):
nwb_cam_device = video_obj.device.name
# returns whatever was captured in the first group (within the parentheses) of the regular expression -- in this case, 0
key["video_file_num"] = int(
re.match(cam_device_str, nwb_cam_device)[1]
continue

nwb_cam_device = video_obj.device.name

# returns whatever was captured in the first group (within the
# parentheses) of the regular expression - in this case, 0

key["video_file_num"] = int(
re.match(cam_device_str, nwb_cam_device)[1]
)
camera_name = video_obj.device.camera_name
if CameraDevice & {"camera_name": camera_name}:
key["camera_name"] = video_obj.device.camera_name
else:
raise KeyError(
f"No camera with camera_name: {camera_name} found "
+ "in CameraDevice table."
)
camera_name = video_obj.device.camera_name
if CameraDevice & {"camera_name": camera_name}:
key["camera_name"] = video_obj.device.camera_name
else:
raise KeyError(
f"No camera with camera_name: {camera_name} found "
+ "in CameraDevice table."
)
key["video_file_object_id"] = video_obj.object_id
self.insert1(key)
is_found = True
key["video_file_object_id"] = video_obj.object_id
self.insert1(key, skip_duplicates=skip_duplicates)
is_found = True

if not is_found and verbose:
logger.info(
Expand All @@ -431,7 +437,7 @@ def _no_transaction_make(self, key, verbose=True):
)

@classmethod
def update_entries(cls, restrict={}):
def update_entries(cls, restrict=True):
existing_entries = (cls & restrict).fetch("KEY")
for row in existing_entries:
if (cls & row).fetch1("camera_name"):
Expand Down
2 changes: 2 additions & 0 deletions src/spyglass/common/common_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ def prompt_insert(

if table_type:
table_type += " "
else:
table_type = ""

logger.info(
f"{table}{table_type} '{name}' was not found in the"
Expand Down
3 changes: 0 additions & 3 deletions src/spyglass/common/common_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def generate_pos_components(
orientation = pynwb.behavior.CompassDirection()
velocity = pynwb.behavior.BehavioralTimeSeries()

# NOTE: CBroz1 removed a try/except ValueError that surrounded all
# .create_X_series methods. dpeg22 could not recall purpose

time_comments = dict(
comments=spatial_series.comments,
timestamps=position_info["time"],
Expand Down
5 changes: 3 additions & 2 deletions src/spyglass/common/common_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ActivityLog(dj.Manual):
"""

@classmethod
def log(cls, name):
logger.warning(f"Function scheduled for deprecation: {name}")
def log(cls, name, warning=True) -> None:
if warning:
logger.warning(f"Function scheduled for deprecation: {name}")
cls.insert1(dict(dj_user=dj.config["database.user"], function=name))
Loading

0 comments on commit 7f1b22a

Please sign in to comment.