<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<div>So I report here the problem as a bug.<br>
</div>
<div><br>
</div>
<div>Here is the minimal example of my problem (with the imports) : <br>
</div>
<div><font size="4" face="monospace"><br>
</font></div>
<font size="4" face="monospace">import astropy.units as u<br>
from astropy.convolution import convolve<br>
import numpy as np<br>
from astropy.io import fits<br>
from astropy.convolution import Gaussian2DKernel<br>
from copy import deepcopy<br>
<br>
#The aim is to convolve the map in the file file.fits from a resolution of 1.6 arcsec to 6 arcsec<br>
inhdu = fits.open('file.fits')<br>
<br>
fromfwhm = 1.6*u.arcsec<br>
tofwhm = 6*u.arcsec<br>
    <br>
#calculate kernel size<br>
f2s = 2.*np.sqrt(2*np.log(2))<br>
<br>
pixel_size = (abs(inhdu[0].header['CDELT1']) *u.deg).to('arcsec')<br>
#CDELT is a keyword in the header that gives the size of the pixel in an angular unit.<br>
    <br>
kernel_sigma = np.sqrt( (tofwhm)**2 - (fromfwhm)**2 ) / pixel_size / f2s<br>
    <br>
kernel = Gaussian2DKernel(stddev=kernel_sigma)<br>
<br>
result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True)<br>
    <br>
outhdu = hdudeepcopy(inhdu)<br>
outhdu[0].data = result<br>
<br>
</font>
<div><font size="3" face="Courier New"><font size="4" face="monospace">outhdu.writeto(WriteTo, overwrite=True)</font> 
</font><br>
</div>
<div><br>
</div>
<div>And, as a reminder, here is the error that I had:</div>
<div><font size="2" face="Tahoma" color="black"><span style="font-size:10pt;" dir="ltr">
<pre style="margin-top:14pt;margin-bottom:14pt;">~/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:
<b>--> 642</b><b>         </b><b>result </b><b>=</b><b> convolve</b><b>(</b><b>inhdu</b><b>[</b><b>0</b><b>]</b><b>.</b><b>data</b><b>,</b><b> kernel</b><b>,</b><b> boundary </b><b>=</b><b> </b><b>'fill'</b><b>,</b><b> fill_value </b><b>=</b><b> float</b><b>(</b><b>'NaN'</b><b>)</b><b>,</b><b> preserve_nan</b><b>=</b><b>True</b><b>)</b>
    643         #result = convolve_fft(inhdu[0].data, kernel)
    644 

~/.local/lib/python3.6/site-packages/astropy/nddata/<b><i>decorators.py</i></b><b><i> in </i></b><b><i>wrapper</i></b>(data, *args, **kwargs)
    244                                   AstropyUserWarning)
    245 
<b>--> 246</b><b>             </b><b>result </b><b>=</b><b> func</b><b>(</b><b>data</b><b>,</b><b> </b><b>*</b><b>args</b><b>,</b><b> </b><b>**</b><b>kwargs</b><b>)</b>
    247 
    248             if unpack and repack:

~/.local/lib/python3.6/site-packages/astropy/convolution/<b><i>convolve.py</i></b><b><i> in </i></b><b><i>convolve</i></b>(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol)
    336     if normalize_kernel:
    337         if not nan_interpolate:
<b>--> 338</b><b>             </b><b>result </b><b>/=</b><b> kernel_sum</b>
    339     else:
    340         if nan_interpolate:

~/.local/lib/python3.6/site-packages/astropy/units/<b><i>quantity.py</i></b><b><i> in </i></b><b><i>__array_ufunc__</i></b>(self, function, method, *inputs, **kwargs)
    473             return result
    474 
<b>--> 475</b><b>         </b><b>return</b><b> self</b><b>.</b><b>_result_as_quantity</b><b>(</b><b>result</b><b>,</b><b> unit</b><b>,</b><b> out</b><b>)</b>
    476 
    477     def _result_as_quantity(self, result, unit, out):

~/.local/lib/python3.6/site-packages/astropy/units/<b><i>quantity.py</i></b><b><i> in </i></b><b><i>_result_as_quantity</i></b>(self, result, unit, out)
    512         # the output is of the correct Quantity subclass, as it was passed
    513         # through check_output.
<b>--> 514</b><b>         </b><b>out</b><b>.</b><b>_set_unit</b><b>(</b><b>unit</b><b>)</b>
    515         return out
    516 

<b>AttributeError</b><b>: 'numpy.ndarray' object has no attribute '_set_unit'<br><br></b><font face="Tahoma">Thank </font><font face="Tahoma">you for all the answere</font><font face="Tahoma">s that I had here.</font></pre>
</span></font></div>
</div>
</body>
</html>