Skip to content
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

Open
snowman2 opened this issue Jan 19, 2021 · 5 comments
Open

DOC: Example of converting 2D coordinates to regular grid #209

snowman2 opened this issue Jan 19, 2021 · 5 comments
Labels
documentation Documentation related issue proposal Idea for a new feature.

Comments

@snowman2
Copy link
Member

Your data has unevenly spaced 2D lat/lon values.

That means that either:

  1. Your data is not geographic and was re-projected to lat/lon in the 2D space to preserve the coordinate locations.
  2. Your data is not represented in an evenly spaced grid.

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)

@snowman2
Copy link
Member Author

There are several options for the case where the data is unevently spaced and you want to convert it to a regular grid;

@snowman2
Copy link
Member Author

snowman2 commented Jan 19, 2021

geocube:
Step 1: https://gis.stackexchange.com/questions/384581/raster-to-geopandas/384691#384691

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,
)

@snowman2 snowman2 added proposal Idea for a new feature. documentation Documentation related issue labels Jan 19, 2021
@Zepy1
Copy link

Zepy1 commented Aug 26, 2021

There are several options for the case where the data is unevently spaced and you want to convert it to a regular grid;

* `pyresample`: https://pyresample.readthedocs.io/en/latest/swath.html (maybe @djhoese could assist here?)

* The `rasterize_points_` functions powered by scipy: https://github.com/corteva/geocube/blob/master/geocube/rasterize.py

* `gdal.Grid`: https://gdal.org/python/osgeo.gdal-module.html#Grid

Also the Xoak library seems promising to perform point-wise selection of irregularly spaced data : https://xoak.readthedocs.io/en/latest/examples/introduction.html

@snowman2
Copy link
Member Author

See: #202

@snowman2
Copy link
Member Author

Related #724

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation related issue proposal Idea for a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants