Skip to content

Commit

Permalink
Merge pull request #46 from cehbrecht/added-demo-notebooks
Browse files Browse the repository at this point in the history
added demo notebooks
  • Loading branch information
cehbrecht committed Aug 7, 2019
2 parents 8db9e13 + e4aabb1 commit 37d20fe
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/source/_static/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Readme
======

placeholder for _static folder.
14 changes: 13 additions & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Examples
########

You can try this notebook examples online using Binder, or view the notebooks on NBViewer.
You can try these notebook online using Binder, or view the notebooks on NBViewer.

.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/ESGF/esgf-pyclient.git/master?filepath=notebooks
Expand All @@ -16,9 +16,21 @@ You can try this notebook examples online using Binder, or view the notebooks on
:alt: NBViewer
:height: 20

Basic Usage
===========

.. toctree::
:maxdepth: 1

notebooks/examples/search
notebooks/examples/logon
notebooks/examples/download

Demo
====

.. toctree::
:maxdepth: 1

notebooks/demo/subset-cmip5
notebooks/demo/subset-cmip6
180 changes: 180 additions & 0 deletions notebooks/demo/subset-cmip5.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Subset CMIP5 Datasets with xarray\n",
"\n",
"xarray: http://xarray.pydata.org/en/stable/index.html"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Search CMIP5 Dataset with ESGF pyclient\n",
"\n",
"using: https://esgf-pyclient.readthedocs.io/en/latest/index.html"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pyesgf.search import SearchConnection\n",
"conn = SearchConnection('https://esgf-data.dkrz.de/esg-search', distrib=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ctx = conn.new_context(\n",
" project='CMIP5', \n",
" experiment='rcp45',\n",
" model='HadCM3',\n",
" ensemble='r1i1p1',\n",
" time_frequency='mon',\n",
" realm='atmos',\n",
" data_node='esgf-data1.ceda.ac.uk',\n",
" )\n",
"ctx.hit_count"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = ctx.search()[0]\n",
"result.dataset_id"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"files = result.file_context().search()\n",
"for file in files:\n",
" if 'tasmax' in file.opendap_url:\n",
" tasmax_url = file.opendap_url\n",
" print(tasmax_url)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ESGF Logon"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pyesgf.logon import LogonManager\n",
"lm = LogonManager()\n",
"lm.logoff()\n",
"lm.is_logged_on()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"lm.logon(hostname='esgf-data.dkrz.de', interactive=True, bootstrap=True)\n",
"lm.is_logged_on()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Subset single dataset with xarray\n",
"\n",
"Using OpenDAP: http://xarray.pydata.org/en/stable/io.html?highlight=opendap#opendap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"ds = xr.open_dataset(tasmax_url, chunks={'time': 120})\n",
"print(ds)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"da = ds['tasmax']\n",
"da = da.isel(time=slice(0, 1))\n",
"da = da.sel(lat=slice(-50, 50), lon=slice(0, 50))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"da.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download to NetCDF"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"da.to_netcdf('tasmax.nc')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 37d20fe

Please sign in to comment.