In [68]:
import astropy.io.fits as afits
In [69]:
hdul = afits.open('./a.fits')
In [71]:
data = hdul[0].data
In [72]:
import numpy
In [99]:
data.shape
Out[99]:
(1600, 1800)
In [73]:
pyplot.imshow(numpy.log(1 + data), vmin=7, vmax=8)
pyplot.colorbar()
Out[73]:
<matplotlib.colorbar.Colorbar at 0xb4338c8d0>
In [74]:
from scipy.ndimage import gaussian_filter
In [75]:
def smoothArray_original(array, bad, sigma):
    convolved = gaussian_filter(numpy.where(bad, 0.0, array), sigma, mode="constant", cval=0.0)
    numerator = gaussian_filter(numpy.ones_like(array), sigma, mode="constant", cval=0.0)
    denominator = gaussian_filter(numpy.where(bad, 0.0, 1.0), sigma, mode="constant", cval=0.0)
    return convolved*numerator/denominator
In [84]:
def smoothArray_new(array, bad, sigma):
    convolved = gaussian_filter(numpy.where(bad, 0.0, array), sigma, mode="constant", cval=0.0)
    denominator = gaussian_filter(numpy.where(bad, 0.0, 1.0), sigma, mode="constant", cval=0.0)
    return convolved / denominator # do not multiply numerator
In [98]:
pyplot.imshow(smoothArray_original(data, numpy.isnan(data), 50)) ; pyplot.show()
pyplot.imshow(smoothArray_new(data, numpy.isnan(data), 50))
/Users/michitaro/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:22: RuntimeWarning: divide by zero encountered in true_divide
/Users/michitaro/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:22: RuntimeWarning: invalid value encountered in true_divide
/Users/michitaro/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:4: RuntimeWarning: divide by zero encountered in true_divide
  after removing the cwd from sys.path.
/Users/michitaro/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:4: RuntimeWarning: invalid value encountered in true_divide
  after removing the cwd from sys.path.
Out[98]:
<matplotlib.image.AxesImage at 0xb3f67f1d0>