[AstroPy] Problem with the latest version of astropy and numpy
Simon Conseil
simon at sconseil.fr
Mon Aug 26 11:04:58 EDT 2019
https://github.com/astropy/astropy/issues/9168
As mentioned in the ticket, you use units for the kernel (kernel.array
is a Quantity) so at least this explains why the crash happen in a
quantity method.
Simon
Le 26/08/2019 à 15:16, LAMBERT-HUYGHE Antigone a écrit :
> So I report here the problem as a bug.
>
> Here is the minimal example of my problem (with the imports) :
>
> import astropy.units as u
> from astropy.convolution import convolve
> import numpy as np
> from astropy.io import fits
> from astropy.convolution import Gaussian2DKernel
> from copy import deepcopy
>
> #The aim is to convolve the map in the file file.fits from a resolution of 1.6 arcsec to 6 arcsec
> inhdu = fits.open('file.fits')
>
> fromfwhm = 1.6*u.arcsec
> tofwhm = 6*u.arcsec
>
> #calculate kernel size
> f2s = 2.*np.sqrt(2*np.log(2))
>
> pixel_size = (abs(inhdu[0].header['CDELT1']) *u.deg).to('arcsec')
> #CDELT is a keyword in the header that gives the size of the pixel in an angular unit.
>
> kernel_sigma = np.sqrt( (tofwhm)**2 - (fromfwhm)**2 ) / pixel_size / f2s
>
> kernel = Gaussian2DKernel(stddev=kernel_sigma)
>
> result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True)
>
> outhdu = hdudeepcopy(inhdu)
> outhdu[0].data = result
>
> outhdu.writeto(WriteTo, overwrite=True)
>
> And, as a reminder, here is the error that I had:
>
> ~/Bureau/Codes/python_lib/mylib/fits.py in fits_convolve(infits, fromfwhm, tofwhm, GaussianTrim, WriteTo, pixkey, pixkey_unit, returnHDU, verbose)
> 640 result[i, :, :] = convolve(plane, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True)
> 641 else:
> --> 642 result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True)
> 643 #result = convolve_fft(inhdu[0].data, kernel)
> 644
>
> ~/.local/lib/python3.6/site-packages/astropy/nddata/decorators.py in wrapper(data, *args, **kwargs)
> 244 AstropyUserWarning)
> 245
> --> 246 result = func(data, *args, **kwargs)
> 247
> 248 if unpack and repack:
>
> ~/.local/lib/python3.6/site-packages/astropy/convolution/convolve.py in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol)
> 336 if normalize_kernel:
> 337 if not nan_interpolate:
> --> 338 result /= kernel_sum
> 339 else:
> 340 if nan_interpolate:
>
> ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs)
> 473 return result
> 474
> --> 475 return self._result_as_quantity(result, unit, out)
> 476
> 477 def _result_as_quantity(self, result, unit, out):
>
> ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out)
> 512 # the output is of the correct Quantity subclass, as it was passed
> 513 # through check_output.
> --> 514 out._set_unit(unit)
> 515 return out
> 516
>
> AttributeError: 'numpy.ndarray' object has no attribute '_set_unit'
>
> Thank you for all the answeres that I had here.
>
>
> _______________________________________________
> 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/f027e921/attachment.html>
More information about the AstroPy
mailing list