From 28c55bcbea20c4859e58b7deb23d32efcaf3b668 Mon Sep 17 00:00:00 2001 From: MilagrosMarin Date: Thu, 21 Dec 2023 22:40:12 +0100 Subject: [PATCH] move `dj.config()` from init to pipeline.py --- element_deeplabcut/__init__.py | 20 ---------------- notebooks/tutorial_pipeline.py | 43 +++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/element_deeplabcut/__init__.py b/element_deeplabcut/__init__.py index 7f2535c..8b13789 100644 --- a/element_deeplabcut/__init__.py +++ b/element_deeplabcut/__init__.py @@ -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", "") diff --git a/notebooks/tutorial_pipeline.py b/notebooks/tutorial_pipeline.py index 861f465..f337df0 100644 --- a/notebooks/tutorial_pipeline.py +++ b/notebooks/tutorial_pipeline.py @@ -8,15 +8,23 @@ 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"] = {} @@ -24,6 +32,7 @@ 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") @@ -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):