Skip to content

Commit

Permalink
deploy: c642621
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbuntemeyer committed Sep 11, 2023
1 parent 9dacdc9 commit 88f7755
Show file tree
Hide file tree
Showing 11 changed files with 1,089 additions and 291 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 50 additions & 63 deletions _sources/domains.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The `dummy='topo'` argument means, we want a dummy variable in the dataset to see how the domain looks like. For the dummy topography, we use the `cdo topo` operator in the background. So maybe you have to install `python-cdo`, e.g., `conda install -c conda-forge python-cdo`. Working with xarray datasets means, that we can use all the nice functions of xarray including plotting, e.g.,"
"The `dummy='topo'` argument means, we want a dummy variable in the dataset to see how the domain looks like. For the dummy topography, we use the `cdo topo` operator in the background. So maybe you have to install `python-cdo`, e.g., `conda install -c conda-forge python-cdo`. Working with xarray datasets means, that we can use all the nice functions of xarray including plotting. The latest versions of `py-cordex` also come with an xarray accessor that allows you, e.g., to get a quick overview of the domain, using, e.g."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from matplotlib import pyplot as plt\n",
"\n",
"# plt.figure(figsize=(8,8))\n",
"eur11.cx.map()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also use the dummy topography to plot an overview:"
]
},
{
Expand Down Expand Up @@ -148,7 +167,7 @@
" import cartopy.feature as cf\n",
" import matplotlib.pyplot as plt\n",
"\n",
" plt.figure(figsize=(20, 10))\n",
" plt.figure(figsize=(10, 10))\n",
" projection = ccrs.PlateCarree()\n",
" transform = ccrs.RotatedPole(pole_latitude=pole[1], pole_longitude=pole[0])\n",
" # ax = plt.axes(projection=projection)\n",
Expand Down Expand Up @@ -210,7 +229,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The domains are actually created from csv tables. To checkout the tables you can have a look at `dm.TABLES`. This is a dictionary of dataframes created during the import of the model from a number of csv tables that define standard cordex domains. E.g., available tables are:"
"The domains are actually created from [a csv table](https://github.com/WCRP-CORDEX/domain-tables/blob/main/rotated-latitude-longitude.csv). The domains are created using the `create_dataset` function, in which the data from the table is fed, e.g.:"
]
},
{
Expand All @@ -219,14 +238,14 @@
"metadata": {},
"outputs": [],
"source": [
"cx.domains.tables[\"cordex-high-res\"]"
"cx.create_dataset?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The domains are created using the `create_dataset` function, e.g.:"
"Let's create the EUR-11 domain manually from the numbers in the table:"
]
},
{
Expand All @@ -235,14 +254,7 @@
"metadata": {},
"outputs": [],
"source": [
"help(cx.create_dataset)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create the EUR-11 domain manually from the numbers in the table:"
"cx.domains.table.loc[\"EUR-11\"]"
]
},
{
Expand Down Expand Up @@ -287,45 +299,6 @@
"You can now use the `create_dataset` function to create any domain as an xarray dataset."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Check out the Africa domain!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"afr11 = cx.cordex_domain(\"AFR-11\", dummy=\"topo\")\n",
"afr11"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pole = (\n",
" afr11.rotated_latitude_longitude.grid_north_pole_longitude,\n",
" afr11.rotated_latitude_longitude.grid_north_pole_latitude,\n",
")\n",
"pole"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot(afr11.topo, pole)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -394,7 +367,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's plot all cordex core domains into one overview:"
"Now, let's plot all cordex core domains into one overview. We will identify them by their resolution:"
]
},
{
Expand All @@ -403,10 +376,13 @@
"metadata": {},
"outputs": [],
"source": [
"table = cx.domains.table\n",
"\n",
"plots(\n",
" [\n",
" cx.cordex_domain(name, dummy=\"topo\")\n",
" for name in cx.domains.tables[\"cordex-core\"].index\n",
" for name in table.index\n",
" if table.loc[name].dlon == 0.22\n",
" ],\n",
" borders=False,\n",
")"
Expand All @@ -433,6 +409,15 @@
"We will use some CMIP6 model data from the ESGF to show how we can do the regridding:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!wget https://raw.githubusercontent.com/remo-rcm/pyremo-data/main/orog_fx_MPI-ESM1-2-HR_historical_r1i1p1f1_gn.nc"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -441,9 +426,11 @@
"source": [
"import xarray as xr\n",
"\n",
"ds = xr.open_dataset(\n",
" \"https://esgf3.dkrz.de/thredds/dodsC/cmip6/CMIP/MPI-M/MPI-ESM1-2-HR/historical/r1i1p1f1/Amon/tas/gn/v20190710/tas_Amon_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_199501-199912.nc\"\n",
")\n",
"# https://raw.githubusercontent.com/remo-rcm/pyremo-data/main/orog_fx_MPI-ESM1-2-HR_historical_r1i1p1f1_gn.nc\n",
"ds = xr.open_dataset(\"orog_fx_MPI-ESM1-2-HR_historical_r1i1p1f1_gn.nc\")\n",
"# ds = xr.open_dataset(\n",
"# \"https://esgf3.dkrz.de/thredds/dodsC/cmip6/CMIP/MPI-M/MPI-ESM1-2-HR/historical/r1i1p1f1/Amon/tas/gn/v20190710/tas_Amon_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_199501-199912.nc\"\n",
"# )\n",
"# ds = xr.open_dataset(\n",
"# \"http://esgf-data3.ceda.ac.uk/thredds/dodsC/esg_cmip6/CMIP6/CMIP/MOHC/UKESM1-0-LL/historical/r1i1p1f2/Amon/tas/gn/v20190406/tas_Amon_UKESM1-0-LL_historical_r1i1p1f2_gn_185001-194912.nc\"\n",
"# )\n",
Expand Down Expand Up @@ -495,7 +482,7 @@
"metadata": {},
"outputs": [],
"source": [
"remap_cdo = Cdo().remapbil(\"EUR-11_grid.nc\", input=ds.isel(time=0), returnXArray=\"tas\")\n",
"remap_cdo = Cdo().remapbil(\"EUR-11_grid.nc\", input=ds, returnXArray=\"orog\")\n",
"remap_cdo"
]
},
Expand All @@ -505,7 +492,7 @@
"metadata": {},
"outputs": [],
"source": [
"(remap_cdo - 273.5).plot()"
"remap_cdo.plot()"
]
},
{
Expand Down Expand Up @@ -547,7 +534,7 @@
"metadata": {},
"outputs": [],
"source": [
"remap_xe = regridder(ds.tas.isel(time=0))"
"remap_xe = regridder(ds.orog)"
]
},
{
Expand All @@ -556,7 +543,7 @@
"metadata": {},
"outputs": [],
"source": [
"(remap_xe - 273.5).plot()"
"remap_xe.plot()"
]
},
{
Expand Down Expand Up @@ -585,7 +572,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -599,7 +586,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 88f7755

Please sign in to comment.