metoppv / improver

IMPROVER is a library of algorithms for meteorological post-processing.
http://improver.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
101 stars 84 forks source link

Change to nbhood plugin to satisfy Numpy warning and future Numpy error. #1992

Closed Kat-90 closed 2 months ago

Kat-90 commented 2 months ago

Description:

During the investigation work into IMPROVER wind gusts I noticed an error in our nbhood plugin when using a more up to date environment than we use for production:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

It tripped me up a bit trying to work out what the problem was. This error is a VisibleDeprecationWarning in our current environment which explains things better:

/improver/nbhood/nbhood.py:102: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  open_grid = np.array(np.ogrid[[slice(-x, x + 1) for x in (ranges, ranges)]])

To avoid tripping up on this again in the future this PR suggests we implement the change it requires now.

Testing: