Skip to content

Vectorize Impact.impact_at_reg CSR reduction and points_to_raster boxes - #1358

Open
napattan wants to merge 1 commit into
CLIMADA-project:developfrom
napattan:fix/vectorize-impact-at-reg-points-to-raster-1357
Open

napattan wants to merge 1 commit into
CLIMADA-project:developfrom
napattan:fix/vectorize-impact-at-reg-points-to-raster-1357

Conversation

@napattan

Copy link
Copy Markdown

Changes proposed in this PR:

  • Re-apply the vectorizations from perf(engine,coordinates): vectorize Impact.impact_at_reg CSR reduction and points_to_raster boxes #1350 (Impact.impact_at_reg via np.unique(..., return_inverse=True) + CSR sparse indicator matrix multiplication, and climada.util.coordinates.points_to_raster apply_box via shapely.box) following revert a7849c8, with performance characteristics unchanged from perf(engine,coordinates): vectorize Impact.impact_at_reg CSR reduction and points_to_raster boxes #1350.
  • Fix PR #1350 introduced an integration test failure #1357 in Impact.impact_at_reg by flattening agg_regions with np.asarray(agg_regions).ravel() and sizing the indicator matrix rows from n_reg = agg_regions.size (shape=(self.imp_mat.shape[1], agg_reg_unique.size), with explicit guards for empty or over-length agg_regions) so callers passing len(agg_regions) < self.imp_mat.shape[1] (such as climada.test.test_util_calibrate, where exposure() has 3 points with 1 unassigned centroid and agg_regions=["a", "b"] has length 2) match the prior np.where column selection identically.
  • Add unit tests in TestImpactReg.test_agg_regions_length covering shorter, 2D, over-length, and empty agg_regions (verified locally with pytest climada/test/test_util_calibrate.py climada/engine/test/test_impact.py climada/util/test/test_coordinates.py), and move the CHANGELOG.md entry to ## Unreleased > ### Changed.

This PR fixes #1357

PR Author Checklist

PR Reviewer Checklist

* re-apply CLIMADA-project#1350 vectorizations for Impact.impact_at_reg and points_to_raster
* fix Impact.impact_at_reg row indexing when len(agg_regions) < n_exp (CLIMADA-project#1357)
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.

1 participant