Skip to content

Commit

Permalink
move dj.config() from init to pipeline.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MilagrosMarin committed Dec 21, 2023
1 parent ab3370a commit 28c55bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
20 changes: 0 additions & 20 deletions element_deeplabcut/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
import os
import datajoint as dj

if "custom" not in dj.config:
dj.config["custom"] = {}

# overwrite dj.config['custom'] values with environment variables if available

dj.config["custom"]["database.prefix"] = os.getenv(
"DATABASE_PREFIX", dj.config["custom"].get("database.prefix", "")
)

dj.config["custom"]["dlc_root_data_dir"] = os.getenv(
"DLC_ROOT_DATA_DIR", dj.config["custom"].get("dlc_root_data_dir", "")
)

dj.config["custom"]["dlc_processed_data_dir"] = os.getenv(
"DLC_PROCESSED_DATA_DIR", dj.config["custom"].get("dlc_processed_data_dir", "")
)

db_prefix = dj.config["custom"].get("database.prefix", "")
43 changes: 29 additions & 14 deletions notebooks/tutorial_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@
from element_animal.subject import Subject
from element_lab.lab import Source, Lab, Protocol, User, Project

__all__ = [
"Subject",
"Source",
"Lab",
"Protocol",
"User",
"Project",
"Session",
]

if "custom" not in dj.config:
dj.config["custom"] = {}

# overwrite dj.config['custom'] values with environment variables if available

dj.config["custom"]["database.prefix"] = os.getenv(
"DATABASE_PREFIX", dj.config["custom"].get("database.prefix", "")
)

dj.config["custom"]["dlc_root_data_dir"] = os.getenv(
"DLC_ROOT_DATA_DIR", dj.config["custom"].get("dlc_root_data_dir", "")
)

dj.config["custom"]["dlc_processed_data_dir"] = os.getenv(
"DLC_PROCESSED_DATA_DIR", dj.config["custom"].get("dlc_processed_data_dir", "")
)

if "custom" not in dj.config:
dj.config["custom"] = {}

db_prefix = dj.config["custom"].get("database.prefix", "")


# Declare functions for retrieving data
def get_dlc_root_data_dir() -> list:
"""Returns a list of root directories for Element DeepLabCut"""
dlc_root_dirs = dj.config.get("custom", {}).get("dlc_root_data_dir")
Expand All @@ -46,18 +55,24 @@ def get_dlc_processed_data_dir() -> str:
return None


# Activate "lab", "subject", "session" schema -------------
__all__ = [
"Subject",
"Source",
"Lab",
"Protocol",
"User",
"Project",
"Session",
]

# Activate schemas -------------

lab.activate(db_prefix + "lab")

subject.activate(db_prefix + "subject", linking_module=__name__)

Experimenter = lab.User
Session = session.Session
session.activate(db_prefix + "session", linking_module=__name__)

# Activate equipment table ------------------------------------


@lab.schema
class Device(dj.Lookup):
Expand Down

0 comments on commit 28c55bc

Please sign in to comment.