In this first tutorial the basics of the methods and properties of the SingleImage class are explained.
This object class represents the basic unit of data which we will manipulate. Basically it starts containing pixel data, with its mask. First lets create an instance of this class with a numpy array.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
from properimage import single_image as s
%matplotlib inline
In [2]:
pixel = np.random.random((128,128))*5.
# Add some stars to it
star = [[35, 38, 35],
[38, 90, 39],
[35, 39, 34]]
for i in range(25):
x, y = np.random.randint(120, size=2)
pixel[x:x+3,y:y+3] = star
mask = np.random.randint(2, size=(128,128))
for i in range(10):
mask = mask & np.random.randint(2, size=(128,128))
img = s.SingleImage(pixel, mask)
We can see that the img object created automatically produces an output
displaying the number of sources found.
This just accounts for sources good enough for PSF estimation, which is
the first step for any processing ProperImage is intended for.
If we try to print the instance, (or obtain the representation output) we find that the explicit origin of the pixeldata is being displayed
In [3]:
print(img)
If you would like to acces the data inside the object img just ask for pixeldata.
In [4]:
img.pixeldata
Out[4]:
As can be seen it is a numpy masked array, with bad pixels flagged.
In [5]:
plt.figure(figsize=(6,6))
plt.imshow(img.pixeldata, cmap='Greys')
Out[5]:
We can check the best sources extracted.
In [6]:
img.best_sources[['x', 'y', 'cflux']]
Out[6]:
And also obtain the estimation of PSF.
As the PSF may vary across the field, we use the method described in Lauer T. (2002) for spatially variant PSF.
The methodology returns a series of image-sized coefficients $a_i$ and a series of basis PSF elements $p_i$.
In [7]:
a_fields, psf_basis = img.get_variable_psf()
As in our simple example we don't vary the PSF we obtain only a PSF element, and a None coefficient.
In [8]:
len(psf_basis), psf_basis[0].shape
Out[8]:
In [9]:
a_fields
Out[9]:
We may check the looks of the psf_basis single element.
In [10]:
plt.imshow(psf_basis[0])
Out[10]: