def get_longitudes_and_latitudes(self, nx=180, ny=172, lat_center=49.65698, lon_center=-96.99443, dx=45000): """ get longitudes and latitudes of the AMNO grid """ #coordinates with respect to the pole, divided by #dx [xc, yc] = latlon2psxy(lat_center, lon_center) self.lon_center = lon_center self.lat_center = lat_center self.dx = dx self.dy = dx print('Coordinates of the grid center ', xc * dx, yc * dx) xmin = xc - (nx - 1) / 2.0 ymin = yc - (ny - 1) / 2.0 self.x_min = xmin self.y_min = ymin print( 'These coordinates can be verified with cccma site points (2,2) and (181, 173) respectively' ) print('lower left: ', psxy2latlon(xmin, ymin)) print('upper right: ', psxy2latlon(xmin + nx - 1, ymin + ny - 1)) longitudes = np.zeros((nx, ny)) latitudes = np.zeros((nx, ny)) for i in range(nx): for j in range(ny): latitudes[i, j], longitudes[i, j] = psxy2latlon(xmin + i, ymin + j) return longitudes, latitudes
def get_longitudes_and_latitudes(self, nx = 180, ny = 172, lat_center = 49.65698, lon_center = -96.99443, dx = 45000): """ get longitudes and latitudes of the AMNO grid """ #coordinates with respect to the pole, divided by #dx [xc, yc] = latlon2psxy(lat_center, lon_center) self.lon_center = lon_center self.lat_center = lat_center self.dx = dx self.dy = dx print 'Coordinates of the grid center ', xc * dx, yc * dx xmin = xc - (nx - 1) / 2.0 ymin = yc - (ny - 1) / 2.0 self.x_min = xmin self.y_min = ymin print 'These coordinates can be verified with cccma site points (2,2) and (181, 173) respectively' print 'lower left: ', psxy2latlon(xmin, ymin) print 'upper right: ', psxy2latlon(xmin + nx - 1 , ymin + ny - 1) longitudes = np.zeros((nx, ny)) latitudes = np.zeros((nx, ny)) for i in range(nx): for j in range(ny): latitudes[i,j], longitudes[i, j] = psxy2latlon(xmin + i, ymin + j) return longitudes, latitudes
def get_indices_of_the_closest_point_to(self, lon, lat): """ get indices of the point closest to the coord (lon, lat) """ [x, y] = latlon2psxy(lat, lon) return round(x - self.x_min), round(y - self.y_min)