Пример #1
0
'125450842' '125450841'
#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑Input values↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑#

if id == []:
    time, ids, lat, lon = getobs_drift_byrange(
        gbox, input_time)  #get  and organize data

else:
    every_time_total, id_s = [], []
    totalday = 0
    region = 'wv'
    lat_data, lon_data = get_coastline_coordinate(
        region)  #gets coastline coordinate
    for q in range(len(id)):
        #print id[q]
        time, ids, lat, lon = getobs_drift_byid(
            id[q], input_time)  #get  and organize data
        distance = 0
        for z in range(len(lat_data)):
            if haversine(
                    lon_data[z], lat_data[z], lon[-1], lat[-1]
            ) < 0.6:  #1.0 represent  1 kilometer   , get rid of landed drifter
                print haversine(lon_data[z], lat_data[z], lon[-1], lat[-1])
                distance = 1
                break
        if distance == 0:
            every_time_total.append(date2num(time[-1]) - date2num(time[0]))
            totalday = totalday + date2num(time[-1]) - date2num(
                time[0])  # get number of total ploted drifters
    drifter_n, index_day = [], []
    for i in range(30):  #set y columns to 30 columns
        drifter_n.append(
Пример #2
0
input_time=[dt.datetime(2012,1,1,0,0,0,0,pytz.UTC),dt.datetime(2013,7,1,0,0,0,0,pytz.UTC)] # start time and end time
gbox=[-70.035594,-70.597883,42.766619,42.093197] #  maxlon, minlon,maxlat,minlat
id=[] # id list, if you are not clear dedicated id, let id=[]
#'125450842''125450841'
#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑Input values↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑#

fig = plt.figure()
ax = fig.add_subplot(111)  
polygon=[(gbox[0],gbox[2]),(gbox[0],gbox[3]),(gbox[1],gbox[3]),(gbox[1],gbox[2])]
if id==[]:
    
    time,ids,lats,lons=getobs_drift_byrange(gbox,input_time)
    id=list(set(ids))
    rgbcolors=colors(len(id))
    for k in range(len(id)):
        time,ids,lat,lon=getobs_drift_byid(id[k],input_time)
        for z in range(len(lat)):
            inside=point_in_poly(lon[z],lat[z],polygon)
            if inside == True:
              break

        lat=lat[z:]
        lon=lon[z:]

        plt.plot(lon[0],lat[0],'.',markersize=30,color=rgbcolors[k+1],label=str(id[k]))
        plt.plot(np.reshape(lon,np.size(lon)),np.reshape(lat,np.size(lat)),color=rgbcolors[k+1])
else:
    lats,lons=[],[]
    rgbcolors=colors(len(id))
    for m in range(len(id)):
        time,ids,lat,lon=getobs_drift_byid(id[m],input_time)
axes = axes.ravel()  #get axes
for y in range(len(ids)):
    
    id=[int(a) for a in ids[y]]  # convert to ints

    if id==[]:
        time,ids_un,lat,lon=getobs_drift_byrange(gbox,input_time)  #get  and organize data

    else:
        every_time_total,id_s=[],[]
        totalday=0;total_drifter=0
        region='wv'
        lat_data, lon_data=get_coastline_coordinate(region)  # gets coastline coordinate
        for q in range(len(id)):
            print id[q]
            time,id_un,lat,lon=getobs_drift_byid(id[q],input_time)  #get  and organize data
            distance=0
            for z in range(len(lat_data)):
                if haversine(lon_data[z], lat_data[z], lon[-1], lat[-1])< 0.5: #1.0 represent  1 kilometer   , get rid of landed drifter
                    #print haversine(lon_data[z], lat_data[z], lon[-1], lat[-1])
                    distance=1
                    break
            if distance==0:
                every_time_total.append(date2num(time[-1])-date2num(time[0]))
                totalday=totalday+date2num(time[-1])-date2num(time[0])  
                total_drifter+=1 # get number of total ploted drifters
        drifter_n,index_day=[],[]    
        for i in range(15): #set y columns to 30 columns
             drifter_n.append(len([x for x in every_time_total if (20*i+20)>x >= (20*i)]))
             index_day.append(str(20*i)+'-'+str(20*i+20))  # for setting y label
         
Пример #4
0
gbox = [-70.035594, -70.597883, 42.766619,
        42.093197]  #  maxlon, minlon,maxlat,minlat
id = []  # id list, if you are not clear dedicated id, let id=[]
#'125450842''125450841'
#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑Input values↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑#

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(
    for k in range(len(id)):
        time, ids, lat, lon = getobs_drift_byidrange(id[k], gbox, input_time)
        plt.plot(lon[0],
                 lat[0],
                 '.',
                 markersize=30,
                 color=rgbcolors[k + 1],
                 label=str(id[k]))
        plt.plot(np.reshape(lon, np.size(lon)),
                 np.reshape(lat, np.size(lat)),
                 color=rgbcolors[k + 1])
else:
    lats, lons = [], []
    rgbcolors = colors(len(id))
    for m in range(len(id)):
        time, ids, lat, lon = getobs_drift_byid(id[m], input_time)
        plt.plot(lon[-1],
                 lat[-1],
                 '.',
                 markersize=30,
                 color=rgbcolors[m + 1],
                 label=str(id[m]))
        plt.plot(np.reshape(lon, np.size(lon)),
                 np.reshape(lat, np.size(lat)),
                 color=rgbcolors[m + 1])
        for n in range(len(lat)):
            lats.append(lat[n])
            lons.append(lon[n])
basemap_region('ne')

plt.title(str(time[0].strftime("%d-%b-%Y %H")) + 'h')
Пример #6
0
pydir='../'
sys.path.append(pydir)
#################Input values#############################################
input_time=[dt.datetime(1980,1,1,0,0,0,0,pytz.UTC),dt.datetime(2014,10,15,0,0,0,0,pytz.UTC)] # start time and end time
gbox=[-70.035594,-70.597883,42.766619,42.093197] #  maxlon, minlon,maxlat,minlat
id=[] # id list, if you are not clear dedicated id, let id=[]
#'125450842''125450841'
#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑Input values↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑#
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:  
               lat=lat[z:]  # delete data which are before coming in the polygon
               lon=lon[z:]
               time=time[z:]
               path=[] #set path, point 
               for i in range(len(lat)):
                 path.append((lat[i],lon[i]))
               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
               mymap.addpath(path,colors[k])
               break
else: