def ERA_RegularImgGrid(res_lat=0.25, res_lon=0.25): """ Create ECMWF regular cell grid Parameters ---------- res_lat : float, optional (default: 0.25) Resolution in Y direction res_lon : float, optional (default: 0.25) Resolution in X direction Returns ---------- CellGrid : pygeogrids.CellGrid Regular, global CellGrid with 5DEG*5DEG cells """ # np.arange is not precise... f_lon = (1. / res_lon) f_lat = (1. / res_lat) res_lon = res_lon * f_lon res_lat = res_lat * f_lat lon = np.arange(0., 360. * f_lon, res_lon) lat = np.arange(90. * f_lat, -90 * f_lat - res_lat, -1 * res_lat) lons_gt_180 = np.where(lon > (180. * f_lon)) lon[lons_gt_180] = lon[lons_gt_180] - (360. * f_lon) lon, lat = np.meshgrid(lon, lat) glob_basic_grid = BasicGrid(lon.flatten() / f_lon, lat.flatten() / f_lat) glob_cell_grid = glob_basic_grid.to_cell_grid(cellsize=5.) return glob_cell_grid
def ERA_RegularImgGrid(res_lat=0.25, res_lon=0.25): """ Create ECMWF regular cell grid Parameters ---------- res_lat : float, optional (default: 0.25) Resolution in Y direction res_lon : float, optional (default: 0.25) Resolution in X direction Returns ---------- CellGrid : pygeogrids.CellGrid Regular, global CellGrid with 5DEG*5DEG cells """ lon = np.arange(0., 360. - res_lon / 2., res_lon) lat = np.arange(90., -1. * 90. - res_lat / 2., -1. * res_lat) lons_gt_180 = np.where(lon > 180.0) lon[lons_gt_180] = lon[lons_gt_180] - 360. lon, lat = np.meshgrid(lon, lat) glob_basic_grid = BasicGrid(lon.flatten(), lat.flatten()) glob_cell_grid = glob_basic_grid.to_cell_grid(cellsize=5.) return glob_cell_grid
def ERA_RegularImgGrid( res_lat: float = 0.25, res_lon: float = 0.25, bbox: Tuple[float, float, float, float] = None, ) -> CellGrid: """ Create regular cell grid for bounding box with the selected resolution. Parameters ---------- res_lat: float, optional (default: 0.25) Grid resolution (in degrees) in latitude direction. res_lon: float, optional (default: 0.25) Grid resolution (in degrees) in longitude direction. bbox: tuple, optional (default: None) (min_lon, min_lat, max_lon, max_lat) - wgs84 bbox to cut the global grid to. Returns ---------- CellGrid : CellGrid Regular, CellGrid with 5DEG*5DEG cells for the passed bounding box. """ # np.arange is not precise... f_lon = 1.0 / res_lon f_lat = 1.0 / res_lat res_lon = res_lon * f_lon res_lat = res_lat * f_lat lon = np.arange(0.0, 360.0 * f_lon, res_lon) lat = np.arange(90.0 * f_lat, -90 * f_lat - res_lat, -1 * res_lat) lons_gt_180 = np.where(lon > (180.0 * f_lon)) lon[lons_gt_180] = lon[lons_gt_180] - (360.0 * f_lon) lon, lat = np.meshgrid(lon, lat) glob_basic_grid = BasicGrid(lon.flatten() / f_lon, lat.flatten() / f_lat) glob_cell_grid = glob_basic_grid.to_cell_grid(cellsize=5.0) if bbox is not None: gpis = glob_cell_grid.get_bbox_grid_points( lonmin=bbox[0], latmin=bbox[1], lonmax=bbox[2], latmax=bbox[3] ) glob_cell_grid = glob_cell_grid.subgrid_from_gpis(gpis) return glob_cell_grid