'FutureWarning in scipy stats

I made a function who's role is to calculate radial average and radial median for each bin and test it for one *.tif format image.

import numpy as np
from math import fabs
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from PIL import Image
from scipy import stats

def av_radial_profile(data, center):
    y, x = np.indices((data.shape))
    r = np.hypot(x - center[0],y - center[1])
    r = r.astype(np.int)
    b = len(set(r.ravel()))
    av_radialprofile = stats.binned_statistic(r.ravel(), data.ravel(), statistic ='mean', bins = b)[0]
    
    median_radialprofile = stats.binned_statistic(r.ravel(), data.ravel(), statistic = lambda q: np.nanmedian(q), bins = b)[0]  

    return median_radialprofile, av_radialprofile
    
img = mpimg.imread('test.tif',0)
center, radi = (509, 546), 55
rad2, rad3 = av_radial_profile(img, center)

The picture is here:
the tif-format picture

After running this code, I face the following Warning message:

~miniconda3/lib/python3.7/site-packages/scipy/stats/_binned_statistic.py:607: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  result = result[core]

I tried to search the cause of the problem and saw that the reason might be based on old packages versions. So after that I updated all packages with conda and reran my code, but warning message didn't disappear.

Maybe, someone came across with the same problem. I'll be very grateful for any help and notes regarding my code.



Solution 1:[1]

In scipy 1.3.1 the 'offending' code is now

# Remove outliers (indices 0 and -1 for each bin-dimension).
core = tuple([slice(None)] + Ndim * [slice(1, -1)])
result = result[core]

In the scipy/stats/_binned_statistic.py file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hpaulj