예제 #1
0
파일: drawer.py 프로젝트: MNandor/DatViz
def colorPixel(a, points):

    #mindist = 100
    cur = 0
    totalDist = 0
    for point in points:
        distance = dist(a, toPixels(point[0], point[1]))
        #mindist = min(distance, mindist)
        cur += (point[2] - 0.5) / distance
        totalDist += 1 / distance

    #print(cur, totalDist, cur/totalDist)
    cur = 0.5 + cur / totalDist

    return valToColor(cur, coldest, hottest)
예제 #2
0
파일: getdata.py 프로젝트: jian-cui/pyocean
def get_w_depth(xi, yi, url='http://geoport.whoi.edu/thredds/dodsC/bathy/gom03_v03'):
    try:    
        dataset = open_url(url)
        
    except:
        print 'Sorry, ' + url + ' is not available' 
        sys.exit(0)

    #read lat, lon,topo from url
    xgom_array = dataset['lon']
    ygom_array = dataset['lat']
    dgom_array = dataset['topo'].topo

    #print dgom_array.shape, xgom_array[5:9],dgom_array[5]

    #convert the array to a list
    xgom, ygom = [], []
    
    for i in xgom_array:
        if i > xi[0] - 0.000834 and i < xi[0] + 0.000834:
            xgom.append(i)
  
    for i  in ygom_array:
        if i > yi[0] - 0.000834 and i < yi[0] + 0.000834:
            ygom.append(i)


    x_index, y_index = [], []
    (ys, xs) = dgom_array.shape

    for i in range(0, len(xgom)):
        x_index.append(int(round(np.interp(xgom[i], xgom_array, range(xs)))))
    for i in range(0, len(ygom)):
        y_index.append(int(round(np.interp(ygom[i], ygom_array, range(ys)))))
    
    dep, distkm, dist1 = [], [], []

    for k in range(len(x_index)):
        for j in range(len(y_index)):
            dep.append(dgom_array[(y_index[j], x_index[k])])
       
            distkm, b = dist(ygom[j], xgom[k], yi[0], xi[0],)
            dist1.append(distkm)

    #get the nearest,second nearest,third nearest point.
    dist_f_nearest = sorted(dist1)[0]
    dist_s_nearest = sorted(dist1)[1]
    dist_t_nearest = sorted(dist1)[2]
    
    index_dist_nearest = range(len(dist1))
    index_dist_nearest.sort(lambda x, y:cmp(dist1[x], dist1[y]))
    
    dep_f_nearest = dep[index_dist_nearest[0]]
    dep_s_nearest = dep[index_dist_nearest[1]]
    dep_t_nearest = dep[index_dist_nearest[2]]

    #compute the finally depth
    d1 = dist_f_nearest
    d2 = dist_s_nearest
    d3 = dist_t_nearest
    def1 = dep_f_nearest
    def2 = dep_s_nearest
    def3 = dep_t_nearest
    depth_finally = def1 * d2 * d3 / (d1 * d2 + d2 * d3 + d1 * d3) + def2 * d1 * d3 / (d1 * d2 + d2 * d3 + d1 * d3) + def3 * d2 * d1 / (d1 * d2 + d2 * d3 + d1 * d3)

    return depth_finally
    f.seek(0, 2)
    write_line(f, data)

#def save_excel1(filename, data, head):
#    dexcel = xlwt.Workbook()
#    dtable = dexcel.sheets()[0]
#    rows = dtable.nrows
#    if not rows:
#        for i in head:
#            dtable.put_cell(rows, head.index(i), i)
#            dtable.put_cell(rows+1, head.index(i), data[head.index(i)])
#    else:
#        for i in data:
#            dtable.put_cell(rows, data.index(i), data[data.index(i)])
#    dexcel.save
time_input = input_with_default('the time you want to calculate', '11-21 11:33')
time_cal = time.strptime(time_input, "%m-%d %H:%M")
ID = input_with_default('drifter ID', 130410701)
lat_fcasted = input_with_default('latitude forecasted', 4150.1086)
lont_fcasted = input_with_default('longitude forecasted', 7005.7876)
datafile = r'http://www.nefsc.noaa.gov/drifter/drift_audubon_2013_1.dat'
f = urlopen(datafile)
#f = open(datafile)
coor = pos_real(f, time_cal, ID)
distance = dist(coor[0], coor[1], float(lat_fcasted), float(lont_fcasted))
print distance[0]
data = (time_input, ID, str(distance[0]))
#save_excel('distance.xls', data = (time_input, ID, str(distance[0])))
fs = open('distance.dat', 'a+')
write_data(fs, data, 'date ID distance')
fs.close()
예제 #4
0
def get_w_depth(xi,
                yi,
                url='http://geoport.whoi.edu/thredds/dodsC/bathy/gom03_v03'):
    try:
        dataset = open_url(url)

    except:
        print 'Sorry, ' + url + ' is not available'
        sys.exit(0)

    #read lat, lon,topo from url
    xgom_array = dataset['lon']
    ygom_array = dataset['lat']
    dgom_array = dataset['topo'].topo

    #print dgom_array.shape, xgom_array[5:9],dgom_array[5]

    #convert the array to a list
    xgom, ygom = [], []

    for i in xgom_array:
        if i > xi[0] - 0.000834 and i < xi[0] + 0.000834:
            xgom.append(i)

    for i in ygom_array:
        if i > yi[0] - 0.000834 and i < yi[0] + 0.000834:
            ygom.append(i)

    x_index, y_index = [], []
    (ys, xs) = dgom_array.shape

    for i in range(0, len(xgom)):
        x_index.append(int(round(np.interp(xgom[i], xgom_array, range(xs)))))
    for i in range(0, len(ygom)):
        y_index.append(int(round(np.interp(ygom[i], ygom_array, range(ys)))))

    dep, distkm, dist1 = [], [], []

    for k in range(len(x_index)):
        for j in range(len(y_index)):
            dep.append(dgom_array[(y_index[j], x_index[k])])

            distkm, b = dist(
                ygom[j],
                xgom[k],
                yi[0],
                xi[0],
            )
            dist1.append(distkm)

    #get the nearest,second nearest,third nearest point.
    dist_f_nearest = sorted(dist1)[0]
    dist_s_nearest = sorted(dist1)[1]
    dist_t_nearest = sorted(dist1)[2]

    index_dist_nearest = range(len(dist1))
    index_dist_nearest.sort(lambda x, y: cmp(dist1[x], dist1[y]))

    dep_f_nearest = dep[index_dist_nearest[0]]
    dep_s_nearest = dep[index_dist_nearest[1]]
    dep_t_nearest = dep[index_dist_nearest[2]]

    #compute the finally depth
    d1 = dist_f_nearest
    d2 = dist_s_nearest
    d3 = dist_t_nearest
    def1 = dep_f_nearest
    def2 = dep_s_nearest
    def3 = dep_t_nearest
    depth_finally = def1 * d2 * d3 / (
        d1 * d2 + d2 * d3 + d1 * d3) + def2 * d1 * d3 / (
            d1 * d2 + d2 * d3 + d1 * d3) + def3 * d2 * d1 / (d1 * d2 +
                                                             d2 * d3 + d1 * d3)

    return depth_finally
예제 #5
0

#def save_excel1(filename, data, head):
#    dexcel = xlwt.Workbook()
#    dtable = dexcel.sheets()[0]
#    rows = dtable.nrows
#    if not rows:
#        for i in head:
#            dtable.put_cell(rows, head.index(i), i)
#            dtable.put_cell(rows+1, head.index(i), data[head.index(i)])
#    else:
#        for i in data:
#            dtable.put_cell(rows, data.index(i), data[data.index(i)])
#    dexcel.save
time_input = input_with_default('the time you want to calculate',
                                '11-21 11:33')
time_cal = time.strptime(time_input, "%m-%d %H:%M")
ID = input_with_default('drifter ID', 130410701)
lat_fcasted = input_with_default('latitude forecasted', 4150.1086)
lont_fcasted = input_with_default('longitude forecasted', 7005.7876)
datafile = r'http://www.nefsc.noaa.gov/drifter/drift_audubon_2013_1.dat'
f = urlopen(datafile)
#f = open(datafile)
coor = pos_real(f, time_cal, ID)
distance = dist(coor[0], coor[1], float(lat_fcasted), float(lont_fcasted))
print distance[0]
data = (time_input, ID, str(distance[0]))
#save_excel('distance.xls', data = (time_input, ID, str(distance[0])))
fs = open('distance.dat', 'a+')
write_data(fs, data, 'date ID distance')
fs.close()