GenericMappingTools / GenericMappingTools/pygmt

xyz2grd crashes python with large grids

Open
#3,086 11 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

Description

### Description of the problem

I am trying to create a grd file using pygmt's xyz2grd with a numpy array. The numpy array is large (64 pixels per degree corresponding to 11520 x 23040). Running the xyz2grd command kills the python kernel and gives the following result
```
python3.12(11590,0x1e10f1c40) malloc: *** error for object 0x3ff142fe20000000: pointer being freed was not allocated
python3.12(11590,0x1e10f1c40) malloc: *** set a breakpoint in malloc_error_break to debug
[1] 11590 abort ipython
```
I have the same problem on macOS and on Fedora linux (though on fedora, I don't think a error is reported, it just crashes).

### Minimal Complete Verifiable Example

```python
import numpy as np
import pygmt

nlat = 180 * 64
nlon = 360 * 64
array = np.empty((nlat, nlon))
spacing = 1/64

grd = pygmt.xyz2grd(array, spacing=spacing, region=[0, 360, -90, 90], registration='p')
```

### Full error message

```python-traceback
python3.12(11590,0x1e10f1c40) malloc: *** error for object 0x3ff142fe20000000: pointer being freed was not allocated
python3.12(11590,0x1e10f1c40) malloc: *** set a breakpoint in malloc_error_break to debug
[1] 11590 abort ipython
```

### System information

```bash
PyGMT information:
version: v0.11.0
System information:
python: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:01:35) [Clang 16.0.6 ]
executable: /Users/lunokhod/miniconda3/envs/py312/bin/python
machine: macOS-14.3-arm64-arm-64bit
Dependency information:
numpy: 1.26.3
pandas: 2.1.4
xarray: 2023.12.0
netCDF4: 1.6.5
packaging: 23.2
contextily: None
geopandas: None
ipython: None
rioxarray: None
ghostscript: 10.02.1
GMT library information:
binary version: 6.5.0
cores: 10
grid layout: rows
image layout:
library path: /Users/lunokhod/miniconda3/envs/py312/lib/libgmt.dylib
padding: 2
plugin dir: /Users/lunokhod/miniconda3/envs/py312/lib/gmt/plugins
share dir: /Users/lunokhod/miniconda3/envs/py312/share/gmt
version: 6.5.0
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.