Skip to content

Commit

Permalink
add script/functions for running video capsules
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsridhar12345 committed Jan 10, 2024
1 parent 9fe16fe commit 85ffe81
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
44 changes: 39 additions & 5 deletions src/npc_lims/metadata/codeocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
]
"""Result from CodeOcean API when querying data assets."""

EYE_TRACKING_CAPSULE_ID = '4cf0be83-2245-4bb1-a55c-a78201b14bfe'
DLC_SIDE_TRACKING_CAPSULE_ID = 'facff99f-d3aa-4ecd-8ef8-a343c38197aa'
DLC_FACE_TRACKING_CAPSULE_ID = 'a561aa4c-2066-4ff2-a916-0db86b918cdf'
FACEMAP_CAPSULE_ID = '670de0b3-f73d-4d22-afe6-6449c45fada4'

class SessionIndexError(IndexError):
pass
Expand Down Expand Up @@ -454,16 +458,46 @@ def update_permissions_for_data_asset(data_asset: DataAssetAPI) -> None:
)
response.raise_for_status()

def get_data_assets_dict(session_id: str, type: str='raw') -> list[dict[str, str]]:
"""
Gets the dictionary that is passed in to the run capsule function from aind codeocean api
>>> get_data_assets_dict('686740_2023-10-26', type='raw')
[{'id': 'aed59ffa-c7db-4246-84cc-d4bb61f4cbc7', 'mount': 'ecephys_686740_2023-10-26_12-29-08'}]
"""

# add more types if needed
if type == 'raw':
data_assets=[
{"id": data_asset["id"], "mount": data_asset["name"]}
for data_asset in [get_session_raw_data_asset(session_id)]
]

return data_assets

def run_eye_tracking_capsule(session_id: str) -> None:
get_codeocean_client().run_capsule(
"4cf0be83-2245-4bb1-a55c-a78201b14bfe",
data_assets=[
{"id": data_asset["id"], "mount": data_asset["name"]}
for data_asset in [get_session_raw_data_asset(session_id)]
],
EYE_TRACKING_CAPSULE_ID,
get_data_assets_dict(session_id, type='raw'),
).raise_for_status()

def run_dlc_side_tracking_capsule(session_id: str) -> None:
get_codeocean_client().run_capsule(
DLC_SIDE_TRACKING_CAPSULE_ID,
get_data_assets_dict(session_id, type='raw'),
).raise_for_status()

def run_dlc_face_tracking_capsule(session_id: str) -> None:
get_codeocean_client().run_capsule(
DLC_FACE_TRACKING_CAPSULE_ID,
get_data_assets_dict(session_id, type='raw'),
).raise_for_status()

def run_facemap_capsule(session_id: str) -> None:
get_codeocean_client().run_capsule(
FACEMAP_CAPSULE_ID,
get_data_assets_dict(session_id, type='raw'),
).raise_for_status()

def run_capsules_for_units_spikes_kilosort_codeocean(session_id: str) -> None:
raw_data_asset = get_session_raw_data_asset(session_id)
Expand Down
15 changes: 15 additions & 0 deletions src/npc_lims/scripts/run_video_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import npc_lims.metadata.codeocean as codeocean
import npc_lims.status as status

def main() -> None:
for session_info in status.get_session_info():
if not session_info.is_uploaded:
continue

codeocean.run_eye_tracking_capsule(session_info.id)
codeocean.run_dlc_side_tracking_capsule(session_info.id)
codeocean.run_dlc_face_tracking_capsule(session_info.id)
codeocean.run_facemap_capsule(session_info.id)

if __name__ == '__main__':
main()

1 comment on commit 85ffe81

@bjhardcastle
Copy link
Member

@bjhardcastle bjhardcastle commented on 85ffe81 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjunsridhar12345

def get_data_assets_dict(session_id: str, type: str='raw') -> list[dict[str, str]]:
"""
Gets the dictionary that is passed in to the run capsule function from aind codeocean api
>>> get_data_assets_dict('686740_2023-10-26', type='raw')
[{'id': 'aed59ffa-c7db-4246-84cc-d4bb61f4cbc7', 'mount': 'ecephys_686740_2023-10-26_12-29-08'}]
"""

a few comments:

  • you definitely want to avoid naming variables type, which overwrites the built-in.. _type would be better, but something more descriptive would even better: I actually have no idea this is doing
  • you currently have an if type == path with no else path. I'm actually surprised mypy allowed this. If I pass type="" I'd get an incomprehensible AttributeError: data_assets does not exist and have to look at the source code. You should instead raise a ValueError and say what the accepted values for type are.
  • you also change the type hint for type to be Literal["raw"] to be more helpful

Please sign in to comment.