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

burn_vector_geometry and polygonize #126

Merged
merged 12 commits into from
Jul 31, 2023
Merged

burn_vector_geometry and polygonize #126

merged 12 commits into from
Jul 31, 2023

Conversation

Huite
Copy link
Collaborator

@Huite Huite commented Jul 26, 2023

Add vector utilities such as provided by GDAL for raster data.

Copy link
Contributor

@JoerivanEngelen JoerivanEngelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, my comments mostly concern comments, documentation and type annotation.
I got one comment to provide an example to burn points into a grid which would require a bit of work though.

#
# In this example, we mark the faces that are covered by a certain province.

provinces = xu.data.provinces_nl().to_crs(28992)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment why you call to_crs here, is it because the data is in a different CRS? Or because it has no CRS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be reprojected from WGS84. I've added a paragraph of explanation.

# In this example, we mark the faces that are covered by a certain province.

provinces = xu.data.provinces_nl().to_crs(28992)
provinces["value"] = range(len(provinces))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
provinces["value"] = range(len(provinces))
provinces["value"] = range(len(provinces)) # Give each province a unique label

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the extra paragraph.

#
# The exterior boundaries of the province polygons will provide
# a collection of linestrings that we can burn into the grid:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, I think it is good to also add an example with points. For example, two points indicating the locations of the cities of Delft and Utrecht. Just to prove that xugrid can do it, and in what form points are expected (as GeoDataFrame containing shapely points).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done using the centroids of the provinces.

faces: IntArray,
vertices: FloatArray,
):
# TODO: move this into numba_celltree instead?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to add this TODO to all functions that need to be moved to numba_celltree, like point_in_triangle. This will help communicating to other developers which functions might need to be moved to numba_celltree. Also don't forget to open an issue for this!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Parameters
----------
gdf: geopandas.GeoDataFrame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gdf: geopandas.GeoDataFrame
gdf: geopandas.GeoDataFrame
Collection of polygons, points, and/or lines to be burned into the grid.

Parameters
----------
gdf: geopandas.GeoDataFrame
like: UgridDataArray, UgridDataset, or Ugrid2d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
like: UgridDataArray, UgridDataset, or Ugrid2d
like: UgridDataArray, UgridDataset, or Ugrid2d
Grid to burn vector data into.

def test_burn_polygons(grid, polygons_and_values):
polygons, values = polygons_and_values
output = np.full(grid.n_face, np.nan)
burn._burn_polygons(polygons, grid, values, all_touched=False, output=output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, also add a test where all_touched=True


def burn_vector_geometry(
gdf: "geopandas.GeoDataframe", # type: ignore # noqa
like: "xugrid.Ugrid2d",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit in doubt about the name like here, conceptually I perceived this method different than regrid_like or full_like. As it is returning a copy of like however, it is essentially doing such a thing, but it feels a bit unintuitive. I cannot think of a better name though. grid doesn't cover it (as UgridDataset is also allowed), and template introduces suddenly new nomenclature to the package. Just sharing my thoughts, you can resolve without notice.


def burn_vector_geometry(
gdf: "geopandas.GeoDataframe", # type: ignore # noqa
like: "xugrid.Ugrid2d",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
like: "xugrid.Ugrid2d",
like: Union["xugrid.Ugrid2d", "xugrid.UgridDataArray", "xugrid.UgridDataset"],

@Huite Huite merged commit ecfc059 into main Jul 31, 2023
2 checks passed
@Huite Huite deleted the burn branch July 31, 2023 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants