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

Better spatial mean #260

Merged
merged 4 commits into from
Sep 26, 2023
Merged

Better spatial mean #260

merged 4 commits into from
Sep 26, 2023

Conversation

aulemahal
Copy link
Collaborator

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
  • (If applicable) Documentation has been added / updated (for bug fixes / features).
  • (If applicable) Tests have been added.
  • This PR does not seem to break the templates.
  • HISTORY.rst has been updated (with summary of main changes).
    • Link to issue (:issue:number) and pull request (:pull:number) has been added.

What kind of change does this PR introduce?

  • One can now pass region='global' to spatial_mean. It will simply be replace by a bbox region covering the whole globe.
  • spatial_mean, method xesmf will automatically segmentize the polygons down to a resolution of 1°, to ensure a correct average.
  • Make out_chunks available in regrid_dataset and spatial_mean if using xesmf >= 0.8
  • Fix spatial_mean with method xesmf and a GeoDataFrame as shape.

Does this PR introduce a breaking change?

Shouldn't.

Other information:

Added a test for region='global'.

@aulemahal aulemahal requested a review from RondeauG September 25, 2023 18:26
Copy link
Contributor

@juliettelavoie juliettelavoie left a comment

Choose a reason for hiding this comment

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

Juste pour bien comprendre, segmentize: c'est que les vertices du polygone sont trop longues et on les sépare en plusieurs et simplify: c'est que les vertices sont trop courtes, alors on en combine plusieurs ensemble ?

Est-ce que le 1 en argument de segmentize c'est aussi en degré?

@aulemahal
Copy link
Collaborator Author

Exact! Les deux ont un argument "tolerance" dans les mêmes unités que les coordonnées des polygones. Donc des degrés pour tout nos cas. simplify est évidemment un peu plus complexe, y a aussi des tests de validité et autres, mais l'idée c'est en effet l'inverse de segmentize.

Copy link
Collaborator

@RondeauG RondeauG left a comment

Choose a reason for hiding this comment

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

LGTM! I'm happy to see that bug finally resolved 😄

call_kwargs["out_chunks"] = kwargs_copy.pop("out_chunks")

# Pre-emptive segmentization. Same threshold as xESMF, but there's not strong analysis behind this choice
geoms = shapely.segmentize(polygon.geometry, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Am I right in thinking that this will be skipped if we provided a shapefile with a resolution finer than 1°?

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 won't do anything to the shape indeed.

geoms == shapely.segmentize(geoms, 1) if no geom has any vertex longer than 1.

@aulemahal aulemahal merged commit fec1a0d into main Sep 26, 2023
@aulemahal aulemahal deleted the better-spaaverage branch September 26, 2023 20:28
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.

Improve spatial_mean
3 participants