for k in range(c): t=254/(c)*(k) color=r,s,t rgbcolors.append(color) hexcolor=[] for i in rgbcolors: hexcolor.append('#%02x%02x%02x' % i) return hexcolor polygon=[(gbox[0],gbox[2]),(gbox[0],gbox[3]),(gbox[1],gbox[3]),(gbox[1],gbox[2])] #set polygon if id==[]: time,ids,lats,lons=getobs_drift_byrange(gbox,input_time) mymap = basemap_xu.maps(np.mean(lats), np.mean(lons), 12) #set center point of the map id=list(set(ids)) colors=hexcolors(len(id)) #get hex colors,like '00FF00' for k in range(len(id)): time,ids,lat,lon=getobs_drift_byid(id[k],input_time) # get data by id for z in range(len(lat)): # make plotting drifter start in gbox inside=point_in_poly(lon[z],lat[z],polygon) if inside == True: break if z>1: lat=lat[0:z-1] #get rid of drifters which start from the polygon lon=lon[0:z-1] time=time[0:z-1] path=[] #set path, point for i in range(len(lat)): path.append((lat[i],lon[i])) #mymap.addpoint(lat[i],lon[i],colors[k]) title='id:'+str(id[k])+' time on this point:'+time[0].strftime('%d-%m-%Y %H:%M') #title='id:'+str(id[k])+'\n starttime'+time[0].strftime('%d-%m-%Y %H:%M') mymap.addpoint(lat[0],lon[0], colors[k],title) #plot them
gbox=[-70.0,-72.0,42.0,40.0] # maxlon, minlon,maxlat,minlat id=[135410701] # id list, if you are not clear dedicated id, let id=[] '125450842''125450841' #↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑Input values↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑# f = open(str(gbox[3])+'.dat', 'w') # create file and name it f.writelines('id'+' '+'lat '+' lon '+' time'+' \n') if id==[]: time,ids,lat,lon=getobs_drift_byrange(gbox,input_time) #get and organize data for k in range(len(ids)): # write them f.writelines(str(ids[k])+' '+'%10.2f' % lat[k]+' '+'%10.2f' % lon[k]+' '+' '\ +str(time[k].strftime('%Y-%m-%d %H:%M:%S'))+'\n') else: for q in range(len(id)): time,ids,lat,lon=getobs_drift_byid(id[q],input_time) #get and organize data for k in range(len(ids)): #write them f.writelines(str(ids[k])+' '+'%10.2f' % lat[k]+' '+'%10.2f' % lon[k]+' '+' '\ +str(time[k].strftime('%Y-%m-%d %H:%M:%S'))+'\n') f.close() ''' fig = plt.figure() ax = fig.add_subplot(111) plt.title(str(time[0].strftime("%d-%b-%Y %H"))+'h') lat_wanted=lat[-1] lon_wanted=lon[-1] plt.plot(lon_wanted,lat_wanted,'.',markersize=30,color='r',label='end')
path=[] for i in range(len(lat)): path.append((lat[i],lon[i])) mymap.addpoint(lat[i],lon[i],'black') #mymap.addradpoint(drifter_data[lat][0],drifter_data[1][0], 95, "#FF0000","my-location") mymap.addradpoint(lat[0],lon[0], 295, "red") mymap.addradpoint(lat[-1],lon[-1], 295, "blue") mymap.addpath(path,rgbcolors[k])#00FF00 #mymap.coloricon #mymap.getcycle #mymap.zoom #mymap.setgrids(37.42, 43.43, 0.1, -70.15, -60.14, 0.1) else: rgbcolors=colors(len(id)) for m in range(len(id)): time,ids,lat,lon=getobs_drift_byid(id[m],input_time) mymap = pygmaps.maps(np.mean(lat), np.mean(lon), 12) path=[] for i in range(len(lat)): path.append((lat[i],lon[i])) #mymap.addpoint(lat[i],lon[i],'black') #mymap.addradpoint(drifter_data[lat][0],drifter_data[1][0], 95, "#FF0000","my-location") mymap.addradpoint(lat[0],lon[0], 295, "red") mymap.addradpoint(lat[-1],lon[-1], 295, "blue") mymap.addpath(path,[50, 50, 0.0])#00FF00 mymap.draw('./mymap.html')
plot_getsst(ask_input,utc,sorted(gbox)) # get sst data and polt it if id==[]: time,ids,lats,lons=getobs_drift_byrange(gbox,input_time) id=list(set(ids)) rgbcolors=colors(len(id)) # set different colors to different drifter for k in range(len(id)): time,ids,lat_d,lon_d=getobs_drift_byidrange(id[k],gbox,input_time) #get drifters' data plt.plot(lon_d[0],lat_d[0],'.',markersize=30,color=rgbcolors[k+1],label=str(id[k])) plt.plot(np.reshape(lon_d,np.size(lon_d)),np.reshape(lat_d,np.size(lat_d)),color=rgbcolors[k+1]) #plot else: lats,lons=[],[] rgbcolors=colors(len(id)) # set different colors to different drifter for m in range(len(id)): time,ids,lat_d,lon_d=getobs_drift_byid(id[m],input_time) #get drifters' data by id plt.plot(lon_d[0],lat_d[0],'.',markersize=30,color=rgbcolors[m+1],label=str(id[m])) plt.plot(np.reshape(lon_d,np.size(lon_d)),np.reshape(lat_d,np.size(lat_d)),color=rgbcolors[m+1]) for n in range(len(lat_d)): lats.append(lat_d[n]) lons.append(lon_d[n]) plt.title(str(time[0].strftime("%d-%b-%Y %H"))+'h') pylab.ylim([sorted(gbox)[2]+0.01,sorted(gbox)[3]-0.01]) # set range area . pylab.xlim([sorted(gbox)[0]+0.01,sorted(gbox)[1]-0.01]) #pylab.ylim([min(lats)-(max(lats)-min(lats))/6.0,max(lats)+(max(lats)-min(lats))/6.0]) #pylab.xlim([min(lons)-(max(lons)-min(lons))/6.0,max(lons)+(max(lons)-min(lons))/6.0]) #ax.patch.set_facecolor('lightblue') #set background color bathy=True region='wv' # set basemap