<jupyter_start><jupyter_text>Tutorial - Part 1 - The SingleImage Class==========================================In this first tutorial the basics of the methods and properties of theSingleImage 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.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from properimage import single_image as s

%matplotlib inline
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)<jupyter_output><empty_output><jupyter_text>We can see that the `img` object created automatically produces an outputdisplaying the number of sources found.  This just accounts for sources good enough for PSF estimation, which isthe first step for any processing `ProperImage` is intended for.If we try to print the instance, (or obtain the representation output) we findthat the explicit origin of the data is being displayed<jupyter_code>print(img)<jupyter_output>SingleImage instance for ndarray<jupyter_text>If you would like to acces the data inside the object `img` just ask for `data`.<jupyter_code>img.data<jupyter_output><empty_output><jupyter_text>As can be seen it is a numpy masked array, with bad pixels flagged.<jupyter_code>plt.figure(figsize=(6,6))
plt.imshow(img.data, cmap='Greys')<jupyter_output><empty_output><jupyter_text>We can check the best sources extracted.<jupyter_code>img.best_sources[['x', 'y', 'cflux']]<jupyter_output><empty_output><jupyter_text>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$.<jupyter_code>a_fields, psf_basis = img.get_variable_psf()<jupyter_output>updating stamp shape to (15,15)
(16, 16) (225, 16)<jupyter_text>As in our simple example we don't vary the PSF we obtain only a PSF element, and a `None` coefficient.<jupyter_code>len(psf_basis), psf_basis[0].shape
a_fields<jupyter_output><empty_output><jupyter_text>We may check the looks of the `psf_basis` single element.<jupyter_code>plt.imshow(psf_basis[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1079740557039298, 'fraction_numerical': 0.027088897367417018, 'mean_word_length': 5.9, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '437992', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 899, 'n_tokens_neox': 832, 'n_words': 291, 'path': 'docs/source/tutorial/Tutorial01.ipynb', 'repo_name': 'chaorun/ProperImage', 'size': '2621'}