obi-notebook 0.2.dev0__tar.gz → 0.2.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/PKG-INFO +1 -1
  2. obi_notebook-0.2.dev2/example.ipynb +333 -0
  3. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook/get_entities.py +39 -5
  4. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook.egg-info/PKG-INFO +1 -1
  5. obi_notebook-0.2.dev0/example.ipynb +0 -147
  6. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/.github/workflows/sdist.yml +0 -0
  7. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/.github/workflows/tox.yml +0 -0
  8. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/.gitignore +0 -0
  9. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/CHANGELOG.rst +0 -0
  10. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/LICENSE.txt +0 -0
  11. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/README.md +0 -0
  12. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/demo.gif +0 -0
  13. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/pyproject.toml +0 -0
  14. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/setup.cfg +0 -0
  15. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook/__init__.py +0 -0
  16. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook/get_projects.py +0 -0
  17. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook.egg-info/SOURCES.txt +0 -0
  18. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook.egg-info/dependency_links.txt +0 -0
  19. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook.egg-info/requires.txt +0 -0
  20. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/src/obi_notebook.egg-info/top_level.txt +0 -0
  21. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/tox.ini +0 -0
  22. {obi_notebook-0.2.dev0 → obi_notebook-0.2.dev2}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: obi_notebook
3
- Version: 0.2.dev0
3
+ Version: 0.2.dev2
4
4
  Summary: convenience functions for OBI notebooks
5
5
  Author-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
6
6
  Maintainer-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
@@ -0,0 +1,333 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "7eb47475-67c6-499a-a2b4-19f8a64974d0",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import obi_auth\n",
11
+ "\n",
12
+ "from obi_notebook import get_entities, get_projects\n",
13
+ "\n",
14
+ "environment_str = \"staging\""
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "markdown",
19
+ "id": "4d984b92-cadd-4b07-9813-b2333272610f",
20
+ "metadata": {},
21
+ "source": [
22
+ "get authentication token for production"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 2,
28
+ "id": "323cb45c-91e3-451f-8a80-374e61433d31",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "token = obi_auth.get_token(environment=environment_str)"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "markdown",
37
+ "id": "b60e8643-3ad5-4619-a052-5bd8b64713fd",
38
+ "metadata": {},
39
+ "source": [
40
+ "a widget to select project to use"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": 3,
46
+ "id": "77c47560-1163-4466-83fc-43abc6e0801a",
47
+ "metadata": {},
48
+ "outputs": [
49
+ {
50
+ "data": {
51
+ "application/vnd.jupyter.widget-view+json": {
52
+ "model_id": "639a72897c7045f78bb7aea5afbec767",
53
+ "version_major": 2,
54
+ "version_minor": 0
55
+ },
56
+ "text/plain": [
57
+ "Dropdown(description='Select:', options=(('Proximal vs. distal inhibition', {'id': '32008ab5-76cf-47cd-b98b-a5…"
58
+ ]
59
+ },
60
+ "metadata": {},
61
+ "output_type": "display_data"
62
+ }
63
+ ],
64
+ "source": [
65
+ "project_context = get_projects.get_projects(token, env=\"staging\")"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 4,
71
+ "id": "d538dcac-1bdc-496b-8840-a7b32ea842ed",
72
+ "metadata": {},
73
+ "outputs": [
74
+ {
75
+ "data": {
76
+ "text/plain": [
77
+ "ProjectContext(project_id=UUID('32008ab5-76cf-47cd-b98b-a5013b30b533'), virtual_lab_id=UUID('1d8cccc0-f992-46aa-aac6-88e63c914314'), environment=<DeploymentEnvironment.staging: 'staging'>)"
78
+ ]
79
+ },
80
+ "execution_count": 4,
81
+ "metadata": {},
82
+ "output_type": "execute_result"
83
+ }
84
+ ],
85
+ "source": [
86
+ "project_context"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": 5,
92
+ "id": "93029f77-d71f-40f4-8c4d-9f23d2b650bc",
93
+ "metadata": {},
94
+ "outputs": [
95
+ {
96
+ "data": {
97
+ "application/vnd.jupyter.widget-view+json": {
98
+ "model_id": "e4b6463129a546d394d57efc46d07d7c",
99
+ "version_major": 2,
100
+ "version_minor": 0
101
+ },
102
+ "text/plain": [
103
+ "HBox(children=(Dropdown(description='Scale:', index=1, options=('pair', 'small', 'microcircuit', 'region', 'sy…"
104
+ ]
105
+ },
106
+ "metadata": {},
107
+ "output_type": "display_data"
108
+ },
109
+ {
110
+ "data": {
111
+ "application/vnd.jupyter.widget-view+json": {
112
+ "model_id": "9201fb70a891499cadada69780277194",
113
+ "version_major": 2,
114
+ "version_minor": 0
115
+ },
116
+ "text/plain": [
117
+ "Output()"
118
+ ]
119
+ },
120
+ "metadata": {},
121
+ "output_type": "display_data"
122
+ }
123
+ ],
124
+ "source": [
125
+ "circuit_ids = []\n",
126
+ "circuit_ids = get_entities.get_entities(\n",
127
+ " \"circuit\",\n",
128
+ " token,\n",
129
+ " circuit_ids,\n",
130
+ " return_entities=False,\n",
131
+ " multi_select=True,\n",
132
+ " show_pages=True,\n",
133
+ " project_context=project_context,\n",
134
+ " page_size=10,\n",
135
+ " default_scale=\"small\",\n",
136
+ " exclude_scales=[\"single\"],\n",
137
+ " add_columns=[\"subject.name\"],\n",
138
+ " env=environment_str,\n",
139
+ ")"
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "execution_count": 9,
145
+ "id": "da699ed4-39fd-4602-b54d-58a0b58c2539",
146
+ "metadata": {},
147
+ "outputs": [
148
+ {
149
+ "data": {
150
+ "text/plain": [
151
+ "['b86271b6-c56f-4c26-b502-05ef5bb514b6',\n",
152
+ " '3877500c-126d-410c-aa09-e44831464e80',\n",
153
+ " 'd66cea8b-5c9d-4bfb-bbfd-ca3d5fb5f12c']"
154
+ ]
155
+ },
156
+ "execution_count": 9,
157
+ "metadata": {},
158
+ "output_type": "execute_result"
159
+ }
160
+ ],
161
+ "source": [
162
+ "circuit_ids"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 6,
168
+ "id": "a5f5445d-a61a-4fbe-962f-51e701434771",
169
+ "metadata": {},
170
+ "outputs": [
171
+ {
172
+ "data": {
173
+ "application/vnd.jupyter.widget-view+json": {
174
+ "model_id": "5fb0a08d2ce94d58a039c47fdd2f217f",
175
+ "version_major": 2,
176
+ "version_minor": 0
177
+ },
178
+ "text/plain": [
179
+ "HBox(children=(Combobox(value='', description='M-Type:', ensure_option=True, options=('A_BC', 'A_BFP', 'ACB_CT…"
180
+ ]
181
+ },
182
+ "metadata": {},
183
+ "output_type": "display_data"
184
+ },
185
+ {
186
+ "data": {
187
+ "application/vnd.jupyter.widget-view+json": {
188
+ "model_id": "a0c7ca20d54946f2af3e181c3adb3d70",
189
+ "version_major": 2,
190
+ "version_minor": 0
191
+ },
192
+ "text/plain": [
193
+ "Output()"
194
+ ]
195
+ },
196
+ "metadata": {},
197
+ "output_type": "display_data"
198
+ }
199
+ ],
200
+ "source": [
201
+ "morph_ids = []\n",
202
+ "morph_ids = get_entities.get_entities(\n",
203
+ " \"cell-morphology\",\n",
204
+ " token,\n",
205
+ " morph_ids,\n",
206
+ " return_entities=False,\n",
207
+ " multi_select=True,\n",
208
+ " show_pages=True,\n",
209
+ " project_context=project_context,\n",
210
+ " page_size=100,\n",
211
+ " add_columns=[\"mtypes\"],\n",
212
+ " env=environment_str,\n",
213
+ ")"
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "execution_count": 7,
219
+ "id": "2c9d28c4",
220
+ "metadata": {},
221
+ "outputs": [
222
+ {
223
+ "data": {
224
+ "text/plain": [
225
+ "['50248fe3-83bd-4c88-917b-63bcf0e01385',\n",
226
+ " '1c8ce2b1-3da1-4953-9b1b-bee8656000c4',\n",
227
+ " '15d02969-1e40-40ba-9081-d475d05897fd']"
228
+ ]
229
+ },
230
+ "execution_count": 7,
231
+ "metadata": {},
232
+ "output_type": "execute_result"
233
+ }
234
+ ],
235
+ "source": [
236
+ "morph_ids"
237
+ ]
238
+ },
239
+ {
240
+ "cell_type": "code",
241
+ "execution_count": 10,
242
+ "id": "90757b52",
243
+ "metadata": {},
244
+ "outputs": [
245
+ {
246
+ "data": {
247
+ "application/vnd.jupyter.widget-view+json": {
248
+ "model_id": "c2a91b53873b4e1fa54c161a59830f6b",
249
+ "version_major": 2,
250
+ "version_minor": 0
251
+ },
252
+ "text/plain": [
253
+ "HBox(children=(Combobox(value='', description='EM-Dataset:', ensure_option=True, options=('Portion 65 of the I…"
254
+ ]
255
+ },
256
+ "metadata": {},
257
+ "output_type": "display_data"
258
+ },
259
+ {
260
+ "data": {
261
+ "application/vnd.jupyter.widget-view+json": {
262
+ "model_id": "a08fd579c61b4377a0dd01478a5951be",
263
+ "version_major": 2,
264
+ "version_minor": 0
265
+ },
266
+ "text/plain": [
267
+ "Output()"
268
+ ]
269
+ },
270
+ "metadata": {},
271
+ "output_type": "display_data"
272
+ }
273
+ ],
274
+ "source": [
275
+ "cell_mesh_ids = []\n",
276
+ "circuit_ids = get_entities.get_entities(\n",
277
+ " \"em-cell-mesh\",\n",
278
+ " token,\n",
279
+ " cell_mesh_ids,\n",
280
+ " return_entities=False,\n",
281
+ " multi_select=True,\n",
282
+ " show_pages=True,\n",
283
+ " project_context=project_context,\n",
284
+ " page_size=10,\n",
285
+ " env=environment_str,\n",
286
+ " add_columns=[\"dense_reconstruction_cell_id\", \"subject.name\"],\n",
287
+ ")"
288
+ ]
289
+ },
290
+ {
291
+ "cell_type": "code",
292
+ "execution_count": 11,
293
+ "id": "6964ebe2",
294
+ "metadata": {},
295
+ "outputs": [
296
+ {
297
+ "data": {
298
+ "text/plain": [
299
+ "['2205be1a-a6db-4523-9a7b-0af309996583']"
300
+ ]
301
+ },
302
+ "execution_count": 11,
303
+ "metadata": {},
304
+ "output_type": "execute_result"
305
+ }
306
+ ],
307
+ "source": [
308
+ "cell_mesh_ids"
309
+ ]
310
+ }
311
+ ],
312
+ "metadata": {
313
+ "kernelspec": {
314
+ "display_name": ".venv (3.13.1)",
315
+ "language": "python",
316
+ "name": "python3"
317
+ },
318
+ "language_info": {
319
+ "codemirror_mode": {
320
+ "name": "ipython",
321
+ "version": 3
322
+ },
323
+ "file_extension": ".py",
324
+ "mimetype": "text/x-python",
325
+ "name": "python",
326
+ "nbconvert_exporter": "python",
327
+ "pygments_lexer": "ipython3",
328
+ "version": "3.13.1"
329
+ }
330
+ },
331
+ "nbformat": 4,
332
+ "nbformat_minor": 5
333
+ }
@@ -10,7 +10,9 @@ from IPython.display import clear_output, display
10
10
 
11
11
  LST_MTYPES_ = None
12
12
  LST_SPECIES_ = None
13
+ LST_EMDATASETS_ = None
13
14
  STR_NO_MTYPE = "NONE"
15
+ ENTITY_CLASS_DICT = {"em-cell-mesh": "EMCellMesh"}
14
16
 
15
17
 
16
18
  def _estimate_column_widths(df, char_width=8, padding=2, max_size=250):
@@ -29,7 +31,10 @@ def _resolve_list_to_first_element(obj):
29
31
  return obj["pref_label"]
30
32
 
31
33
 
32
- _df_postprocess_funs = {"reconstruction-morphology": {"mtypes": _resolve_list_to_first_element}}
34
+ _df_postprocess_funs = {
35
+ "reconstruction-morphology": {"mtypes": _resolve_list_to_first_element},
36
+ "em-cell-mesh": {"dense_reconstruction_cell_id": str},
37
+ }
33
38
 
34
39
 
35
40
  def _list_of_existing_mtypes(entity_core_url, token):
@@ -62,6 +67,21 @@ def _list_of_existing_species(entity_core_url, token):
62
67
  return LST_SPECIES_
63
68
 
64
69
 
70
+ def _list_of_existing_em_dense_datasets(entity_core_url, token):
71
+ global LST_EMDATASETS_
72
+ if LST_EMDATASETS_ is None:
73
+ response = requests.get(
74
+ f"{entity_core_url}/em-dense-reconstruction-dataset",
75
+ headers={"authorization": f"Bearer {token}"},
76
+ params={"page_size": 1000},
77
+ timeout=30,
78
+ )
79
+ data = response.json()
80
+ df_species = pd.json_normalize(data["data"])
81
+ LST_EMDATASETS_ = list(df_species["name"])
82
+ return LST_EMDATASETS_
83
+
84
+
65
85
  def get_entities(
66
86
  entity_type,
67
87
  token,
@@ -108,7 +128,8 @@ def get_entities(
108
128
  description="Scale:",
109
129
  )
110
130
  filters_dict["scale"] = scale_filter
111
- elif entity_type == "reconstruction-morphology":
131
+ filters_dict["name__ilike"] = widgets.Text(description="Name:")
132
+ elif entity_type == "reconstruction-morphology" or entity_type == "cell-morphology":
112
133
  lst_mtypes = _list_of_existing_mtypes(entity_core_url, token) + [""]
113
134
  mtype_filter = widgets.Combobox(
114
135
  placeholder="Select M-Type",
@@ -120,8 +141,17 @@ def get_entities(
120
141
  lst_species = _list_of_existing_species(entity_core_url, token) + [""]
121
142
  species_filter = widgets.Dropdown(options=lst_species, value="", description="Species:")
122
143
  filters_dict["species__name"] = species_filter
123
-
124
- filters_dict["name__ilike"] = widgets.Text(description="Name:")
144
+ filters_dict["name__ilike"] = widgets.Text(description="Name:")
145
+ elif entity_type == "em-cell-mesh":
146
+ lst_em_datasets = _list_of_existing_em_dense_datasets(entity_core_url, token) + [""]
147
+ em_dataset_filter = widgets.Combobox(
148
+ placeholder="Select EM Dataset",
149
+ description="EM-Dataset:",
150
+ options=lst_em_datasets,
151
+ ensure_option=True,
152
+ )
153
+ filters_dict["em_dense_reconstruction_dataset__name__ilike"] = em_dataset_filter
154
+ filters_dict["dense_reconstruction_cell_id"] = widgets.Text(description="Cell ID:")
125
155
 
126
156
  if show_pages:
127
157
  filters_dict["page"] = widgets.Dropdown(
@@ -252,7 +282,11 @@ def get_entities(
252
282
  token_manager=token,
253
283
  )
254
284
 
255
- model_class = getattr(models, entity_type.capitalize())
285
+ entity_class_default = "".join(
286
+ [_token.capitalize() for _token in entity_type.split("-")]
287
+ )
288
+ entity_class_name = ENTITY_CLASS_DICT.get(entity_type, entity_class_default)
289
+ model_class = getattr(models, entity_class_name)
256
290
  retrieved_entities = client.search_entity(
257
291
  entity_type=model_class, query={"id__in": list(l_ids)}
258
292
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: obi_notebook
3
- Version: 0.2.dev0
3
+ Version: 0.2.dev2
4
4
  Summary: convenience functions for OBI notebooks
5
5
  Author-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
6
6
  Maintainer-email: Open Brain Institute <jean-denis.courcol@epfl.ch>
@@ -1,147 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "7eb47475-67c6-499a-a2b4-19f8a64974d0",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import obi_auth\n",
11
- "\n",
12
- "from obi_notebook import get_entities, get_projects"
13
- ]
14
- },
15
- {
16
- "cell_type": "markdown",
17
- "id": "4d984b92-cadd-4b07-9813-b2333272610f",
18
- "metadata": {},
19
- "source": [
20
- "get authentication token for production"
21
- ]
22
- },
23
- {
24
- "cell_type": "code",
25
- "execution_count": null,
26
- "id": "323cb45c-91e3-451f-8a80-374e61433d31",
27
- "metadata": {},
28
- "outputs": [],
29
- "source": [
30
- "token = obi_auth.get_token(environment=\"production\")"
31
- ]
32
- },
33
- {
34
- "cell_type": "markdown",
35
- "id": "b60e8643-3ad5-4619-a052-5bd8b64713fd",
36
- "metadata": {},
37
- "source": [
38
- "a widget to select project to use"
39
- ]
40
- },
41
- {
42
- "cell_type": "code",
43
- "execution_count": null,
44
- "id": "77c47560-1163-4466-83fc-43abc6e0801a",
45
- "metadata": {},
46
- "outputs": [],
47
- "source": [
48
- "project_context = get_projects.get_projects(token)"
49
- ]
50
- },
51
- {
52
- "cell_type": "code",
53
- "execution_count": null,
54
- "id": "d538dcac-1bdc-496b-8840-a7b32ea842ed",
55
- "metadata": {},
56
- "outputs": [],
57
- "source": [
58
- "project_context"
59
- ]
60
- },
61
- {
62
- "cell_type": "code",
63
- "execution_count": null,
64
- "id": "93029f77-d71f-40f4-8c4d-9f23d2b650bc",
65
- "metadata": {},
66
- "outputs": [],
67
- "source": [
68
- "circuit_ids = []\n",
69
- "circuit_ids = get_entities.get_entities(\n",
70
- " \"circuit\",\n",
71
- " token,\n",
72
- " circuit_ids,\n",
73
- " return_entities=False,\n",
74
- " multi_select=True,\n",
75
- " show_pages=True,\n",
76
- " project_context=project_context,\n",
77
- " page_size=10,\n",
78
- " default_scale=\"small\",\n",
79
- " exclude_scales=[\"single\"],\n",
80
- " add_columns=[\"subject.name\"],\n",
81
- ")"
82
- ]
83
- },
84
- {
85
- "cell_type": "code",
86
- "execution_count": null,
87
- "id": "da699ed4-39fd-4602-b54d-58a0b58c2539",
88
- "metadata": {},
89
- "outputs": [],
90
- "source": [
91
- "circuit_ids"
92
- ]
93
- },
94
- {
95
- "cell_type": "code",
96
- "execution_count": null,
97
- "id": "a5f5445d-a61a-4fbe-962f-51e701434771",
98
- "metadata": {},
99
- "outputs": [],
100
- "source": [
101
- "morph_ids = []\n",
102
- "morph_ids = get_entities.get_entities(\n",
103
- " \"reconstruction-morphology\",\n",
104
- " token,\n",
105
- " morph_ids,\n",
106
- " return_entities=False,\n",
107
- " multi_select=True,\n",
108
- " show_pages=True,\n",
109
- " project_context=project_context,\n",
110
- " page_size=100,\n",
111
- " add_columns=[\"mtypes\"],\n",
112
- ")"
113
- ]
114
- },
115
- {
116
- "cell_type": "code",
117
- "execution_count": null,
118
- "id": "ab24b139",
119
- "metadata": {},
120
- "outputs": [],
121
- "source": [
122
- "morph_ids"
123
- ]
124
- }
125
- ],
126
- "metadata": {
127
- "kernelspec": {
128
- "display_name": ".venv (3.13.1)",
129
- "language": "python",
130
- "name": "python3"
131
- },
132
- "language_info": {
133
- "codemirror_mode": {
134
- "name": "ipython",
135
- "version": 3
136
- },
137
- "file_extension": ".py",
138
- "mimetype": "text/x-python",
139
- "name": "python",
140
- "nbconvert_exporter": "python",
141
- "pygments_lexer": "ipython3",
142
- "version": "3.13.1"
143
- }
144
- },
145
- "nbformat": 4,
146
- "nbformat_minor": 5
147
- }
File without changes
File without changes