Ejemplo n.º 1
0
       c+=1
    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)):
Ejemplo n.º 2
0
import pytz
from hx import getobs_drift_byrange,getobs_drift_byid
ops=os.defpath
pydir='../'
sys.path.append(pydir)
#################Input values#############################################
input_time=[dt.datetime(2013,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.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()


'''