[AstroPy] Problem with the latest version of astropy and numpy

Simon Conseil simon at sconseil.fr
Mon Aug 26 08:22:31 EDT 2019


The issue tracker is on github:

https://github.com/astropy/astropy/issues/new

Simon


Le 26/08/2019 à 12:58, LAMBERT-HUYGHE Antigone a écrit :
> Hi,
>
> Ok, where can I send the bug report? I will construct the minimal example ASAP.
>
> Best,
> Antigone
> ________________________________
> De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr]
> Envoyé : lundi 26 août 2019 11:59
> À : astropy at python.org
> Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy
>
>
> Hi,
>
> It is indeed weird that it tries to convert to a quantity if you are using Numpy arrays. There were significant changes in the convolution sub-package in Astropy 3.2 so this is probably worth a bug report, and ideally adding a minimal example to reproduce the issue (showing how you build the kernel).
>
> Best,
>
> Simon
>
> Le 26/08/2019 à 09:24, LAMBERT-HUYGHE Antigone a écrit :
>
> Hi,
>
> I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy).
>
> I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following:
>
> convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08)
>
> Parameters
>
> array NDData<https://docs.astropy.org/en/stable/api/astropy.nddata.NDData.html#astropy.nddata.NDData><https://docs.astropy.org/en/stable/api/astropy.nddata.NDData.html#astropy.nddata.NDData> or numpy.ndarray<https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray><https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray> or array-like
>
> The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData<https://docs.astropy.org/en/stable/api/astropy.nddata.NDData.html#astropy.nddata.NDData><https://docs.astropy.org/en/stable/api/astropy.nddata.NDData.html#astropy.nddata.NDData>, the mask of the NDData<https://docs.astropy.org/en/stable/api/astropy.nddata.NDData.html#astropy.nddata.NDData><https://docs.astropy.org/en/stable/api/astropy.nddata.NDData.html#astropy.nddata.NDData> will be used as the mask argument.
>
> kernel numpy.ndarray<https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray><https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray> or Kernel<https://docs.astropy.org/en/stable/api/astropy.convolution.Kernel.html#astropy.convolution.Kernel><https://docs.astropy.org/en/stable/api/astropy.convolution.Kernel.html#astropy.convolution.Kernel>
>
> The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value.
>
> [...]
> Returns
>
> result numpy.ndarray<https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray><https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray>
>
> An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float.
>
> I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve.
>
> Best,
>
> Antigone
> ________________________________
> De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org<mailto:astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org>] de la part de Kenneth Anderson [kanderso at gemini.edu<mailto:kanderso at gemini.edu>]
> Envoyé : vendredi 23 août 2019 17:04
> À : Astronomical Python mailing list
> Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy
>
> Hi Antigone,
>
> I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the  'out' object, should be an astropy.units.Quantity object, not a numpy object.
>
> It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack.
>
>  From the docstr:
> ---------------------
> _result_as_quantity(self, result, unit, out):
>          [ ... ]
>          Parameters
>          ----------
>          result : `~numpy.ndarray` or tuple of `~numpy.ndarray`
>              Array(s) which need to be turned into quantity.
>          unit : `~astropy.units.Unit` or None
>              Unit for the quantities to be returned (or `None` if the result
>              should not be a quantity).  Should be tuple if result is a tuple.
>          out : `~astropy.units.Quantity` or None
>              Possible output quantity. Should be `None` or a tuple if result
>              is a tuple.
>
>          Returns
>          -------
>          out : `~astropy.units.Quantity`
>             With units set.
>
> salud,
> k
>
>
>
>
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org<mailto:AstroPy at python.org>
> https://mail.python.org/mailman/listinfo/astropy
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20190826/12672c8d/attachment.html>


More information about the AstroPy mailing list