for i in range(a): r=254/(a)*(i) for j in range(b): s=254/(b)*(j) 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]))
import sys import glob from matplotlib.dates import num2date,date2num import numpy as np from drifter_functions import hexcolors pydir='../' sys.path.append(pydir) filename='seal.dat' drifter_num=[23,130400661.0, 134402201.0, 156490031.0, 130400671.0, 120350752.0, 120350753.0, 140360731.0, 130400681.0, 130400682.0, 130260781.0, 130260783.0, 154490031.0, 145350201.0, 120350751.0, 125350721.0, 125350722.0, 125350723.0, 125350724.0, 125350725.0, 142270151.0, 142270152.0, 136230731.0, 130400672.0, 152410671.0, 153340771.0, 153340772.0, 130290791.0, 130290792.0, 140350701.0, 140350702.0, 140350703.0, 140350704.0, 152350705.0, 145380091.0] colors=hexcolors(len(drifter_num)) FN=glob.glob('*.dat') # get all csv files in 1 folder mymap = basemap_xu.maps(30, -60, 4) for filename in FN: d=np.genfromtxt(filename) lat1=d[:,8] lon1=d[:,7] idd=d[:,0] #mymap = basemap_xu.maps(np.mean(lat1), np.mean(lon1), 12) for x in range(len(drifter_num)): idg1=list(ml.find(idd==drifter_num[x])) #idg2=list(ml.find(np.array(time1)<=datetime_wanted+interval/ 24)) "'0.25' means the usual Interval, It can be changed base on different drift data " #idg3=list(ml.find(np.array(time1)>=datetime_wanted-0.1)) #idg23=list(set(idg2).intersection(set(idg3)))
#################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: 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
pydir = '../' sys.path.append(pydir) from drifter_functions import getcodar_ctl_file, hexcolors import basemap_xu ############################################### filename = './123.txt' drifter_num = [3534, 3546, 3578, 3586] #drifter_num=[3534] colors = hexcolors(len(drifter_num)) #change format d = np.genfromtxt(filename) lat1 = d[:, 4] lon1 = d[:, 3] idd = d[:, 0] mymap = basemap_xu.maps(np.mean(lat1), np.mean(lon1), 12) for x in range(len(drifter_num)): idg1 = list(ml.find(idd == drifter_num[x])) #idg2=list(ml.find(np.array(time1)<=datetime_wanted+interval/ 24)) "'0.25' means the usual Interval, It can be changed base on different drift data " #idg3=list(ml.find(np.array(time1)>=datetime_wanted-0.1)) #idg23=list(set(idg2).intersection(set(idg3))) # find which data we need idg = idg1 print 'the length of drifter data is ' + str(len(idg)), str(len( set(idg))) + ' . if same, no duplicate' lat, lon, time = [], [], [] for u in range(len(idg)): lat.append(round(lat1[idg[u]], 4))
pydir='../' sys.path.append(pydir) from drifter_functions import getcodar_ctl_file,hexcolors import basemap_xu ############################################### filename='./123.txt' drifter_num=[3534,3546,3578,3586] #drifter_num=[3534] colors=hexcolors(len(drifter_num)) #change format d=np.genfromtxt(filename) lat1=d[:,4] lon1=d[:,3] idd=d[:,0] mymap = basemap_xu.maps(np.mean(lat1), np.mean(lon1), 12) for x in range(len(drifter_num)): idg1=list(ml.find(idd==drifter_num[x])) #idg2=list(ml.find(np.array(time1)<=datetime_wanted+interval/ 24)) "'0.25' means the usual Interval, It can be changed base on different drift data " #idg3=list(ml.find(np.array(time1)>=datetime_wanted-0.1)) #idg23=list(set(idg2).intersection(set(idg3))) # find which data we need idg=idg1 print 'the length of drifter data is '+str(len(idg)),str(len(set(idg)))+' . if same, no duplicate' lat,lon,time=[],[],[] for u in range(len(idg)): lat.append(round(lat1[idg[u]],4)) lon.append(round(lon1[idg[u]],4))
from basemap_xu import * import basemap_xu ########## CONSTRUCTOR: pygmaps.maps(latitude, longitude, zoom) ############################## # DESC: initialize a map with latitude and longitude of center point # and map zoom level "15" # PARAMETER1: latitude (float) latittude of map center point # PARAMETER2: longitude (float) latittude of map center point # PARAMETER3: zoom (int) map zoom level 0~20 # RETURN: the instant of pygmaps #======================================================================================== mymap = basemap_xu.maps(37.428, -122.145, 16) ########## FUNCTION: setgrids(start-Lat, end-Lat, Lat-interval, start-Lng, end-Lng, Lng-interval) ###### # DESC: set grids on map # PARAMETER1: start-Lat (float), start (minimum) latittude of the grids # PARAMETER2: end-Lat (float), end (maximum) latittude of the grids # PARAMETER3: Lat-interval (float) grid size in latitude # PARAMETER4: start-Lng (float), start (minimum) longitude of the grids # PARAMETER5: end-Lng (float), end (maximum) longitude of the grids # PARAMETER6: Lng-interval (float) grid size in longitude # RETURN: no returns #======================================================================================== mymap.setgrids(37.42, 37.43, 0.001, -122.15, -122.14, 0.001) ########## FUNCTION: addpoint(latitude, longitude, [color])############################# # DESC: add a point into a map and dispaly it, color is optional default is red # PARAMETER1: latitude (float) latitude of the point # PARAMETER2: longitude (float) longitude of the point # PARAMETER3: color (string) color of the point showed in map, using HTML color code