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 all 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ dj_local_conf.json
log*.txt
scratch/
scratch*.py
**/*.nfs*
**/*.nfs*

# Test
.coverage
1 change: 0 additions & 1 deletion aeon/README.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
#
6 changes: 5 additions & 1 deletion 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 All @@ -10,4 +12,6 @@
del version, PackageNotFoundError

# Set functions available directly under the 'aeon' top-level namespace
from aeon.io.api import load as load # noqa: PLC0414
from aeon.io.api import load

__all__ = ["load"]
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."""
38 changes: 23 additions & 15 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
cur_lightness = (lightness * val) + (
min_lightness * (1 - val)
) # get cur lightness relative to `hex_col`
cur_lightness = max(min(cur_lightness, lightness), min_lightness) # set min, max bounds
cur_rgb_col = hls_to_rgb(hue, cur_lightness, saturation) # convert to rgb
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,23 @@ 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:
- 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
"""Generates a dictionary of patch styles given a list of patch_names.

The dictionary contains dictionaries which map patch names to their respective styles.
Below are the keys for each nested dictionary and their contents:

- colors: patch name to color
- markers: patch name to marker
- symbols: patch name to symbol
- linestyles: patch name to linestyle
"""
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)),
}
30 changes: 14 additions & 16 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 All @@ -13,9 +15,8 @@ def gridframes(frames, width, height, shape: None | int | tuple[int, int] = None
:param list frames: A list of frames to include in the grid layout.
:param int width: The width of the output grid image, in pixels.
:param int height: The height of the output grid image, in pixels.
:param optional shape:
Either the number of frames to include, or the number of rows and columns
in the output grid image layout.
:param optional shape: Either the number of frames to include,
or the number of rows and columns in the output grid image layout.
:return: A new image containing the arrangement of the frames in a grid.
"""
if shape is None:
Expand Down Expand Up @@ -67,13 +68,12 @@ def groupframes(frames, n, fun):
def triggerclip(data, events, before=None, after=None):
"""Split video data around the specified sequence of event timestamps.

:param DataFrame data:
A pandas DataFrame where each row specifies video acquisition path and frame number.
:param DataFrame data: A pandas DataFrame where each row specifies
video acquisition path and frame number.
:param iterable events: A sequence of timestamps to extract.
:param Timedelta before: The left offset from each timestamp used to clip the data.
:param Timedelta after: The right offset from each timestamp used to clip the data.
:return:
A pandas DataFrame containing the frames, clip and sequence numbers for each event timestamp.
:return: A pandas DataFrame containing the frames, clip and sequence numbers for each event timestamp.
"""
if before is None:
before = pd.Timedelta(0)
Expand All @@ -100,9 +100,8 @@ def triggerclip(data, events, before=None, after=None):
def collatemovie(clipdata, fun):
"""Collates a set of video clips into a single movie using the specified aggregation function.

:param DataFrame clipdata:
A pandas DataFrame where each row specifies video path, frame number, clip and sequence number.
This DataFrame can be obtained from the output of the triggerclip function.
:param DataFrame clipdata: A pandas DataFrame where each row specifies video path, frame number,
clip and sequence number. This DataFrame can be obtained from the output of the triggerclip function.
:param callable fun: The aggregation function used to process the frames in each clip.
:return: The sequence of processed frames representing the collated movie.
"""
Expand All @@ -114,14 +113,13 @@ def collatemovie(clipdata, fun):
def gridmovie(clipdata, width, height, shape=None):
"""Collates a set of video clips into a grid movie with the specified pixel dimensions and grid layout.

:param DataFrame clipdata:
A pandas DataFrame where each row specifies video path, frame number, clip and sequence number.
This DataFrame can be obtained from the output of the triggerclip function.
:param DataFrame clipdata: A pandas DataFrame where each row specifies video path, frame number,
clip and sequence number.
This DataFrame can be obtained from the output of the triggerclip function.
:param int width: The width of the output grid movie, in pixels.
:param int height: The height of the output grid movie, in pixels.
:param optional shape:
Either the number of frames to include, or the number of rows and columns
in the output grid movie layout.
:param optional shape: Either the number of frames to include,
or the number of rows and columns in the output grid movie layout.
:return: The sequence of processed frames representing the collated grid movie.
"""
return collatemovie(clipdata, lambda g: gridframes(g, width, height, shape))
10 changes: 6 additions & 4 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 Expand Up @@ -71,7 +73,7 @@ def rateplot(
:param datetime, optional end: The right bound of the time range for the continuous rate.
:param datetime, optional smooth: The size of the smoothing kernel applied to the rate output.
:param DateOffset, Timedelta or str, optional smooth:
The size of the smoothing kernel applied to the continuous rate output.
The size of the smoothing kernel applied to the continuous rate output.
:param bool, optional center: Specifies whether to center the convolution kernels.
:param Axes, optional ax: The Axes on which to draw the rate plot and raster.
"""
Expand Down Expand Up @@ -117,11 +119,11 @@ def colorline(

:param array-like x, y: The horizontal / vertical coordinates of the data points.
:param array-like, optional z:
The dynamic variable used to color each data point by indexing the color map.
The dynamic variable used to color each data point by indexing the color map.
:param str or ~matplotlib.colors.Colormap, optional cmap:
The colormap used to map normalized data values to RGBA colors.
The colormap used to map normalized data values to RGBA colors.
:param matplotlib.colors.Normalize, optional norm:
The normalizing object used to scale data to the range [0, 1] for indexing the color map.
The normalizing object used to scale data to the range [0, 1] for indexing the color map.
:param Axes, optional ax: The Axes on which to draw the colored line.
"""
if ax is None:
Expand Down
18 changes: 15 additions & 3 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 @@ -60,7 +62,6 @@ def visits(data, onset="Enter", offset="Exit"):
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

# rename columns and sort data
data.rename({time_onset: lonset, id_onset: "id", time_offset: loffset}, axis=1, inplace=True)
data = data[["id"] + [name for name in data.columns if "_" in name] + [lonset, loffset, "duration"]]
Expand All @@ -83,7 +84,7 @@ def rate(events, window, frequency, weight=1, start=None, end=None, smooth=None,
:param datetime, optional end: The right bound of the time range for the continuous rate.
:param datetime, optional smooth: The size of the smoothing kernel applied to the rate output.
:param DateOffset, Timedelta or str, optional smooth:
The size of the smoothing kernel applied to the continuous rate output.
The size of the smoothing kernel applied to the continuous rate output.
:param bool, optional center: Specifies whether to center the convolution kernels.
:return: A Series containing the continuous event rate over time.
"""
Expand All @@ -101,7 +102,18 @@ 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
):
"""Computes the event rate from a sequence of events over a specified window."""
"""Computes the event rate from a sequence of events over a specified window.

:param Series events: The discrete sequence of events, with timestamps in seconds as index.
:param int window_len_sec: The length of the window over which the event rate is estimated.
:param DateOffset, Timedelta or str frequency: The sampling frequency for the continuous rate.
:param int, optional unit_len_sec: The length of one sample point. Default is 60 seconds.
:param datetime, optional start: The left bound of the time range for the continuous rate.
:param datetime, optional end: The right bound of the time range for the continuous rate.
:param int, optional smooth: The size of the smoothing kernel applied to the continuous rate output.
:param bool, optional center: Specifies whether to center the convolution kernels.
:return: A Series containing the continuous event rate over time.
"""
# events is an array with the time (in seconds) of event occurence
# window_len_sec is the size of the window over which the event rate is estimated
# unit_len_sec is the length of one sample point
Expand Down
28 changes: 24 additions & 4 deletions aeon/dj_pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""DataJoint pipeline for Aeon."""

import hashlib
import logging
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 All @@ -30,11 +35,17 @@ def dict_to_uuid(key) -> uuid.UUID:
return uuid.UUID(hex=hashed.hexdigest())


def fetch_stream(query, drop_pk=True):
def fetch_stream(query, drop_pk=True, round_microseconds=True):
"""Fetches data from a Stream table based on a query and returns it as a DataFrame.

Provided a query containing data from a Stream table,
fetch and aggregate the data into one DataFrame indexed by "time"

Args:
query (datajoint.Query): A query object containing data from a Stream table
drop_pk (bool, optional): Drop primary key columns. Defaults to True.
round_microseconds (bool, optional): Round timestamps to microseconds. Defaults to True.
(this is important as timestamps in mysql is only accurate to microseconds)
"""
df = (query & "sample_count > 0").fetch(format="frame").reset_index()
cols2explode = [
Expand All @@ -46,7 +57,16 @@ 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
)
if not df.empty and round_microseconds:
logging.warning("Rounding timestamps to microseconds is now enabled by default."
" To disable, set round_microseconds=False.")
df.index = df.index.round("us")
return df


Expand All @@ -57,5 +77,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}")
Loading