[SciPy-User] Updating SciPy from 0.9.0 to 0.10.1 triggers undesired behavior in NumPy 1.6.2

Ralf Gommers ralf.gommers@googlemail....
Tue Jul 31 11:43:36 CDT 2012


On Mon, Jul 30, 2012 at 6:33 PM, Wolfgang Draxinger <
Wolfgang.Draxinger@physik.uni-muenchen.de> wrote:

> Hi,
>
> first my apologies for crossposting this to two maillists, but as both
> projects are affected I think this is in order.
>
> Like the subject says I encountered some undesired behavior in the
> interaction of SciPy with NumPy.
>
> Using the "old" SciPy version 0.9.0 everything works fine and smooth.
> But upgrading to SciPy-0.10.1 triggers some ValueError in
> numpy.histogram2d of NumPy-1.6.2 when executing one of my programs.
>
> I developed a numerical evaluation system for our detectors here. One of
> the key operations is determining the distribution of some 2-dimensional
> variable space based on the values found in the image delivered by the
> detector, where each pixel has associated values for the target
> variables. This goes something like the following
>
>    ABdist, binsA, binsB = numpy.histogram2d(
>        B_yz.ravel(),
>        A_yz.ravel(),
>        [B_bins, A_bins],
>        weights=image.ravel() )
>
> The bins parameter can be either [int, int] or [array, array], that
> makes no difference in the outcome.
>
> The mappings A_yz and B_yz are created using
> scipy.interpolate.griddata. We have a list of pairs of pairs which are
> determined by measurement. Basically in the calibration step we vary
> variables A,B and store at which Y,Z we get the corresponding signal.
> So essentially this is a (A,B) -> (Y,Z) mapping. In the region of
> interest is has a bijective subset that's also smooth. However the
> original data also contains areas where (Y,Z) has no corresponding
> (A,B) or where multiple (A,B) map to the same (Y,Z); like said, those
> lie outside the RoI. For our measurements we need to reverse this
> process, i.e. we want to do (Y,Z) -> (A,B).
>
> So I use griddata to evaluate a discrete reversal for this
> mapping, of the same dimensions that the to be evaluated image has:
>
>    gry, grz = numpy.mgrid[self.y_lim[0]:self.y_lim[1]:self.y_res*1j,
>                           self.z_lim[0]:self.z_lim[1]:self.z_res*1j]
>    # for whatever reason I have to do the following
>    # assigning to evalgrid directly breaks the program.
>    evalgrid = (gry, grz)
>
>    points = (Y.ravel(), Z.ravel())
>
>    def gd(a):
>        return scinp.griddata(
>            points,
>            a.ravel(),
>            evalgrid,
>            method='cubic' )
>
>    A_yz = gd(A)
>    B_yz = gd(B)
>
> where A,B,Y,Z have the same dimensions and are the ordered lists/arrays
> of the scalar values of the two sets mapped between. As you can see,
> this approach does also involve the elements of the sets, which are not
> mapped bijectively. As lying outside the convex boundary or not being
> properly interpolatable they should receive the fill value.
>
> As long as I stay with SciPy-0.9.0 everything works fine. However after
> upgrading to SciPy-0.10.1 the histogram2d step fails with a ValueError.
> The version of NumPy is 1.6.2 for both cases.
>
> /usr/lib64/python2.7/site-packages/numpy/ma/core.py:772: RuntimeWarning:
> invalid value encountered in absolute
>   return umath.absolute(a) * self.tolerance >= umath.absolute(b)
> Traceback (most recent call last):
>   File "./ephi.py", line 71, in <module>
>     ABdist, binsA, binsB = numpy.histogram2d(B_yz.ravel(), A_yz.ravel(),
> [B_bins, A_bins], weights=image.ravel())
>   File "/usr/lib64/python2.7/site-packages/numpy/lib/twodim_base.py", line
> 615, in histogram2d
>     hist, edges = histogramdd([x,y], bins, range, normed, weights)
>   File "/usr/lib64/python2.7/site-packages/numpy/lib/function_base.py",
> line 357, in histogramdd
>     decimal = int(-log10(mindiff)) + 6
> ValueError: cannot convert float NaN to integer
>
> Any ideas on this?
>

Looks to me like the issue only has to do with a change in griddata, and
nothing with histogram2d. The return values from griddata must be
different.

I suggest that you compare the return values from griddata for 0.9.0 and
0.10.1 with your input data, then try to reduce that comparison to a small
self-contained example that shows the difference. This will allow us to
debug the issue further.

Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120731/e971ba81/attachment-0001.html 


More information about the SciPy-User mailing list