astropy / reproject

Python-based Astronomical image reprojection :milky_way: - maintainer @astrofrog
https://reproject.readthedocs.io
BSD 3-Clause "New" or "Revised" License
105 stars 64 forks source link

map_coordinates in adaptive reprojection does not accept read-only arrays #449

Closed astrofrog closed 1 week ago

astrofrog commented 2 weeks ago

The following example:

import numpy as np
from reproject import reproject_adaptive
from astropy.wcs import WCS

wcs1 = WCS(naxis=2)
wcs2 = WCS(naxis=2)
wcs2.wcs.crpix = [2, 2]

array = np.random.random((128, 128))
array.flags.writeable = False

reproject_adaptive((array, wcs1), wcs2, shape_out=(128, 128))

fails with:

Traceback (most recent call last):
  File "/Users/tom/tmp/test_adaptive.py", line 12, in <module>
    reproject_adaptive((array, wcs1), wcs2, shape_out=(128, 128))
  File "/Users/tom/Code/Astropy/reproject/reproject/adaptive/high_level.py", line 233, in reproject_adaptive
    return _reproject_dispatcher(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tom/Code/Astropy/reproject/reproject/common.py", line 144, in _reproject_dispatcher
    return reproject_func(
           ^^^^^^^^^^^^^^^
  File "/Users/tom/Code/Astropy/reproject/reproject/adaptive/core.py", line 160, in _reproject_adaptive_2d
    map_coordinates(
  File "reproject/adaptive/deforest.pyx", line 355, in reproject.adaptive.deforest.map_coordinates
  File "<stringsource>", line 663, in View.MemoryView.memoryview_cwrapper
  File "<stringsource>", line 353, in View.MemoryView.memoryview.__cinit__
ValueError: buffer source array is read-only

I think we should make sure we support read-only arrays, though I'm not quite sure how to modify the Cython to do this. @svank - do you happen to know how to do this?