Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup dependencies + fix YAML bug + fix diagram + fix typo in docstring + tutorial setup #103

Merged
merged 20 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cc24a03
adjusted length of fields of varchar
MilagrosMarin Dec 11, 2023
71af568
Revert "adjusted length of fields of varchar"
MilagrosMarin Dec 12, 2023
3b635d6
update docstring for `model_description` varchar
MilagrosMarin Dec 12, 2023
ab3370a
Update `diagram_flowchart` as in array-ephys repo
MilagrosMarin Dec 21, 2023
28c55bc
move `dj.config()` from init to pipeline.py
MilagrosMarin Dec 21, 2023
820711e
setup install directly from GitHub instead of PyPI
MilagrosMarin Dec 21, 2023
cc0424c
minor update on tutorial markdowns as in array-ephys
MilagrosMarin Dec 22, 2023
ebe6f2b
minor change in dependency version in setup
MilagrosMarin Dec 22, 2023
8e0d9dd
change name of flowchart as in element-ca-imaging
MilagrosMarin Dec 22, 2023
a5e59e5
change name of `flowchart.svg` in notebook
MilagrosMarin Dec 22, 2023
95e10df
move `import os` from `__init__` to `tutorial_pipeline`
MilagrosMarin Dec 22, 2023
a50836d
fix `input_dir` and `output_dir` in the tutorial
MilagrosMarin Dec 22, 2023
fbab55d
Address the bug introduced by the latest update to the YAML dependency
MilagrosMarin Dec 22, 2023
0885f48
update outputs of the tutorial notebook
MilagrosMarin Dec 22, 2023
9b61920
from `safe_load` to `load`
MilagrosMarin Jan 1, 2024
d1b86ce
black formatting `dlc_reader.py`
MilagrosMarin Jan 3, 2024
fddad64
black formatting `tutorial.ipynb`
MilagrosMarin Jan 3, 2024
cd358eb
update `changelog` and `version.py`
MilagrosMarin Jan 4, 2024
abc10df
Refactor YAML loader instant. for consistency
MilagrosMarin Jan 4, 2024
d6fe551
add YAML object as recommended in parallel PR#102
MilagrosMarin Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
],
},
)