Skip to content

Commit e018e90

Browse files
committed
Add notebook example for cohort group metadata
1 parent 51f101e commit e018e90

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Cohort group metadata quick demo\n",
8+
"\n",
9+
"This notebook shows how to load cohort-group metadata tables and filter them with `cohort_group_query`."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"from malariagen_data import ag3 as _ag3\n",
19+
"from malariagen_data.anoph.cohort_group_metadata import AnophelesCohortGroupMetadata"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"cohort_meta = AnophelesCohortGroupMetadata(\n",
29+
" url=\"simplecache::gs://vo_agam_release_master_us_central1\",\n",
30+
" public_url=\"gs://vo_agam_release_master_us_central1/\",\n",
31+
" config_path=_ag3.CONFIG_PATH,\n",
32+
" major_version_number=_ag3.MAJOR_VERSION_NUMBER,\n",
33+
" major_version_path=_ag3.MAJOR_VERSION_PATH,\n",
34+
" pre=True,\n",
35+
" simplecache={\"cache_storage\": \"../gcs_cache\"},\n",
36+
")\n",
37+
"cohort_meta"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": null,
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"df_admin1_month = cohort_meta.cohort_group_metadata(\"admin1_month\")\n",
47+
"df_admin1_month.head()"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"df_bf = cohort_meta.cohort_group_metadata(\n",
57+
" \"admin1_month\",\n",
58+
" cohort_group_query=\"country == 'Burkina Faso' and year >= 2010\",\n",
59+
")\n",
60+
"df_bf.loc[:, [\"cohort_id\", \"cohort_size\", \"country\", \"year\", \"month\", \"admin1_name\"]].head()"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"df_bf.groupby([\"year\", \"month\"], as_index=False)[\"cohort_size\"].sum().head()"
70+
]
71+
}
72+
],
73+
"metadata": {
74+
"kernelspec": {
75+
"display_name": "Python 3 (ipykernel)",
76+
"language": "python",
77+
"name": "python3"
78+
},
79+
"language_info": {
80+
"codemirror_mode": {
81+
"name": "ipython",
82+
"version": 3
83+
},
84+
"file_extension": ".py",
85+
"mimetype": "text/x-python",
86+
"name": "python",
87+
"nbconvert_exporter": "python",
88+
"pygments_lexer": "ipython3",
89+
"version": "3.11.0"
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 5
94+
}

tests/anoph/test_cohort_group_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def ag3_sim_api(ag3_sim_fixture):
1616
pre=True,
1717
)
1818

19+
1920
def case_ag3_sim(ag3_sim_fixture, ag3_sim_api):
2021
return ag3_sim_fixture, ag3_sim_api
2122

0 commit comments

Comments
 (0)