reproject functions preserve source dtype#146
Open
mikegraham wants to merge 1 commit into
Open
Conversation
reproject_arr_to_match_profile allocated a float64 destination array then
copied it back with .astype(src_dtype): we can get rid of the middleman.
reproject_arr_to_new_crs allocated float64 regardless of input dtype.
Changes both to allocate np.zeros with dtype=src_dtype from the start.
$ for branch in reproject-dtype-fix dev; do
git checkout "$branch"
python -c "
import numpy as np
import timeit
from affine import Affine
from rasterio.crs import CRS
from dem_stitcher.rio_tools import reproject_arr_to_match_profile, update_profile_resolution
profile = {
'driver': 'GTiff',
'dtype': 'float32',
'width': 3601,
'height': 3601,
'count': 1,
'nodata': -9999.0,
'crs': CRS.from_epsg(4326),
'transform': Affine(1/3600, 0, -120, 0, -1/3600, 47),
}
arr = np.random.rand(1, 3601, 3601).astype(np.float32)
ref = update_profile_resolution(profile, 1/3600)
print(timeit.timeit(lambda: reproject_arr_to_match_profile(arr, profile, ref), number=50))"
done
Switched to branch 'reproject-dtype-fix'
22.2185484910151
Switched to branch 'dev'
Your branch and 'origin/dev' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" if you want to integrate the remote branch with yours)
24.99464279296808
ed67ba5 to
7f83044
Compare
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.
Closes #145
reproject_arr_to_match_profile allocated a float64 destination array then copied it back with .astype(src_dtype): we can get rid of the middleman.
reproject_arr_to_new_crs allocated float64 regardless of input dtype.
Changes both to allocate np.zeros with dtype=src_dtype from the start.