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

Enhancements and refactoring: Ruff checks resolved #443

Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
833f9e9
feat: add one-off logic to ingest fullpose data for social02
ttngu207 Aug 8, 2024
0558cbb
Merge branch 'datajoint_pipeline' into dev_fullpose_for_social02
ttngu207 Aug 20, 2024
e9c7fa2
Create reingest_fullpose_sleap_data.py
ttngu207 Aug 21, 2024
38b44e0
Allow reading model metadata from local folder
glopesdev Sep 26, 2024
028ffc5
Avoid iterating over None
glopesdev Sep 26, 2024
25b7195
Avoid iterating over the config file twice
glopesdev Sep 26, 2024
f77ac1d
Avoid mixing dtypes with conditional assignment
glopesdev Sep 26, 2024
ac2aa13
Remove whitespace on blank line
glopesdev Sep 26, 2024
caf3ce1
Use replace function instead of explicit loop
glopesdev Sep 27, 2024
93428c8
Improve error logic when model metadata not found
glopesdev Sep 27, 2024
00c1cca
Test loading poses with local model metadata
glopesdev Sep 27, 2024
6b32583
Use all components other than time and device name
glopesdev Sep 27, 2024
010fdb9
Add regression test for poses with register prefix
glopesdev Oct 2, 2024
0a88b79
Infer base prefix from stream search pattern
glopesdev Oct 2, 2024
f925d75
Use full identity likelihood vectors in test data
glopesdev Oct 2, 2024
83cd905
Merge pull request #421 from SainsburyWellcomeCentre/gl-issue-418
glopesdev Oct 3, 2024
36ee97a
Update worker.py
ttngu207 Oct 10, 2024
b54e1c3
new readers and schemas for reduced data storage in db
jkbhagatio Oct 10, 2024
d6cf52f
updated tests
jkbhagatio Oct 10, 2024
f12e359
cleaned up linting for ruff
jkbhagatio Oct 10, 2024
daf6224
updated pandas and changed S to s lmao
jkbhagatio Oct 10, 2024
6d798b8
chore: code cleanup
ttngu207 Oct 15, 2024
ea3c2ef
Merge remote-tracking branch 'upstream/ingestion_readers_schemas' int…
ttngu207 Oct 15, 2024
697c0a8
chore: delete the obsolete `dataset` (replaced by `schemas`)
ttngu207 Oct 15, 2024
2ef32c3
chore: clean up `load_metadata`
ttngu207 Oct 16, 2024
d5bd0fe
feat(ingestion): use new `ingestion_schemas`
ttngu207 Oct 16, 2024
8725e8f
feat(streams): update streams with new ingestion_schemas
ttngu207 Oct 16, 2024
0f210e1
fix(ingestion_schemas): downsampling Encoder
ttngu207 Oct 16, 2024
d365bcd
fix(ingestion_schemas): minor fix in `_Encoder`, calling `super()` init
ttngu207 Oct 18, 2024
cb90843
fix(harp reader): remove rows where the index is zero
ttngu207 Oct 18, 2024
9c7e9d9
fix(BlockForaging): bugfix in col rename
ttngu207 Oct 18, 2024
0a9c1e1
fix(block_analysis): bugfix in extracting `subject_in_patch` time
ttngu207 Oct 21, 2024
4020900
feat(fetch_stream): flag to round to microseconds
ttngu207 Oct 21, 2024
566c3ed
fix(block_analysis): bugfix `in_patch_timestamps`
ttngu207 Oct 21, 2024
28e39c1
Update reingest_fullpose_sleap_data.py
ttngu207 Oct 21, 2024
41a248d
Create reingest_fullpose_sleap_data.py
ttngu207 Aug 21, 2024
cda41fb
Update reingest_fullpose_sleap_data.py
ttngu207 Oct 21, 2024
6f7f541
Merge branch 'dev_fullpose_for_social02' into datajoint_pipeline
ttngu207 Oct 21, 2024
f783067
fix: `social_02.Pose03` in `ingestion_schemas` only
ttngu207 Oct 21, 2024
3e59db8
Update reingest_fullpose_sleap_data.py
ttngu207 Oct 21, 2024
64900ad
Update reingest_fullpose_sleap_data.py
ttngu207 Oct 21, 2024
538e4e5
feat(tracking): add `BlobPositionTracking`
ttngu207 Oct 22, 2024
290fe4e
fix(block_analysis): various fixes and code improvements
ttngu207 Oct 22, 2024
fb18016
fix: improve logic to search for chunks in a given block
ttngu207 Oct 22, 2024
8f2fffc
feat(script): add script `sync_ingested_and_raw_epochs`
ttngu207 Oct 23, 2024
8762fcf
fix(sync_ingested_and_raw_epochs): minor code cleanup
ttngu207 Oct 24, 2024
9078085
fix(BlockSubjectAnalysis): handle edge case where the encoder data ar…
ttngu207 Oct 24, 2024
6005df1
fix: resolve D100 error
MilagrosMarin Oct 28, 2024
edb30e8
fix: fix: resolve D104 error
MilagrosMarin Oct 28, 2024
46b832b
fix: fix: resolve D105 error
MilagrosMarin Oct 28, 2024
7cfd46c
fix: resolve D107 error
MilagrosMarin Oct 28, 2024
7c596c3
fix: resolve E201, E202, and E203 errors by applying Black formatting
MilagrosMarin Oct 28, 2024
dabe579
fix: resolve E231 error through previous commit too
MilagrosMarin Oct 28, 2024
7c40d82
fix: resolve E702
MilagrosMarin Oct 28, 2024
6c9cb2e
fix: resolve S101: substitute `assert` detected by `if...raise` and a…
MilagrosMarin Oct 28, 2024
047d8ec
fix: resolve additional S101: replaced `assert` with explicit `if...r…
MilagrosMarin Oct 28, 2024
c14d7de
fix: eliminate extra parenthesis introduced in the last commit
MilagrosMarin Oct 28, 2024
e5daa6d
feat: addressed all S101 checks - delete from pyproject.toml
MilagrosMarin Oct 28, 2024
b50ca42
fix: resolve PT013 errors: Incorrect import of `pytest`
MilagrosMarin Oct 28, 2024
d5e3fe6
fix: remove PT013 from pyproject.toml and add docstrings for `dj_conf…
MilagrosMarin Oct 28, 2024
a9cacf2
fix: resolve E501 errors
MilagrosMarin Oct 28, 2024
bcb4c82
fix: resolve E401 error
MilagrosMarin Oct 28, 2024
e805caf
fix: resolve B905 by setting default value of strict to False
MilagrosMarin Oct 28, 2024
35e0096
fix: resolve B905 by setting default value of strict to False
MilagrosMarin Oct 28, 2024
dff8a87
fix: resolve D205 error
MilagrosMarin Oct 28, 2024
0b86908
fix: resolve D202 error
MilagrosMarin Oct 28, 2024
de642c8
fix: resolve I001 error
MilagrosMarin Oct 28, 2024
a7f72ee
fix: resolve B006 in `plotting.py` by fixing mutable default argument
MilagrosMarin Oct 28, 2024
0b631dc
fix: resolve B021 error
MilagrosMarin Oct 28, 2024
7dd455a
fix: update deprecation of `datetime.utcnow()`
MilagrosMarin Oct 28, 2024
7b614c9
fix: resolve D102 by adding docstring in public methods
MilagrosMarin Oct 28, 2024
e7c05f4
fix: resolve D103 error
MilagrosMarin Oct 28, 2024
10bb40f
fix: resolve E501 error + black formatting with max length 105
MilagrosMarin Oct 28, 2024
4b9b0e7
fix: resolve E501 issues
MilagrosMarin Oct 28, 2024
4d76c77
fix: resolve F401 issues
MilagrosMarin Oct 28, 2024
163ff9f
fix: resolve B905 issues
MilagrosMarin Oct 28, 2024
e320939
fix: add to previous commit another change
MilagrosMarin Oct 28, 2024
3ac3652
fix: resolve S324 issue
MilagrosMarin Oct 28, 2024
71f100d
fix: resolve E722 issues
MilagrosMarin Oct 28, 2024
6ab8bad
fix: resolve B904 issue
MilagrosMarin Oct 29, 2024
07d6a35
fix: resolve UP038 issues
MilagrosMarin Oct 29, 2024
445770a
fix: resolve D205 issues
MilagrosMarin Oct 29, 2024
4c82c40
fix: resolve D202 issues
MilagrosMarin Oct 29, 2024
7ddb5cd
fix: resolve F403
MilagrosMarin Oct 29, 2024
8b58eee
fix: Resolve PLR2004 issues
MilagrosMarin Oct 29, 2024
4f66d8c
fix: resolve SIM108 issue by refactoring code
MilagrosMarin Oct 29, 2024
3303c58
fix: resolve I001 issues
MilagrosMarin Oct 29, 2024
d44fed1
fix: another round of global ruff check
MilagrosMarin Oct 29, 2024
71ac75f
fix: another round: all checks passed for `aeon/analysis`
MilagrosMarin Oct 29, 2024
f722085
fix: another round: all checks passed for `aeon/dj_pipeline`
MilagrosMarin Oct 29, 2024
ae9bc98
fix: another round: all checks passed for `aeon/io` - code refactored
MilagrosMarin Oct 29, 2024
d0cdee9
fix: another round: all checks passed for `aeon/tests`
MilagrosMarin Oct 29, 2024
31b7fb3
fix: another round: all checks passed for `.`
MilagrosMarin Oct 29, 2024
cc7e759
fix: fix datetime deprecation with timezone
MilagrosMarin Oct 29, 2024
269cf16
fix: add missing comment in table definition
MilagrosMarin Oct 29, 2024
5c7637e
fix: fix one I001 error
MilagrosMarin Oct 29, 2024
cb7226a
fix: add `UP017:Use `datetime.UTC` alias` as ignored
MilagrosMarin Oct 29, 2024
2cc6f29
fix: E741 substitute with meaniniful variables
MilagrosMarin Oct 29, 2024
268e0a4
fix: update variable names
MilagrosMarin Oct 29, 2024
7f1431f
fix: review
MilagrosMarin Oct 29, 2024
6ad3b0a
fix: review
MilagrosMarin Oct 29, 2024
5262570
fix: review - exception for md5
MilagrosMarin Oct 29, 2024
18b3aa5
fix: review
MilagrosMarin Oct 29, 2024
115ea45
fix: review
MilagrosMarin Oct 29, 2024
ec008b9
fix: review
MilagrosMarin Oct 29, 2024
1c91dad
fix: review
MilagrosMarin Oct 29, 2024
c19d92f
fix: review
MilagrosMarin Oct 29, 2024
afa6ff9
fix: review
MilagrosMarin Oct 29, 2024
842f933
fix: review
MilagrosMarin Oct 29, 2024
8aa55a9
fix: review
MilagrosMarin Oct 29, 2024
88ae62e
fix: review
MilagrosMarin Oct 29, 2024
4c69b82
fix: review
MilagrosMarin Oct 29, 2024
2dda4f0
fix: review
MilagrosMarin Oct 29, 2024
abab112
fix: review
MilagrosMarin Oct 29, 2024
2b96423
fix: update pyproject.toml
MilagrosMarin Oct 29, 2024
a438f83
fix(internal team review):
MilagrosMarin Oct 29, 2024
8c8317a
fix(internal team review):
MilagrosMarin Oct 29, 2024
bbec40a
fix(internal team review):
MilagrosMarin Oct 29, 2024
0796793
fix(internal team review):
MilagrosMarin Oct 29, 2024
d3c3881
fix(internal team review):
MilagrosMarin Oct 29, 2024
4600e99
fix(internal team review): Revert to previous version since it is aut…
MilagrosMarin Oct 29, 2024
e3dfdf5
fix(internal team review): revert replacement of assert in `tests` an…
MilagrosMarin Oct 30, 2024
ebecb00
chore: minor fixes to address PR review comments
ttngu207 Oct 30, 2024
24582de
fix: revert changes in `streams.py`
MilagrosMarin Oct 31, 2024
22d6452
fix: revert black formatting -> max line length from 88 to 105
MilagrosMarin Oct 31, 2024
fc49b51
fix: revert changes in `streams.py`
MilagrosMarin Oct 31, 2024
48493cb
fix: revert stream.py change in dependencies order
MilagrosMarin Oct 31, 2024
69dee9b
Fix docstring indent in `movies.py`
lochhh Nov 1, 2024
6793ffd
Fix docstring indent `plotting.py`
lochhh Nov 1, 2024
c1cdb08
Fix docstring indent + unapply black in `utils.py`
lochhh Nov 1, 2024
b0952eb
fix: address PR comments
ttngu207 Nov 5, 2024
8f9752f
fix: revert changes in `aeon/README.md`
MilagrosMarin Nov 6, 2024
2e40630
Update aeon/analysis/block_plotting.py
MilagrosMarin Nov 6, 2024
8090089
Update aeon/README.md
MilagrosMarin Nov 6, 2024
efa5590
Update aeon/analysis/block_plotting.py
MilagrosMarin Nov 6, 2024
f21d79a
Update aeon/dj_pipeline/__init__.py
MilagrosMarin Nov 6, 2024
6ef1b3a
Update aeon/dj_pipeline/acquisition.py
MilagrosMarin Nov 6, 2024
8d468b9
Update aeon/dj_pipeline/acquisition.py
MilagrosMarin Nov 6, 2024
9816f0f
Update aeon/dj_pipeline/analysis/block_analysis.py
MilagrosMarin Nov 6, 2024
3904810
Update aeon/dj_pipeline/analysis/block_analysis.py
MilagrosMarin Nov 6, 2024
6a72beb
Update aeon/dj_pipeline/analysis/block_analysis.py
MilagrosMarin Nov 6, 2024
714a8fe
Update aeon/dj_pipeline/analysis/block_analysis.py
MilagrosMarin Nov 6, 2024
b3da517
Update aeon/dj_pipeline/analysis/block_analysis.py
MilagrosMarin Nov 6, 2024
c60d67c
Update aeon/schema/octagon.py
MilagrosMarin Nov 6, 2024
d2559ee
Update aeon/schema/schemas.py
MilagrosMarin Nov 6, 2024
ac12ae0
Update aeon/schema/social_02.py
MilagrosMarin Nov 6, 2024
cb12408
Update aeon/dj_pipeline/analysis/block_analysis.py
MilagrosMarin Nov 6, 2024
20adbdf
Update aeon/dj_pipeline/analysis/visit.py
MilagrosMarin Nov 6, 2024
ed72295
Update aeon/dj_pipeline/analysis/visit_analysis.py
MilagrosMarin Nov 6, 2024
89ac8b3
Update aeon/dj_pipeline/analysis/visit_analysis.py
MilagrosMarin Nov 6, 2024
8bfdfcf
Update aeon/dj_pipeline/analysis/visit_analysis.py
MilagrosMarin Nov 6, 2024
08ae696
Update aeon/dj_pipeline/create_experiments/create_socialexperiment.py
MilagrosMarin Nov 6, 2024
da16630
Update aeon/dj_pipeline/create_experiments/create_socialexperiment_0.py
MilagrosMarin Nov 6, 2024
65e2c61
Update aeon/dj_pipeline/populate/worker.py
MilagrosMarin Nov 6, 2024
2981366
Update aeon/dj_pipeline/scripts/clone_and_freeze_exp01.py
MilagrosMarin Nov 6, 2024
26b90ea
Update aeon/dj_pipeline/scripts/clone_and_freeze_exp02.py
MilagrosMarin Nov 6, 2024
4167c01
Update aeon/dj_pipeline/subject.py
MilagrosMarin Nov 6, 2024
ec5e143
Update aeon/dj_pipeline/analysis/visit.py
MilagrosMarin Nov 6, 2024
8350dee
Update aeon/dj_pipeline/subject.py
MilagrosMarin Nov 6, 2024
43e6e9b
Update aeon/dj_pipeline/tracking.py
MilagrosMarin Nov 6, 2024
32d2ae8
Update aeon/dj_pipeline/tracking.py
MilagrosMarin Nov 6, 2024
ebcf952
Merge remote-tracking branch 'origin/datajoint_pipeline' into datajoi…
MilagrosMarin Nov 6, 2024
8358ce4
fix(tracking): improve logic for retrieving `anchor_part`
ttngu207 Nov 6, 2024
61ec7ae
feat(acquisition): add `ExperimentTimeline` table
ttngu207 Nov 6, 2024
f564c3b
update(subject): update logic to keep up with the latest changes in P…
ttngu207 Nov 6, 2024
007512a
feat(sciviz): add entry form for `ExperimentTimeline`
ttngu207 Nov 6, 2024
52b0017
Update aeon/dj_pipeline/create_experiments/create_experiment_02.py
MilagrosMarin Nov 8, 2024
9e8183d
Update aeon/dj_pipeline/tracking.py
MilagrosMarin Nov 8, 2024
a7ad6f3
Update aeon/dj_pipeline/tracking.py
MilagrosMarin Nov 8, 2024
cf15a81
Update aeon/dj_pipeline/utils/load_metadata.py
MilagrosMarin Nov 8, 2024
fd3baa0
Update aeon/dj_pipeline/utils/plotting.py
MilagrosMarin Nov 8, 2024
f8d947d
Update aeon/dj_pipeline/utils/plotting.py
MilagrosMarin Nov 8, 2024
d8f5887
Update aeon/dj_pipeline/utils/plotting.py
MilagrosMarin Nov 8, 2024
7e0e9c4
Update aeon/dj_pipeline/utils/plotting.py
MilagrosMarin Nov 8, 2024
ce1a22f
Update aeon/dj_pipeline/utils/plotting.py
MilagrosMarin Nov 8, 2024
d5cab69
Update aeon/dj_pipeline/utils/plotting.py
MilagrosMarin Nov 8, 2024
5f8f127
Update aeon/dj_pipeline/utils/streams_maker.py
MilagrosMarin Nov 8, 2024
89022c7
Update aeon/dj_pipeline/utils/streams_maker.py
MilagrosMarin Nov 8, 2024
ff2ef8c
Update aeon/dj_pipeline/utils/streams_maker.py
MilagrosMarin Nov 8, 2024
42fdb2c
Update aeon/io/api.py
MilagrosMarin Nov 8, 2024
07e657e
Update aeon/io/api.py
MilagrosMarin Nov 8, 2024
29876d9
Update aeon/io/reader.py
MilagrosMarin Nov 8, 2024
6d35eb9
Update aeon/schema/foraging.py
MilagrosMarin Nov 8, 2024
e8ba357
Update aeon/io/reader.py
MilagrosMarin Nov 8, 2024
90a4ad5
Update aeon/io/reader.py
MilagrosMarin Nov 8, 2024
3aa1be2
Update aeon/schema/octagon.py
MilagrosMarin Nov 8, 2024
2f8ad79
Merge branch 'MilagrosMarin-datajoint_pipeline' into datajoint_pipeline
MilagrosMarin Nov 8, 2024
a1d9f75
fix: fix conflicts
MilagrosMarin Nov 8, 2024
73751c1
fix: two minor ruff checks
MilagrosMarin Nov 12, 2024
819a6de
Merge pull request #2 from SainsburyWellcomeCentre/pr-443
MilagrosMarin Nov 12, 2024
3661162
Merge branch 'datajoint_pipeline' of https://github.com/MilagrosMarin…
ttngu207 Nov 12, 2024
992b49b
Merge pull request #3 from ttngu207/dev_ruff443
MilagrosMarin Nov 12, 2024
dd830df
fix: fix new ruff checks from latest PRs merged 446
MilagrosMarin Nov 13, 2024
50ce619
chore: update gitignore with `.coverage`
MilagrosMarin Nov 13, 2024
387277b
fix: add suggestions from reviewer
MilagrosMarin Nov 13, 2024
50f5ff1
fix: add suggested doctstring from reviewer
MilagrosMarin Nov 13, 2024
7202221
fix: fix definition comment
MilagrosMarin Nov 13, 2024
6be26d1
fix: remove noqa
MilagrosMarin Nov 13, 2024
6279bda
fix: solve #noqa's
MilagrosMarin Nov 13, 2024
3149f29
Fix indentations in docstrings
lochhh Nov 18, 2024
c41bd02
Standardise module descriptions
lochhh Nov 19, 2024
886b6e0
Merge pull request #4 from SainsburyWellcomeCentre/pr-443
MilagrosMarin Nov 20, 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
2 changes: 1 addition & 1 deletion aeon/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
# README # noqa D100
2 changes: 2 additions & 0 deletions aeon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Top-level package for aeon."""

from importlib.metadata import PackageNotFoundError, version

try:
Expand Down
1 change: 1 addition & 0 deletions aeon/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Utilities for analyzing data."""
28 changes: 17 additions & 11 deletions aeon/analysis/block_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
patch_markers_linestyles = ["solid", "dash", "dot", "dashdot", "longdashdot"]


def gen_hex_grad(hex_col, vals, min_l=0.3):
def gen_hex_grad(hex_col, vals, min_lightness=0.3):
"""Generates an array of hex color values based on a gradient defined by unit-normalized values."""
# Convert hex to rgb to hls
h, l, s = rgb_to_hls(*[int(hex_col.lstrip("#")[i : i + 2], 16) / 255 for i in (0, 2, 4)]) # noqa: E741
hue, lightness, saturation = rgb_to_hls(
*[int(hex_col.lstrip("#")[i : i + 2], 16) / 255 for i in (0, 2, 4)]
)
grad = np.empty(shape=(len(vals),), dtype="<U10") # init grad
for i, val in enumerate(vals):
cur_l = (l * val) + (min_l * (1 - val)) # get cur lightness relative to `hex_col`
cur_l = max(min(cur_l, l), min_l) # set min, max bounds
cur_rgb_col = hls_to_rgb(h, cur_l, s) # convert to rgb
curl_lightness = (lightness * val) + (
min_lightness * (1 - val)
) # get cur lightness relative to `hex_col`
curl_lightness = max(min(curl_lightness, lightness), min_lightness) # set min, max bounds
cur_rgb_col = hls_to_rgb(hue, curl_lightness, saturation) # convert to rgb
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
cur_hex_col = "#{:02x}{:02x}{:02x}".format(
*tuple(int(c * 255) for c in cur_rgb_col)
) # convert to hex
Expand All @@ -55,19 +59,21 @@ def conv2d(arr, kernel):

def gen_subject_colors_dict(subject_names):
"""Generates a dictionary of subject colors based on a list of subjects."""
return {s: c for s, c in zip(subject_names, subject_colors)}
return dict(zip(subject_names, subject_colors, strict=False))
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved


def gen_patch_style_dict(patch_names):
"""Based on a list of patches, generates a dictionary of:
"""Based on a list of patches, generates a dictionary of the following items.

- patch_colors_dict: patch name to color
- patch_markers_dict: patch name to marker
- patch_symbols_dict: patch name to symbol
- patch_linestyles_dict: patch name to linestyle

"""
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
return {
"colors": {p: c for p, c in zip(patch_names, patch_colors)},
"markers": {p: m for p, m in zip(patch_names, patch_markers)},
"symbols": {p: s for p, s in zip(patch_names, patch_markers_symbols)},
"linestyles": {p: ls for p, ls in zip(patch_names, patch_markers_linestyles)},
"colors": dict(zip(patch_names, patch_colors, strict=False)),
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
"markers": dict(zip(patch_names, patch_markers, strict=False)),
"symbols": dict(zip(patch_names, patch_markers_symbols, strict=False)),
"linestyles": dict(zip(patch_names, patch_markers_linestyles, strict=False)),
}
2 changes: 2 additions & 0 deletions aeon/analysis/movies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Helper functions for processing video data."""

import math

import cv2
Expand Down
2 changes: 2 additions & 0 deletions aeon/analysis/plotting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Helper functions for plotting data."""

import math

import matplotlib.pyplot as plt
Expand Down
16 changes: 14 additions & 2 deletions aeon/analysis/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Helper functions for data analysis and visualization."""

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -59,7 +61,10 @@ def visits(data, onset="Enter", offset="Exit"):
# duplicate offsets indicate missing data from previous pairing
missing_data = data.duplicated(subset=time_offset, keep="last")
if missing_data.any():
data.loc[missing_data, ["duration"] + [name for name in data.columns if rsuffix in name]] = pd.NA
data.loc[
missing_data,
["duration"] + [name for name in data.columns if rsuffix in name],
] = pd.NA

# rename columns and sort data
data.rename({time_onset: lonset, id_onset: "id", time_offset: loffset}, axis=1, inplace=True)
Expand Down Expand Up @@ -99,7 +104,14 @@ def rate(events, window, frequency, weight=1, start=None, end=None, smooth=None,


def get_events_rates(
events, window_len_sec, frequency, unit_len_sec=60, start=None, end=None, smooth=None, center=False
events,
window_len_sec,
frequency,
unit_len_sec=60,
start=None,
end=None,
smooth=None,
center=False,
):
"""Computes the event rate from a sequence of events over a specified window."""
# events is an array with the time (in seconds) of event occurence
Expand Down
15 changes: 12 additions & 3 deletions aeon/dj_pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""DataJoint pipeline for Aeon."""

import hashlib
import os
import uuid

import datajoint as dj

logger = dj.logger

_default_database_prefix = os.getenv("DJ_DB_PREFIX") or "aeon_"
_default_repository_config = {"ceph_aeon": "/ceph/aeon"}

Expand Down Expand Up @@ -46,7 +50,12 @@ def fetch_stream(query, drop_pk=True):
df.rename(columns={"timestamps": "time"}, inplace=True)
df.set_index("time", inplace=True)
df.sort_index(inplace=True)
df = df.convert_dtypes(convert_string=False, convert_integer=False, convert_boolean=False, convert_floating=False)
df = df.convert_dtypes(
convert_string=False,
convert_integer=False,
convert_boolean=False,
convert_floating=False,
)
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
return df


Expand All @@ -57,5 +66,5 @@ def fetch_stream(query, drop_pk=True):
from .utils import streams_maker

streams = dj.VirtualModule("streams", streams_maker.schema_name)
except:
pass
except Exception as e:
logger.debug(f"Could not import streams module: {e}")
39 changes: 28 additions & 11 deletions aeon/dj_pipeline/acquisition.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
"""DataJoint schema for the acquisition pipeline."""

import datetime
import json
import pathlib
import re

import datajoint as dj
import numpy as np
import pandas as pd

from aeon.analysis import utils as analysis_utils
from aeon.dj_pipeline import get_schema_name, lab, subject
from aeon.dj_pipeline.utils import paths
from aeon.io import api as io_api
from aeon.io import reader as io_reader
from aeon.schema import schemas as aeon_schemas

logger = dj.logger
schema = dj.schema(get_schema_name("acquisition"))

logger = dj.logger


# ------------------- Some Constants --------------------------

_ref_device_mapping = {
Expand All @@ -35,7 +37,7 @@ class ExperimentType(dj.Lookup):
experiment_type: varchar(32)
"""

contents = zip(["foraging", "social"])
contents = zip(["foraging", "social"], strict=False)


@schema
Expand Down Expand Up @@ -63,7 +65,7 @@ class DevicesSchema(dj.Lookup):
devices_schema_name: varchar(32)
"""

contents = zip(aeon_schemas.__all__)
contents = zip(aeon_schemas.__all__, strict=False)


# ------------------- Data repository/directory ------------------------
Expand All @@ -75,7 +77,7 @@ class PipelineRepository(dj.Lookup):
repository_name: varchar(16)
"""

contents = zip(["ceph_aeon"])
contents = zip(["ceph_aeon"], strict=False)


@schema
Expand All @@ -84,7 +86,7 @@ class DirectoryType(dj.Lookup):
directory_type: varchar(16)
"""

contents = zip(["raw", "processed", "qc"])
contents = zip(["raw", "processed", "qc"], strict=False)


# ------------------- GENERAL INFORMATION ABOUT AN EXPERIMENT --------------------
Expand Down Expand Up @@ -136,6 +138,7 @@ class Note(dj.Part):

@classmethod
def get_data_directory(cls, experiment_key, directory_type="raw", as_posix=False):
"""Get the data directory for the specified ``experiment_key`` and ``directory_type``."""
try:
repo_name, dir_path = (
cls.Directory & experiment_key & {"directory_type": directory_type}
Expand All @@ -145,7 +148,8 @@ def get_data_directory(cls, experiment_key, directory_type="raw", as_posix=False

dir_path = pathlib.Path(dir_path)
if dir_path.exists():
assert dir_path.is_relative_to(paths.get_repository_path(repo_name))
if not dir_path.is_relative_to(paths.get_repository_path(repo_name)):
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(f"{dir_path} is not relative to the repository path.")
data_directory = dir_path
else:
data_directory = paths.get_repository_path(repo_name) / dir_path
Expand All @@ -155,6 +159,7 @@ def get_data_directory(cls, experiment_key, directory_type="raw", as_posix=False

@classmethod
def get_data_directories(cls, experiment_key, directory_types=None, as_posix=False):
"""Get the data directories for the specified ``experiment_key`` and ``directory_types``."""
if directory_types is None:
directory_types = (cls.Directory & experiment_key).fetch(
"directory_type", order_by="load_order"
Expand Down Expand Up @@ -223,7 +228,11 @@ def ingest_epochs(cls, experiment_name):
with cls.connection.transaction:
# insert new epoch
cls.insert1(
{**epoch_key, **directory, "epoch_dir": epoch_dir.relative_to(raw_data_dir).as_posix()}
{
**epoch_key,
**directory,
"epoch_dir": epoch_dir.relative_to(raw_data_dir).as_posix(),
}
)
epoch_list.append(epoch_key)

Expand Down Expand Up @@ -279,7 +288,7 @@ class Meta(dj.Part):
-> master
---
bonsai_workflow: varchar(36)
commit: varchar(64) # e.g. git commit hash of aeon_experiment used to generated this particular epoch
commit: varchar(64) # e.g., git commit hash of aeon_experiment used to generate this epoch
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
source='': varchar(16) # e.g. aeon_experiment or aeon_acquisition (or others)
metadata: longblob
metadata_file_path: varchar(255) # path of the file, relative to the experiment repository
Expand All @@ -300,6 +309,7 @@ class ActiveRegion(dj.Part):
"""

def make(self, key):
"""Ingest metadata into EpochConfig."""
from aeon.dj_pipeline.utils import streams_maker
from aeon.dj_pipeline.utils.load_metadata import (
extract_epoch_config,
Expand Down Expand Up @@ -369,6 +379,7 @@ class File(dj.Part):

@classmethod
def ingest_chunks(cls, experiment_name):
"""Ingest chunks for the specified ``experiment_name``."""
device_name = _ref_device_mapping.get(experiment_name, "CameraTop")

all_chunks, raw_data_dirs = _get_all_chunks(experiment_name, device_name)
Expand Down Expand Up @@ -516,6 +527,7 @@ class SubjectWeight(dj.Part):
"""

def make(self, key):
"""Ingest environment data into Environment table."""
chunk_start, chunk_end = (Chunk & key).fetch1("chunk_start", "chunk_end")

# Populate the part table
Expand Down Expand Up @@ -579,6 +591,7 @@ class Name(dj.Part):
"""

def make(self, key):
"""Ingest active configuration data into EnvironmentActiveConfiguration table."""
chunk_start, chunk_end = (Chunk & key).fetch1("chunk_start", "chunk_end")
data_dirs = Experiment.get_data_directories(key)
devices_schema = getattr(
Expand Down Expand Up @@ -608,10 +621,13 @@ def make(self, key):


def _get_all_chunks(experiment_name, device_name):
"""Get all chunks for the specified ``experiment_name`` and ``device_name``."""
directory_types = ["quality-control", "raw"]
raw_data_dirs = {
dir_type: Experiment.get_data_directory(
experiment_key={"experiment_name": experiment_name}, directory_type=dir_type, as_posix=False
experiment_key={"experiment_name": experiment_name},
directory_type=dir_type,
as_posix=False,
MilagrosMarin marked this conversation as resolved.
Show resolved Hide resolved
)
for dir_type in directory_types
}
Expand All @@ -629,6 +645,7 @@ def _get_all_chunks(experiment_name, device_name):


def _match_experiment_directory(experiment_name, path, directories):
"""Match the path to the experiment directory."""
for k, v in directories.items():
raw_data_dir = v
if pathlib.Path(raw_data_dir) in list(path.parents):
Expand Down
1 change: 1 addition & 0 deletions aeon/dj_pipeline/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Utilities for analyzing data."""
Loading
Loading