<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><a class="moz-txt-link-freetext" href="https://github.com/astropy/astropy/issues/9168">https://github.com/astropy/astropy/issues/9168</a></p>
<p>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.</p>
<p>Simon<br>
</p>
<div class="moz-cite-prefix">Le 26/08/2019 à 15:16, LAMBERT-HUYGHE
Antigone a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:A04EC7BAE538C148A4B6A95FFDFCCCAF3312C0C6@e-exdage-b0.extra.cea.fr">
<pre class="moz-quote-pre" wrap="">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.
</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
AstroPy mailing list
<a class="moz-txt-link-abbreviated" href="mailto:AstroPy@python.org">AstroPy@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/astropy">https://mail.python.org/mailman/listinfo/astropy</a>
</pre>
</blockquote>
</body>
</html>