Skip to content

Commit

Permalink
update notebooks for 0.4.0 (#98)
Browse files Browse the repository at this point in the history
* update notebooks

* removed obsolete notebooks

* update intake demo

* update cordex demo

* added cmip5 demo

* update cmip6 demo for c4i
  • Loading branch information
cehbrecht committed Apr 19, 2022
1 parent 4c11f76 commit d773459
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 466 deletions.
72 changes: 36 additions & 36 deletions notebooks/c4i/c4i-demo-cmip6-average.ipynb

Large diffs are not rendered by default.

201 changes: 82 additions & 119 deletions notebooks/demo/demo-intake-catalog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,54 @@
"import intake"
]
},
{
"cell_type": "markdown",
"id": "fewer-robert",
"metadata": {},
"source": [
"## Open remote catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "becoming-theater",
"id": "textile-fortune",
"metadata": {},
"outputs": [],
"source": [
"# cat_url = \"https://raw.githubusercontent.com/cp4cds/c3s_34g_manifests/master/intake/catalogs/c3s.yaml\"\n",
"cat_url = \"https://github.com/cehbrecht/c3s_34g_manifests/raw/fix-intake-catalog/intake/catalogs/c3s.yaml\"\n",
"cat = intake.open_catalog(cat_url)\n"
"# filter catalog\n",
"def filter_by_time(df, collection, time=None):\n",
" # a common search we do in rook\n",
" start = end = None\n",
" if time:\n",
" if \"/\" in time:\n",
" start, end = time.split(\"/\")\n",
" start = start.strip()\n",
" end = end.strip()\n",
" else:\n",
" start = time.strip()\n",
" \n",
" start = start or \"1800-01-01\"\n",
" end = end or \"2500-12-31\"\n",
" \n",
" sdf = df.fillna({'start_time': '1000-01-01T12:00:00', 'end_time': '3000-12-31T12:00:00'})\n",
"\n",
" result = sdf.loc[(sdf.ds_id == collection) & (sdf.end_time >= start) & (sdf.start_time <= end)]\n",
" return list(result.path.sort_values().to_dict().values())\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "awful-clearance",
"cell_type": "markdown",
"id": "fewer-robert",
"metadata": {},
"outputs": [],
"source": [
"list(cat)"
"## Open remote catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "nearby-alert",
"id": "becoming-theater",
"metadata": {},
"outputs": [],
"source": [
"print(cat['c3s-cmip6'])"
"# cat_url = \"https://raw.githubusercontent.com/cp4cds/c3s_34g_manifests/master/intake/catalogs/c3s.yaml\"\n",
"cat_url = \"https://github.com/cehbrecht/c3s_34g_manifests/raw/fix-intake-catalog/intake/catalogs/c3s.yaml\"\n",
"cat = intake.open_catalog(cat_url)\n",
"list(cat)"
]
},
{
Expand All @@ -75,198 +85,151 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ceramic-today",
"metadata": {},
"outputs": [],
"source": [
"df = cat['c3s-cmip6'].read()"
]
},
{
"cell_type": "markdown",
"id": "convertible-naples",
"metadata": {},
"source": [
"### Show memory usage"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "weekly-argentina",
"id": "dc65a830-2602-4afb-84dd-74c5130db310",
"metadata": {},
"outputs": [],
"source": [
"df.info(memory_usage='deep')"
]
},
{
"cell_type": "markdown",
"id": "minus-briefing",
"metadata": {},
"source": [
"## Show first datasets"
"print(cat['c3s-cmip6'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "assured-bobby",
"id": "ceramic-today",
"metadata": {},
"outputs": [],
"source": [
"df.head()"
"df_cmip6 = cat['c3s-cmip6'].read()\n",
"df_cmip6"
]
},
{
"cell_type": "markdown",
"id": "induced-politics",
"id": "naughty-timothy",
"metadata": {},
"source": [
"## Show number of datasets"
"### Filter dataset dataset by time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "complimentary-recovery",
"id": "quality-strand",
"metadata": {},
"outputs": [],
"source": [
"df.ds_id.nunique()"
"result = filter_by_time(\n",
" df_cmip6, \n",
" collection=\"c3s-cmip6.CMIP.SNU.SAM0-UNICON.historical.r1i1p1f1.day.pr.gn.v20190323\",\n",
" time=\"2000-01-01/2001-12-31\")\n",
"result"
]
},
{
"cell_type": "markdown",
"id": "dominant-watch",
"id": "architectural-suspension",
"metadata": {},
"source": [
"## Define a search function for dataset and time"
"### Search dataset ..."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "textile-fortune",
"id": "important-algebra",
"metadata": {},
"outputs": [],
"source": [
"def search(df, collection, time=None):\n",
" # a common search we do in rook\n",
" start = end = None\n",
" if time:\n",
" if \"/\" in time:\n",
" start, end = time.split(\"/\")\n",
" start = start.strip()\n",
" end = end.strip()\n",
" else:\n",
" start = time.strip()\n",
" \n",
" start = start or \"1800-01-01\"\n",
" end = end or \"2500-12-31\"\n",
" \n",
" sdf = df.fillna({'start_time': '1000-01-01T12:00:00', 'end_time': '3000-12-31T12:00:00'})\n",
"\n",
" result = sdf.loc[(sdf.ds_id == collection) & (sdf.end_time >= start) & (sdf.start_time <= end)]\n",
" return list(result.path.sort_values().to_dict().values())\n",
" "
]
},
{
"cell_type": "markdown",
"id": "naughty-timothy",
"metadata": {},
"source": [
"## Search for a dataset with time restrictions"
"df = df_cmip6.loc[\n",
" (df_cmip6.variable_id==\"tas\") \n",
" & (df_cmip6.experiment_id==\"historical\")\n",
" & (df_cmip6.table_id==\"day\")\n",
" & (df_cmip6.member_id==\"r1i1p1f1\")\n",
" & (df_cmip6.institution_id==\"MIROC\")\n",
"]\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "quality-strand",
"id": "maritime-association",
"metadata": {},
"outputs": [],
"source": [
"result = search(\n",
" df, \n",
" collection=\"c3s-cmip6.CMIP.SNU.SAM0-UNICON.historical.r1i1p1f1.day.pr.gn.v20190323\",\n",
" time=\"2000-01-01/2001-12-31\")\n",
"result"
"df.ds_id.unique()"
]
},
{
"cell_type": "markdown",
"id": "peripheral-president",
"id": "159209e3-bb6d-4280-8c44-240de51d28bf",
"metadata": {},
"source": [
"## Search for dataset with no time axis (fx, fixed fields)"
"## Load Catalog for C3S-CORDEX"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "hairy-potential",
"id": "b8c69d80-3e2c-4892-9707-8882ed4d1aaa",
"metadata": {},
"outputs": [],
"source": [
"df.loc[df.table_id==\"fx\"].ds_id"
"print(cat['c3s-cordex'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "anonymous-winner",
"id": "d04937d7-744b-45db-876a-ae487751b0ab",
"metadata": {},
"outputs": [],
"source": [
"collection = df.iloc[29].ds_id\n",
"collection"
"df_cordex = cat['c3s-cordex'].read()\n",
"df_cordex"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "complicated-transaction",
"id": "46ec77bb-ce85-4b52-96bb-3e5bb81dabf6",
"metadata": {},
"outputs": [],
"source": [
"result = search(df, collection=collection, time=\"2000-01-01/2010-12-31\")\n",
"result"
]
},
{
"cell_type": "markdown",
"id": "architectural-suspension",
"metadata": {},
"source": [
"## Other searches ..."
"df = df_cordex.loc[\n",
" (df_cordex.variable==\"tas\") \n",
" & (df_cordex.experiment==\"rcp85\")\n",
" & (df_cordex.domain==\"EUR-11\")\n",
" & (df_cordex.time_frequency==\"mon\")\n",
" & (df_cordex.driving_model==\"MOHC-HadGEM2-ES\")\n",
" & (df_cordex.ensemble==\"r1i1p1\")\n",
"]\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "important-algebra",
"id": "8f5fb385-f19b-4263-8b6a-ba71316307e8",
"metadata": {},
"outputs": [],
"source": [
"result = df.loc[\n",
" (df.variable_id==\"tas\") \n",
" & (df.experiment_id==\"historical\")\n",
" & (df.table_id==\"day\")\n",
" & (df.member_id==\"r1i1p1f1\")\n",
" & (df.institution_id==\"MIROC\")\n",
"]\n",
"result.head()"
"collection = df.ds_id.unique()[0]\n",
"collection"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "maritime-association",
"id": "86e9b6df-777d-44a8-9a17-3326f4821651",
"metadata": {},
"outputs": [],
"source": [
"result.ds_id.unique()"
"result = filter_by_time(\n",
" df_cordex, \n",
" collection=collection,\n",
" time=\"2006-01-01/2006-12-31\")\n",
"result"
]
}
],
Expand All @@ -286,7 +249,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions notebooks/demo/demo-rooki-average-time.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
"metadata": {},
"outputs": [],
"source": [
"ds = resp.datasets()[0]\n",
"ds"
"#ds = resp.datasets()[0]\n",
"#ds"
]
},
{
Expand Down Expand Up @@ -155,7 +155,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit d773459

Please sign in to comment.