Skip to content

slow haz.plot_intensity() function #1071

@timschmi95

Description

@timschmi95

The hazard.plot_intensity() function is comparably slow in most cases, taking 20+ seconds. A line profiling reveals that (in my 3 tested cases) around 75% of the time is spent in the u_plot.add_shapes() function which adds the country boundaries.

Replacing the existing

shp_file = shapereader.natural_earth(
        resolution="10m", category="cultural", name="admin_0_countries"
    )
shp = shapereader.Reader(shp_file)
for geometry in shp.geometries():
    axis.add_geometries(
        [geometry], crs=ccrs.PlateCarree(), facecolor="none", edgecolor="dimgray"
    )

with

BORDERS2_10m = cfeature.NaturalEarthFeature('cultural', 'admin_0_countries',
                                '10m', edgecolor='dimgray', facecolor='none')
axis.add_feature(BORDERS2_10m)

or simply
axis.add_feature(cfeature.BORDERS, edgecolor='dimgrey')

reduces this percentage to essentially 0, making the overall function 4x faster. The maps look exactly the same.

I believe the data of the 10m borders is already downloaded by default in the cartopy package and never needs an internet connection. At least it works for me in a completely new environment without internet access. However, it could be that my mamba linked the cartopy package from another environment, where I actually had the data downloaded once, and therefore needs to be downloaded by the user once. I could double-check that.

Shall I create a pull request for this change, or is there something that speaks against it?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions