<jupyter_start><jupyter_text>calculating the mean stack of a set of FITS images.<jupyter_code>from astropy.io import fits
import matplotlib.pyplot as plt
i1=fits.open("image0.fits")
i2=fits.open("image1.fits")
i3=fits.open("image2.fits")
i4=fits.open("image3.fits")
i2.info()
data1=i1[0].data
data2=i2[0].data
data3=i3[0].data
data4=i4[0].data
print(data1.shape)
import numpy as np
def load_fits(filename):
    h=fits.open(filename)
    data=h[0].data
    arg_max=np.argmax(data)
    max_pos=np.unravel_index(arg_max,data.shape)
    return(max_pos)
plt.imshow(data4,cmap=plt.cm.viridis)
plt.xlabel("x pixels (RA)")
plt.ylabel("y pixels (DEC)")
plt.colorbar()
plt.show()
def mean_stack(files):
    file=fits.open(files[0])
    data=file[0].data
    file.close()
    n=len(files)
    if n>1:
        for i in range(1,n):
            file=fits.open(files[i])
            data+=file[0].data
            file.close
    return(data/n)
data=mean_stack(['image0.fits', 'image1.fits', 'image2.fits','image3.fits'])
plt.imshow(data)
plt.xlabel("x pixels (RA)")
plt.ylabel("y pixels (DEC)")
plt.colorbar()
plt.show()<jupyter_output><empty_output><jupyter_text>calculating median stack of a set of FITS images<jupyter_code>import time
start=time.perf_counter()
from statistics import median
def median_stack(files):
    d=[[]]
    data_final=[[]]
    for i in files:
        file=fits.open(i)
        data=file[0].data
        for i1 in range(len(data)):
            for j1 in range(len(data[0])):
                data_final[i1][j1].append(data[i1][j1])
    for i1 in range(len(data)):
        for j1 in range(len(data[0])):
            d[i1][j1]=median(data_final[i1][j1])
    return(d)
end=time.perf_counter()-start
data=mean_stack(['image0.fits', 'image1.fits', 'image2.fits','image3.fits'])
plt.imshow(data)
plt.colorbar()
plt.xlabel("RA")
plt.ylabel("DEC")
plt.show()<jupyter_output><empty_output><jupyter_text>finding time taken for  codes to run<jupyter_code>import time
start=time.perf_counter()
end=time.perf_counter()-start
end
time_stat(np.mean,10*5,1000)
import numpy
def time_stat(f,size,trails):
    s=time.perf_counter()
    for i in range(trails):
        data=np.random.rand(size)
        x=f(data)
    f=time.perf_counter()-s
    return(f)<jupyter_output><empty_output><jupyter_text>finding memory coonsumed by codes to run<jupyter_code>import sys
import numpy as np
a=np.array([])
b=np.array([1,2])
c=np.array([[],[]]) 
sys.getsizeof(b)
b.nbytes
b.size*b.itemsize<jupyter_output><empty_output><jupyter_text>Binapprox methods<jupyter_code>import statistics as stat
import numpy as np
def median_bins(data,b):
    mean=stat.mean(data)
    std_dev=stat.stdev(data)
    minval=mean-std_dev
    maxval=mean+std_dev
    # Initializing bins
    bin_width=(std_dev*2)/b
    bins=np.zeros(b)
    left_bin=0
    # Bin values
    for value in data:
        if value < minval:
            left_bin += 1
        elif value < maxval:
            bin = int((value - minval)/bin_width)
            bins[bin]+= 1
    return(mean,std_dev,left_bin,bins)
def median_approx(data,b):
    mean,std,left_bin,bins=median_bins(data,b)
    N=len(data)
    mid=(N+1)/2
    count=left_bin
    for b,bincount in enumerate(bins):
        count+=bincount
        if count>=mid:
            break
    width=(2*std)/b
    median=mean-std + width*(b+0.5)
    return(median)
median_bins([1, 1, 3, 2, 2, 6], 3)
median_approx([1,5,7,7,7,3,6,1,1],4)
median_approx([0, 1], 5)
median_approx([1,1,3,2,2,6], 3)
fits1=['image0.fits', 'image1.fits', 'image2.fits','image3.fits']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1599439775910364, 'fraction_numerical': 0.02857142857142857, 'mean_word_length': 4.029577464788733, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '474199', 'license': 'MIT', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1409, 'n_words': 241, 'path': 'Astronomy_1.ipynb', 'repo_name': 'Dinesh-Adhithya-H/Data-driven-astronomy', 'size': '3570'}