Geotiff raster saving broken with numpy >= 2.4.0
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- numpy, python
- Domain
- data-visualization
Research direction
Start in lib/iris/experimental/raster.py around the _gdal_write_array call at line 210, then reproduce the issue with the provided Cube example under numpy >=2.4. Ensure the x/y minimum and step values passed to GDAL are scalar numeric values, and verify that export_geotiff creates the GeoTIFF without raising TypeError.
Written by the indexing model from the issue text.
Description
🐛 Bug Report
The function iris.experimental.raster.export_geotiff fails with numpy>=2.4.0 with the following GDAL error:
File " ... /site-packages/osgeo/gdal.py", line 4468, in SetGeoTransform
return _gdal.Dataset_SetGeoTransform(self, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: not a number
This is due to how the parameters are passed to the ...
How To Reproduce
Steps to reproduce the behaviour:
from iris.cube import Cube
from iris.coords import DimCoord
from iris.experimental.raster import export_geotiff
import numpy as np
lats = DimCoord(np.arange(5), standard_name="latitude", units="degrees")
lats.guess_bounds()
lons = DimCoord(np.arange(5), standard_name="longitude", units="degrees")
lons.guess_bounds()
c = Cube(
data=np.arange(25, dtype=np.float64).reshape(5,5),
standard_name="depth",
dim_coords_and_dims=((lats, 0), (lons,1))
)
export_geotiff(c, '/tmp/geo.tiff') # throws a TypeError
Expected behaviour
Does not throw a TypeError!
Environment
- OS & Version: RHEL10
- Iris Version: 3.15.0
Proposed Fix
The issue appears to be with the values passed to _gdal_write_array in experimental/raster.py:
https://github.com/SciTools/iris/blob/6d9ef5e7af7dfb0e26bac398650606827c883a07/lib/iris/experimental/raster.py#L210
The [xy]_min and [xy]_step values should be plain python floats, or numpy floats, but this routine passes in the following:
x_min=np.float64(-0.5), x_step=array([1.]), y_max=np.float64(4.5), y_step=array([-1.])
which is a mixture of scalar and 1D array numpy values. This appeared to silently work up until numpy==2.4.0, but is now failing.
The fix should be as simple as ensuring those values are plain python floats, or a numpy scalar, perhaps by using .item() which is safe to use on scalars and 1D arrays (and will throw an error if the arrays is greater than length 1).
- Dominant language
- Python
- Stars
- 724
- Forks
- 317
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SciTools/iris
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100