Skip to content

reproject functions preserve source dtype#146

Open
mikegraham wants to merge 1 commit into
ACCESS-Cloud-Based-InSAR:devfrom
mikegraham:reproject-dtype-fix
Open

reproject functions preserve source dtype#146
mikegraham wants to merge 1 commit into
ACCESS-Cloud-Based-InSAR:devfrom
mikegraham:reproject-dtype-fix

Conversation

@mikegraham
Copy link
Copy Markdown

@mikegraham mikegraham commented Mar 7, 2026

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.

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
@mikegraham mikegraham force-pushed the reproject-dtype-fix branch from ed67ba5 to 7f83044 Compare March 7, 2026 07:24
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.

Reproject functions use default dtype rather than data dtype

1 participant