You are on page 1of 4

2023/9/28 19:28 A7 - Jupyter Notebook

In [1]: import numpy as np


import matplotlib.pyplot as plt
from astropy.io import fits
from astropy.stats import sigma_clipped_stats
from scipy.stats import linregress

(a) Data taken with WiFeS have overscan columns on each side of the detector (i.e. left and
right as viewed in DS9). As discussed in the lecture, overscan pixels are not exposed to light
during an exposure, but contain all the same electronics as the rest of the detector and so
provide a detailed way to track small changes in the bias, dark current, or readout noise. By
inspecting the data in either one of the files, find how many columns of overscan pixels there
are on each side.

Answer: For both data sets, the overscan columns in left side is about 53, and the right side is
about 53 as well.

(b) (1 mark) Find the mean value of these overscan columns in each of the two files. For the
purposes of this assignment use the mean of all the overscan pixels in a given image. In order
to remove potential outliers (e.g. cosmic rays), it’s best to compute the mean using
astropy.stats.sigma clipped stats, which will iteratively remove outliers more then some
standard deviation from the mean at each iteration. While the sigma clipped stats function
returns the mean, median, and standard deviation, you only need the first value here (i.e. the
mean). This can be achieved by calling: clipped mean, clipped med, clipped std = sigma
clipped stats(input array) which will store each of the three outputs into a corresponding
variable. Subtract the derived mean overscan value from the data, and store this overscan-
subtracted data for each file separately as variables d1 and d2. (Hint: you can create an array
of just the columns you want using the numpy.hstack command. For example, if I wanted to
select out only the first and last 10 columns from a given python array, I would write:

columns I want = np.hstack((data array[:,:10], data array[:,-10]))

In [3]: filename = 'OBK-124800-WiFeS-Blue-UT20230911T065035-5.fits'


filename2 = 'OBK-124800-WiFeS-Blue-UT20230911T065214-6.fits'
#open the fits file
open_file = fits.open(filename)
open_file2 = fits.open(filename2)
#load data from extension 0. To make sure we avoid weird
#integer effects, cast the data to floating point.
data1 = open_file[0].data.astype(float)
header = open_file[0].header
open_file.close()
data2 = open_file2[0].data.astype(float)
header2 = open_file2[0].header

localhost:8888/notebooks/Desktop/学习/ASTR2013/assignment/A7.ipynb 1/4
2023/9/28 19:28 A7 - Jupyter Notebook

In [4]: overscan1 = np.hstack((data1[:,:52], data1[:,4150:4200]))


clipped_mean1, clipped_med1, clipped_std1 = sigma_clipped_stats(overscan1)
overmean1 = clipped_mean1
overscan2 = np.hstack((data2[:,:52], data2[:,4150:4200]))
clipped_mean2, clipped_med2, clipped_std2 = sigma_clipped_stats(overscan2)
overmean2 = clipped_mean2
d1 = data1-overmean1
d2 = data2-overmean2
print("The mean overscan value for data1 is : {:.2f}", clipped_mean1)
print("The mean overscan value for data2 is : {:.2f}", clipped_mean2)

The mean overscan value for data1 is : {:.2f} 2062.8420787134655


The mean overscan value for data2 is : {:.2f} 2062.924925164638

(c) Overscan pixels can also be used to derive an estimate of the readout noise. Using the
data stored in d1, estimate the readout noise for WiFeS using the sigma clippped stats routine
to compute the standard deviation (in ADU)

In [5]: clipped_mean, clipped_med, clipped_std = sigma_clipped_stats(overscan1)


print('The readout noise for WiFeS is about {:.1f} ADU'.format(clipped_std))

The readout noise for WiFeS is about 3.5 ADU

(d)

localhost:8888/notebooks/Desktop/学习/ASTR2013/assignment/A7.ipynb 2/4
2023/9/28 19:28 A7 - Jupyter Notebook

In [10]: d1 = open_file[0].data.astype(float)
d2 = open_file2[0].data.astype(float)

q = (d2[321:341,:]-d1[321:341,:])-(d2[320:340,:]-d1[320:340,:])
var_q = np.var(q,axis = 0)

mean1 = np.mean(d1[320:341], axis=0) - np.mean(d1[:,:52])
mean2 = np.mean(d2[320:341], axis=0) - np.mean(d2[:,:52])
plt.scatter(mean1, var_q/4 - (3.5)**2)

#do a linear regression to find the slope
slope, intercept, r_value, p_value, std_err = linregress(mean1, var_q/4 - (2.8)**2)
slope2, intercept2, r_value2, p_value2, std_err2 = linregress(mean2, var_q/4 - (2.8)*
print("Gain in electrons per ADU for data1: {:.2f}".format(1/slope))

plt.axis([-20,2000,0,5000])
plt.xlabel('Pixel Mean')
plt.ylabel('Pixel Variance')

Gain in electrons per ADU for data1: 1.36

Out[10]: Text(0, 0.5, 'Pixel Variance')

localhost:8888/notebooks/Desktop/学习/ASTR2013/assignment/A7.ipynb 3/4
2023/9/28 19:28 A7 - Jupyter Notebook

In [9]: plt.scatter(mean2,var_q/4 - (3.5)**2,color = 'b')


print("Gain in electrons per ADU for data2: {:.2f}".format(1/slope2))

plt.axis([-20,2000,0,5000])
plt.xlabel('Pixel Mean')
plt.ylabel('Pixel Variance')

Gain in electrons per ADU for data2: 1.32

Out[9]: Text(0, 0.5, 'Pixel Variance')

In [ ]: ​

localhost:8888/notebooks/Desktop/学习/ASTR2013/assignment/A7.ipynb 4/4

You might also like