-
Notifications
You must be signed in to change notification settings - Fork 59
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
Spatial averaging over a polygon - roadmap discussion #422
Comments
I'm interested in this discussion. For regular grids I thought of subsampling each grid point 10 x 10 times, apply For irregular grids I don't have an idea... |
Hi @mathause, Please do chime in. |
@huard Wouldn't this be better discussed in https://github.com/roocs/clisops? |
@Zeitsperre not a bad idea. So let me write here the conclusions of the little review I did: I looked at many python package providing geospatial tools for xarray datasets and realized that there aren't many. Of all studied packages, As more specifically for spatial averages over a polygon, no other xarray-compatible package offer the feature. There is an implementation in ocgis and it looks like ESMF could do it, pending implementations in ESMFpy and xESMF. However, methods suggest by myself in internal discussions seem easier to implement and would be fit for clisops. I suggest we close this issue and reopen an new one in clisops discussing these. |
In my mind the the most complete methodology would be to approach this more as a GIS analysis.
This should work for both irregular and regular grids.. biggest challenge (as often is the case) is likely dealing with irregular grid cells that cross the -180,180 longitude or are near the poles. This could also potentially be computationally 'long' depending on grid resolution and spatial domain (e.g. 1km over the entire globe?) in which case we might like to have different options |
I agree completely. What I tried and presented last time was mainly that without 3. It should be easy to implement, I am just waiting on both an answer on my clisops issue and some "free" time on my side. |
See https://github.com/NCPP/ocgis/blob/61d88c60e9070215f28c1317221c2e074f8fb145/src/ocgis/regrid/base.py#L24 doing pretty much this with xESMF. |
Just read the code quickly. Implementing the ESMF Mesh into xESMF would indeed be quite useful. It looks like a lot of work, though! Implementing our method in clisops wouldl be much faster for quantitatively similar results. But working on xESMF has a greater potential and userbase. |
I thought that since we had a reference implementation, the amount of work would not be so large, but that was just a guess, not the result of an actual analysis. |
Getting a bit confused ... but the example actually using ESMpy directly correct? And we would like to reproduce via xESMF in order to be able to leverage dask? |
Yes, xESMF was not a thing at the time. |
In any case there seems to be a lot of robust code in the example @huard linked to ... I would tend to agree that we should do our best to avoid reproducing something that exists already unless we can make a very clear case for it. Would there be a way to use the code to provide an output of spatial weights only.... e,g, identify grid ids in the subset (any grid that touches the subset polygon) and associated areas as the output and not necessarily apply the regridding itself? Dask shouldn't be critical in this case. A subsequently call to |
Maybe my lack of experience with ESMF is making me estimate longer times, but the main problem is that xESMF is lacking all implementation of the Mesh object of ESMpy/ESMF. This is the part I think is not simple, if even possible? Lacking in ESMpy is mesh element vith more than 4 corners, but it seems to be lacking in ESMF also ! https://esmf-org.github.io/801branch_docs/ESMF_refdoc/node5.html#SECTION050102100000000000000 Speed wise, Fortran is clearly faster for large tasks, but the shapely option should be fast enough too. But you're right : even if a first draft implementation would be easy, all the testing + covering all cases will take some time. |
i.e. in my case ESMpy should be fine |
@aulemahal By Mesh, do you mean the grid with the cell corners ? If yes, there is a PR for this already by yours truly. Still needs to work, but nothing major. |
Answering myself but there seems to be a |
@huard Cool! I'm guessing you mean "generating the grid corners" in order to use conservative methods? |
@huard sorry if I am still a bit confused. Does xESMF weight calculation etc only work on 'grids' .. i.e. it will correctly intersect and weight the transfer of one grid to another but would not necessarily handle a case where we intersect a grid with an irregular shaped drainage basin / province boundary ... in this case gridcells intersecting the edge of the polygon create oddly shaped 'slivers' with mutliple vertices (likely >4) This could be linked to @aulemahal comments about mesh triangles as well I suppose? |
@aulemahal Got it. Yes, it's possible that it does not yet exist in ESMPy. I agree this would be problematic, since it's not just a matter of xESMF wrapping. @tlogan2000 Correct for xESMF, but the fortran ESMF library handles the case of irregular polygons. OCGIS uses this functionality, which we used in flyingpigeon. |
@huard @tlogan2000
For single polygons, I believe implementation to xESMF shouldn't be so hard, given that the PR computing lat and lon bounds is merged. However it lacks:
Note that adding the dependency of either shapely + pyproj or directly geopandas would be necessary for implementation in xESMF. A logical way I see would be to accept GeoDataFrames as inputs (instead of xarray datasets) in order to generate ESMpy Meshes. |
I suggest we close this issue now that the roadmap is fairly clear. |
Description
Propose strategy to compute spatial averages over a polygon. Needs to account for non-uniform grid area and partial overlap, holes in polygons.
Options discussed so far:
Document below experience with both approaches, testing, benchmarks, etc.
The text was updated successfully, but these errors were encountered: