Skip to content

Instantly share code, notes, and snippets.

@psigen
Created August 25, 2016 17:03
Show Gist options
  • Save psigen/3010ca245c198b1aa90e32ca703879e8 to your computer and use it in GitHub Desktop.
Save psigen/3010ca245c198b1aa90e32ca703879e8 to your computer and use it in GitHub Desktop.
Exporting logfile data to CSV.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas\n",
"import platypus.io.logs"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Import the data from the specified logfile\n",
"log_filename = '../tests/platypus/io/platypus_20160519_013623.txt'\n",
"data = platypus.io.logs.load(log_filename)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Extract position of boat and remove duplicate entries.\n",
"data[\"pose\"][\"time\"] = data[\"pose\"].index\n",
"position = data['pose'][['time', 'latitude', 'longitude']].drop_duplicates(subset='time', keep='first')\n",
"position = position[['latitude', 'longitude']] # remove unneeded time column after de-duplication\n",
"\n",
"# Put together all the sensor data we are looking for.\n",
"sensor_frames = data['ATLAS_DO'], data['ES2'], data['ATLAS_PH']\n",
"sensor_data = pandas.concat(sensor_frames, axis=1)\n",
"\n",
"# Find the position for each sensor reading.\n",
"sensor_position = position.reindex(sensor_data.index, method='nearest')\n",
"output = pandas.concat((sensor_position, sensor_data), axis=1)\n",
"\n",
"# Fill in missing values with last known values.\n",
"output = output.apply(pandas.Series.interpolate, method='nearest')\n",
"output['time'] = output.index.astype(np.int64)\n",
"output.to_csv('out.csv', index=False,\n",
" columns=('time', 'latitude', 'longitude', 'do', 'ec', 't', 'ph'))"
]
},
{
"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