{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nLoad station data based on NetCDF files\n=======================================\n\nIn this example we show how to load station data based on NetCDF files.\nThe data is loaded with the pymepps package. Thanks to Ingo Lange we\ncould use original data from the Wettermast for this example. In the\nfollowing the data is loaded, plotted and saved as json file.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pymepps\nimport matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We could use the global pymepps open\\_station\\_dataset function to open\nthe Wettermast data. We have to specify the data path and the data type.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "wm_ds = pymepps.open_station_dataset('../data/station/wettermast.nc', 'nc')\n\nprint(wm_ds)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we could extract the temperature in 2 m height. For this we use the\nselect method of the resulted dataset.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "t2m = wm_ds.select('TT002_M10')\n\nprint(type(t2m))\nprint(t2m.describe())"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We could see that the resulting temperature is a normal pandas.Series.\nSo it is possible to use all pandas methods, e.g. plotting of the\nSeries.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "t2m.plot()\nplt.xlabel('Date')\nplt.ylabel('Temperature in \u00b0C')\nplt.title('Temperature at the Wettermast Hamburg')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Pymepps uses an accessor to extend the pandas functionality. The\naccessor could be accessed with Series.pp. At the moment there is only a\nlonlat attribute, update, save and load method defined, but it is\nplanned to expand the number of additional methods.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(t2m.pp.lonlat)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We could see that the logitude and latitude are None at the moment,\nbecause we haven't set the yet. We could either set them directly or set\nthe coordintes in the open\\_station\\_dataset function with the lonlat\nargument.\n\n"
      ]
    }
  ],
  "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": 0
}