In [1]:
from scipy.optimize import curve_fit
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
time = np.linspace(0, 10, 200)
counts = 50 * np.sin(2 * np.pi * 1. / 2.5 * time) + 100 + np.random.normal(0, 5., len(time))
plt.plot(time, counts, 'k.')
counts_err = 4 * np.random.rand(len(time)) + 1
plt.errorbar(time, counts, yerr=counts_err, fmt="r")
In [3]:
def lc_model(time, amplitude, period, dc):
return amplitude * np.sin(2 * np.pi * 1. / period * time) + dc
In [4]:
popt, pcov = curve_fit(lc_model, time, counts, p0=[50, 2.5, 100], sigma=counts_err)
print(popt)
print(pcov)
In [5]:
perr = np.sqrt(np.diag(pcov))
print("Amplitude =", popt[0], "+/-", perr[0])
print("Period =", popt[1], "+/-", perr[1])
print("DC =", popt[2], "+/-", perr[2])
In [6]:
plt.errorbar(time, counts, yerr=counts_err, fmt="none", label='Data')
plt.plot(time, lc_model(time, popt[0], popt[1], popt[2]),'r-', label='Model')
plt.xlabel('Time (hour)')
plt.ylabel('Counts')
plt.legend()
In [7]:
from astropy.io import fits
hdulist = fits.open("XTE_J1550_564_30191011500A_2_13kev_0.01s_0_2505s.fits")
hdulist.info()
In [8]:
primary = hdulist[0]
primary.header
Out[8]:
In [9]:
print(primary.header['OBJECT '])
In [10]:
rate = hdulist[1]
rate.data
Out[10]:
In [11]:
print(rate.data.shape)
print(rate.data.field(1))
In [12]:
time = rate.data.field(0)[:500]
counts = rate.data.field(1)[:500]
plt.plot(time, counts)
plt.xlabel('Time (s)')
plt.ylabel('Rate (count/s)')
In [13]:
hdulist.close()