Skip to content

Commit

Permalink
Helper function for adding data to kachery (LorenFrankLab#729)
Browse files Browse the repository at this point in the history
* add helper function for adding data to kachery

* Use dj config default for default kachery zone

* insert to kacher selection in single call
  • Loading branch information
samuelbray32 authored Dec 21, 2023
1 parent 00bb398 commit 1d407ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/spyglass/sharing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
AnalysisNwbfileKachery,
AnalysisNwbfileKacherySelection,
KacheryZone,
share_data_to_kachery,
)
41 changes: 41 additions & 0 deletions src/spyglass/sharing/sharing_kachery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datajoint.errors import DataJointError

from spyglass.utils.dj_mixin import SpyglassMixin
from spyglass.settings import config

from ..common.common_lab import Lab # noqa: F401
from ..common.common_nwbfile import AnalysisNwbfile
Expand Down Expand Up @@ -215,3 +216,43 @@ def download_file(analysis_file_name: str) -> bool:
raise Exception(f"{analysis_file_name} cannot be downloaded")

return True


def share_data_to_kachery(
restriction={},
table_list=[],
zone_name=None,
):
"""Share data to kachery
Parameters
----------
restriction : dict, optional
restriction to select what data should be shared from table, by default {}
table_list : list, optional
List of tables to share data from, by default []
zone_name : str, optional
What kachery zone to share the data to, by default zone in spyglass.settings.config,
which looks for `KACHERY_ZONE` environmental variable, but defaults to
'franklab.default'
Raises
------
ValueError
Does not allow sharing of all data in table
"""
if not zone_name:
zone_name = config["KACHERY_ZONE"]
kachery_selection_key = {"kachery_zone_name": zone_name}
if not restriction:
raise ValueError("Must provide a restriction to the table")
selection_inserts = []
for table in table_list:
analysis_file_list = (table & restriction).fetch("analysis_file_name")
for file in analysis_file_list: # Add all analysis to shared list
kachery_selection_key["analysis_file_name"] = file
selection_inserts.append(kachery_selection_key)
AnalysisNwbfileKacherySelection.insert(
selection_inserts, skip_duplicates=True
)
AnalysisNwbfileKachery.populate()

0 comments on commit 1d407ac

Please sign in to comment.