Skip to content

Instantly share code, notes, and snippets.

@seumasmorrison
Created August 27, 2015 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seumasmorrison/b244990dbf60a568dea0 to your computer and use it in GitHub Desktop.
Save seumasmorrison/b244990dbf60a568dea0 to your computer and use it in GitHub Desktop.
Notebook for reading David's Matlab .mat time series of significant wave height and mean period and converting into a time indexed Pandas DataFrame
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import scipy.io as io"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"C:\\Users\\le12jm\\Downloads\n"
]
}
],
"source": [
"cd C://Users//le12jm//Downloads"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Volume in drive C is Windows\n",
" Volume Serial Number is FCEA-3AC0\n",
"\n",
" Directory of C:\\Users\\le12jm\\Downloads\n",
"\n",
"26/08/2015 09:29 71,725 BragarTS.mat\n",
"26/08/2015 09:29 99,387 SiadarTS.mat\n",
" 2 File(s) 171,112 bytes\n",
" 0 Dir(s) 190,927,060,992 bytes free\n"
]
}
],
"source": [
"ls *.mat"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"bragar_ts_dict = io.loadmat('BragarTS.mat')\n",
"siadar_ts_dict = io.loadmat('SiadarTS.mat')"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bragar_timestamps_strings = bragar_ts_dict.items()[0][1]\n",
"siadar_timestamps_strings = siadar_ts_dict.items()[0][1]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def strings_to_timestamps(timestamps_strings):\n",
" timestamps = []\n",
" for timestamp in timestamps_strings:\n",
" timestamps.append(datetime.strptime(timestamp,\"%d-%b-%Y %H:%M:%S\"))\n",
" return timestamps\n",
"bragar_timestamps = strings_to_timestamps(bragar_timestamps_strings)\n",
"siadar_timestamps = strings_to_timestamps(siadar_timestamps_strings)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bragar_datetimeindex = pd.DatetimeIndex(bragar_timestamps)\n",
"siadar_datetimeindex = pd.DatetimeIndex(siadar_timestamps)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bragar_df = pd.DataFrame(bragar_ts_dict.items()[1][1], index = bragar_datetimeindex)\n",
"siadar_df = pd.DataFrame(siadar_ts_dict.items()[1][1], index = siadar_datetimeindex)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bragar_df.columns = ['Hm0','mean_period']\n",
"siadar_df.columns = ['Hm0','mean_period']"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bragar_df.to_pickle('Bragar_Hm0_mean_period')\n",
"siadar_df.to_pickle('Siadar_Hm0_mean_period')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment