Skip to content

Conversation

@timschmi95
Copy link
Collaborator

@timschmi95 timschmi95 commented Jul 10, 2025

Changes proposed in this PR:

  • Substantially speeding up plots by directly adding all borders with one call, rather than loop through each geometry object, when adding countries and coastlines in the u_plot.add_shapes function. I've tested the new function in multiple tutorials and my own data (both with standard and projected coordinates) and the plots look equivalent.
  • Set the default value of the recently implemented mask_distance in hazard plots from 0.01 to 0.03.

This PR fixes #1071
Substantially speeds up hazard.plot_intensity (and other functions that use u_plot.add_shapes). Before the update, adding the country borders took up to 75% of the overall time, which is reduced to <1%, significantly speeding up the overall function.

The change of the default mask_distance is somewhat independent. While testing many plots in the tutorial, we noticed in multiple instances the haz.plot_intensity() with the recently updated raster plotting functionality (PR #1047) showed small white gaps within gridded data, if there are fewer than ~80 regularly spaced gridpoints in one direction. Changing the default from 0.01 to 0.03 allows smooth plots for data with fewer (down to ~30) gridpoints per side, while keeping the default interpolation distance for data with gaps reasonably small.
Of course, users can always adjust the parameter depending on their data, but increasing the default will lead to fewer user seeing gaps in their gridded hazard data plot and needing to dig into the keyword arguments of the haz.plot_intensity() function.

PR Author Checklist

PR Reviewer Checklist

@timschmi95
Copy link
Collaborator Author

As an example of the grid spacing, with centroids as defined in the main climada tutorial (1_main_climada.ipynb):
grafik
The plot with the default of 0.01 looks like this:
grafik
and with 0.03 it gets filled:
grafik

Of course on the other hand, the default 'filled borders' in e.g. a plot with France and it's colonies are a bit larger.

Copy link
Member

@peanutfun peanutfun left a comment

Choose a reason for hiding this comment

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

Thank you for the quick PR! 🙌

Please add two entries into the changelog, one for the change to add_shapes and the speedup of the plotting, and one for the change in mask_distance. Also, please make sure the pre-commit hooks run through. The code is not properly formatted by black, see the failing test.

@ValentinGebhart, please check if you concur with the changes to mask_distance.

@ValentinGebhart
Copy link
Collaborator

Thanks @timschmi95! Very much agree with the new default value of mask_distance.

@timschmi95
Copy link
Collaborator Author

Changelog is updated and tests passing. Is it ready to merge then @peanutfun ?

Copy link
Member

@peanutfun peanutfun left a comment

Choose a reason for hiding this comment

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

Huh? I must have been confusing by you closing the issue already, @timschmi95. I thought it was already merged. Good to go! 🚀

@timschmi95 timschmi95 merged commit c3b5376 into develop Jul 11, 2025
19 checks passed
@timschmi95 timschmi95 deleted the feature/plot_intensity_efficiency branch July 11, 2025 09:10
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.

4 participants