Repository navigation
feat: speedup downscaling by making it a matrix multiplication - #15
Merged
Merged
Conversation
blallen
reviewed
Oct 15, 2026
blallen
reviewed
Oct 15, 2026
blallen
left a comment
There was a problem hiding this comment.
The implementation here looks good, just got worried about off by one and cell boundary errors. I found a few cases myself, codex found some others with orientation and etc. Posted examples of tests and/or fixes to help out. I think all of this is mostly edge cases, but they feel like the kind that would be nasty to debug without the extra guards.
blallen
approved these changes
Oct 15, 2026
jeffseif
commented
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
One of the heavy steps in
attributeis downscaling the 30 m emissions rasters to MAPSPAM's 10 km grid for statistical attribution. It wrote each band in full to a GeoTIFF on disk, then had a GDAL warped VRT average it down, which loaded the whole band (about 6 GiB) for every read. A tile took 5-7 minutes, peaked near 50 GiB at 8 workers (enough to OOMHND) and left a.tifand.vrtper band in the temp directory.This change computes the same averages as matrix multiplications on each dask chunk and adds them up across chunks, so nothing is written to disk and memory holds a few chunks rather than whole bands.
Notes
Manually testing
I ran for the
HNDandTWNtiles, saw a runtime of 2 minutes instead of 5 and peak memory of ~3 GiB, and verified that the results were identical for all bands.