Example #1
0
 def animate(
         n
 ):  #del ax.collections[:]; del ax.lines[:]; ax.cla();ax.clf()
     ax.cla()
     if streamline == 'ON':
         plt.streamplot(lonpps[n],
                        latpps[n],
                        US[n],
                        VS[n],
                        color=speeds[n],
                        arrowsize=4,
                        cmap=plt.cm.cool,
                        density=2.0)
     for j in range(stp_num):
         if n == 0:  #facecolor=colors[i]'''
             ax.annotate('Start %d' % (j + 1),
                         xy=(lon_set[j][0], lat_set[j][0]),
                         xytext=(lon_set[j][0] + 0.01 * stp_num,
                                 lat_set[j][0] + 0.01 * stp_num),
                         fontsize=6,
                         arrowprops=dict(arrowstyle="fancy"))
         if n < len(lon_set[j]):  #markerfacecolor='r',
             ax.plot(lon_set[j][:n + 1],
                     lat_set[j][:n + 1],
                     'o-',
                     color=colors[j],
                     markersize=4,
                     label='Start %d' % (j + 1))
     draw_basemap(ax, points)  # points is using here
Example #2
0
 def animate(n):  #del ax.collections[:]; del ax.lines[:]; ;
     ax.cla()
     draw_basemap(ax, points)  # points is using here
     for j in xrange(stp_num):
         ax.plot(lon_set[j][0],
                 lat_set[j][0],
                 color=colors[j],
                 marker='x',
                 markersize=4)
         if n >= len(lon_set[j]):
             ax.plot(lon_set[j][-1],
                     lat_set[j][-1],
                     'o',
                     color=colors[j],
                     markersize=5)
         if n < 5:
             if n < len(lon_set[j]):
                 ax.plot(lon_set[j][:n + 1],
                         lat_set[j][:n + 1],
                         'o-',
                         color=colors[j],
                         markersize=4)  #,label='Depth=10m'
         if n >= 5:
             if n < len(lon_set[j]):
                 ax.plot(lon_set[j][n - 4:n + 1],
                         lat_set[j][n - 4:n + 1],
                         'o-',
                         color=colors[j],
                         markersize=4)
Example #3
0
 def animate(n):  # del ax.collections[:]; del ax.lines[:]; ;
     ax.cla()
     if track_way == "backward":
         Time = (locstart_time - timedelta(hours=n)).strftime("%d-%b-%Y %H:%M")
     else:
         Time = (locstart_time + timedelta(hours=n)).strftime("%d-%b-%Y %H:%M")
     plt.suptitle(
         "%.f%% simulated drifters ashore\n%d days, %d m, %s" % (int(round(p)), track_days, depth, Time)
     )
     if streamline == "ON":
         plt.streamplot(
             lonpps[n], latpps[n], US[n], VS[n], color=speeds[n], arrowsize=4, cmap=plt.cm.cool, density=2.0
         )
     for j in xrange(stp_num):
         ax.plot(lon_set[j][0], lat_set[j][0], color=colors[j % 10], marker="x", markersize=4)
         if n >= len(lon_set[j]):
             ax.plot(lon_set[j][-1], lat_set[j][-1], "o", color=colors[j % 10], markersize=5)
         if n < 5:
             if n < len(lon_set[j]):
                 ax.plot(
                     lon_set[j][: n + 1], lat_set[j][: n + 1], "o-", color=colors[j % 10], markersize=4
                 )  # ,label='Depth=10m'
         if n >= 5:
             if n < len(lon_set[j]):
                 ax.plot(
                     lon_set[j][n - 4 : n + 1],
                     lat_set[j][n - 4 : n + 1],
                     "o-",
                     color=colors[j % 10],
                     markersize=4,
                 )
     draw_basemap(ax, points)  # points is using here
Example #4
0
 def animate(
         n
 ):  #del ax.collections[:]; del ax.lines[:]; ax.cla();ax.clf()
     ax.cla()
     ax.plot(drifter_points['lon'],
             drifter_points['lat'],
             'bo-',
             markersize=6,
             label='Drifter')
     if streamline == 'ON':
         plt.streamplot(lonpps[n],
                        latpps[n],
                        US[n],
                        VS[n],
                        color=speeds[n],
                        arrowsize=4,
                        cmap=plt.cm.cool,
                        density=2.0)
     if n == 0:  #facecolor=colors[i]'''
         ax.annotate(
             an2,
             xy=(dr_points['lon'][-1], dr_points['lat'][-1]),
             xytext=(dr_points['lon'][-1] + 0.01 * track_days,
                     dr_points['lat'][-1] + 0.01 * track_days),
             fontsize=6,
             arrowprops=dict(arrowstyle="fancy"))
     ax.plot(model_points['lon'][:n + 1],
             model_points['lat'][:n + 1],
             'ro-',
             markersize=6,
             label=MODEL)
     draw_basemap(ax, points)  # points is using here
Example #5
0
 def animate(n):  # del ax.collections[:]; del ax.lines[:]; ax.cla();ax.clf()
     ax.cla()
     if streamline == "ON":
         plt.streamplot(
             lonpps[n], latpps[n], US[n], VS[n], color=speeds[n], arrowsize=4, cmap=plt.cm.cool, density=2.0
         )
     for j in range(stp_num):
         if n == 0:  # facecolor=colors[i]'''
             ax.annotate(
                 "Start %d" % (j + 1),
                 xy=(lon_set[j][0], lat_set[j][0]),
                 xytext=(lon_set[j][0] + 0.01 * stp_num, lat_set[j][0] + 0.01 * stp_num),
                 fontsize=6,
                 arrowprops=dict(arrowstyle="fancy"),
             )
         if n < len(lon_set[j]):  # markerfacecolor='r',
             ax.plot(
                 lon_set[j][: n + 1],
                 lat_set[j][: n + 1],
                 "o-",
                 color=colors[j % 10],
                 markersize=4,
                 label="Start %d" % (j + 1),
             )
     draw_basemap(ax, points)  # points is using here
Example #6
0
 def animate(n): #del ax.collections[:]; del ax.lines[:]; ax.cla();ax.clf()
     ax.cla()
     ax.plot(drifter_points['lon'],drifter_points['lat'],'bo-',markersize=6,label='Drifter')
     if streamline == 'ON':
         plt.streamplot(lonpps[n],latpps[n],US[n],VS[n], color=speeds[n],arrowsize=4,cmap=plt.cm.cool,density=2.0)              
     if n==0:#facecolor=colors[i]'''
         ax.annotate(an2,xy=(dr_points['lon'][-1],dr_points['lat'][-1]),xytext=(dr_points['lon'][-1]+0.01*track_days,
                     dr_points['lat'][-1]+0.01*track_days),fontsize=6,arrowprops=dict(arrowstyle="fancy"))
     ax.plot(model_points['lon'][:n+1],model_points['lat'][:n+1],'ro-',markersize=6,label=MODEL)
     draw_basemap(ax, points)  # points is using here
Example #7
0
 def animate(n): #del ax.collections[:]; del ax.lines[:]; ;
     ax.cla()
     draw_basemap(ax, points)  # points is using here
     for j in xrange(stp_num):
         ax.plot(lon_set[j][0],lat_set[j][0],color=colors[j],marker='x',markersize=4)
         if n>=len(lon_set[j]):
             ax.plot(lon_set[j][-1],lat_set[j][-1],'o',color=colors[j],markersize=5)
         if n<5:                
             if n<len(lon_set[j]):
                 ax.plot(lon_set[j][:n+1],lat_set[j][:n+1],'o-',color=colors[j],markersize=4)#,label='Depth=10m'            
         if n>=5:
             if n<len(lon_set[j]):
                 ax.plot(lon_set[j][n-4:n+1],lat_set[j][n-4:n+1],'o-',color=colors[j],markersize=4)
 def animate(n): #del ax.collections[:]; del ax.lines[:]; ;
     ax.cla()  
     if track_way=='backward':
         Time = (locstart_time-timedelta(hours=n)).strftime("%d-%b-%Y %H:%M")
     else:
         Time = (locstart_time+timedelta(hours=n)).strftime("%d-%b-%Y %H:%M")
     plt.suptitle('%.f%% simulated drifters ashore\n%d days, %d m, %s'%(int(round(p)),track_days,depth,Time))
     
     plt.streamplot(lonpps[n],latpps[n],US[n],VS[n], color=speeds[n],arrowsize=4,cmap=plt.cm.cool,density=2.0)
     
     for i in range(dft_num):
         ax.plot(dlon_set[i],dlat_set[i],'-',color=colors[i%7],linewidth=2,label=drifter_ID[i][-5:])
         
     for j in xrange(stp_num):
         ax.plot(lon_set[j][0],lat_set[j][0],color='k',marker='x',markersize=3)#colors[j%10]
         if n>=len(lon_set[j]):
             ax.plot(lon_set[j][-1],lat_set[j][-1],'o',color='black',markersize=5)
         if n<len(lon_set[j]):
             if n<5:                
                 ax.plot(lon_set[j][:n+1],lat_set[j][:n+1],'o-',color='black',markersize=3)#,label='Depth=10m'            
             if n>=5:
                 ax.plot(lon_set[j][n-4:n+1],lat_set[j][n-4:n+1],'o-',color='black',markersize=3)
     
     for i in range(dft_num):
         if smtime[n] > mtime[i][-1]:
             #ax.plot(dlon_set[i],dlat_set[i],'-',color=colors[i%7],linewidth=2,label=drifter_ID[i][-5:])
             ax.plot(mlon_set[i][-1],mlat_set[i][-1],'o',color=colors[i%7],markersize=5)
         if smtime[n] in mtime[i]:
             mti = mtime[i].index(smtime[n])
             '''ax.annotate(drifter_ID[i],xy=(dlon_set[i][-1],dlat_set[i][-1]),xytext=(dlon_set[i][-1]+0.01*track_days,
                         dlat_set[i][-1]+0.01*track_days),fontsize=6,arrowprops=dict(arrowstyle="fancy")) #'''
             #ax.plot(dlon_set[i],dlat_set[i],'-',color=colors[i%7],linewidth=2,label=drifter_ID[i][-5:]) # ,markersize=6, linewidth = 4
             if mti<5:
                 ax.plot(mlon_set[i][:mti+1],mlat_set[i][:mti+1],'o-',color=colors[i%7],markersize=4) #,label='Model'
             if mti>=5:
                 ax.plot(mlon_set[i][mti-4:mti+1],mlat_set[i][mti-4:mti+1],'o-',color=colors[i%7],markersize=4) #,label='Model'
     draw_basemap(ax, points)  # points is using here
        strt = '2015'+'-'+str(np.array(ddata[2])[j])+'-'+str(np.array(ddata[3])[j])+' '+str(np.array(ddata[4])[j])+':'+str(np.array(ddata[5])[j])
        temptime = datetime.strptime(strt,'%Y-%m-%d %H:%M')
        ts.append(temptime) #'''
        ths = (temptime - basetime).total_seconds()/3600
        ds.append(int(round(ths)))
    #mint.append(min(ds)); maxt.append(max(ds))
    times.append(np.array(ts)); ctime.append(np.array(ds)); toltime.extend(ds)
    lons.append(np.array(ddata[7])); lats.append(np.array(ddata[8]))
    loop_num.append(len(ddata[7]))

#mintime = min(mint); maxtime = max(maxt)
#mtime = range(mintime,maxtime+1)
toltime = set(toltime); #print 'Frames number:'
toltime = list(toltime); toltime.sort(); print 'plotting...',len(toltime)

draw_basemap(ax, points)  # points is using here
#print type(lons[0][:])

if result == 'plot':
    for i in range(len(lons)):
        plt.plot(lons[i],lats[i],'-',color = colors[i%10],markersize=20)

#ax.plot(drifter_points['lon'],drifter_points['lat'],'bo-',markersize=6,label='Drifter')
'''ax.annotate(an2,xy=(dr_points['lon'][-1],dr_points['lat'][-1]),xytext=(dr_points['lon'][-1]+0.01*track_days,
            dr_points['lat'][-1]+0.01*track_days),fontsize=6,arrowprops=dict(arrowstyle="fancy"))#'''

if result == 'animation':
    length = 1; 
    if len(toltime)>1000:
        length = 3
    print 'frame:',len(toltime)
Example #10
0
            points, depth, track_way)
        np.savez('streamline.npz',
                 lonpps=lonpps,
                 latpps=latpps,
                 US=US,
                 VS=VS,
                 speeds=speeds)
        image_style = 'animation'

    ########################### Plot #####################################
    plt.title('Drifter: {0} {1}'.format(drifter_ID, MODEL))
    #colors=uniquecolors(len(points['lats'])) #config colors
    an2 = str(dr_points['time'][-1].strftime('%m/%d-%H:%M'))

    if image_style == 'plot':  #facecolor=colors[i]'''
        draw_basemap(ax, points)  # points is using here
        ax.annotate(an2,
                    xy=(dr_points['lon'][-1], dr_points['lat'][-1]),
                    xytext=(dr_points['lon'][-1] + 0.01 * track_days,
                            dr_points['lat'][-1] + 0.01 * track_days),
                    fontsize=6,
                    arrowprops=dict(arrowstyle="fancy"))
        ax.plot(drifter_points['lon'],
                drifter_points['lat'],
                'bo-',
                markersize=6,
                label='Drifter')
        ax.plot(model_points['lon'],
                model_points['lat'],
                'ro',
                markersize=4,
Example #11
0
from datetime import datetime, timedelta
from track_functions import get_drifter,get_fvcom,get_roms,draw_basemap,uniquecolors,clickmap, points_between, points_square,extend_units,totdis
from matplotlib import animation

def extend_units(point, unit, num):
    '''point = (lat,lon); length: units is decimal degrees.
       return a squre points(lats,lons) on center point'''
    (lat,lon) = point; 
    lats=[]; lons=[]
    #unit = unit
    leh = unit*num
    
    #ps = np.mgrid[lat-leh:lat+leh+1:2j, lon-leh:lon+leh+1:2j]; print ps
    #ps = ps*unit
    lts = np.arange(lat-leh,lat+leh+unit,unit); lns = np.arange(lon-leh,lon+leh+unit,unit)
    llp = np.meshgrid(lts,lns); #print llp
    lats.extend(llp[0].flatten()); lons.extend(llp[1].flatten())

    return lats,lons
centerpoint = (41.9,-70.26); unit = 0.04; number = 3
st_lat,st_lon = extend_units(centerpoint,unit,number)
print st_lat,st_lon
points = {'lats':[],'lons':[]}  # collect all points we've gained
points['lats'].extend(st_lat); points['lons'].extend(st_lon)
#points['lats'].extend(latc); points['lons'].extend(lonc)
fig = plt.figure() #figsize=(16,9)
ax = fig.add_subplot(111)
draw_basemap(fig, ax, points)
ax.plot(st_lon,st_lat,'bo')
plt.show()
Example #12
0
            endtime = starttime + timedelta(days=DAYS)
        else:
            endtime = starttime + timedelta(days=3)
    # read data points from fvcom and roms websites and store them

    #set latitude and longitude arrays for basemap
    lonsize = [min(points_drifter['lon']), max(points_drifter['lon'])]
    latsize = [min(points_drifter['lat']), max(points_drifter['lat'])]
    diff_lon = (lonsize[0]-lonsize[1])*4 # leave space in sides
    diff_lat = (latsize[1]-latsize[0])*4
    lonsize = [lonsize[0]-diff_lon,lonsize[1]+diff_lon]
    latsize = [latsize[0]-diff_lat,latsize[1]+diff_lat]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    draw_basemap(fig, ax, lonsize, latsize)
    ax.plot(points_drifter['lon'],points_drifter['lat'],'ro-',label='drifter')
    ax.plot(points_drifter['lon'][0],points_drifter['lat'][0],'c.',label='Startpoint',markersize=20)
    if MODEL in ('FVCOM', 'BOTH'):
        get_fvcom_obj = get_fvcom(GRID)
        url_fvcom = get_fvcom_obj.get_url(starttime, endtime)
        points_fvcom = get_fvcom_obj.get_track(lon,lat,DEPTH,url_fvcom)           # iterates fvcom's data
        dist_fvcom = distance((points_drifter['lat'][-1],points_drifter['lon'][-1]),(points_fvcom['lat'][-1],points_fvcom['lon'][-1]))
        print 'The separation of fvcom was %f kilometers for drifter %s' % (dist_fvcom[0], ID )
        ax.plot(points_fvcom['lon'],points_fvcom['lat'],'yo-',label='fvcom')
    if MODEL in ('ROMS', 'BOTH'):
        get_roms_obj = get_roms()
        url_roms = get_roms_obj.get_url(starttime, endtime)
        points_roms = get_roms_obj.get_track(lon, lat, DEPTH, url_roms)
        if type(points_roms['lat']) == np.float64:                             # ensures that the single point case still functions properly   
            points_roms['lon'] = [points_roms['lon']] 
Example #13
0
    url_roms = get_obj.get_url(start_time, end_time)
    point = get_obj.get_track(st_point[0], st_point[1], DEPTH, url_roms)
fc_set['lons'].extend(point['lon'])
fc_set['lats'].extend(point['lat'])
for h in zip(point['lat'], point['lon']):
    f_file.write('%f,%f\n' % h)
f_file.close()
#################### Plotting ##########################
points = {'lats': [], 'lons': []}  # collect all points we've gained
points['lats'].extend(dr_set['lats'])
points['lons'].extend(dr_set['lons'])
points['lats'].extend(fc_set['lats'])
points['lons'].extend(fc_set['lons'])
fig = plt.figure()  #figsize=(16,9)
ax = fig.add_subplot(111)
draw_basemap(fig, ax, points)
'''ax.plot(dr_set['lons'][0],dr_set['lats'][0],'c.',markersize=16) #,label='Startpoint'
ax.annotate(an[0], xy=(dr_set['lons'][0]+0.005,dr_set['lats'][0]+0.005),fontsize=6,
            xytext=(dr_set['lons'][0]+0.03,dr_set['lats'][0]+0.03),
            arrowprops=dict(arrowstyle="wedge")) #facecolor=colors[i]'''
#colors=uniquecolors(len(points['lats'])) #config colors
plt.title('Drifter: {0} {1} track'.format(drifter_ID, MODE))


################
def animate(n):  # the function of the animation
    #ax.cla()
    #del ax.lines() #apply to plot
    #del ax.collection() #apply to scatter
    if n < a[0]:
        if n == 0: