else: days=jd_id[-1]+366-jd_id[0] elif num_times_strattle_new_year==2: days=jd_id[-1]+365+(365-jd_id[0]) elif num_times_strattle_new_year==3:# added this case when Lester Bell strattled the new year 3 times!!! days=jd_id[-1]+365+365+(365-jd_id[0]) totaldays+=days # get name of school and teacher [PI,lab,depth]=read_codes_names(id_list[i]) # gets name, lab/school, and depth from codes.dat #get the totdist distkm,bear=[],[] for n in range(1,len(lat_id)): #d,b = dist(lat_id[n-1], lon_id[n-1], lat_id[n], lon_id[n]) d,b = distance((lat_id[n-1], lon_id[n-1]), (lat_id[n], lon_id[n])) distkm.append(d) bear.append(b) totdist=sum(distkm) totaldistance+=totdist #get the s2end #s2end,bear2=dist(lat_id[0],lon_id[0],lat_id[-1],lon_id[-1]) s2end,bear2=distance((lat_id[0],lon_id[0]),(lat_id[-1],lon_id[-1])) #get the u,v,spd u,v,spd,jdn = ll2uv(jd_id,lat_id,lon_id) # maybe we should be using a different time here #get the meanu,meanv,meanspd meanu = numpy.mean(u) meanv = numpy.mean(v) meanspd = numpy.mean(spd)
def multi_track(drifter_ids, depth, days, lat_incr, lon_incr, starttime): ''' This function retrieves all the data needed and returns it all ''' drifter = get_drifter(ID) # Retrive drifter data print ID if starttime: if days: nodes_drifter = drifter.get_track(starttime,days) else: nodes_drifter = drifter.get_track(starttime) else: nodes_drifter = drifter.get_track() ''' determine latitude, longitude, start, and end times of the drifter?''' lon, lat = nodes_drifter['lon'][0], nodes_drifter['lat'][0] # adjust for the added 5 hours in the models starttime = nodes_drifter['time'][0]-timedelta(hours=5) endtime = nodes_drifter['time'][-1]-timedelta(hours=5) print starttime ''' read data points from fvcom and roms websites and store them''' mod = '30yr' # mod has to be '30yr' or 'GOM3' or 'massbay' get_fvcom_obj = get_fvcom(mod) url_fvcom = get_fvcom_obj.get_url(starttime, endtime) nodes_fvcom = get_fvcom_obj.get_track(lon,lat,depth,url_fvcom) # iterates fvcom's data get_roms_obj = get_roms() url_roms = get_roms_obj.get_url(starttime, endtime) nodes_roms = get_roms_obj.get_track(lon, lat, depth, url_roms) if type(nodes_roms['lat']) == np.float64: # ensures that the single point case still functions properly nodes_roms['lon'] = [nodes_roms['lon']] nodes_roms['lat'] = [nodes_roms['lat']] '''Calculate the distance seperation''' dist_roms = distance((nodes_drifter['lat'][-1],nodes_drifter['lon'][-1]),(nodes_roms['lat'][-1],nodes_roms['lon'][-1])) dist_fvcom = distance((nodes_drifter['lat'][-1],nodes_drifter['lon'][-1]),(nodes_fvcom['lat'][-1],nodes_fvcom['lon'][-1])) print 'The seperation of roms was %f and of fvcom was %f kilometers from drifter %s' % (dist_roms[0], dist_fvcom[0], ID ) ''' set latitude and longitude arrays for basemap''' lonsize = [min_data(nodes_drifter['lon'],nodes_fvcom['lon']), max_data(nodes_drifter['lon'],nodes_fvcom['lon'])] latsize = [min_data(nodes_drifter['lat'],nodes_fvcom['lat']), max_data(nodes_drifter['lat'],nodes_fvcom['lat'])] diff_lon = .1 diff_lat = .1 lonsize = [lonsize[0]-diff_lon,lonsize[1]+diff_lon] latsize = [latsize[0]-diff_lat,latsize[1]+diff_lat] return nodes_drifter, nodes_roms, nodes_fvcom, lonsize, latsize, starttime
def get_w_depth(xi,yi): url='http://geoport.whoi.edu/thredds/dodsC/bathy/gom03_v1_0'#url='http://geoport.whoi.edu/thredds/dodsC/bathy/crm_vol1.nc' ): if xi[0]>999.: # if it comes in decimal -minutes, conert it #for kk in range(len(xi)): (y2,x2)=dm2dd(yi[0],xi[0]) yi[0]=y2 xi[0]=x2 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.00834 and i < xi[0] + 0.00834: xgom.append(i) for i in ygom_array: if i > yi[0] - 0.00834 and i < yi[0] + 0.00834: 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 = distance((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
get_fvcom_obj = get_fvcom(mod) url_fvcom = get_fvcom_obj.get_url(starttime, endtime) nodes_fvcom = get_fvcom_obj.get_track(lon,lat,depth,url_fvcom) # iterates fvcom's data #get_roms_obj = get_roms() #url_roms = get_roms_obj.get_url(starttime, endtime) #nodes_roms = get_roms_obj.get_track(lon, lat, depth, url_roms) #if type(nodes_roms['lat']) == np.float64: # ensures that the single point case still functions properly # nodes_roms['lon'] = [nodes_roms['lon']] # nodes_roms['lat'] = [nodes_roms['lat']] '''Calculate the distance seperation''' #dist_roms = distance((nodes_drifter['lat'][-1],nodes_drifter['lon'][-1]),(nodes_roms['lat'][-1],nodes_roms['lon'][-1])) dist_fvcom = distance((nodes_drifter['lat'][-1],nodes_drifter['lon'][-1]),(nodes_fvcom['lat'][-1],nodes_fvcom['lon'][-1])) #print 'The seperation of roms was %f and of fvcom was %f kilometers for drifter %s' % (dist_roms[0], dist_fvcom[0], ID ) ''' set latitude and longitude arrays for basemap''' lonsize = [min_data(nodes_drifter['lon'],nodes_fvcom['lon']), max_data(nodes_drifter['lon'],nodes_fvcom['lon'])] latsize = [min_data(nodes_drifter['lat'],nodes_fvcom['lat']), max_data(nodes_drifter['lat'],nodes_fvcom['lat'])] diff_lon = (lonsize[0]-lonsize[1])*4 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]
def get_w_depth(xi, yi): #xi:lon yi:lat url = 'http://geoport.whoi.edu/thredds/dodsC/bathy/gom03_v1_0' #url='http://geoport.whoi.edu/thredds/dodsC/bathy/crm_vol1.nc' ): if xi[0] > 999.: # if it comes in decimal -minutes, conert it #for kk in range(len(xi)): (y2, x2) = dm2dd(yi[0], xi[0]) yi[0] = y2 xi[0] = x2 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.00834 and i < xi[0] + 0.00834: xgom.append(i) for i in ygom_array: if i > yi[0] - 0.00834 and i < yi[0] + 0.00834: 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 = distance((ygom[j], xgom[k]), (yi[0], xi[0])) dist1.append(distkm) #print dist1 if len(dist1) >= 3: #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) else: depth_finally = np.array([[-9999]]) return depth_finally
def get_w_depth(xi, yi, url='http://geoport.whoi.edu/thredds/dodsC/bathy/gom03_v1_0'):# xi is longitude,like [-69.2,-69.1].yi is latitude,like[41.0,41.1] 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 np.shape(xgom_array),xgom_array[0],xi[0] #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: #if i > xi[0] - 0.0834 and i < xi[0] + 0.0834: xgom.append(i) for i in ygom_array: if i > yi[0] - 0.000834 and i < yi[0] + 0.000834: #if i > yi[0] - 0.0834 and i < yi[0] + 0.0834: ygom.append(i) print np.shape(xgom) 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],) distkm, b = distance((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[0]