def waternode(self, lon, lat, depth, url): ''' return points ''' data = self.get_data(url) nodes = dict(temp=[]) mask = data['mask_rho'][:] lon_rho = data['lon_rho'][:] lat_rho = data['lat_rho'][:] lons = jata.shrink(lon_rho, mask[1:,1:].shape) lats = jata.shrink(lat_rho, mask[1:,1:].shape) print 'finding the nearest node ...' index, nearestdistance = self.nearest_point_index(lon,lat,lons,lats) index=[index[0][0],index[1][0]] depth_layers = data['h'][index[0]][index[1]]*data['s_rho'] layer = np.argmin(abs(depth_layers-depth)) print 'extracting modeled time' ot=data['ocean_time'][:] print len(ot) otdt=[] # datetime version of ocean_time for k in range(len(ot)): otdt.append(dt(2006,1,1,0,0)+td(seconds=ot[k])) print 'extracting modeled temperature for this depth and site' nodes=data['temp'][:,layer,index[0],index[1]] modtso=pd.DataFrame(nodes, index=otdt) return modtso
def __waternode(self, lon, lat, url): ''' return points ''' self.data = self.get_data(url) nodes = dict(lon=lon, lat=lat) mask = self.data['mask_rho'][:] lon_rho = self.data['lon_rho'][:] lat_rho = self.data['lat_rho'][:] u = self.data['u'][:,-1] v = self.data['v'][:,-1] lons = jata.shrink(lon_rho, mask[1:,1:].shape) lats = jata.shrink(lat_rho, mask[1:,1:].shape) print 'lons', len(lons),len(lons[0]) for i in range(0, self.hours): print 'roms',i u_t = jata.shrink(u[i], mask[1:,1:].shape) v_t = jata.shrink(v[i], mask[1:,1:].shape) index, nearestdistance = self.nearest_point_index(lon,lat,lons,lats) print 'index', index print 'u_t', len(u_t), len(u_t[0]) u_p = u_t[index[0]][index[1]] v_p = v_t[index[0]][index[1]] ''' for ut, vt in zip(u_p, v_p): if ut: break if not ut: # raise Exception('point hit the land') print 'point hit the land' break if not ut: print 'point hit the land' break u_p = u_t[index[0]][index[1]] v_p = v_t[index[0]][index[1]] ''' if not u_p: print 'point hit the land' break dx = 60*60*float(u_p) dy = 60*60*float(v_p) lon = lon + dx/(111111*np.cos(lat*np.pi/180)) lat = lat + dy/111111 nodes['lon'] = np.append(nodes['lon'],lon) nodes['lat'] = np.append(nodes['lat'],lat) return nodes