Skip to content

Commit 905dd84

Browse files
committed
Versioning and some cleaning
1 parent e94fd33 commit 905dd84

File tree

10 files changed

+131
-156
lines changed

10 files changed

+131
-156
lines changed

docs/notebooks/naps_graphics.ipynb

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,13 @@
465465
"metadata": {},
466466
"outputs": [],
467467
"source": [
468-
"dset = sleap.load_file(\"example_1h.slp\")\n",
469-
"track_occupancy = list(dset.get_track_occupancy(dset.video).values())\n",
470-
"track_start_end = [[rangelist.start, rangelist.end] for rangelist in track_occupancy]\n",
471-
"track_length = [rangelist.end- rangelist.start for rangelist in track_occupancy]\n",
468+
"# dset = sleap.load_file(\"example_1h.slp\")\n",
469+
"# track_occupancy = list(dset.get_track_occupancy(dset.video).values())\n",
470+
"# track_start_end = [[rangelist.start, rangelist.end] for rangelist in track_occupancy]\n",
471+
"# track_length = [rangelist.end- rangelist.start for rangelist in track_occupancy]\n",
472472
"\n",
473-
"frame_rate = 20\n",
474-
"data=[ l/frame_rate for l in track_length],\n"
473+
"# frame_rate = 20\n",
474+
"# data=[ l/frame_rate for l in track_length],\n"
475475
]
476476
},
477477
{
@@ -482,10 +482,10 @@
482482
"source": [
483483
"from turtle import title\n",
484484
"import h5py\n",
485-
"with h5py.File('example_1h.analysis.h5', 'r') as f:\n",
485+
"with h5py.File('example_sleap_output.analysis.h5', 'r') as f:\n",
486486
" occupancy_matrix_slp = f['track_occupancy'][:]\n",
487487
" \n",
488-
"with h5py.File('/Genomics/ayroleslab2/scott/bees/naps_data/example_1h_1130to1230pm_naps.analysis.h5', 'r') as f:\n",
488+
"with h5py.File('example_naps_output.analysis.h5', 'r') as f:\n",
489489
" occupancy_matrix_naps = f['track_occupancy'][:]\n",
490490
" \n",
491491
"missing_freq_slp = np.sum(occupancy_matrix_slp.T == 1,axis=1) / occupancy_matrix_slp.shape[0]\n",
@@ -498,7 +498,7 @@
498498
"metadata": {},
499499
"outputs": [],
500500
"source": [
501-
"aruco_only = np.load(\"output_aruco_1h.npy\")\n",
501+
"aruco_only = np.load(\"example_aruco_output.npy\")\n",
502502
"aruco_only = aruco_only[0:72000,0,0,:]\n",
503503
"occupancy_matrix_aruco = ~np.isnan(aruco_only)\n",
504504
"missing_freq_aruco = np.sum(occupancy_matrix_aruco.T == 1,axis=1) / occupancy_matrix_aruco.shape[0]\n",
@@ -570,26 +570,31 @@
570570
"mpl.rcParams[\"font.family\"] = \"sans-serif\"\n",
571571
"mpl.rcParams[\"font.sans-serif\"] = [\"Arial\", \"DejaVu Sans\"]\n",
572572
"mpl.rcParams[\"axes.titlesize\"] = \"x-large\" # medium, large, x-large, xx-large\n",
573-
"\n",
573+
"import palettable\n",
574574
"mpl.style.use(\"seaborn-deep\")\n",
575575
"# palette = sns.color_palette(cc.glasbey, n_colors=arr.shape[3])\n",
576576
"fig, ax = plt.subplots(1, 1, figsize=(6, 6))\n",
577577
"# fig.suptitle(\"Missingness frequency of tracklets\")\n",
578578
"sns.set_style(\"ticks\")\n",
579579
"import itertools\n",
580+
"from matplotlib.colors import to_rgba\n",
580581
"def patch_violinplot():\n",
581582
" from matplotlib.collections import PolyCollection\n",
582583
" ax = plt.gca()\n",
584+
" i = 0\n",
583585
" for art in ax.get_children():\n",
584-
" if isinstance(art, PolyCollection):\n",
585-
" art.set_edgecolor('#424952')\n",
586-
" art.set_linewidth(1)\n",
587-
" art.set_alpha(0.5)\n",
586+
" if isinstance(art, PolyCollection):\n",
587+
" art.set_edgecolor(palettable.wesanderson.Moonrise7_5.mpl_colors[i])\n",
588+
" i=i+1\n",
589+
" # art.set_linewidth(1)\n",
590+
" # art.set_alpha(0.1)\n",
591+
"# for violin, alpha in zip(ax.collections[::2], [0.2]):\n",
592+
"# violin.set_facecolor(to_rgba(violin.get_facecolor(), alpha=alpha))\n",
588593
" \n",
589-
"list_of_missing_freqs = [missing_freq_aruco, missing_freq_slp, missing_freq_naps]\n",
594+
"list_of_missing_freqs = [missing_freq_slp, missing_freq_aruco, missing_freq_naps]\n",
590595
"data = pd.DataFrame(\n",
591596
" (_ for _ in itertools.zip_longest(*list_of_missing_freqs)),\n",
592-
" columns=[\"ArUco\", \"SLEAP\", \"NAPS\"],\n",
597+
" columns=[\"SLEAP\", \"ArUco\", \"NAPS\"],\n",
593598
")\n",
594599
"sns.violinplot(\n",
595600
" ax=ax,\n",
@@ -598,18 +603,36 @@
598603
" inner=\"quartile\",\n",
599604
" bw=0.15,\n",
600605
" palette=palettable.wesanderson.Moonrise7_5.mpl_colors,\n",
601-
" linewidth=1.5,\n",
602-
" \n",
606+
" linewidth=1.5, \n",
607+
" # alpha=0.8\n",
603608
")\n",
609+
"for violin, alpha in zip(ax.collections, [0.2,0.2,0.2]):\n",
610+
" violin.set_facecolor(to_rgba(violin.get_facecolor(), alpha=alpha))\n",
611+
"\n",
612+
"for l in ax.lines[0::3]:\n",
613+
" l.set_linewidth(0)\n",
614+
"for l in ax.lines[2::3]:\n",
615+
" l.set_linewidth(0)\n",
616+
" \n",
617+
"# for c in data:\n",
618+
"# sns.pointplot(c,np.nanmean(data[c]))\n",
619+
"\n",
604620
"patch_violinplot()\n",
605621
"plt.ylim(0, 100)\n",
606622
"sns.despine(offset=10, trim=False)\n",
607623
"plt.ylabel(\"Track Occupancy (%)\")\n",
608624
"plt.title(\"Track Occupancy Distribution by Source\", fontsize=16, y=1.025)\n",
609625
"plt.tight_layout()\n",
610-
"plt.savefig(\"figures/track_length_violin.jpeg\", dpi=600)\n",
626+
"plt.savefig(\"figures/track_length_violin.jpg\", dpi=600)\n",
611627
"# plt.legend(labels=[\"SLEAP\", \"NAPS\", \"ArUco\"], title = \"Source of Tracks\", loc=\"upper center\")\n"
612628
]
629+
},
630+
{
631+
"cell_type": "code",
632+
"execution_count": null,
633+
"metadata": {},
634+
"outputs": [],
635+
"source": []
613636
}
614637
],
615638
"metadata": {

docs/notebooks/sorted_length_dist.ipynb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@
143143
"\n",
144144
"plt.savefig(\"figures/sorted_length_distribution.jpg\", dpi=600)"
145145
]
146-
},
147-
{
148-
"cell_type": "code",
149-
"execution_count": null,
150-
"metadata": {},
151-
"outputs": [],
152-
"source": []
153146
}
154147
],
155148
"metadata": {

docs/notebooks/t50_plot.ipynb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,15 @@
133133
"ax[2].set_title(\"NAPS\")\n",
134134
"ax[2].axvline(x=t50_naps, ymin=0,ymax=occupancy_cumsum_naps[t50_naps-1],color=\"black\",linewidth=2,linestyle=\"--\")\n",
135135
"plt.setp(ax,ylim=(0,1))\n",
136+
"plt.setp(ax,xlim=(200,257))\n",
136137
"\n",
137138
"# plt.xlim(0, 16)\n",
138139
"sns.despine(offset=3, trim=False)\n",
139140
"# plt.legend(labels=[\"ArUco\", \"SLEAP\", \"NAPS\"], title = \"Source of Tracks\")\n",
140141
"fig.tight_layout(rect=[0.05, 0.05, 1, 1])\n",
141142
"\n",
142-
"plt.savefig(\"figures/t50_distribution.jpg\", dpi=600)"
143+
"plt.savefig(\"figures/t50_distribution_200through257.jpg\", dpi=600)"
143144
]
144-
},
145-
{
146-
"cell_type": "code",
147-
"execution_count": null,
148-
"metadata": {},
149-
"outputs": [],
150-
"source": []
151145
}
152146
],
153147
"metadata": {

naps/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Basic Information
22
__name__ = "naps-track"
3-
__version__ = "0.1.15"
3+
__version__ = "1.0.0"
44
__summary__ = "NAPS (NAPS is ArUco Plus SLEAP)"
55
__url__ = "https://github.com/kocherlab/naps"
66
__code__ = "https://github.com/kocherlab/naps"
@@ -10,7 +10,7 @@
1010
__copyright__ = "2022"
1111

1212
# Author Information
13-
__authors__ = "Scott Wolf, Dee Ruttenberg, Daniel Knapp, Andrew Webb, Ian Traniello Grace McKenzie-Smith, Joshua Shaevitz and Sarah Kocher"
13+
__authors__ = "Scott Wolf, Dee Ruttenberg, Daniel Knapp, Andrew Webb, Ian Traniello, Grace McKenzie-Smith, Joshua Shaevitz, and Sarah Kocher"
1414
1515

1616
import logging

naps/matching.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env python
2-
import os
3-
import cv2
42
import math
5-
6-
import numpy as np
7-
3+
import os
84
from collections import defaultdict
95
from typing import Iterable, Tuple
6+
7+
import cv2
8+
import numpy as np
109
from ray.util.multiprocessing import Pool
1110

1211
from naps.aruco import ArUcoModel
@@ -25,11 +24,12 @@ def __init__(
2524
tag_node_matrix: np.ndarray,
2625
threads: int,
2726
min_sleap_score: float = 0.1,
28-
**kwargs
29-
):
27+
**kwargs,
28+
):
3029

3130
# Confirm the video file exists
32-
if not os.path.isfile(video_filename): raise Exception (f'{video_filename} does not exist')
31+
if not os.path.isfile(video_filename):
32+
raise Exception(f"{video_filename} does not exist")
3333

3434
# Video arguments
3535
self.video_filename = video_filename

tests/test_aruco.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_ArUcoModel_tag_sets(tag_set):
4848
except Exception as exc:
4949
assert False, f"Tag set {tag_set} raised an exception {exc}"
5050

51+
5152
def test_ArUcoModel_tag_set_dict_error():
5253

5354
param_dict = {
@@ -63,6 +64,7 @@ def test_ArUcoModel_tag_set_dict_error():
6364
test_model = ArUcoModel.withTagSet("DICT_4X4_FAIL", **param_dict)
6465
test_model.buildModel()
6566

67+
6668
def test_ArUcoModel_no_tag_set_error():
6769

6870
param_dict = {
@@ -77,6 +79,7 @@ def test_ArUcoModel_no_tag_set_error():
7779
with pytest.raises(Exception) as e_info:
7880
test_model = ArUcoModel.withTagSet(**param_dict)
7981

82+
8083
@pytest.mark.parametrize(
8184
"param, value",
8285
[
@@ -106,14 +109,15 @@ def test_ArUcoModel_params_type_error(param, value):
106109
test_model = ArUcoModel.withTagSet("DICT_4X4_100", **param_dict)
107110
test_model.buildModel()
108111

112+
109113
@pytest.mark.parametrize(
110114
"coords, tag",
111115
[
112-
([100, 350,100, 350], 1),
113-
([100, 350,800,1050], 2),
114-
([450, 700,450, 700], 3),
115-
([800,1050,100, 350], 4),
116-
([800,1050,800,1050], 5),
116+
([100, 350, 100, 350], 1),
117+
([100, 350, 800, 1050], 2),
118+
([450, 700, 450, 700], 3),
119+
([800, 1050, 100, 350], 4),
120+
([800, 1050, 800, 1050], 5),
117121
],
118122
)
119123
def test_ArUcoModel_detect(coords, tag):
@@ -136,8 +140,10 @@ def test_ArUcoModel_detect(coords, tag):
136140

137141
# Open the aruco image
138142
aruco_image = cv2.imread("tests/data/example_ArUco_image.jpg", 0)
139-
tag_image = aruco_image[coords[0] - 100:coords[1] + 100, coords[2] - 100:coords[3] + 100]
143+
tag_image = aruco_image[
144+
coords[0] - 100 : coords[1] + 100, coords[2] - 100 : coords[3] + 100
145+
]
140146

141147
# Detect ArUco tags
142148
_, tags, _ = test_model.detect(tag_image)
143-
assert tags[0][0] == tag
149+
assert tags[0][0] == tag

tests/test_cost_matrix.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pandas as pd
2-
import pytest
32

43
from naps.cost_matrix import CostMatrix
54

@@ -13,7 +12,7 @@ def test_CostMatrix():
1312
2: {"a": [3], "b": [1, 2, 3], "c": [3]},
1413
3: {"a": [2], "b": [1, 2, 3], "c": []},
1514
4: {"a": [2], "b": [1, 2, 3], "c": []},
16-
5: {"a": [1, 2], "b": [2], "c": [1, 3]}
15+
5: {"a": [1, 2], "b": [2], "c": [1, 3]},
1716
}
1817

1918
# Create the cost matrix, the assign the track/tag pairs

0 commit comments

Comments
 (0)