-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: Example of converting 2D coordinates to regular grid #209
Comments
There are several options for the case where the data is unevently spaced and you want to convert it to a regular grid;
|
rds = xarray.open_dataset("path_to_file.nc")
df = rds.squeeze().to_dataframe().reset_index()
geometry = gpd.points_from_xy(df.x, df.y)
gdf = gpd.GeoDataFrame(df, crs=rds.rio.crs, geometry=geometry) Step 2: https://corteva.github.io/geocube/stable/examples/rasterize_point_data.html from geocube.api.core import make_geocube
from geocube.rasterize import rasterize_points_griddata
geo_grid = make_geocube(
vector_data=gdf,
resolution=(-0.1, 0.1),
rasterize_function=rasterize_points_griddata,
) |
Also the Xoak library seems promising to perform point-wise selection of irregularly spaced data : https://xoak.readthedocs.io/en/latest/examples/introduction.html |
See: #202 |
Related #724 |
Your data has unevenly spaced 2D lat/lon values.
That means that either:
If (1) is your problem, you will need to re-project your data from 2D latlon back to the projected coordinates in 1D, add the 1D x&y coordinates to your dataset. Then it should work.
If (2) is your problem, then you will need to decide on the resolution of your grid, the bounds of your area of interest, and resample your data to the new regularly spaced grid. Then it will work.
From: #47 (comment)
The text was updated successfully, but these errors were encountered: