blob: 12bf8a64e5c505a5228c4acacf4fbcc65f142254 [file] [log] [blame]
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Flexible RCMES Workflow\n",
"\n",
"* Typical Steps:\n",
" * Load Datasets\n",
" * Temporal Regrids\n",
" * Spatial Regrids\n",
" * Evaluate Metrics\n",
" * Plot Results\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Make sure that OCW functions are available."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'functions'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-0a14eee734d6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmagic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'matplotlib inline'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mfunctions\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mloadDatasets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtemporalRebins\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcommonLatLonGrid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mspatialRegrids\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mfunctions\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mcomputeMetrics\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontourPlot\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmymap\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# def mymap(f, s): return map(f, s) # sequential single-core map function\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'functions'"
]
}
],
"source": [
"%matplotlib inline\n",
"from functions import loadDatasets, temporalRebins, commonLatLonGrid, spatialRegrids\n",
"from functions import computeMetrics, contourPlot, mymap\n",
"\n",
"# def mymap(f, s): return map(f, s) # sequential single-core map function"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load Reference Dataset and one or more Model Datasets"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "Missing parentheses in call to 'print' (<ipython-input-2-06a67660f049>, line 7)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-2-06a67660f049>\"\u001b[0;36m, line \u001b[0;32m7\u001b[0m\n\u001b[0;31m print datasets\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m Missing parentheses in call to 'print'\n"
]
}
],
"source": [
"path1 = \"/Users/bdwilson/Documents/code/RCMES/Workshop/AFRICA_UC-WRF311_CTL_ERAINT_MM_50km-rg_1989-2008_tasmax.nc\"\n",
"variable1 = \"tasmax\"\n",
"path2 = \"/Users/bdwilson/Documents/code/RCMES/Workshop/AFRICA_KNMI-RACMO2.2b_CTL_ERAINT_MM_50km_1989-2008_tasmax.nc\"\n",
"variable2 = \"tasmax\"\n",
"\n",
"datasets = loadDatasets([(path1, variable1), (path2, variable2)], dir='./')\n",
"print datasets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Temporal Rebin"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ocw.dataset_processor as dsp\n",
"from datetime import timedelta\n",
"\n",
"timeRes=timedelta(days=365)\n",
"datasets = temporalRebins(datasets, timeRes)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Spatial Regrid"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"latRes = 1.0 # degrees\n",
"lonRes = 1.0 # degrees\n",
"lats, lons = commonLatLonGrid(datasets, latRes, lonRes)\n",
"# Find common spatial bounds, return desired grid with specified resolution\n",
"\n",
"datasets = spatialRegrids(datasets, lats, lons)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Compute Metric(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"metricNames = ['Bias']\n",
"results = computeMetrics(datasets, metricNames, subregions=None)\n",
"bias = results[0][0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot Bias between two models as time-series of contour maps"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"outputName = \"wrf_bias_compared_to_knm\"\n",
"config = {'gridshape': (4, 5),\n",
" 'ptitle': 'TASMAX Bias of WRF Compared to KNMI (1989 - 2008)',\n",
" 'subtitles': range(1989, 2009, 1)\n",
" }\n",
"\n",
"plotFile = contourPlot(bias, lats, lons, outputName, **config)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image, display\n",
"\n",
"display(Image(plotFile))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}