Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "worksheets": [
- {
- "cells": [
- {
- "metadata": {},
- "cell_type": "code",
- "input": "import os",
- "prompt_number": 5,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "%matplotlib inline\nfrom matplotlib import pyplot as plt",
- "prompt_number": 6,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "heading",
- "source": "reading the SPEArTC Dataset in Matlab Format",
- "level": 1
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": "SPEArTC is now available in Matlab format as a structured array \n\nAfter loading the dataset (Matlab command: load speartc_January_2014) \nThe array will be available under the variable TC in a <1x1117> structure (there are 1117 \ntracks in the data set from 1840-2013) \n\n** The TC structured array has the following field variables:**\n- For i=1:1117 the (TC(i).fields are as follows: \n + TC(i).serial_number [unique TC serial number as decoded below] \n + TC(i).season [the 1969/70 season would be noted as 1970] \n + TC(i).number [storm number within a season] \n + TC(i).name [name of the storm] \n + TC(i).time(1:6) [a TC position point’s time as follows as 6 distinct sub-fields] \n + year \n + month \n + day \n + hour \n + minute \n + second \n- TC(i).pos [position – latitude and longitude at that point) \n- TC(i).speed (maximum sustained wind speed at that point) \n- TC(i).press (central pressure at that point) \n- TC(i).maxspd (maximum wind speed over the entire life of the TC) \n- TC(i).len (number of points in a TC’s track) \n\n**SPEArTC TC Serial Number Decoding**: \nNNNNJJJHYYXXX \n- NNNN: year that storm has an initial data point \n- JJJ: Julian Day that the storm has an initial data point \n- H: Hemisphere (all TCs in the SPEArTC dataset will be “S”) \n- YY: 2-digit latitude of first data point for a TC \n- XXX: 3-digit longitude of first data point for a TC "
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "import os\nimport pandas as pd\nimport numpy as np\nfrom datetime import datetime",
- "prompt_number": 61,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "dpath = os.path.expanduser('~/data/speartc/')",
- "prompt_number": 10,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "from scipy.io.matlab import whosmat, loadmat",
- "prompt_number": 11,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "data = loadmat(os.path.join(dpath, 'speartc_January_2014-REV-A.mat'), struct_as_record=False)",
- "prompt_number": 45,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "data = data['TC'][0]",
- "prompt_number": 59,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "df = []\nfor TC in data:\n # only saves the TC tracks for after 1969\n if min(TC.time[:,0]) >= 1969:\n dates = []\n for i in xrange(len(TC.time)): \n dates.append(datetime(*TC.time[i]))\n frame = pd.DataFrame(TC.press, index=dates, columns=['pressure'])\n frame.index.name = 'datetime'\n if len(TC.name) > 1: \n frame['name'] = [x[0] for x in TC.name.flatten()]\n else: \n frame['name'] = TC.name[0]\n frame['sn'] = [x[0][0] for x in TC.serial_number]\n frame['maxspd'] = TC.maxspd[0][0]\n frame['number'] = TC.number[0][0]\n frame['season'] = TC.season[0][0]\n frame['lat'] = TC.pos[0][0]\n frame['lon'] = TC.pos[0][1]\n frame['speed'] = TC.speed\n df.append(frame)\n else:\n pass",
- "prompt_number": 62,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "dfp = pd.concat(df)",
- "prompt_number": 63,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "dfp.tail()",
- "prompt_number": 65,
- "outputs": [
- {
- "output_type": "pyout",
- "html": "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>pressure</th>\n <th>name</th>\n <th>sn</th>\n <th>maxspd</th>\n <th>number</th>\n <th>season</th>\n <th>lat</th>\n <th>lon</th>\n <th>speed</th>\n </tr>\n <tr>\n <th>datetime</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2013-05-01 06:00:00</th>\n <td> 992</td>\n <td> ZANE</td>\n <td> 2013115S09153</td>\n <td> 60</td>\n <td> 8</td>\n <td> 2013</td>\n <td>-8.84</td>\n <td> 152.86</td>\n <td> 50</td>\n </tr>\n <tr>\n <th>2013-05-01 09:00:00</th>\n <td> 996</td>\n <td> ZANE</td>\n <td> 2013115S09153</td>\n <td> 60</td>\n <td> 8</td>\n <td> 2013</td>\n <td>-8.84</td>\n <td> 152.86</td>\n <td> 45</td>\n </tr>\n <tr>\n <th>2013-05-01 12:00:00</th>\n <td> 993</td>\n <td> ZANE</td>\n <td> 2013115S09153</td>\n <td> 60</td>\n <td> 8</td>\n <td> 2013</td>\n <td>-8.84</td>\n <td> 152.86</td>\n <td> 45</td>\n </tr>\n <tr>\n <th>2013-05-01 15:00:00</th>\n <td> 999</td>\n <td> ZANE</td>\n <td> 2013115S09153</td>\n <td> 60</td>\n <td> 8</td>\n <td> 2013</td>\n <td>-8.84</td>\n <td> 152.86</td>\n <td> 35</td>\n </tr>\n <tr>\n <th>2013-05-01 17:00:00</th>\n <td> 1001</td>\n <td> ZANE</td>\n <td> 2013115S09153</td>\n <td> 60</td>\n <td> 8</td>\n <td> 2013</td>\n <td>-8.84</td>\n <td> 152.86</td>\n <td> 30</td>\n </tr>\n </tbody>\n</table>\n</div>",
- "metadata": {},
- "prompt_number": 65,
- "text": " pressure name sn maxspd number season \\\ndatetime \n2013-05-01 06:00:00 992 ZANE 2013115S09153 60 8 2013 \n2013-05-01 09:00:00 996 ZANE 2013115S09153 60 8 2013 \n2013-05-01 12:00:00 993 ZANE 2013115S09153 60 8 2013 \n2013-05-01 15:00:00 999 ZANE 2013115S09153 60 8 2013 \n2013-05-01 17:00:00 1001 ZANE 2013115S09153 60 8 2013 \n\n lat lon speed \ndatetime \n2013-05-01 06:00:00 -8.84 152.86 50 \n2013-05-01 09:00:00 -8.84 152.86 45 \n2013-05-01 12:00:00 -8.84 152.86 45 \n2013-05-01 15:00:00 -8.84 152.86 35 \n2013-05-01 17:00:00 -8.84 152.86 30 "
- }
- ],
- "language": "python",
- "trusted": false,
- "collapsed": false
- },
- {
- "metadata": {},
- "cell_type": "code",
- "input": "dfp.to_csv('/Users/nicolasf/operational/ICU/TC_guidance/data/spearTC_data_1969_2013.csv')",
- "prompt_number": 173,
- "outputs": [],
- "language": "python",
- "trusted": false,
- "collapsed": false
- }
- ],
- "metadata": {}
- }
- ],
- "metadata": {
- "name": "",
- "signature": "sha256:b1e0cfb57b3f0cb36a28c1bff443a23d57dddb62c2e709067940470443e1d735"
- },
- "nbformat": 3
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement