Created
March 26, 2014 01:51
-
-
Save spmls/9775500 to your computer and use it in GitHub Desktop.
Plotting up a transect of water level points measured in out West study area of Fire Island (Sept 2013 fieldwork)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "metadata": { | |
| "name": "Fire Island West points" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "%matplotlib inline\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.basemap import Basemap, pyproj\nfrom shapely.geometry import LineString\nfrom math import sqrt\nimport plotly\np = plotly.plotly('spml', '7g0nbc0nfp')", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 11 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "fname = 'fi13_groin_nov12.xls'\ndata = pd.read_excel(fname,'points',index_col = 0)", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 2 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "topo = []\nfor i in data.index:\n if data.loc[i]['type'] == 'topo':\n topo.append([data.loc[i]['easting'],data.loc[i]['northing'],data.loc[i]['elev']])\ntopo = np.asarray(topo)\n\nwl = []\nfor i in data.index:\n if data.loc[i]['type'] == 'wl':\n wl.append([data.loc[i]['easting'],data.loc[i]['northing'],data.loc[i]['elev']])\nwl = np.asarray(wl)", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 3 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "x0, y0 = 654920, 4500745\nx1, y1 = 654945, 4500733\nx2, y2 = 654978, 4500752\n\nline_p = {'x':[x0,x1,x2],'y':[y0,y1,y2],\n 'line': {'color': 'red'},\n 'name':'Line to interpolate onto'}\ntopo_p = {'x':topo[:,0],'y':topo[:,1],\n 'type':'scatter',\n 'mode': 'markers',\n 'marker': {'color': 'black'},\n 'name':'topo [m]',\n 'text': topo[:,2]}\nwater_p = {'x':wl[:,0],'y':wl[:,1],\n 'type':'scatter',\n 'mode': 'markers',\n 'marker': {'color': 'blue'},\n 'name':'waterlevel [m]',\n 'text':wl[:,2]}\n\nlayout = { 'hovermode':'closest','title':'click-drag to zoom-in<br>double-click to zoom-out',\\\n'xaxis':{'showticklabels':True,'ticks':'','linecolor':'white','showgrid':True,'zeroline':False, 'title':'easting [m]'},\\\n'yaxis':{'showticklabels':True,'ticks':'','linecolor':'white','showgrid':True,'zeroline':False, 'title':'northing [m]'},\\\n'title':'Map of West field site on Fire Island'}\n\np.iplot([line_p,topo_p, water_p], layout=layout)", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "html": "<iframe height=\"550\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~spml/38\" width=\"100%\"></iframe>", | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 47, | |
| "text": "<IPython.core.display.HTML at 0x77995c0>" | |
| } | |
| ], | |
| "prompt_number": 47 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "left_seg_dist = int(sqrt((x1-x0)**2 + (y1-y0)**2))\nright_seg_dist = int(sqrt((x2-x1)**2 + (y2-y0)**2))\n\nleft_seg_x, left_seg_y = np.linspace(x0,x1,left_seg_dist), np.linspace(y0,y1,left_seg_dist)\nright_seg_x, right_seg_y = np.linspace(x1,x2,right_seg_dist), np.linspace(y1,y2,right_seg_dist)\n\ntransect = []\nfor i in range(0, np.size(left_seg_x)):\n transect.append((left_seg_x[i],left_seg_y[i]))\nfor i in range(0, np.size(right_seg_x)):\n transect.append((right_seg_x[i],right_seg_y[i]))", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 30 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "def point2distanceonline(x,y,line):\n \n # distances from point to line\n distances = [sqrt((x-i[0])**2 + (y-i[1])**2) for i in line] \n \n # distances along line segment\n last = int(np.size(transect)/2 -1)\n line_seg_distances = [sqrt((line[i+1][0]-line[i][0])**2 + (line[i+1][1]-line[i][1])**2) for i in range(0, last)] \n cumsum_distances = np.zeros_like(distances)\n cumsum_distances[1:] = np.cumsum(line_seg_distances)\n \n # distance along line segment where point projects\n idx = np.where(distances == np.min(distances))[0][0]\n distance = cumsum_distances[idx]\n \n return distance", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 34 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "topo_transect = [(point2distanceonline(topo[i,0],topo[i,1],transect),topo[i,2]) for i in range(0,np.size(topo[:,0]))]\nwl_transect = [(point2distanceonline(wl[i,0],wl[i,1],transect),wl[i,2]) for i in range(0,np.size(wl[:,0]))] ", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 50 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "topo_transect = np.sort(topo_transect, axis = 0)\nwl_transect = np.sort(wl_transect, axis = 0)", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 53 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "topo_p = {'x':topo_transect[:,0],'y':topo_transect[:,1],\n 'type':'scatter',\n 'mode':'lines+markers',\n 'line': {'color': 'black'},\n 'marker': {'color': 'black'},\n 'name':'topography'}\nwl_p = {'x':wl_transect[:,0],'y':wl_transect[:,1],\n 'type': 'scatter',\n 'mode':'lines+markers',\n 'line': {'color': 'blue'},\n 'marker': {'color': 'blue'},\n 'name':'water level'}\n\nlayout = { 'hovermode':'closest','title':'measured water level markers',\\\n'xaxis':{'showticklabels':True,'ticks':'','linecolor':'white','showgrid':True,'zeroline':False, 'title':'distance E -> W [m]'},\\\n'yaxis':{'showticklabels':True,'ticks':'','linecolor':'white','showgrid':True,'zeroline':False, 'title':'elevation above NAVD88 [m]'}}\n\np.iplot([topo_p,wl_p], layout = layout)", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "html": "<iframe height=\"550\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~spml/49\" width=\"100%\"></iframe>", | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 66, | |
| "text": "<IPython.core.display.HTML at 0x77e74a8>" | |
| } | |
| ], | |
| "prompt_number": 66 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": "", | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment