<jupyter_start><jupyter_text>Imoport necessary modules<jupyter_code>import numpy as np
import sep

import astropy.io
from astropy.io import fits 

%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import rcParams

# Set image dimensions with rcParams
rcParams['figure.figsize'] = [10., 8.]<jupyter_output><empty_output><jupyter_text>Open fits file and extract data<jupyter_code>#fits image declaration and array conversion

hdu_list = fits.open('hlsp_hudf12_hst_wfc3ir_udfmain_f105w_v1.0_drz.fits')
data = hdu_list[0].data
data = data.byteswap().newbyteorder()<jupyter_output><empty_output><jupyter_text>Display image<jupyter_code>#image view
m, s = np.mean(data), np.std(data)
plt.imshow(data, interpolation='nearest', cmap='gray', vmin=m-s, vmax=m+s, origin='lower')
plt.colorbar();

plt.savefig('f105w_fig_1')<jupyter_output><empty_output><jupyter_text>Extract background from image data<jupyter_code>#measure spacially varying background on the image
bkg = sep.Background(data)<jupyter_output><empty_output><jupyter_text>Display global background level and rms<jupyter_code>#'global' mean noise of image background
print(bkg.globalback)
print(bkg.globalrms)
#evaluate background as 2-d array maintaining size of original image
bkg_image = bkg.back()<jupyter_output><empty_output><jupyter_text>Display image of separated background<jupyter_code>#view the background
plt.imshow(bkg_image, interpolation='nearest', cmap='gray', origin='lower')
plt.colorbar();

plt.savefig('f105w_fig_2')
#evaluate background noise as 2-d array maintaining size of original image
bkg_rms = bkg.rms()<jupyter_output><empty_output><jupyter_text>Display image of background rms<jupyter_code>#view the background noise
plt.imshow(bkg_rms, interpolation='nearest', cmap='gray', origin='lower')
plt.colorbar();

plt.savefig('f105w_fig_3')<jupyter_output><empty_output><jupyter_text>Separate background from image data<jupyter_code>#subtraction of background noise
data_sub = data - bkg<jupyter_output><empty_output><jupyter_text>Extract the objects from the image<jupyter_code># Define source of objects, set threshold of object detection, set variance for detection threshold
objects = sep.extract(data_sub, 1.5, err=bkg.globalrms)<jupyter_output><empty_output><jupyter_text>List the number of detected objects from the array<jupyter_code># Display amount of objects detected as the length of the array
len(objects)<jupyter_output><empty_output><jupyter_text>Show the background-subtracted image and create shapes to highlight each detected object<jupyter_code>from matplotlib.patches import Ellipse

#plot background subtracted image
fig, ax = plt.subplots()
m, s = np.mean(data_sub), np.std(data_sub)
im = ax.imshow(data_sub, interpolation='nearest', cmap='gray', vmin=m-s, vmax=m+s, origin='lower')

#plot an ellipse for each object
for i in range(len(objects)):
    e = Ellipse(xy = (objects['x'][i], objects['y'][i]),
               width = 6*objects['a'][i],
               height = 6*objects['b'][i],
               angle = objects['theta'][i] * 180. / np.pi)
    e.set_facecolor('none')
    e.set_edgecolor('red')
    ax.add_artist(e)
    
plt.savefig('f105w_fig_4')<jupyter_output><empty_output><jupyter_text>Display the parameters extracted from the objects array<jupyter_code>#available fields
objects.dtype.names<jupyter_output><empty_output><jupyter_text>Extract the location and flux data from each object<jupyter_code>flux, fluxerr, flag = sep.sum_circle(data_sub, objects['x'], objects['y'], 3.0, err=bkg.globalrms, gain=1.0)<jupyter_output><empty_output><jupyter_text>Create loop to display the flux from the first 10 detected objects<jupyter_code>#shows the first ten object results
for i in range(10):
    print("object {:d}: flux = {:f} +/- {:f}".format(i, flux[i], fluxerr[i]))<jupyter_output><empty_output><jupyter_text>Convert flux data to AB magnitude, and create histogram to plot data<jupyter_code>data = hdu_list[0]
PHOTPLAM = data.header['PHOTPLAM']
PHOTFLAM = data.header['PHOTFLAM']

#convert flux to ABMAG
abmag_zpt = -2.5 * np.log10(PHOTFLAM) - 21.10 - 5 * np.log10(PHOTPLAM) + 18.692
abmag = -2.5 * np.log10(np.fabs(flux)) + abmag_zpt

#create histogram of ABMAG flux conversions
plt.hist(abmag, range=[15,40], bins=300)

plt.savefig('f105w_fig_5')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12158406669754517, 'fraction_numerical': 0.017832329782306623, 'mean_word_length': 7.057835820895522, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '489942', 'license': 'MIT', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1524, 'n_words': 341, 'path': 'Final_project_HDF_f105w_evaluation.ipynb', 'repo_name': 'ChrisAvalos/astr-119-final', 'size': '4318'}