For image subtraction the package has a module called propersubtract
, which implements a main diff
function.
In [1]:
from copy import copy
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
%matplotlib inline
In [2]:
from astropy.visualization import LinearStretch, LogStretch
from astropy.visualization import ZScaleInterval, MinMaxInterval
from astropy.visualization import ImageNormalize
In [3]:
palette = copy(plt.cm.gray)
palette.set_bad('r', 1.0)
#palette.set_under('r', 1.0)
#palette.set_over('r', 1.0)
In [4]:
import properimage.single_image as si
import properimage.propersubtract as ps
In [5]:
ref_path = './../../../data/aligned_eso085-030-004.fit'
new_path = './../../../data/aligned_eso085-030-005.fit'
To get the subtraction we need to run this function by using both paths for example:
In [6]:
from astropy.io.fits import getdata
plt.figure(figsize=(16, 12))
plt.subplot(121)
ref = getdata(ref_path)
norm = ImageNormalize(ref, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.imshow(ref, cmap=plt.cm.gray, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
plt.subplot(122)
ref = getdata(new_path)
norm = ImageNormalize(ref, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.imshow(ref, cmap=plt.cm.gray, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[6]:
In [32]:
result = ps.diff(ref=ref_path, new=new_path, smooth_psf=False, fitted_psf=True,
align=False, iterative=False, beta=False, shift=False)
The result is a list of numpy arrays.
The arrays are in order: D, P, Scorr, mask
In [33]:
D = result[0]
P = result[1]
Scorr = result[2]
mask = result[3]
In [34]:
norm = ImageNormalize(D.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(D.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[34]:
In [35]:
norm = ImageNormalize(P, interval=MinMaxInterval(),
stretch=LogStretch())
xc, yc = np.where(P==P.max())
xc, yc = np.round(xc[0]), np.round(yc[0])
plt.imshow(P[xc-10:xc+10, yc-10:yc+10], norm=norm,
cmap='viridis', interpolation='none')
plt.colorbar()
Out[35]:
In [36]:
norm = ImageNormalize(Scorr.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(Scorr.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[36]:
In [37]:
plt.hist(np.ma.MaskedArray(D.real, mask=mask).filled(0).flatten(), log=True, bins=500)
#plt.xlim(-10, 10)
plt.show()
In [38]:
simage = np.ma.MaskedArray(Scorr.real, mask=mask).filled(0).flatten()
plt.hist(simage/np.std(simage), log=True, bins=500)
#plt.xlim(-4, 4)
plt.show()
This is related to the quantities derived in Zackay et al. works. $S_{corr} = P_D \otimes D$
In [39]:
D, P, Scorr, mask = ps.diff(ref=ref_path, new=new_path,
align=False, iterative=False, beta=True)
The result is a list of numpy arrays.
The arrays are in order: D, P, Scorr, mask
In [40]:
norm = ImageNormalize(D.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(D.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[40]:
In [41]:
norm = ImageNormalize(P, interval=MinMaxInterval(),
stretch=LogStretch())
xc, yc = np.where(P==P.max())
xc, yc = np.round(xc[0]), np.round(yc[0])
plt.imshow(P[xc-10:xc+10, yc-10:yc+10], norm=norm,
cmap='viridis', interpolation='none')
plt.colorbar()
Out[41]:
In [42]:
norm = ImageNormalize(Scorr.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(Scorr.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[42]:
In [43]:
plt.hist(np.ma.MaskedArray(D.real, mask=mask).filled(0).flatten(), log=True, bins=500)
#plt.xlim(-10, 10)
plt.show()
In [44]:
simage = np.ma.MaskedArray(Scorr.real, mask=mask).filled(0).flatten()
plt.hist(simage/np.std(simage), log=True, bins=500)
#plt.xlim(-4, 4)
plt.show()
We have the option of using the iterative methods without beta
In [45]:
D, P, Scorr, mask = ps.diff(ref=ref_path, new=new_path, align=False, iterative=True, beta=False)
The result is a list of numpy arrays.
The arrays are in order: D, P, Scorr, mask
In [47]:
norm = ImageNormalize(D.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(D.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[47]:
In [48]:
norm = ImageNormalize(P, interval=MinMaxInterval(),
stretch=LogStretch())
xc, yc = np.where(P==P.max())
xc, yc = np.round(xc[0]), np.round(yc[0])
plt.imshow(P[xc-10:xc+10, yc-10:yc+10], norm=norm,
cmap='viridis', interpolation='none')
plt.colorbar()
Out[48]:
In [49]:
norm = ImageNormalize(Scorr.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(Scorr.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[49]:
In [50]:
plt.hist(np.ma.MaskedArray(D.real, mask=mask).filled(0).flatten(), log=True, bins=500)
#plt.xlim(-10, 10)
plt.show()
In [51]:
simage = np.ma.MaskedArray(Scorr.real, mask=mask).filled(0).flatten()
plt.hist(simage/np.std(simage), log=True, bins=500)
#plt.xlim(-4, 4)
plt.show()
We have the option of using the iterative methods without beta
In [52]:
D, P, Scorr, mask = ps.diff(ref=ref_path, new=new_path, smooth_psf=False, fitted_psf=True,
align=False, iterative=True, beta=True, shift=True)
The result is a list of numpy arrays.
The arrays are in order: D, P, Scorr, mask
In [53]:
norm = ImageNormalize(D.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(22, 22))
plt.imshow(np.ma.MaskedArray(D.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[53]:
In [54]:
norm = ImageNormalize(P, interval=MinMaxInterval(),
stretch=LogStretch())
xc, yc = np.where(P==P.max())
xc, yc = np.round(xc[0]), np.round(yc[0])
plt.imshow(P[xc-10:xc+10, yc-10:yc+10], norm=norm,
cmap='viridis', interpolation='none')
plt.colorbar()
Out[54]:
In [55]:
norm = ImageNormalize(Scorr.real, interval=ZScaleInterval(),
stretch=LinearStretch())
plt.figure(figsize=(12, 12))
plt.imshow(np.ma.MaskedArray(Scorr.real, mask=mask),
cmap=palette, norm=norm, interpolation='none')
plt.colorbar(orientation='horizontal')
Out[55]:
In [56]:
plt.hist(np.ma.MaskedArray(D.real, mask=mask).filled(0).flatten(), log=True, bins=500)
#plt.xlim(-10, 10)
plt.show()
In [57]:
simage = np.ma.MaskedArray(Scorr.real, mask=mask).filled(0).flatten()
plt.hist(simage/np.std(simage), log=True, bins=500)
#plt.xlim(-10, 4)
plt.show()