Skip to content

Commit

Permalink
Merge pull request #103 from MilagrosMarin/main
Browse files Browse the repository at this point in the history
Update setup dependencies + fix YAML bug + fix diagram + fix typo in docstring + tutorial setup
  • Loading branch information
kushalbakshi authored Jan 4, 2024
2 parents 5b12e5e + d6fe551 commit 499d85e
Show file tree
Hide file tree
Showing 10 changed files with 754 additions and 900 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.2.11] - 2023-01-04

+ Fix - docstring typo
+ Fix - `dj.config()` setup moved to `tutorial_pipeline.py` instead of `__init__.py`
+ Bugfix - Resolved AttributeError from the latest update of the YAML dependency
+ Update - Flowchart images to increase consistency with other DataJoint Elements
+ Update - Elements installed directly from GitHub instead of PyPI

## [0.2.10] - 2023-11-20

+ Fix - Revert fixing of networkx version in setup
Expand Down
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", "")
10 changes: 6 additions & 4 deletions element_deeplabcut/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import cv2
import csv
import yaml
from ruamel.yaml import YAML
import inspect
import importlib
import numpy as np
Expand Down Expand Up @@ -239,8 +239,9 @@ def extract_new_body_parts(cls, dlc_config: dict, verbose: bool = True):
".yaml",
), f"dlc_config is neither dict nor filepath\n Check: {dlc_config_fp}"
if dlc_config_fp.suffix in (".yml", ".yaml"):
yaml = YAML(typ="safe", pure=True)
with open(dlc_config_fp, "rb") as f:
dlc_config = yaml.safe_load(f)
dlc_config = yaml.load(f)
# -- Check and insert new BodyPart --
assert "bodyparts" in dlc_config, f"Found no bodyparts section in {dlc_config}"
tracked_body_parts = cls.fetch("body_part")
Expand Down Expand Up @@ -307,7 +308,7 @@ class Model(dj.Manual):
config_template (longblob): Dictionary of the config for analyze_videos().
project_path ( varchar(255) ): DLC's project_path in config relative to root.
model_prefix ( varchar(32) ): Optional. Prefix for model files.
model_description ( varchar(1000) ): Optional. User-entered description.
model_description ( varchar(300) ): Optional. User-entered description.
TrainingParamSet (foreign key): Optional. Training parameters primary key.
Note:
Expand Down Expand Up @@ -381,8 +382,9 @@ def insert_new_model(
"dlc_config is not a filepath" + f"\n Check: {dlc_config_fp}"
)
if dlc_config_fp.suffix in (".yml", ".yaml"):
yaml = YAML(typ="safe", pure=True)
with open(dlc_config_fp, "rb") as f:
dlc_config = yaml.safe_load(f)
dlc_config = yaml.load(f)
if isinstance(params, dict):
dlc_config.update(params)

Expand Down
5 changes: 3 additions & 2 deletions element_deeplabcut/readers/dlc_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
from pathlib import Path
import pickle
import ruamel.yaml as yaml
from ruamel.yaml import YAML
from element_interface.utils import find_root_directory, dict_to_uuid
from .. import model
from ..model import get_dlc_root_data_dir
Expand Down Expand Up @@ -145,7 +145,8 @@ def yml(self):
"""json-structured config.yaml file contents"""
if self._yml is None:
with open(self.yml_path, "rb") as f:
self._yml = yaml.safe_load(f)
yaml = YAML(typ="safe", pure=True)
self._yml = yaml.load(f)
return self._yml

@property
Expand Down
2 changes: 1 addition & 1 deletion element_deeplabcut/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Package metadata
"""
__version__ = "0.2.10"
__version__ = "0.2.11"
82 changes: 81 additions & 1 deletion images/flowchart.drawio

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion images/flowchart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,470 changes: 618 additions & 852 deletions notebooks/tutorial.ipynb

Large diffs are not rendered by default.

44 changes: 30 additions & 14 deletions notebooks/tutorial_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import datajoint as dj
from collections import abc
from element_lab import lab
Expand All @@ -8,22 +9,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 +56,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
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
packages=find_packages(exclude=["contrib", "docs", "tests*"]),
scripts=[],
install_requires=[
"datajoint>=0.13",
"datajoint>=0.13.0",
"graphviz",
"pydot",
"ipykernel",
Expand All @@ -40,10 +40,10 @@
],
"dlc_gui": ["deeplabcut[gui]"],
"elements": [
"element-lab>=0.3.0",
"element-animal>=0.1.8",
"element-session>=0.1.5",
"element-interface>=0.6.0",
"element-lab @ git+https://github.com/datajoint/element-lab.git",
"element-animal @ git+https://github.com/datajoint/element-animal.git",
"element-session @ git+https://github.com/datajoint/element-session.git",
"element-interface @ git+https://github.com/datajoint/element-interface.git",
],
},
)

0 comments on commit 499d85e

Please sign in to comment.