forked from xhx509/sst
/
getsst_drifter_raw.py
107 lines (96 loc) · 4.45 KB
/
getsst_drifter_raw.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 21 13:42:41 2012
@author:huanxin
"""
##################################################
#from this project, you can get a picture of sst and drifter data. it could get
# input value from 3 options. (1)from contorl file,(2) from your raw_input
#(include date and file )
#in order to show start and end point clearly, we point them out on the picture
#input values: drifter number,filename, start time, time period
#output values: maxlon,minlon,maxlat,minlat,lat,lon
###################################################
import sys
import pytz
from matplotlib.dates import num2date,date2num
import matplotlib.pyplot as plt
import matplotlib.mlab as ml
import numpy as np
import datetime as dt
from hx import getcodar_ctl_file,plot_getsst,getdrift_raw
sys.path.append('/net/home3/ocn/jmanning/py/mygit/modules/')
from basemap import basemap_region
drifter='pro' #"processed" or "raw"
option='3'
def range_latlon(filename,driftnumber): # function neede in case of "raw" drifter date
d=ml.load(filename)
id=ml.find(d[:,0]==int(driftnumber))
lat1=d[id,8]
lon1=d[id,7]
maxlon=max(lon1)
minlon=min(lon1)
maxlat=max(lat1)
minlat=min(lat1)
return maxlon,minlon,maxlat,minlat,lat1,lon1
utc = pytz.timezone('UTC')
png_num=0 #for save picture
#option=raw_input("If you have a file of column lat and lon,please input '1'\nIf you want to input points' location, please input '2'\n"
#"If you want to use the control file,please input '3'\n")
if option=='3':
inputfilename='getcodar_bydrifter_ctl.txt' #default control file
(datetime_wanted,filename,driftnumber,url,model_option,num,interval_dtime,interval,step_size)=getcodar_ctl_file(inputfilename)
if drifter=='raw':
maxlon,minlon,maxlat,minlat,lat,lon=range_latlon(filename,driftnumber)
else:
drifter_data=getdrift_raw(filename,driftnumber,interval,datetime_wanted) #uses pydap to get remote drifter data
lon=drifter_data['lon']
lat=drifter_data['lat']
maxlon=max(lon)
minlon=min(lon)
maxlat=max(lat)
minlat=min(lat)
if option=='2':
datetime_wanted=date2num(dt.datetime.strptime(raw_input("please input datetime you wanted, the format like: 2012,8,26,0,0\n"),'%Y,%m,%d,%H,%M'))
lat_list=raw_input("Please input points SW & NE latitude in order,and split them by ',':")
lon_list=raw_input("Please input points lon in order,and split them by ',':")
lat1=lat_list[0:].split(',')
lon1=lon_list[0:].split(',')
lat,lon=[],[]
for q in range(len(lon1)):
lat.append(float(lat1[q]))
lon.append(float(lon1[q]))
maxlon=max(lon1)
minlon=min(lon1)
maxlat=max(lat1)
minlat=min(lat1)
if option=='1':
datetime_wanted=date2num(dt.datetime.strptime(raw_input("please input datetime you wanted, the format like: 2012,8,26,0,0\n"),'%Y,%m,%d,%H,%M'))
filename=raw_input('Please input your file path and name:\n')
maxlon,minlon,maxlat,minlat,lat,lon=range_latlon(filename)
#make sure the picture can show lat and lon clearly
if maxlat-minlat<=0.1:
maxlat=maxlat+0.01
minlat=minlat-0.01
if maxlon-minlon<=0.1:
maxlon=maxlon+0.01
minlon=minlon-0.01
gbox=[minlon-1.0,maxlon+1.0, minlat-0.03, maxlat+0.03] # get edge for get sst
for x in range(num):
ask_input=num2date(datetime_wanted) #get time for getsst
#plt.title(str(num2date(datetime_wanted).strftime("%d-%b-%Y %H"))+'h')
plot_getsst(ask_input,utc,gbox)
lat_wanted=lat[-1]
lon_wanted=lon[-1]
#find wanted point lat,lon
#plt.plot(lon_wanted,lat_wanted,'.',markersize=30,color='m',label='end')
plt.plot(np.reshape(lon,np.size(lon)),np.reshape(lat,np.size(lat)),linewidth=3,color='black')
#plt.plot(lon[0],lat[0],'.',markersize=20,color='g',label='start') # start time
plt.annotate('start',xy=(lon[0],lat[0]),xytext=(lon[0]+(maxlon-minlon)/10,lat[0]+(maxlat-minlat)/10),color='white',arrowprops=dict(facecolor='white',frac=0.3, shrink=0.05))
plt.annotate('end',xy=(lon[-1],lat[-1]),xytext=(lon[-1]+(maxlon-minlon)/10,lat[-1]-(maxlat-minlat)/5),color='white',arrowprops=dict(facecolor='white',frac=0.3, shrink=0.05))
plt.title('Drifter '+driftnumber+' and '+ask_input.strftime('%d %b %Y')+' SST')
#basemap_standard([int(minlat),np.ceil(maxlat)],[int(minlon-1.5),np.ceil(maxlon)+1.0],2.0) #overrides xlim and ylims set previously
bathy=True
region='wv'
basemap_region(region)
plt.show()