Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.10 KB | None | 0 0
  1. {
  2. "worksheets": [
  3. {
  4. "cells": [
  5. {
  6. "metadata": {},
  7. "cell_type": "code",
  8. "input": "import os",
  9. "prompt_number": 5,
  10. "outputs": [],
  11. "language": "python",
  12. "trusted": false,
  13. "collapsed": false
  14. },
  15. {
  16. "metadata": {},
  17. "cell_type": "code",
  18. "input": "%matplotlib inline\nfrom matplotlib import pyplot as plt",
  19. "prompt_number": 6,
  20. "outputs": [],
  21. "language": "python",
  22. "trusted": false,
  23. "collapsed": false
  24. },
  25. {
  26. "metadata": {},
  27. "cell_type": "heading",
  28. "source": "reading the SPEArTC Dataset in Matlab Format",
  29. "level": 1
  30. },
  31. {
  32. "metadata": {},
  33. "cell_type": "markdown",
  34. "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 "
  35. },
  36. {
  37. "metadata": {},
  38. "cell_type": "code",
  39. "input": "import os\nimport pandas as pd\nimport numpy as np\nfrom datetime import datetime",
  40. "prompt_number": 61,
  41. "outputs": [],
  42. "language": "python",
  43. "trusted": false,
  44. "collapsed": false
  45. },
  46. {
  47. "metadata": {},
  48. "cell_type": "code",
  49. "input": "dpath = os.path.expanduser('~/data/speartc/')",
  50. "prompt_number": 10,
  51. "outputs": [],
  52. "language": "python",
  53. "trusted": false,
  54. "collapsed": false
  55. },
  56. {
  57. "metadata": {},
  58. "cell_type": "code",
  59. "input": "from scipy.io.matlab import whosmat, loadmat",
  60. "prompt_number": 11,
  61. "outputs": [],
  62. "language": "python",
  63. "trusted": false,
  64. "collapsed": false
  65. },
  66. {
  67. "metadata": {},
  68. "cell_type": "code",
  69. "input": "data = loadmat(os.path.join(dpath, 'speartc_January_2014-REV-A.mat'), struct_as_record=False)",
  70. "prompt_number": 45,
  71. "outputs": [],
  72. "language": "python",
  73. "trusted": false,
  74. "collapsed": false
  75. },
  76. {
  77. "metadata": {},
  78. "cell_type": "code",
  79. "input": "data = data['TC'][0]",
  80. "prompt_number": 59,
  81. "outputs": [],
  82. "language": "python",
  83. "trusted": false,
  84. "collapsed": false
  85. },
  86. {
  87. "metadata": {},
  88. "cell_type": "code",
  89. "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",
  90. "prompt_number": 62,
  91. "outputs": [],
  92. "language": "python",
  93. "trusted": false,
  94. "collapsed": false
  95. },
  96. {
  97. "metadata": {},
  98. "cell_type": "code",
  99. "input": "dfp = pd.concat(df)",
  100. "prompt_number": 63,
  101. "outputs": [],
  102. "language": "python",
  103. "trusted": false,
  104. "collapsed": false
  105. },
  106. {
  107. "metadata": {},
  108. "cell_type": "code",
  109. "input": "dfp.tail()",
  110. "prompt_number": 65,
  111. "outputs": [
  112. {
  113. "output_type": "pyout",
  114. "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>",
  115. "metadata": {},
  116. "prompt_number": 65,
  117. "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 "
  118. }
  119. ],
  120. "language": "python",
  121. "trusted": false,
  122. "collapsed": false
  123. },
  124. {
  125. "metadata": {},
  126. "cell_type": "code",
  127. "input": "dfp.to_csv('/Users/nicolasf/operational/ICU/TC_guidance/data/spearTC_data_1969_2013.csv')",
  128. "prompt_number": 173,
  129. "outputs": [],
  130. "language": "python",
  131. "trusted": false,
  132. "collapsed": false
  133. }
  134. ],
  135. "metadata": {}
  136. }
  137. ],
  138. "metadata": {
  139. "name": "",
  140. "signature": "sha256:b1e0cfb57b3f0cb36a28c1bff443a23d57dddb62c2e709067940470443e1d735"
  141. },
  142. "nbformat": 3
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement