-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance_analysis.py
107 lines (96 loc) · 4.42 KB
/
distance_analysis.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 Mon Jun 06 15:38:26 2016
@author: siirias
"""
import numpy as np
import sys
import matplotlib.pyplot as plt
hsp=[33,45,67,98,116,134,186]
#print lats[hsp],lons[hsp]
def draw_map(lats,lons,hsp):
try:
plt.close(fig)
except:
fir=None
fig=plt.figure(figsize=(8,12))
plt.clf()
bmap = Basemap(llcrnrlon=18,llcrnrlat=55,urcrnrlon=21,urcrnrlat=59, resolution = 'i')
bmap.drawcoastlines()
bmap.fillcontinents()
bmap.drawparallels(np.arange(50.,69,1.),labels=[1,0,0,0],linewidth=0)
bmap.drawmeridians(np.arange(12.,30,1.),labels=[0,0,0,1],linewidth=0)
x,y=bmap(a1.obs['ape']['lon'][:],a1.obs['ape']['lat'][:])
bmap.plot(x,y,'k-',linewidth=2)
x,y=bmap(a2.obs['ape']['lon'][:],a2.obs['ape']['lat'][:])
bmap.plot(x,y,'k-',linewidth=2)
x,y=bmap(a3.obs['ape']['lon'][:],a3.obs['ape']['lat'][:])
bmap.plot(x,y,'k-',linewidth=2)
for i in hsp:
x,y=bmap(lons[i],lats[i])
plt.plot(x,y,'ro',markersize=15,alpha=0.8)
#plt.text(x-0.3,y+0.0,'{}'.format(i),color='blue')
#sys.exit("")
print "Calculating distances"
avg_distances=[]
points=195
max_dist=100
dist_under=np.zeros((points,max_dist))
for i in range(points):
(time,dist,lats,lons)=plot_full_distance(ref_is_no=i,vmin=0,vmax=160)
avg_distances.append(np.mean(dist))
for d in range(max_dist):
for j in range(points):
if(d>dist[j]):
dist_under[i,d]+=1
plt.plot([time[i],time[i]],[plt.ylim()[0],plt.ylim()[1]] \
,color="#ff0000",linewidth=3)
save_file="distances_{:03}.png".format(i)
plt.savefig(save_file,dpi=120)
if(dist_under[i,20]>20):
print lats[i],lons[i],dist_under[i,20]
print "Drawing nearby points"
target_distance=20
for i in range(points):
DT=mp.dates.num2date(time[i])
date_str="{:04}{:02}{:02}".format(DT.year,DT.month,DT.day)
plt.close();plt.clf()
plot_full_data(new_fig=True,ref_point=(lats[i],lons[i]), ref_dist=target_distance,time_highlight=date_str ,value="salt", vmin=11,vmax=13,tmin=735600,tmax=735850)
save_file="Salt_cut_dist_{:02}_{:03}.png".format(target_distance,i)
plt.savefig(save_file,dpi=120)
plt.close();plt.clf()
plot_full_data(new_fig=True,ref_point=(lats[i],lons[i]), ref_dist=target_distance,time_highlight=date_str, high_no=i,value="temp")
save_file="Temp_cut_dist_{:02}_{:03}.png".format(target_distance,i)
plt.savefig(save_file,dpi=120)
plt.close();plt.clf()
plot_full_data(new_fig=True,ref_point=(lats[i],lons[i]), ref_dist=target_distance,time_highlight=date_str, high_no=i,value="oxygen", vmin=0,vmax=50,tmin=735600,tmax=735850)
save_file="Oxygen_cut_dist_{:02}_{:03}.png".format(target_distance,i)
plt.savefig(save_file,dpi=120)
print "distance figure"
for i in range(points):
plt.clf()
plt.plot(time,dist_under[:,10],'g')
plt.plot(time,dist_under[:,20],'y')
plt.plot(time,dist_under[:,40],'r')
plt.fill_between(time,dist_under[:,20],dist_under[:,40],facecolor='r')
plt.fill_between(time,dist_under[:,10],dist_under[:,20],facecolor='y')
plt.fill_between(time,time*0.0,dist_under[:,10],facecolor='g')
locs,labels = plt.xticks()
plt.gca().xaxis.set_major_locator(mp.dates.MonthLocator(range(1,12,2)))
plt.gca().xaxis.set_major_formatter(mp.dates.DateFormatter('%m-%y'))
plt.setp(labels,rotation=45)
plt.ylim((0,points))
plt.yticks(range(0,points,20))
plt.ylabel("Profiles closer than")
plt.xlabel("Time")
plt.legend(['10 km','20 km','40 km'])
# plt.plot([time[i],time[i]],[plt.ylim()[0],plt.ylim()[1]],color="#ff0000",linewidth=3)
marker_time=mp.dates.date2num(datetime.datetime.strptime("20140821","%Y%m%d"))
plt.plot([marker_time,marker_time],[plt.ylim()[0],plt.ylim()[1]],color="#888888",linewidth=3)
marker_time=mp.dates.date2num(datetime.datetime.strptime("20150805","%Y%m%d"))
plt.plot([marker_time,marker_time],[plt.ylim()[0],plt.ylim()[1]],color="#888888",linewidth=3)
save_file="Distances_{:03}.png".format(i)
plt.savefig(save_file,dpi=120)
#plt.figure(figsize=(10,15));plot_full_data(value='oxygen',vmin=0,vmax=50,tmin=735600,tmax=735850)
#plt.figure(figsize=(10,15));plot_full_data(value='salt',vmin=11,vmax=13,tmin=735600,tmax=735850)
#Hot SPOTS