Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ client = Client(

# Search for morphologies
iterator = client.search_entity(
entity_type=models.ReconstructionMorphology,
entity_type=models.CellMorphology,
query={"mtype__pref_label": "L5_TPC:A"},
limit=1,
)
Expand All @@ -60,7 +60,7 @@ morphology = next(iterator)
# Upload an asset
client.upload_file(
entity_id=morphology.id,
entity_type=models.ReconstructionMorphology,
entity_type=models.CellMorphology,
file_path="path/to/file.swc",
file_content_type="application/swc",
)
Expand Down
6 changes: 3 additions & 3 deletions examples/01_searching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
" MTypeClass,\n",
" Organization,\n",
" Person,\n",
" ReconstructionMorphology,\n",
" CellMorphology,\n",
" Role,\n",
" Species,\n",
" Strain,\n",
Expand Down Expand Up @@ -228,7 +228,7 @@
"metadata": {},
"outputs": [],
"source": [
"morphs = client.search_entity(entity_type=ReconstructionMorphology, limit=10).all()"
"morphs = client.search_entity(entity_type=CellMorphology, limit=10).all()"
]
},
{
Expand Down Expand Up @@ -258,7 +258,7 @@
"outputs": [],
"source": [
"morphs = client.search_entity(\n",
" entity_type=ReconstructionMorphology, query={\"mtype__pref_label\": \"SR_PC\"}\n",
" entity_type=CellMorphology, query={\"mtype__pref_label\": \"SR_PC\"}\n",
").all()"
]
},
Expand Down
144 changes: 118 additions & 26 deletions examples/02_morphology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@
"from entitysdk.models import (\n",
" BrainLocation,\n",
" BrainRegion,\n",
" CellMorphology,\n",
" CellMorphologyProtocol,\n",
" Contribution,\n",
" MTypeClass,\n",
" MTypeClassification,\n",
" Organization,\n",
" ReconstructionMorphology,\n",
" Role,\n",
" Species,\n",
" Strain,\n",
" Subject,\n",
")\n",
"from entitysdk.types import (\n",
" CellMorphologyGenerationType,\n",
" CellMorphologyProtocolDesign,\n",
" SlicingDirectionType,\n",
")"
]
},
Expand Down Expand Up @@ -130,6 +137,95 @@
"rprint(brain_region)"
]
},
{
"cell_type": "markdown",
"id": "65bea11e",
"metadata": {},
"source": [
"### Create and register a new subject"
]
},
{
"cell_type": "markdown",
"id": "40772ff8",
"metadata": {},
"source": [
"Subjects should be reused if possible, but they can be created when needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c78f0e4d",
"metadata": {},
"outputs": [],
"source": [
"subject = Subject(\n",
" name=\"my-subject-for-morphology\",\n",
" description=\"my-subject-description\",\n",
" sex=\"male\",\n",
" species=species,\n",
" strain=strain,\n",
")\n",
"\n",
"subject = client.register_entity(subject)\n",
"rprint(subject)"
]
},
{
"cell_type": "markdown",
"id": "62e916c9",
"metadata": {},
"source": [
"### Create and register a new morphology protocol"
]
},
{
"cell_type": "markdown",
"id": "1b2dacaf",
"metadata": {},
"source": [
"Morphology protocols should be reused if possible, but they can be created when needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5200e8cf",
"metadata": {},
"outputs": [],
"source": [
"morphology_protocol = CellMorphologyProtocol(\n",
" generation_type=CellMorphologyGenerationType.digital_reconstruction,\n",
" protocol_document=\"https://example.com/\",\n",
" protocol_design=CellMorphologyProtocolDesign.cell_patch,\n",
" slicing_thickness=20.0,\n",
" slicing_direction=SlicingDirectionType.horizontal,\n",
")\n",
"rprint(morphology_protocol.__class__.__name__)\n",
"morphology_protocol = client.register_entity(morphology_protocol)\n",
"rprint(morphology_protocol)"
]
},
{
"cell_type": "markdown",
"id": "ff0d1d01",
"metadata": {},
"source": [
"### Optional, list morphology protocols"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "71818153",
"metadata": {},
"outputs": [],
"source": [
"protocols = client.search_entity(entity_type=CellMorphologyProtocol).all()\n",
"rprint(protocols)"
]
},
{
"cell_type": "markdown",
"id": "a0193055-3448-4d1c-99cc-4d953727ef4e",
Expand All @@ -150,15 +246,15 @@
" y=1173.8499755859375,\n",
" z=4744.60009765625,\n",
")\n",
"morphology = ReconstructionMorphology(\n",
"morphology = CellMorphology(\n",
" cell_morphology_protocol=morphology_protocol,\n",
" name=\"my-morph\",\n",
" description=\"A morphology\",\n",
" species=species,\n",
" strain=strain,\n",
" subject=subject,\n",
" brain_region=brain_region,\n",
" location=brain_location,\n",
" legacy_id=None,\n",
" authorized_public=True,\n",
" authorized_public=False,\n",
")"
]
},
Expand Down Expand Up @@ -190,6 +286,16 @@
"registered = client.register_entity(entity=morphology)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b029401",
"metadata": {},
"outputs": [],
"source": [
"rprint(registered)"
]
},
{
"cell_type": "markdown",
"id": "5a4482d8-d5d4-45b9-80cb-264c1a531216",
Expand Down Expand Up @@ -274,7 +380,7 @@
" # use a filepath to register first asset\n",
" asset1 = client.upload_file(\n",
" entity_id=registered.id,\n",
" entity_type=ReconstructionMorphology,\n",
" entity_type=CellMorphology,\n",
" file_path=file1,\n",
" file_content_type=\"application/x-hdf5\",\n",
" asset_label=\"morphology\",\n",
Expand All @@ -286,7 +392,7 @@
"\n",
" asset2 = client.upload_content(\n",
" entity_id=registered.id,\n",
" entity_type=ReconstructionMorphology,\n",
" entity_type=CellMorphology,\n",
" file_content=buffer,\n",
" file_name=\"buffer.swc\",\n",
" file_content_type=\"application/swc\",\n",
Expand All @@ -311,7 +417,7 @@
"outputs": [],
"source": [
"# with assets and mtypes\n",
"fetched = client.get_entity(entity_id=registered.id, entity_type=ReconstructionMorphology)"
"fetched = client.get_entity(entity_id=registered.id, entity_type=CellMorphology)"
]
},
{
Expand Down Expand Up @@ -370,7 +476,7 @@
"\n",
"rprint(deleted_asset)\n",
"\n",
"fetched = client.get_entity(entity_id=registered.id, entity_type=ReconstructionMorphology)\n",
"fetched = client.get_entity(entity_id=registered.id, entity_type=CellMorphology)\n",
"rprint(fetched.assets)"
]
},
Expand All @@ -390,7 +496,7 @@
"outputs": [],
"source": [
"hits = client.search_entity(\n",
" entity_type=ReconstructionMorphology,\n",
" entity_type=CellMorphology,\n",
" query={\"name__ilike\": \"my-morph\", \"page\": 1, \"page_size\": 2},\n",
" limit=None,\n",
").all()\n",
Expand Down Expand Up @@ -426,7 +532,7 @@
"## register a file\n",
"# asset = client.register_asset(\n",
"# entity_id=registered.id,\n",
"# entity_type=ReconstructionMorphology,\n",
"# entity_type=CellMorphology,\n",
"# name=\"my-morphology.h5\",\n",
"# storage_path=\"path/to/morph.h5\",\n",
"# storage_type=\"aws_s3_open\",\n",
Expand Down Expand Up @@ -458,22 +564,8 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "entitysdk",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
"name": "python"
}
},
"nbformat": 4,
Expand Down
19 changes: 3 additions & 16 deletions examples/03_circuit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"from rich import print as rprint\n",
"from utils import create_mock_circuit_dir\n",
"\n",
"from entitysdk import Client, ProjectContext, models\n",
"from entitysdk import Client, ProjectContext, models, types\n",
"\n",
"entitycore_api_url = \"http://127.0.0.1:8000\"\n",
"project_context = ProjectContext(\n",
Expand Down Expand Up @@ -135,6 +135,7 @@
" entity_id=registered_circuit.id,\n",
" entity_type=models.Circuit,\n",
" name=\"circuit\",\n",
" label=types.AssetLabel.sonata_circuit,\n",
" paths=files,\n",
" )"
]
Expand Down Expand Up @@ -225,22 +226,8 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.10"
"name": "python"
}
},
"nbformat": 4,
Expand Down
24 changes: 14 additions & 10 deletions examples/04_simulation_campaign.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@
" for i in range(5)\n",
"]\n",
"simulation_results = [\n",
" client.register_entity(models.SimulationResult(name=f\"result-{i}\", description=f\"result-{i}\"))\n",
" client.register_entity(\n",
" models.SimulationResult(\n",
" name=f\"result-{i}\",\n",
" description=f\"result-{i}\",\n",
" simulation_id=simulations[i].id,\n",
" )\n",
" )\n",
" for i in range(5)\n",
"]"
]
Expand Down Expand Up @@ -326,7 +332,13 @@
"outputs": [],
"source": [
"results = [\n",
" client.register_entity(models.SimulationResult(name=f\"result-{i}\", description=f\"result-{i}\"))\n",
" client.register_entity(\n",
" models.SimulationResult(\n",
" name=f\"result-{i}\",\n",
" description=f\"result-{i}\",\n",
" simulation_id=simulations[i].id,\n",
" )\n",
" )\n",
" for i in range(5)\n",
"]"
]
Expand Down Expand Up @@ -369,14 +381,6 @@
"source": [
"rprint(updated_executions)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b3260f79-5852-4e61-923f-4325e030fc71",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading