Skip to content

Commit bc595e3

Browse files
committed
Update brainstem_api_tutorial.ipynb
1 parent 3513aaa commit bc595e3

1 file changed

Lines changed: 3 additions & 83 deletions

File tree

brainstem_api_tutorial.ipynb

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -265,87 +265,7 @@
265265
"cell_type": "markdown",
266266
"metadata": {},
267267
"source": [
268-
"# 6. Including Related Models\n",
269-
"\n",
270-
"Brainstem's data models have relationships between them (projects contain sessions, sessions involve subjects, etc.). The include parameter lets you fetch related models in a single request, reducing the number of API calls needed. For example, you can retrieve a project along with all its sessions and subjects in one operation"
271-
]
272-
},
273-
{
274-
"cell_type": "code",
275-
"execution_count": null,
276-
"metadata": {},
277-
"outputs": [],
278-
"source": [
279-
"# Find the Allen Institute: Visual Coding – Neuropixels project\n",
280-
"allen_projects = client.load_model(\n",
281-
" \"project\", \n",
282-
" portal=\"public\", \n",
283-
" filters={'name.iexact': 'Allen Institute: Visual Coding – Neuropixels'}\n",
284-
").json()\n",
285-
"\n",
286-
"# Get project ID\n",
287-
"project_id = allen_projects['projects'][0]['id']\n",
288-
"\n",
289-
"# Get detailed project information with sessions and subjects included\n",
290-
"project_with_data = client.load_model(\n",
291-
" \"project\",\n",
292-
" portal=\"public\",\n",
293-
" id=project_id,\n",
294-
" include=[\"sessions\", \"subjects\"] # Include both sessions and subjects\n",
295-
").json()\n",
296-
"\n",
297-
"# Access project information\n",
298-
"project = project_with_data['project']\n",
299-
"print(f\"Project name: {project['name']}\")\n",
300-
"print(f\"Description: {project['description'][:100]}...\")\n",
301-
"print(f\"Public: {project['is_public']}\")\n",
302-
"\n",
303-
"# Print session and subject counts. We have this data from a single API call\n",
304-
"print(f\"\\nThis project has {len(project['sessions'])} sessions\")\n",
305-
"print(f\"This project has {len(project['subjects'])} subjects\")\n",
306-
"\n",
307-
"# List first 3 subjects directly from the include\n",
308-
"print(\"\\nFirst 3 subjects in the project:\")\n",
309-
"for i, subject_id in enumerate(project['subjects'][:3]):\n",
310-
" print(f\"{i+1}. Subject ID: {subject_id}\")\n",
311-
"\n",
312-
"# List first 3 sessions directly from the include\n",
313-
"print(\"\\nFirst 3 sessions in the project:\")\n",
314-
"for i, session_id in enumerate(project['sessions'][:3]):\n",
315-
" print(f\"{i+1}. Session ID: {session_id}\")\n",
316-
"\n",
317-
"# Get details for a specific session with included dataacquisition\n",
318-
"first_session_id = project['sessions'][0]\n",
319-
"session_with_data = client.load_model(\n",
320-
" \"session\",\n",
321-
" portal=\"public\",\n",
322-
" id=first_session_id,\n",
323-
" include=[\"dataacquisition\"] # Include data acquisition methods\n",
324-
").json()\n",
325-
"\n",
326-
"# Access the session data\n",
327-
"session = session_with_data['session']\n",
328-
"print(f\"\\nSession details:\")\n",
329-
"print(f\"Name: {session['name']}\")\n",
330-
"print(f\"Description: {session['description']}\")\n",
331-
"\n",
332-
"# Now actually use the included dataacquisition data\n",
333-
"if 'dataacquisition' in session:\n",
334-
" data_acq_ids = session['dataacquisition']\n",
335-
" print(f\"\\nThis session has {len(data_acq_ids)} data acquisition method(s) (included in response)\")\n",
336-
" \n",
337-
" # Demonstrate using the included dataacquisition IDs\n",
338-
" if data_acq_ids:\n",
339-
" print(\"\\nData acquisition IDs from session include:\")\n",
340-
" for i, acq_id in enumerate(data_acq_ids):\n",
341-
" print(f\"{i+1}. {acq_id}\")"
342-
]
343-
},
344-
{
345-
"cell_type": "markdown",
346-
"metadata": {},
347-
"source": [
348-
"# 7. Sorting\n",
268+
"# 6. Sorting\n",
349269
"\n",
350270
"You can control the order of returned results using the sort parameter. Sort by any field in ascending order (e.g., alphabetically by name) or use a minus sign prefix for descending order."
351271
]
@@ -383,7 +303,7 @@
383303
"cell_type": "markdown",
384304
"metadata": {},
385305
"source": [
386-
"# 8. Updating data\n",
306+
"# 7. Updating data\n",
387307
"The API supports creating new records and updating existing ones. When creating a record, provide the required fields for that model type. For updates, fetch the existing record, modify its attributes, and save it back. Both operations require appropriate permissions."
388308
]
389309
},
@@ -447,7 +367,7 @@
447367
"cell_type": "markdown",
448368
"metadata": {},
449369
"source": [
450-
"# 9. Deleting data\n",
370+
"# 8. Deleting data\n",
451371
"You can remove records from the database using their IDs. Deletion is permanent, so use this operation with caution. The API will return a success status code (204) when deletion is successful. Like other write operations, deletion requires appropriate permissions."
452372
]
453373
},

0 commit comments

Comments
 (0)