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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"metadata": {},
|
6 |
+
"source": [
|
7 |
+
"# Ralstonia Annotation Tool"
|
8 |
+
]
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"cell_type": "markdown",
|
12 |
+
"metadata": {},
|
13 |
+
"source": [
|
14 |
+
"## Imports"
|
15 |
+
]
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"execution_count": null,
|
20 |
+
"metadata": {},
|
21 |
+
"outputs": [],
|
22 |
+
"source": [
|
23 |
+
"%load_ext autoreload\n",
|
24 |
+
"%autoreload 2"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": null,
|
30 |
+
"metadata": {},
|
31 |
+
"outputs": [],
|
32 |
+
"source": [
|
33 |
+
"from pathlib import Path\n",
|
34 |
+
"from io import StringIO\n",
|
35 |
+
"\n",
|
36 |
+
"import pandas as pd\n",
|
37 |
+
"import panel as pn\n",
|
38 |
+
"\n",
|
39 |
+
"import scripts.tap_const as tc"
|
40 |
+
]
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"cell_type": "markdown",
|
44 |
+
"metadata": {},
|
45 |
+
"source": [
|
46 |
+
"## Setup"
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": null,
|
52 |
+
"metadata": {},
|
53 |
+
"outputs": [],
|
54 |
+
"source": [
|
55 |
+
"pn.extension(\"plotly\", \"tabulator\")\n",
|
56 |
+
"\n",
|
57 |
+
"template = pn.template.BootstrapTemplate(title=\"Ralstonia Annotation Tool\")"
|
58 |
+
]
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"cell_type": "markdown",
|
62 |
+
"metadata": {},
|
63 |
+
"source": [
|
64 |
+
"## Constants"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"cell_type": "code",
|
69 |
+
"execution_count": null,
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"EXPERIMENT = \"72AC_PhD_2404\""
|
74 |
+
]
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"cell_type": "code",
|
78 |
+
"execution_count": null,
|
79 |
+
"metadata": {},
|
80 |
+
"outputs": [],
|
81 |
+
"source": [
|
82 |
+
"# Setup Paths\n",
|
83 |
+
"if tc.phenopsis.joinpath(EXPERIMENT).is_dir() is True:\n",
|
84 |
+
" pt_data = tc.data\n",
|
85 |
+
" pt_images = tc.phenopsis.joinpath(EXPERIMENT)\n",
|
86 |
+
" pt_rotations = tc.dataout.joinpath(\"rotation_angles\").joinpath(f\"{EXPERIMENT}\")\n",
|
87 |
+
"else:\n",
|
88 |
+
" here = Path(\".\").parent\n",
|
89 |
+
" pt_data = here.joinpath(\"data\")\n",
|
90 |
+
" pt_images = here.joinpath(\"images\").joinpath(EXPERIMENT)\n",
|
91 |
+
" pt_rotations = here.joinpath(\"rotation_angles\").joinpath(f\"{EXPERIMENT}\")\n"
|
92 |
+
]
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"cell_type": "markdown",
|
96 |
+
"metadata": {},
|
97 |
+
"source": [
|
98 |
+
"## Functions"
|
99 |
+
]
|
100 |
+
},
|
101 |
+
{
|
102 |
+
"cell_type": "code",
|
103 |
+
"execution_count": null,
|
104 |
+
"metadata": {},
|
105 |
+
"outputs": [],
|
106 |
+
"source": [
|
107 |
+
"def to_dataframe(value):\n",
|
108 |
+
" if not value or not isinstance(value, bytes):\n",
|
109 |
+
" return pd.DataFrame()\n",
|
110 |
+
"\n",
|
111 |
+
" string_io = StringIO(value.decode(\"utf8\"))\n",
|
112 |
+
" return pd.read_csv(string_io, sep=\";\")"
|
113 |
+
]
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"cell_type": "markdown",
|
117 |
+
"metadata": {},
|
118 |
+
"source": [
|
119 |
+
"## Source Selection"
|
120 |
+
]
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"cell_type": "markdown",
|
124 |
+
"metadata": {},
|
125 |
+
"source": [
|
126 |
+
"### Download Template"
|
127 |
+
]
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"cell_type": "code",
|
131 |
+
"execution_count": null,
|
132 |
+
"metadata": {},
|
133 |
+
"outputs": [],
|
134 |
+
"source": [
|
135 |
+
"template_download = pn.widgets.FileDownload(\n",
|
136 |
+
" file=pt_data.joinpath(f\"{EXPERIMENT}_raw.csv\"),\n",
|
137 |
+
" filename=f\"{EXPERIMENT}_raw.csv\",\n",
|
138 |
+
" button_type=\"success\",\n",
|
139 |
+
" label=\"Download template annotation file\",\n",
|
140 |
+
")\n",
|
141 |
+
"template_download"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"cell_type": "markdown",
|
146 |
+
"metadata": {},
|
147 |
+
"source": [
|
148 |
+
"### Upload existing file"
|
149 |
+
]
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"cell_type": "code",
|
153 |
+
"execution_count": null,
|
154 |
+
"metadata": {},
|
155 |
+
"outputs": [],
|
156 |
+
"source": [
|
157 |
+
"file_input = pn.widgets.FileInput(accept=\".csv,.json\")\n",
|
158 |
+
"table = pn.widgets.Tabulator(\n",
|
159 |
+
" pn.bind(to_dataframe, file_input),\n",
|
160 |
+
" pagination=\"local\",\n",
|
161 |
+
" page_size=20,\n",
|
162 |
+
" sizing_mode=\"stretch_width\",\n",
|
163 |
+
")\n",
|
164 |
+
"layout = pn.Column(file_input, table)\n",
|
165 |
+
"layout"
|
166 |
+
]
|
167 |
+
},
|
168 |
+
{
|
169 |
+
"cell_type": "markdown",
|
170 |
+
"metadata": {},
|
171 |
+
"source": [
|
172 |
+
"## Annotation Tools"
|
173 |
+
]
|
174 |
+
},
|
175 |
+
{
|
176 |
+
"cell_type": "code",
|
177 |
+
"execution_count": null,
|
178 |
+
"metadata": {},
|
179 |
+
"outputs": [],
|
180 |
+
"source": [
|
181 |
+
"sl_plant = pn.widgets.Select(name=\"Plant\", options=[])\n",
|
182 |
+
"@pn.depends(table.param.value, watch=True)\n",
|
183 |
+
"def on_file_loaded(file):\n",
|
184 |
+
" sl_plant.options = list(table.value.plant.unique())"
|
185 |
+
]
|
186 |
+
},
|
187 |
+
{
|
188 |
+
"cell_type": "markdown",
|
189 |
+
"metadata": {},
|
190 |
+
"source": [
|
191 |
+
"## Render"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
{
|
195 |
+
"cell_type": "code",
|
196 |
+
"execution_count": null,
|
197 |
+
"metadata": {},
|
198 |
+
"outputs": [],
|
199 |
+
"source": [
|
200 |
+
"template.sidebar.append(\n",
|
201 |
+
" pn.Card(pn.Column(template_download, file_input), title=\"File Manager\"),\n",
|
202 |
+
")\n",
|
203 |
+
"template.sidebar.append(sl_plant)\n",
|
204 |
+
"\n",
|
205 |
+
"template.main.append(table)\n",
|
206 |
+
"\n",
|
207 |
+
"template.servable()"
|
208 |
+
]
|
209 |
+
},
|
210 |
+
{
|
211 |
+
"cell_type": "code",
|
212 |
+
"execution_count": null,
|
213 |
+
"metadata": {},
|
214 |
+
"outputs": [],
|
215 |
+
"source": []
|
216 |
+
}
|
217 |
+
],
|
218 |
+
"metadata": {
|
219 |
+
"kernelspec": {
|
220 |
+
"display_name": "env",
|
221 |
+
"language": "python",
|
222 |
+
"name": "python3"
|
223 |
+
},
|
224 |
+
"language_info": {
|
225 |
+
"codemirror_mode": {
|
226 |
+
"name": "ipython",
|
227 |
+
"version": 3
|
228 |
+
},
|
229 |
+
"file_extension": ".py",
|
230 |
+
"mimetype": "text/x-python",
|
231 |
+
"name": "python",
|
232 |
+
"nbconvert_exporter": "python",
|
233 |
+
"pygments_lexer": "ipython3",
|
234 |
+
"version": "3.11.9"
|
235 |
+
}
|
236 |
+
},
|
237 |
+
"nbformat": 4,
|
238 |
+
"nbformat_minor": 2
|
239 |
+
}
|