-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakegrid.py
More file actions
79 lines (71 loc) · 2.22 KB
/
makegrid.py
File metadata and controls
79 lines (71 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
# Routine to allow users to click on points and return lat,lon lists
# Jim Manning Nov 2014
import sys
from decimal import *
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from pylab import ginput
def basemap_region(region):
path="" # Y:/bathy/"#give the path if these data files are store elsewhere
#if give the region, choose the filename
if region=='sne':
filename='sne_coast.dat'
if region=='cc':
filename='capecod_outline.dat'
if region=='bh':
filename='bostonharbor_coast.dat'
if region=='cb':
filename='cascobay_coast.dat'
if region=='pb':
filename='penbay_coast.dat'
if region=='ma': # mid-atlantic
filename='necscoast_noaa.dat'
if region=='ne': # northeast
filename='necoast_noaa.dat'
if region=='wv': # world vec
filename='necscoast_worldvec.dat'
#open the data
f=open(path+filename)
lon,lat=[],[]
for line in f:#read the lat, lon
lon.append(line.split()[0])
lat.append(line.split()[1])
nan_location=[]
# plot the lat,lon between the "nan"
for i in range(len(lon)):#find "nan" location
if lon[i]=="nan":
nan_location.append(i)
for m in range(1,len(nan_location)):#plot the lat,lon between nan
lon_plot,lat_plot=[],[]
for k in range(nan_location[m-1],nan_location[m]):
lat_plot.append(lat[k])
lon_plot.append(lon[k])
plt.plot(lon_plot,lat_plot,'r')
def clickmap(n):
# this allows users to click on a rough map and define lat/lon points
# where "n" is the number of points
fig=plt.figure()
basemap_region('cc')
pt=fig.ginput(n)
plt.close('all')
lon=list(zip(*pt)[0])
lat=list(zip(*pt)[1])
return lon,lat
def points_between(lat,lon,x):
"""
For 2 positions, interpolate X number of points between them
where "lat" and "lon" are two element list
"x" is the number of points wanted between them
returns lat0,lono
"""
print lat
lato=[]
lono=[]
lati=(lat[1]-lat[0])/float(x)
loni=(lon[1]-lon[0])/float(x)
for j in range(x):
lato.append(lat[0]+lati*j)
lono.append(lon[0]+loni*j)
return lato,lono