ValueError: zero-size array to reduction operation minimum which has no identity

Hy
i am trying to calculate beam blockage using srtm data . i am getting following error .

code:
rasterfile = “D:\FINAL YEAR PROJECT\Wradlib\gt30e060n40.dem”
ds = wrl.io.open_raster(rasterfile)
rastervalues, rastercoords, proj = wrl.georef.extract_raster_dataset(
ds, nodata=-32768.0
)

Clip the region inside our bounding box

ind = wrl.util.find_bbox_indices(rastercoords, rlimits)
rastercoords = rastercoords[ind[1] : ind[3], ind[0] : ind[2], …]
rastervalues = rastervalues[ind[1] : ind[3], ind[0] : ind[2]]

Map rastervalues to polar grid points

polarvalues = wrl.ipol.cart_to_irregular_spline(
rastercoords, rastervalues, polcoords, order=3, prefilter=False
)

error:

ValueError Traceback (most recent call last)
Cell In[8], line 15
12 rastervalues = rastervalues[ind[1] : ind[3], ind[0] : ind[2]]
14 # Map rastervalues to polar grid points
—> 15 polarvalues = wrl.ipol.cart_to_irregular_spline(
16 rastercoords, rastervalues, polcoords, order=3, prefilter=False
17 )

File ~\anaconda3\envs\pyart_env\lib\site-packages\wradlib\ipol.py:1690, in cart_to_irregular_spline(cartgrid, values, newgrid, **kwargs)
1687 nx = cartgrid.shape[1]
1688 ny = cartgrid.shape[0]
→ 1690 cxmin = np.min(cartgrid[…, 0])
1691 cxmax = np.max(cartgrid[…, 0])
1692 cymin = np.min(cartgrid[…, 1])

File ~\anaconda3\envs\pyart_env\lib\site-packages\numpy\core\fromnumeric.py:2953, in min(a, axis, out, keepdims, initial, where)
2836 @array_function_dispatch(_min_dispatcher)
2837 def min(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
2838 where=np._NoValue):
2839 “”"
2840 Return the minimum of an array or minimum along an axis.
2841
(…)
2951 6
2952 “”"
→ 2953 return _wrapreduction(a, np.minimum, ‘min’, axis, None, out,
2954 keepdims=keepdims, initial=initial, where=where)

File ~\anaconda3\envs\pyart_env\lib\site-packages\numpy\core\fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
85 else:
86 return reduction(axis=axis, out=out, **passkwargs)
—> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation minimum which has no identity
anybody have idea how to fix this ?

Hello @pikuljena,

welcome to openradar discourse.

I’m assuming a problem with rlimits not fitting your actual data projection.

Can you please report the contents of rlimits you are using? The content of proj would also be interesting, to see which projection the DEM data is in. rlimits and rastercoords have to be in the same projection.

rlimits
(-0.9529142728897741, 74.71267576099122, 18.012914272889773, 79.00693742464783)

rastercoords
array([[[60.00416667, 39.99583333],
[60.0125 , 39.99583333],
[60.02083333, 39.99583333],
…,
[99.97916667, 39.99583333],
[99.9875 , 39.99583333],
[99.99583333, 39.99583333]],

   [[60.00416667, 39.9875    ],
    [60.0125    , 39.9875    ],
    [60.02083333, 39.9875    ],
    ...,
    [99.97916667, 39.9875    ],
    [99.9875    , 39.9875    ],
    [99.99583333, 39.9875    ]],

   [[60.00416667, 39.97916667],
    [60.0125    , 39.97916667],
    [60.02083333, 39.97916667],
    ...,
    [99.97916667, 39.97916667],
    [99.9875    , 39.97916667],
    [99.99583333, 39.97916667]],

   ...,

   [[60.00416667, -9.97916667],
    [60.0125    , -9.97916667],
    [60.02083333, -9.97916667],
    ...,
    [99.97916667, -9.97916667],
    [99.9875    , -9.97916667],
    [99.99583333, -9.97916667]],

   [[60.00416667, -9.9875    ],
    [60.0125    , -9.9875    ],
    [60.02083333, -9.9875    ],
    ...,
    [99.97916667, -9.9875    ],
    [99.9875    , -9.9875    ],
    [99.99583333, -9.9875    ]],

   [[60.00416667, -9.99583333],
    [60.0125    , -9.99583333],
    [60.02083333, -9.99583333],
    ...,
    [99.97916667, -9.99583333],
    [99.9875    , -9.99583333],
    [99.99583333, -9.99583333]]])

proj
<osgeo.osr.SpatialReference; proxy of <Swig Object of type ‘OSRSpatialReferenceShadow *’ at 0x0000028D800E8360> >
wkt = proj.ExportToWkt()
‘GEOGCS[“WGS 84”,DATUM[“WGS_1984”,SPHEROID[“WGS 84”,6378137,298.257223563,AUTHORITY[“EPSG”,“7030”]],AUTHORITY[“EPSG”,“6326”]],PRIMEM[“Greenwich”,0,AUTHORITY[“EPSG”,“8901”]],UNIT[“degree”,0.0174532925199433,AUTHORITY[“EPSG”,“9122”]],AXIS[“Latitude”,NORTH],AXIS[“Longitude”,EAST],AUTHORITY[“EPSG”,“4326”]]’

ind
(0, 6000, 0, 6000)
after indexing rastercoords becomes an empty array

It looks like your rlimits is (latmin, lonmin, latmax, lonmax) but it should be (lonmin, latmin, lonmax, latmax) → (74.71267576099122, -0.9529142728897741, 79.00693742464783, 18.012914272889773).

1 Like