Skip to content

Commit c36893a

Browse files
Update Cell Morphology model (#126)
* Update Cell Morphology model * Update notebooks and other fixes * Update server schema * Cleanup notebook output * Update CellMorphologyProtocol docstring * Allow to init CellMorphologyProtocol directly (#127) * Update server schema with entitycore 2025.9.7
1 parent 4e9a897 commit c36893a

39 files changed

+1689
-545
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ client = Client(
5151

5252
# Search for morphologies
5353
iterator = client.search_entity(
54-
entity_type=models.ReconstructionMorphology,
54+
entity_type=models.CellMorphology,
5555
query={"mtype__pref_label": "L5_TPC:A"},
5656
limit=1,
5757
)
@@ -60,7 +60,7 @@ morphology = next(iterator)
6060
# Upload an asset
6161
client.upload_file(
6262
entity_id=morphology.id,
63-
entity_type=models.ReconstructionMorphology,
63+
entity_type=models.CellMorphology,
6464
file_path="path/to/file.swc",
6565
file_content_type="application/swc",
6666
)

examples/01_searching.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
" MTypeClass,\n",
1818
" Organization,\n",
1919
" Person,\n",
20-
" ReconstructionMorphology,\n",
20+
" CellMorphology,\n",
2121
" Role,\n",
2222
" Species,\n",
2323
" Strain,\n",
@@ -228,7 +228,7 @@
228228
"metadata": {},
229229
"outputs": [],
230230
"source": [
231-
"morphs = client.search_entity(entity_type=ReconstructionMorphology, limit=10).all()"
231+
"morphs = client.search_entity(entity_type=CellMorphology, limit=10).all()"
232232
]
233233
},
234234
{
@@ -258,7 +258,7 @@
258258
"outputs": [],
259259
"source": [
260260
"morphs = client.search_entity(\n",
261-
" entity_type=ReconstructionMorphology, query={\"mtype__pref_label\": \"SR_PC\"}\n",
261+
" entity_type=CellMorphology, query={\"mtype__pref_label\": \"SR_PC\"}\n",
262262
").all()"
263263
]
264264
},

examples/02_morphology.ipynb

Lines changed: 118 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@
1919
"from entitysdk.models import (\n",
2020
" BrainLocation,\n",
2121
" BrainRegion,\n",
22+
" CellMorphology,\n",
23+
" CellMorphologyProtocol,\n",
2224
" Contribution,\n",
2325
" MTypeClass,\n",
2426
" MTypeClassification,\n",
2527
" Organization,\n",
26-
" ReconstructionMorphology,\n",
2728
" Role,\n",
2829
" Species,\n",
2930
" Strain,\n",
31+
" Subject,\n",
32+
")\n",
33+
"from entitysdk.types import (\n",
34+
" CellMorphologyGenerationType,\n",
35+
" CellMorphologyProtocolDesign,\n",
36+
" SlicingDirectionType,\n",
3037
")"
3138
]
3239
},
@@ -130,6 +137,95 @@
130137
"rprint(brain_region)"
131138
]
132139
},
140+
{
141+
"cell_type": "markdown",
142+
"id": "65bea11e",
143+
"metadata": {},
144+
"source": [
145+
"### Create and register a new subject"
146+
]
147+
},
148+
{
149+
"cell_type": "markdown",
150+
"id": "40772ff8",
151+
"metadata": {},
152+
"source": [
153+
"Subjects should be reused if possible, but they can be created when needed."
154+
]
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": null,
159+
"id": "c78f0e4d",
160+
"metadata": {},
161+
"outputs": [],
162+
"source": [
163+
"subject = Subject(\n",
164+
" name=\"my-subject-for-morphology\",\n",
165+
" description=\"my-subject-description\",\n",
166+
" sex=\"male\",\n",
167+
" species=species,\n",
168+
" strain=strain,\n",
169+
")\n",
170+
"\n",
171+
"subject = client.register_entity(subject)\n",
172+
"rprint(subject)"
173+
]
174+
},
175+
{
176+
"cell_type": "markdown",
177+
"id": "62e916c9",
178+
"metadata": {},
179+
"source": [
180+
"### Create and register a new morphology protocol"
181+
]
182+
},
183+
{
184+
"cell_type": "markdown",
185+
"id": "1b2dacaf",
186+
"metadata": {},
187+
"source": [
188+
"Morphology protocols should be reused if possible, but they can be created when needed."
189+
]
190+
},
191+
{
192+
"cell_type": "code",
193+
"execution_count": null,
194+
"id": "5200e8cf",
195+
"metadata": {},
196+
"outputs": [],
197+
"source": [
198+
"morphology_protocol = CellMorphologyProtocol(\n",
199+
" generation_type=CellMorphologyGenerationType.digital_reconstruction,\n",
200+
" protocol_document=\"https://example.com/\",\n",
201+
" protocol_design=CellMorphologyProtocolDesign.cell_patch,\n",
202+
" slicing_thickness=20.0,\n",
203+
" slicing_direction=SlicingDirectionType.horizontal,\n",
204+
")\n",
205+
"rprint(morphology_protocol.__class__.__name__)\n",
206+
"morphology_protocol = client.register_entity(morphology_protocol)\n",
207+
"rprint(morphology_protocol)"
208+
]
209+
},
210+
{
211+
"cell_type": "markdown",
212+
"id": "ff0d1d01",
213+
"metadata": {},
214+
"source": [
215+
"### Optional, list morphology protocols"
216+
]
217+
},
218+
{
219+
"cell_type": "code",
220+
"execution_count": null,
221+
"id": "71818153",
222+
"metadata": {},
223+
"outputs": [],
224+
"source": [
225+
"protocols = client.search_entity(entity_type=CellMorphologyProtocol).all()\n",
226+
"rprint(protocols)"
227+
]
228+
},
133229
{
134230
"cell_type": "markdown",
135231
"id": "a0193055-3448-4d1c-99cc-4d953727ef4e",
@@ -150,15 +246,15 @@
150246
" y=1173.8499755859375,\n",
151247
" z=4744.60009765625,\n",
152248
")\n",
153-
"morphology = ReconstructionMorphology(\n",
249+
"morphology = CellMorphology(\n",
250+
" cell_morphology_protocol=morphology_protocol,\n",
154251
" name=\"my-morph\",\n",
155252
" description=\"A morphology\",\n",
156-
" species=species,\n",
157-
" strain=strain,\n",
253+
" subject=subject,\n",
158254
" brain_region=brain_region,\n",
159255
" location=brain_location,\n",
160256
" legacy_id=None,\n",
161-
" authorized_public=True,\n",
257+
" authorized_public=False,\n",
162258
")"
163259
]
164260
},
@@ -190,6 +286,16 @@
190286
"registered = client.register_entity(entity=morphology)"
191287
]
192288
},
289+
{
290+
"cell_type": "code",
291+
"execution_count": null,
292+
"id": "6b029401",
293+
"metadata": {},
294+
"outputs": [],
295+
"source": [
296+
"rprint(registered)"
297+
]
298+
},
193299
{
194300
"cell_type": "markdown",
195301
"id": "5a4482d8-d5d4-45b9-80cb-264c1a531216",
@@ -274,7 +380,7 @@
274380
" # use a filepath to register first asset\n",
275381
" asset1 = client.upload_file(\n",
276382
" entity_id=registered.id,\n",
277-
" entity_type=ReconstructionMorphology,\n",
383+
" entity_type=CellMorphology,\n",
278384
" file_path=file1,\n",
279385
" file_content_type=\"application/x-hdf5\",\n",
280386
" asset_label=\"morphology\",\n",
@@ -286,7 +392,7 @@
286392
"\n",
287393
" asset2 = client.upload_content(\n",
288394
" entity_id=registered.id,\n",
289-
" entity_type=ReconstructionMorphology,\n",
395+
" entity_type=CellMorphology,\n",
290396
" file_content=buffer,\n",
291397
" file_name=\"buffer.swc\",\n",
292398
" file_content_type=\"application/swc\",\n",
@@ -311,7 +417,7 @@
311417
"outputs": [],
312418
"source": [
313419
"# with assets and mtypes\n",
314-
"fetched = client.get_entity(entity_id=registered.id, entity_type=ReconstructionMorphology)"
420+
"fetched = client.get_entity(entity_id=registered.id, entity_type=CellMorphology)"
315421
]
316422
},
317423
{
@@ -370,7 +476,7 @@
370476
"\n",
371477
"rprint(deleted_asset)\n",
372478
"\n",
373-
"fetched = client.get_entity(entity_id=registered.id, entity_type=ReconstructionMorphology)\n",
479+
"fetched = client.get_entity(entity_id=registered.id, entity_type=CellMorphology)\n",
374480
"rprint(fetched.assets)"
375481
]
376482
},
@@ -390,7 +496,7 @@
390496
"outputs": [],
391497
"source": [
392498
"hits = client.search_entity(\n",
393-
" entity_type=ReconstructionMorphology,\n",
499+
" entity_type=CellMorphology,\n",
394500
" query={\"name__ilike\": \"my-morph\", \"page\": 1, \"page_size\": 2},\n",
395501
" limit=None,\n",
396502
").all()\n",
@@ -426,7 +532,7 @@
426532
"## register a file\n",
427533
"# asset = client.register_asset(\n",
428534
"# entity_id=registered.id,\n",
429-
"# entity_type=ReconstructionMorphology,\n",
535+
"# entity_type=CellMorphology,\n",
430536
"# name=\"my-morphology.h5\",\n",
431537
"# storage_path=\"path/to/morph.h5\",\n",
432538
"# storage_type=\"aws_s3_open\",\n",
@@ -458,22 +564,8 @@
458564
}
459565
],
460566
"metadata": {
461-
"kernelspec": {
462-
"display_name": "entitysdk",
463-
"language": "python",
464-
"name": "python3"
465-
},
466567
"language_info": {
467-
"codemirror_mode": {
468-
"name": "ipython",
469-
"version": 3
470-
},
471-
"file_extension": ".py",
472-
"mimetype": "text/x-python",
473-
"name": "python",
474-
"nbconvert_exporter": "python",
475-
"pygments_lexer": "ipython3",
476-
"version": "3.11.11"
568+
"name": "python"
477569
}
478570
},
479571
"nbformat": 4,

examples/03_circuit.ipynb

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"from rich import print as rprint\n",
1515
"from utils import create_mock_circuit_dir\n",
1616
"\n",
17-
"from entitysdk import Client, ProjectContext, models\n",
17+
"from entitysdk import Client, ProjectContext, models, types\n",
1818
"\n",
1919
"entitycore_api_url = \"http://127.0.0.1:8000\"\n",
2020
"project_context = ProjectContext(\n",
@@ -135,6 +135,7 @@
135135
" entity_id=registered_circuit.id,\n",
136136
" entity_type=models.Circuit,\n",
137137
" name=\"circuit\",\n",
138+
" label=types.AssetLabel.sonata_circuit,\n",
138139
" paths=files,\n",
139140
" )"
140141
]
@@ -225,22 +226,8 @@
225226
}
226227
],
227228
"metadata": {
228-
"kernelspec": {
229-
"display_name": "Python 3 (ipykernel)",
230-
"language": "python",
231-
"name": "python3"
232-
},
233229
"language_info": {
234-
"codemirror_mode": {
235-
"name": "ipython",
236-
"version": 3
237-
},
238-
"file_extension": ".py",
239-
"mimetype": "text/x-python",
240-
"name": "python",
241-
"nbconvert_exporter": "python",
242-
"pygments_lexer": "ipython3",
243-
"version": "3.12.10"
230+
"name": "python"
244231
}
245232
},
246233
"nbformat": 4,

examples/04_simulation_campaign.ipynb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@
111111
" for i in range(5)\n",
112112
"]\n",
113113
"simulation_results = [\n",
114-
" client.register_entity(models.SimulationResult(name=f\"result-{i}\", description=f\"result-{i}\"))\n",
114+
" client.register_entity(\n",
115+
" models.SimulationResult(\n",
116+
" name=f\"result-{i}\",\n",
117+
" description=f\"result-{i}\",\n",
118+
" simulation_id=simulations[i].id,\n",
119+
" )\n",
120+
" )\n",
115121
" for i in range(5)\n",
116122
"]"
117123
]
@@ -326,7 +332,13 @@
326332
"outputs": [],
327333
"source": [
328334
"results = [\n",
329-
" client.register_entity(models.SimulationResult(name=f\"result-{i}\", description=f\"result-{i}\"))\n",
335+
" client.register_entity(\n",
336+
" models.SimulationResult(\n",
337+
" name=f\"result-{i}\",\n",
338+
" description=f\"result-{i}\",\n",
339+
" simulation_id=simulations[i].id,\n",
340+
" )\n",
341+
" )\n",
330342
" for i in range(5)\n",
331343
"]"
332344
]
@@ -369,14 +381,6 @@
369381
"source": [
370382
"rprint(updated_executions)"
371383
]
372-
},
373-
{
374-
"cell_type": "code",
375-
"execution_count": null,
376-
"id": "b3260f79-5852-4e61-923f-4325e030fc71",
377-
"metadata": {},
378-
"outputs": [],
379-
"source": []
380384
}
381385
],
382386
"metadata": {

0 commit comments

Comments
 (0)